forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.cpp
More file actions
76 lines (59 loc) · 1.58 KB
/
Variable.cpp
File metadata and controls
76 lines (59 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Variable.cpp
//
// Library: CppParser
// Package: SymbolTable
// Module: Variable
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/CppParser/Variable.h"
#include "Poco/String.h"
#include <cstddef>
namespace Poco {
namespace CppParser {
Variable::Variable(const std::string& decl, NameSpace* pNameSpace):
Decl(decl, pNameSpace),
_flags(0),
_isPointer(false),
_type()
{
if (hasAttr(decl, "static"))
_flags |= VAR_STATIC;
if (hasAttr(decl, "mutable"))
_flags |= VAR_MUTABLE;
if (hasAttr(decl, "volatile"))
_flags |= VAR_VOLATILE;
if (hasAttr(decl, "const"))
_flags |= VAR_CONST;
std::size_t pos = decl.rfind(name());
std::string tmp = decl.substr(0, pos);
tmp = Poco::trim(tmp);
pos = tmp.rfind("*");
_isPointer = (pos == (tmp.size()-1));
Poco::replaceInPlace(tmp, "static ", "");
Poco::replaceInPlace(tmp, "mutable ", "");
Poco::replaceInPlace(tmp, "volatile ", "");
Poco::replaceInPlace(tmp, "static\t", "");
Poco::replaceInPlace(tmp, "mutable\t", "");
Poco::replaceInPlace(tmp, "volatile\t", "");
if (tmp.find("const ") == 0)
tmp = tmp.substr(6);
if (tmp.find("const\t") == 0)
tmp = tmp.substr(6);
std::size_t rightCut = tmp.size();
while (rightCut > 0 && (tmp[rightCut-1] == '&' || tmp[rightCut-1] == '*' || tmp[rightCut-1] == '\t' || tmp[rightCut-1] == ' '))
--rightCut;
_type = Poco::trim(tmp.substr(0, rightCut));
}
Variable::~Variable()
{
}
Symbol::Kind Variable::kind() const
{
return Symbol::SYM_VARIABLE;
}
} } // namespace Poco::CppParser