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