forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbol.h
More file actions
268 lines (191 loc) · 5.11 KB
/
Copy pathSymbol.h
File metadata and controls
268 lines (191 loc) · 5.11 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//
// Symbol.h
//
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/Symbol.h#2 $
//
// Library: CppParser
// Package: SymbolTable
// Module: Symbol
//
// Definition of the Symbol class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef CppParser_Symbol_INCLUDED
#define CppParser_Symbol_INCLUDED
#include "Poco/CppParser/CppParser.h"
#include "Poco/CppParser/Attributes.h"
#include "Poco/Foundation.h"
namespace Poco {
namespace CppParser {
class NameSpace;
class CppParser_API Symbol
/// This is the base class for all symbols in the symbol table.
///
/// Every symbol has a unique ID (int) and a namespace (which
/// may be null).
{
public:
enum Kind
{
SYM_ENUM, /// An enumeration
SYM_ENUM_VALUE, /// An enumeration value
SYM_FUNCTION, /// A (member) function
SYM_NAMESPACE, /// A namespace
SYM_PARAMETER, /// A function parameter
SYM_STRUCT, /// A struct or class
SYM_TYPEDEF, /// A typedef
SYM_BUILTIN, /// A built-in type
SYM_VARIABLE /// A (member) variable
};
enum Access
{
ACC_PUBLIC, /// public access
ACC_PROTECTED, /// protected access
ACC_PRIVATE /// private access
};
Symbol();
/// Creates the Symbol and assigns the symbol
/// a unique ID.
Symbol(const std::string& name, NameSpace* pNameSpace = 0);
/// Creates the Symbol and assigns the symbol
/// a unique ID.
virtual ~Symbol();
/// Destroys the Symbol.
int id() const;
/// Returns the symbol's unique ID.
const std::string& name() const;
/// Returns the symbol's (local) name.
NameSpace* nameSpace() const;
/// Returns the symbol's namespace which
/// may be null.
void setAccess(Access v);
/// Sets the symbol's access.
Access getAccess() const;
/// Returns the symbol's access.
void setDocumentation(const std::string& text);
/// Sets the symbol's documentation.
void addDocumentation(const std::string& text);
/// Adds text to the symbol's documentation.
const std::string& getDocumentation() const;
/// Returns the symbol's documentation.
void setFile(const std::string& path);
/// Sets the file where the symbol is declared.
const std::string& getFile() const;
/// Returns the file where the symbol is defined.
void setLineNumber(int line);
/// Sets the line number of the symbol's declaration.
int getLineNumber() const;
/// Returns the line number of the symbol's declaration.
void setPackage(const std::string& package);
/// Sets the symbol's package.
const std::string& getPackage() const;
/// Returns the symbol's package.
void setLibrary(const std::string& library);
/// Sets the symbol's library.
const std::string& getLibrary() const;
/// Returns the symbol's library.
const Attributes& attrs() const;
/// Returns the symbol's attributes.
Attributes& attrs();
/// Returns the symbol's attributes.
const Attributes& getAttributes() const;
/// Returns the symbol's attributes.
void setAttributes(const Attributes& attrs);
/// Sets the symbol's attributes.
std::string fullName() const;
/// Returns the symbol's fully qualified name.
static std::string extractName(const std::string& decl);
/// Extracts the name from the declaration.
virtual Kind kind() const = 0;
/// Returns the symbol's kind.
virtual std::string toString() const = 0;
/// Returns a string representation of the symbol.
bool isPublic() const;
/// Returns true iff the symbol is public.
bool isProtected() const;
/// Returns true iff the symbol is public.
bool isPrivate() const;
/// Returns true iff the symbol is public.
protected:
static bool isIdent(char c);
static bool hasAttr(const std::string& decl, const std::string& attr);
private:
Symbol(const Symbol&);
Symbol& operator = (const Symbol&);
int _id;
std::string _name;
NameSpace* _pNameSpace;
Access _access;
std::string _documentation;
std::string _file;
int _line;
std::string _package;
std::string _library;
Attributes _attrs;
static int _nextId;
};
//
// inlines
//
inline int Symbol::id() const
{
return _id;
}
inline const std::string& Symbol::name() const
{
return _name;
}
inline const std::string& Symbol::getDocumentation() const
{
return _documentation;
}
inline Symbol::Access Symbol::getAccess() const
{
return _access;
}
inline NameSpace* Symbol::nameSpace() const
{
return _pNameSpace;
}
inline const std::string& Symbol::getFile() const
{
return _file;
}
inline int Symbol::getLineNumber() const
{
return _line;
}
inline const std::string& Symbol::getPackage() const
{
return _package;
}
inline const std::string& Symbol::getLibrary() const
{
return _library;
}
inline const Attributes& Symbol::attrs() const
{
return _attrs;
}
inline Attributes& Symbol::attrs()
{
return _attrs;
}
inline bool Symbol::isPublic() const
{
return _access == ACC_PUBLIC;
}
inline bool Symbol::isProtected() const
{
return _access == ACC_PROTECTED;
}
inline bool Symbol::isPrivate() const
{
return _access == ACC_PRIVATE;
}
} } // namespace Poco::CppParser
#endif // CppParser_Symbol_INCLUDED