Debian Codegraph @

plugins/symbolbrowser/symbols/parsers/parser_cpp.cpp

raw symbols SCIP
1 /***************************************************************************
2 A SymbolBrowser plugin for JuffEd editor.
3
4 Copyright: 2010 Aleksander Sokoloff <[email protected]>
5
6 Some of the code based on a ctags project http://ctags.sourceforge.net/
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License.
10 version 2 as published by the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 ***************************************************************************/
21
22 #ifndef PARSER_CPP
23 #define PARSER_CPP
24
25 #include <setjmp.h>
26 #include "../common.h"
27 #include "vstring.h"
28 #include "parserex.h"
29 #include "keyword.h"
30 #include "../symbol.h"
31
32 #define langType Language
33
34 //#define DEBUG
35
36 /*
37 * MACROS
38 */
39
40 #define activeToken(st) ((st)->token [(int) (st)->tokenIndex])
41 #define parentDecl(st) ((st)->parent == NULL ? \
42 DECL_NONE : (st)->parent->declaration)
43 #define isType(token,t) (boolean) ((token)->type == (t))
44 #define insideEnumBody(st) ((st)->parent == NULL ? false : \
45 (boolean) ((st)->parent->declaration == DECL_ENUM))
46 #define isExternCDecl(st,c) (boolean) ((c) == STRING_SYMBOL && \
47 ! (st)->haveQualifyingName && (st)->scope == SCOPE_EXTERN)
48
49 #define isOneOf(c,s) (boolean) (strchr ((s), (c)) != NULL)
50
51 #define isHighChar(c) ((c) != EOF && (unsigned char)(c) >= 0xc0)
52
53 /*
54 * DATA DECLARATIONS
55 */
56
57 enum { NumTokens = 3 };
58
59 typedef enum eException {
60 ExceptionNone, ExceptionEOF, ExceptionFormattingError,
61 ExceptionBraceFormattingError
62 } exception_t;
63
64 /* Used to specify type of keyword.
65 */
66 typedef enum eKeywordId {
67 KEYWORD_NONE = -1,
68 KEYWORD_ATTRIBUTE, KEYWORD_ABSTRACT,
69 KEYWORD_BOOLEAN, KEYWORD_BYTE, KEYWORD_BAD_STATE, KEYWORD_BAD_TRANS,
70 KEYWORD_BIND, KEYWORD_BIND_VAR, KEYWORD_BIT,
71 KEYWORD_CASE, KEYWORD_CATCH, KEYWORD_CHAR, KEYWORD_CLASS, KEYWORD_CONST,
72 KEYWORD_CONSTRAINT, KEYWORD_COVERAGE_BLOCK, KEYWORD_COVERAGE_DEF,
73 KEYWORD_DEFAULT, KEYWORD_DELEGATE, KEYWORD_DELETE, KEYWORD_DO,
74 KEYWORD_DOUBLE,
75 KEYWORD_ELSE, KEYWORD_ENUM, KEYWORD_EXPLICIT, KEYWORD_EXTERN,
76 KEYWORD_EXTENDS, KEYWORD_EVENT,
77 KEYWORD_FINAL, KEYWORD_FLOAT, KEYWORD_FOR, KEYWORD_FOREACH,
78 KEYWORD_FRIEND, KEYWORD_FUNCTION,
79 KEYWORD_GOTO,
80 KEYWORD_IF, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT, KEYWORD_INLINE, KEYWORD_INT,
81 KEYWORD_INOUT, KEYWORD_INPUT, KEYWORD_INTEGER, KEYWORD_INTERFACE,
82 KEYWORD_INTERNAL,
83 KEYWORD_LOCAL, KEYWORD_LONG,
84 KEYWORD_M_BAD_STATE, KEYWORD_M_BAD_TRANS, KEYWORD_M_STATE, KEYWORD_M_TRANS,
85 KEYWORD_MUTABLE,
86 KEYWORD_NAMESPACE, KEYWORD_NEW, KEYWORD_NEWCOV, KEYWORD_NATIVE,
87 KEYWORD_OPERATOR, KEYWORD_OUTPUT, KEYWORD_OVERLOAD, KEYWORD_OVERRIDE,
88 KEYWORD_PACKED, KEYWORD_PORT, KEYWORD_PACKAGE, KEYWORD_PRIVATE,
89 KEYWORD_PROGRAM, KEYWORD_PROTECTED, KEYWORD_PUBLIC,
90 KEYWORD_REGISTER, KEYWORD_RETURN,
91 KEYWORD_SHADOW, KEYWORD_STATE,
92 KEYWORD_SHORT, KEYWORD_SIGNED, KEYWORD_STATIC, KEYWORD_STRING,
93 KEYWORD_STRUCT, KEYWORD_SWITCH, KEYWORD_SYNCHRONIZED,
94 KEYWORD_TASK, KEYWORD_TEMPLATE, KEYWORD_THIS, KEYWORD_THROW,
95 KEYWORD_THROWS, KEYWORD_TRANSIENT, KEYWORD_TRANS, KEYWORD_TRANSITION,
96 KEYWORD_TRY, KEYWORD_TYPEDEF, KEYWORD_TYPENAME,
97 KEYWORD_UINT, KEYWORD_ULONG, KEYWORD_UNION, KEYWORD_UNSIGNED, KEYWORD_USHORT,
98 KEYWORD_USING,
99 KEYWORD_VIRTUAL, KEYWORD_VOID, KEYWORD_VOLATILE,
100 KEYWORD_WCHAR_T, KEYWORD_WHILE
101 } keywordId;
102
103 /* Used to determine whether keyword is valid for the current language and
104 * what its ID is.
105 */
106 typedef struct sKeywordDesc {
107 const char *name;
108 keywordId id;
109 short isValid [5]; /* indicates languages for which kw is valid */
110 } keywordDesc;
111
112 /* Used for reporting the type of object parsed by nextToken ().
113 */
114 typedef enum eTokenType {
115 TOKEN_NONE, /* none */
116 TOKEN_ARGS, /* a parenthetical pair and its contents */
117 TOKEN_BRACE_CLOSE,
118 TOKEN_BRACE_OPEN,
119 TOKEN_COLON, /* the colon character */
120 TOKEN_COMMA, /* the comma character */
121 TOKEN_DOUBLE_COLON, /* double colon indicates nested-name-specifier */
122 TOKEN_KEYWORD,
123 TOKEN_NAME, /* an unknown name */
124 TOKEN_PACKAGE, /* a Java package name */
125 TOKEN_PAREN_NAME, /* a single name in parentheses */
126 TOKEN_SEMICOLON, /* the semicolon character */
127 TOKEN_SPEC, /* a storage class specifier, qualifier, type, etc. */
128 TOKEN_COUNT
129 } tokenType;
130
131 /* This describes the scoping of the current statement.
132 */
133 typedef enum eTagScope {
134 SCOPE_GLOBAL, /* no storage class specified */
135 SCOPE_STATIC, /* static storage class */
136 SCOPE_EXTERN, /* external storage class */
137 SCOPE_FRIEND, /* declares access only */
138 SCOPE_TYPEDEF, /* scoping depends upon context */
139 SCOPE_COUNT
140 } tagScope;
141
142 typedef enum eDeclaration {
143 DECL_NONE,
144 DECL_BASE, /* base type (default) */
145 DECL_CLASS,
146 DECL_ENUM,
147 DECL_EVENT,
148 DECL_FUNCTION,
149 DECL_IGNORE, /* non-taggable "declaration" */
150 DECL_INTERFACE,
151 DECL_NAMESPACE,
152 DECL_NOMANGLE, /* C++ name demangling block */
153 DECL_PACKAGE,
154 DECL_PROGRAM, /* Vera program */
155 DECL_STRUCT,
156 DECL_TASK, /* Vera task */
157 DECL_UNION,
158 DECL_COUNT
159 } declType;
160
161 typedef enum eVisibilityType {
162 ACCESS_UNDEFINED,
163 ACCESS_LOCAL,
164 ACCESS_PRIVATE,
165 ACCESS_PROTECTED,
166 ACCESS_PUBLIC,
167 ACCESS_DEFAULT, /* Java-specific */
168 ACCESS_COUNT
169 } accessType;
170
171 /* Information about the parent class of a member (if any).
172 */
173 typedef struct sMemberInfo {
174 accessType access; /* access of current statement */
175 accessType accessDefault; /* access default for current statement */
176 } memberInfo;
177
178 typedef struct sTokenInfo {
179 tokenType type;
180 keywordId keyword;
181 vString* name; /* the name of the token */
182 unsigned long lineNumber; /* line number of tag */
183 // fpos_t filePosition; /* file position of line containing name */
184 } tokenInfo;
185
186 typedef enum eImplementation {
187 IMP_DEFAULT,
188 IMP_ABSTRACT,
189 IMP_VIRTUAL,
190 IMP_PURE_VIRTUAL,
191 IMP_COUNT
192 } impType;
193
194 /* Describes the statement currently undergoing analysis.
195 */
196 typedef struct sStatementInfo {
197 tagScope scope;
198 declType declaration; /* specifier associated with TOKEN_SPEC */
199 boolean gotName; /* was a name parsed yet? */
200 boolean haveQualifyingName; /* do we have a name we are considering? */
201 boolean gotParenName; /* was a name inside parentheses parsed yet? */
202 boolean gotArgs; /* was a list of parameters parsed yet? */
203 boolean isPointer; /* is 'name' a pointer? */
204 boolean inFunction; /* are we inside of a function? */
205 boolean assignment; /* have we handled an '='? */
206 boolean notVariable; /* has a variable declaration been disqualified ? */
207 impType implementation; /* abstract or concrete implementation? */
208 unsigned int tokenIndex; /* currently active token */
209 tokenInfo* token [(int) NumTokens];
210 tokenInfo* context; /* accumulated scope of current statement */
211 tokenInfo* blockName; /* name of current block */
212 memberInfo member; /* information regarding parent class/struct */
213 vString* parentClasses; /* parent classes */
214 struct sStatementInfo *parent; /* statement we are nested within */
215 } statementInfo;
216
217 /* Describes the type of tag being generated.
218 */
219 typedef enum eTagType {
220 TAG_UNDEFINED,
221 TAG_CLASS, /* class name */
222 TAG_ENUM, /* enumeration name */
223 TAG_ENUMERATOR, /* enumerator (enumeration value) */
224 TAG_EVENT, /* event */
225 TAG_FIELD, /* field (Java) */
226 TAG_FUNCTION, /* function definition */
227 TAG_INTERFACE, /* interface declaration */
228 TAG_LOCAL, /* local variable definition */
229 TAG_MEMBER, /* structure, class or interface member */
230 TAG_METHOD, /* method declaration */
231 TAG_NAMESPACE, /* namespace name */
232 TAG_PACKAGE, /* package name */
233 TAG_PROGRAM, /* program name */
234 TAG_PROPERTY, /* property name */
235 TAG_PROTOTYPE, /* function prototype or declaration */
236 TAG_STRUCT, /* structure name */
237 TAG_TASK, /* task name */
238 TAG_TYPEDEF, /* typedef name */
239 TAG_UNION, /* union name */
240 TAG_VARIABLE, /* variable definition */
241 TAG_EXTERN_VAR, /* external variable declaration */
242 TAG_COUNT /* must be last */
243 } tagType;
244
245 typedef struct sParenInfo {
246 boolean isPointer;
247 boolean isParamList;
248 boolean isKnrParamList;
249 boolean isNameCandidate;
250 boolean invalidContents;
251 boolean nestedArgs;
252 unsigned int parameterCount;
253 } parenInfo;
254
255
256 /*
257 * DATA DEFINITIONS
258 */
259
260 /* Used to index into the CKinds table. */
261 typedef enum {
262 CK_UNDEFINED = -1,
263 CK_CLASS, CK_DEFINE, CK_ENUMERATOR, CK_FUNCTION,
264 CK_ENUMERATION, CK_LOCAL, CK_MEMBER, CK_NAMESPACE, CK_PROTOTYPE,
265 CK_STRUCT, CK_TYPEDEF, CK_UNION, CK_VARIABLE,
266 CK_EXTERN_VARIABLE
267 } cKind;
268
269 static kindOption CKinds [] = {
270 { true, 'c', "class", "classes"},
271 { true, 'd', "macro", "macro definitions"},
272 { true, 'e', "enumerator", "enumerators (values inside an enumeration)"},
273 { true, 'f', "function", "function definitions"},
274 { true, 'g', "enum", "enumeration names"},
275 { false, 'l', "local", "local variables"},
276 { true, 'm', "member", "class, struct, and union members"},
277 { true, 'n', "namespace", "namespaces"},
278 { false, 'p', "prototype", "function prototypes"},
279 { true, 's', "struct", "structure names"},
280 { true, 't', "typedef", "typedefs"},
281 { true, 'u', "union", "union names"},
282 { true, 'v', "variable", "variable definitions"},
283 { false, 'x', "externvar", "external and forward variable declarations"},
284 };
285
286 typedef enum {
287 CSK_UNDEFINED = -1,
288 CSK_CLASS, CSK_DEFINE, CSK_ENUMERATOR, CSK_EVENT, CSK_FIELD,
289 CSK_ENUMERATION, CSK_INTERFACE, CSK_LOCAL, CSK_METHOD,
290 CSK_NAMESPACE, CSK_PROPERTY, CSK_STRUCT, CSK_TYPEDEF
291 } csharpKind;
292
293 static kindOption CsharpKinds [] = {
294 { true, 'c', "class", "classes"},
295 { true, 'd', "macro", "macro definitions"},
296 { true, 'e', "enumerator", "enumerators (values inside an enumeration)"},
297 { true, 'E', "event", "events"},
298 { true, 'f', "field", "fields"},
299 { true, 'g', "enum", "enumeration names"},
300 { true, 'i', "interface", "interfaces"},
301 { false, 'l', "local", "local variables"},
302 { true, 'm', "method", "methods"},
303 { true, 'n', "namespace", "namespaces"},
304 { true, 'p', "property", "properties"},
305 { true, 's', "struct", "structure names"},
306 { true, 't', "typedef", "typedefs"},
307 };
308
309 /* Used to index into the JavaKinds table. */
310 typedef enum {
311 JK_UNDEFINED = -1,
312 JK_CLASS, JK_ENUM_CONSTANT, JK_FIELD, JK_ENUM, JK_INTERFACE,
313 JK_LOCAL, JK_METHOD, JK_PACKAGE, JK_ACCESS, JK_CLASS_PREFIX
314 } javaKind;
315
316 static kindOption JavaKinds [] = {
317 { true, 'c', "class", "classes"},
318 { true, 'e', "enum constant", "enum constants"},
319 { true, 'f', "field", "fields"},
320 { true, 'g', "enum", "enum types"},
321 { true, 'i', "interface", "interfaces"},
322 { false, 'l', "local", "local variables"},
323 { true, 'm', "method", "methods"},
324 { true, 'p', "package", "packages"},
325 };
326
327 /* Used to index into the VeraKinds table. */
328 typedef enum {
329 VK_UNDEFINED = -1,
330 VK_CLASS, VK_DEFINE, VK_ENUMERATOR, VK_FUNCTION,
331 VK_ENUMERATION, VK_LOCAL, VK_MEMBER, VK_PROGRAM, VK_PROTOTYPE,
332 VK_TASK, VK_TYPEDEF, VK_VARIABLE,
333 VK_EXTERN_VARIABLE
334 } veraKind;
335
336 static kindOption VeraKinds [] = {
337 { true, 'c', "class", "classes"},
338 { true, 'd', "macro", "macro definitions"},
339 { true, 'e', "enumerator", "enumerators (values inside an enumeration)"},
340 { true, 'f', "function", "function definitions"},
341 { true, 'g', "enum", "enumeration names"},
342 { false, 'l', "local", "local variables"},
343 { true, 'm', "member", "class, struct, and union members"},
344 { true, 'p', "program", "programs"},
345 { false, 'P', "prototype", "function prototypes"},
346 { true, 't', "task", "tasks"},
347 { true, 'T', "typedef", "typedefs"},
348 { true, 'v', "variable", "variable definitions"},
349 { false, 'x', "externvar", "external variable declarations"}
350 };
351
352 static const keywordDesc KeywordTable [] = {
353 /* C++ */
354 /* ANSI C | C# Java */
355 /* | | | | Vera */
356 /* keyword keyword ID | | | | | */
357 { "__attribute__", KEYWORD_ATTRIBUTE, { 1, 1, 1, 0, 0 } },
358 { "abstract", KEYWORD_ABSTRACT, { 0, 0, 1, 1, 0 } },
359 { "bad_state", KEYWORD_BAD_STATE, { 0, 0, 0, 0, 1 } },
360 { "bad_trans", KEYWORD_BAD_TRANS, { 0, 0, 0, 0, 1 } },
361 { "bind", KEYWORD_BIND, { 0, 0, 0, 0, 1 } },
362 { "bind_var", KEYWORD_BIND_VAR, { 0, 0, 0, 0, 1 } },
363 { "bit", KEYWORD_BIT, { 0, 0, 0, 0, 1 } },
364 { "boolean", KEYWORD_BOOLEAN, { 0, 0, 0, 1, 0 } },
365 { "byte", KEYWORD_BYTE, { 0, 0, 0, 1, 0 } },
366 { "case", KEYWORD_CASE, { 1, 1, 1, 1, 0 } },
367 { "catch", KEYWORD_CATCH, { 0, 1, 1, 0, 0 } },
368 { "char", KEYWORD_CHAR, { 1, 1, 1, 1, 0 } },
369 { "class", KEYWORD_CLASS, { 0, 1, 1, 1, 1 } },
370 { "const", KEYWORD_CONST, { 1, 1, 1, 1, 0 } },
371 { "constraint", KEYWORD_CONSTRAINT, { 0, 0, 0, 0, 1 } },
372 { "coverage_block", KEYWORD_COVERAGE_BLOCK, { 0, 0, 0, 0, 1 } },
373 { "coverage_def", KEYWORD_COVERAGE_DEF, { 0, 0, 0, 0, 1 } },
374 { "do", KEYWORD_DO, { 1, 1, 1, 1, 0 } },
375 { "default", KEYWORD_DEFAULT, { 1, 1, 1, 1, 0 } },
376 { "delegate", KEYWORD_DELEGATE, { 0, 0, 1, 0, 0 } },
377 { "delete", KEYWORD_DELETE, { 0, 1, 0, 0, 0 } },
378 { "double", KEYWORD_DOUBLE, { 1, 1, 1, 1, 0 } },
379 { "else", KEYWORD_ELSE, { 1, 1, 1, 1, 0 } },
380 { "enum", KEYWORD_ENUM, { 1, 1, 1, 1, 1 } },
381 { "event", KEYWORD_EVENT, { 0, 0, 1, 0, 1 } },
382 { "explicit", KEYWORD_EXPLICIT, { 0, 1, 1, 0, 0 } },
383 { "extends", KEYWORD_EXTENDS, { 0, 0, 0, 1, 1 } },
384 { "extern", KEYWORD_EXTERN, { 1, 1, 1, 0, 1 } },
385 { "final", KEYWORD_FINAL, { 0, 0, 0, 1, 0 } },
386 { "float", KEYWORD_FLOAT, { 1, 1, 1, 1, 0 } },
387 { "for", KEYWORD_FOR, { 1, 1, 1, 1, 0 } },
388 { "foreach", KEYWORD_FOREACH, { 0, 0, 1, 0, 0 } },
389 { "friend", KEYWORD_FRIEND, { 0, 1, 0, 0, 0 } },
390 { "function", KEYWORD_FUNCTION, { 0, 0, 0, 0, 1 } },
391 { "goto", KEYWORD_GOTO, { 1, 1, 1, 1, 0 } },
392 { "if", KEYWORD_IF, { 1, 1, 1, 1, 0 } },
393 { "implements", KEYWORD_IMPLEMENTS, { 0, 0, 0, 1, 0 } },
394 { "import", KEYWORD_IMPORT, { 0, 0, 0, 1, 0 } },
395 { "inline", KEYWORD_INLINE, { 0, 1, 0, 0, 0 } },
396 { "inout", KEYWORD_INOUT, { 0, 0, 0, 0, 1 } },
397 { "input", KEYWORD_INPUT, { 0, 0, 0, 0, 1 } },
398 { "int", KEYWORD_INT, { 1, 1, 1, 1, 0 } },
399 { "integer", KEYWORD_INTEGER, { 0, 0, 0, 0, 1 } },
400 { "interface", KEYWORD_INTERFACE, { 0, 0, 1, 1, 1 } },
401 { "internal", KEYWORD_INTERNAL, { 0, 0, 1, 0, 0 } },
402 { "local", KEYWORD_LOCAL, { 0, 0, 0, 0, 1 } },
403 { "long", KEYWORD_LONG, { 1, 1, 1, 1, 0 } },
404 { "m_bad_state", KEYWORD_M_BAD_STATE, { 0, 0, 0, 0, 1 } },
405 { "m_bad_trans", KEYWORD_M_BAD_TRANS, { 0, 0, 0, 0, 1 } },
406 { "m_state", KEYWORD_M_STATE, { 0, 0, 0, 0, 1 } },
407 { "m_trans", KEYWORD_M_TRANS, { 0, 0, 0, 0, 1 } },
408 { "mutable", KEYWORD_MUTABLE, { 0, 1, 0, 0, 0 } },
409 { "namespace", KEYWORD_NAMESPACE, { 0, 1, 1, 0, 0 } },
410 { "native", KEYWORD_NATIVE, { 0, 0, 0, 1, 0 } },
411 { "new", KEYWORD_NEW, { 0, 1, 1, 1, 0 } },
412 { "newcov", KEYWORD_NEWCOV, { 0, 0, 0, 0, 1 } },
413 { "operator", KEYWORD_OPERATOR, { 0, 1, 1, 0, 0 } },
414 { "output", KEYWORD_OUTPUT, { 0, 0, 0, 0, 1 } },
415 { "overload", KEYWORD_OVERLOAD, { 0, 1, 0, 0, 0 } },
416 { "override", KEYWORD_OVERRIDE, { 0, 0, 1, 0, 0 } },
417 { "package", KEYWORD_PACKAGE, { 0, 0, 0, 1, 0 } },
418 { "packed", KEYWORD_PACKED, { 0, 0, 0, 0, 1 } },
419 { "port", KEYWORD_PORT, { 0, 0, 0, 0, 1 } },
420 { "private", KEYWORD_PRIVATE, { 0, 1, 1, 1, 0 } },
421 { "program", KEYWORD_PROGRAM, { 0, 0, 0, 0, 1 } },
422 { "protected", KEYWORD_PROTECTED, { 0, 1, 1, 1, 1 } },
423 { "public", KEYWORD_PUBLIC, { 0, 1, 1, 1, 1 } },
424 { "register", KEYWORD_REGISTER, { 1, 1, 0, 0, 0 } },
425 { "return", KEYWORD_RETURN, { 1, 1, 1, 1, 0 } },
426 { "shadow", KEYWORD_SHADOW, { 0, 0, 0, 0, 1 } },
427 { "short", KEYWORD_SHORT, { 1, 1, 1, 1, 0 } },
428 { "signed", KEYWORD_SIGNED, { 1, 1, 0, 0, 0 } },
429 { "state", KEYWORD_STATE, { 0, 0, 0, 0, 1 } },
430 { "static", KEYWORD_STATIC, { 1, 1, 1, 1, 1 } },
431 { "string", KEYWORD_STRING, { 0, 0, 1, 0, 1 } },
432 { "struct", KEYWORD_STRUCT, { 1, 1, 1, 0, 0 } },
433 { "switch", KEYWORD_SWITCH, { 1, 1, 1, 1, 0 } },
434 { "synchronized", KEYWORD_SYNCHRONIZED, { 0, 0, 0, 1, 0 } },
435 { "task", KEYWORD_TASK, { 0, 0, 0, 0, 1 } },
436 { "template", KEYWORD_TEMPLATE, { 0, 1, 0, 0, 0 } },
437 { "this", KEYWORD_THIS, { 0, 1, 1, 1, 0 } },
438 { "throw", KEYWORD_THROW, { 0, 1, 1, 1, 0 } },
439 { "throws", KEYWORD_THROWS, { 0, 0, 0, 1, 0 } },
440 { "trans", KEYWORD_TRANS, { 0, 0, 0, 0, 1 } },
441 { "transition", KEYWORD_TRANSITION, { 0, 0, 0, 0, 1 } },
442 { "transient", KEYWORD_TRANSIENT, { 0, 0, 0, 1, 0 } },
443 { "try", KEYWORD_TRY, { 0, 1, 1, 0, 0 } },
444 { "typedef", KEYWORD_TYPEDEF, { 1, 1, 1, 0, 1 } },
445 { "typename", KEYWORD_TYPENAME, { 0, 1, 0, 0, 0 } },
446 { "uint", KEYWORD_UINT, { 0, 0, 1, 0, 0 } },
447 { "ulong", KEYWORD_ULONG, { 0, 0, 1, 0, 0 } },
448 { "union", KEYWORD_UNION, { 1, 1, 0, 0, 0 } },
449 { "unsigned", KEYWORD_UNSIGNED, { 1, 1, 1, 0, 0 } },
450 { "ushort", KEYWORD_USHORT, { 0, 0, 1, 0, 0 } },
451 { "using", KEYWORD_USING, { 0, 1, 1, 0, 0 } },
452 { "virtual", KEYWORD_VIRTUAL, { 0, 1, 1, 0, 1 } },
453 { "void", KEYWORD_VOID, { 1, 1, 1, 1, 1 } },
454 { "volatile", KEYWORD_VOLATILE, { 1, 1, 1, 1, 0 } },
455 { "wchar_t", KEYWORD_WCHAR_T, { 1, 1, 1, 0, 0 } },
456 { "while", KEYWORD_WHILE, { 1, 1, 1, 1, 0 } }
457 };
458
459
460
461 class Parser_Cpp: public ParserEx {
462
463 public:
464 Parser_Cpp();
465
466 protected:
467 void parse();
468
469 private:
470 bool isLanguage(langType value) { return value == language(); };
471 //bool isIgnoreToken ( const char *const name, bool *const pIgnoreParens, const char **const replacement);
472 Keywords keywords;
473
474 jmp_buf Exception;
475
476 langType Lang_c;
477 langType Lang_cpp;
478 langType Lang_csharp;
479 langType Lang_java;
480 langType Lang_vera;
481 vString *Signature;
482 boolean CollectingSignature;
483 /* Number used to uniquely identify anonymous structs and unions. */
484 int AnonymousID;
485 statementInfo *CurrentStatement;
486
487 void initToken (tokenInfo* const token);
488 void advanceToken (statementInfo* const st);
489 tokenInfo *prevToken (const statementInfo *const st, unsigned int n);
490 void setToken (statementInfo *const st, const tokenType type);
491 void retardToken (statementInfo *const st);
492 tokenInfo *newToken (void);
493 void deleteToken (tokenInfo *const token);
494 const char *accessString (const accessType access);
495 const char *implementationString (const impType imp);
496 #ifdef DEBUG
497 const char *tokenString (const tokenType type);
498 const char *scopeString (const tagScope scope);
499 const char *declString (const declType declaration);
500 const char *keywordString (const keywordId keyword);
501 void printTockenInfo(tokenInfo *const token);
502 void printStatementInfo(const statementInfo *const st);
503 #endif
504 boolean isContextualKeyword (const tokenInfo *const token);
505 boolean isContextualStatement (const statementInfo *const st);
506 boolean isMember (const statementInfo *const st);
507 void initMemberInfo (statementInfo *const st);
508 void reinitStatement (statementInfo *const st, const boolean partial);
509 void initStatement (statementInfo *const st, statementInfo *const parent);
510 cKind cTagKind (const tagType type);
511 csharpKind csharpTagKind (const tagType type);
512 javaKind javaTagKind (const tagType type);
513 veraKind veraTagKind (const tagType type);
514 const char *tagName (const tagType type);
515 int tagLetter (const tagType type);
516 boolean includeTag (const tagType type, const boolean isFileScope);
517 tagType declToTagType (const declType declaration);
518 const char* accessField (const statementInfo *const st);
519 void addContextSeparator (vString *const scope);
520 // void addOtherFields (tagEntryInfo* const tag, const tagType type,
521 // const statementInfo *const st,
522 // vString *const scope, vString *const typeRef);
523 void findScopeHierarchy (vString *const string,
524 const statementInfo *const st);
525 // void makeExtraTagEntry (const tagType type, tagEntryInfo *const e,
526 // vString *const scope);
527
528 Symbol::SymbolType declToSymbolType (const declType declaration);
529 Symbol *getParent(const statementInfo *const st);
530 void makeTag (const tokenInfo *const token,
531 const statementInfo *const st,
532 boolean isFileScope, const tagType type);
533 boolean isValidTypeSpecifier (const declType declaration);
534 void qualifyEnumeratorTag (const statementInfo *const st, const tokenInfo *const nameToken);
535 void qualifyFunctionTag (const statementInfo *const st, const tokenInfo *const nameToken);
536 void qualifyFunctionDeclTag (const statementInfo *const st, const tokenInfo *const nameToken);
537 void qualifyCompoundTag (const statementInfo *const st, const tokenInfo *const nameToken);
538 void qualifyBlockTag (statementInfo *const st, const tokenInfo *const nameToken);
539 void qualifyVariableTag (const statementInfo *const st,
540 const tokenInfo *const nameToken);
541 int skipToOneOf (const char *const chars);
542 int skipToNonWhite (void);
543 void skipToFormattedBraceMatch (void);
544 void skipToMatch (const char *const pair);
545 void skipParens (void);
546 void skipBraces (void);
547 keywordId analyzeKeyword (const char *const name);
548 void analyzeIdentifier (tokenInfo *const token);
549 void readIdentifier (tokenInfo *const token, const int firstChar);
550 void readPackageName (tokenInfo *const token, const int firstChar);
551 void readPackageOrNamespace (statementInfo *const st, const declType declaration);
552 void processName (statementInfo *const st);
553 void readOperator (statementInfo *const st);
554 void copyToken (tokenInfo *const dest, const tokenInfo *const src);
555 void setAccess (statementInfo *const st, const accessType access);
556 void discardTypeList (tokenInfo *const token);
557 void addParentClass (statementInfo *const st, tokenInfo *const token);
558 void readParents (statementInfo *const st, const int qualifier);
559 void skipStatement (statementInfo *const st);
560 void processInterface (statementInfo *const st);
561 void processToken (tokenInfo *const token, statementInfo *const st);
562 void restartStatement (statementInfo *const st);
563 void skipMemIntializerList (tokenInfo *const token);
564 void skipMacro (statementInfo *const st);
565 boolean skipPostArgumentStuff(statementInfo *const st, parenInfo *const info);
566 void skipJavaThrows (statementInfo *const st);
567 void analyzePostParens (statementInfo *const st, parenInfo *const info);
568 boolean languageSupportsGenerics (void);
569 void processAngleBracket (void);
570 void parseJavaAnnotation (statementInfo *const st);
571 int parseParens (statementInfo *const st, parenInfo *const info);
572 void initParenInfo (parenInfo *const info);
573 void analyzeParens (statementInfo *const st);
574 void addContext (statementInfo *const st, const tokenInfo* const token);
575 boolean inheritingDeclaration (declType decl);
576 void processColon (statementInfo *const st);
577 int skipInitializer (statementInfo *const st);
578 void processInitializer (statementInfo *const st);
579 void parseIdentifier (statementInfo *const st, const int c);
580 void parseGeneralToken (statementInfo *const st, const int c);
581 void nextToken (statementInfo *const st);
582 statementInfo *newStatement (statementInfo *const parent);
583 void deleteStatement (void);
584 void deleteAllStatements (void);
585 boolean isStatementEnd (const statementInfo *const st);
586 void checkStatementEnd (statementInfo *const st);
587 void nest (statementInfo *const st, const unsigned int nestLevel);
588 void tagCheck (statementInfo *const st);
589 void createTags (const unsigned int nestLevel, statementInfo *const parent);
590 void buildKeywordHash (const langType language, unsigned int idx);
591 void initializeCParser (const langType language);
592 void initializeCppParser (const langType language);
593 void initializeCsharpParser (const langType language);
594 void initializeJavaParser (const langType language);
595 void initializeVeraParser (const langType language);
596
597 bool findCTags (const unsigned int passCount);
598 QString tagTypeToStr(const tagType type);
599 };
600
601
602
603 /*****************************************************************************
604 *****************************************************************************/
605 Parser_Cpp::Parser_Cpp(/*Parser_Cpp * parent*/) {
606 AnonymousID = 0;
607 CurrentStatement = NULL;
608 CollectingSignature = false;
609 Lang_c = Lang_cpp = Lang_csharp = Lang_java = Lang_vera = LanguageUnknown;
610 Signature = NULL;
611 }
612
613 /*
614 * Token management
615 */
616
617 void Parser_Cpp::initToken (tokenInfo* const token)
618 {
619 token->type = TOKEN_NONE;
620 token->keyword = KEYWORD_NONE;
621 token->lineNumber = getSourceLineNumber();
622 // token->filePosition = q->getInputFilePosition();
623 vStringClear (token->name);
624 }
625
626 void Parser_Cpp::advanceToken (statementInfo* const st)
627 {
628 if (st->tokenIndex >= (unsigned int) NumTokens - 1)
629 st->tokenIndex = 0;
630 else
631 ++st->tokenIndex;
632 initToken (st->token [st->tokenIndex]);
633 }
634
635 tokenInfo *Parser_Cpp::prevToken (const statementInfo *const st, unsigned int n)
636 {
637 unsigned int tokenIndex;
638 unsigned int num = (unsigned int) NumTokens;
639 Assert (n < num);
640 tokenIndex = (st->tokenIndex + num - n) % num;
641 return st->token [tokenIndex];
642 }
643
644 void Parser_Cpp::setToken (statementInfo *const st, const tokenType type)
645 {
646 tokenInfo *token;
647 token = activeToken (st);
648 initToken (token);
649 token->type = type;
650 }
651
652 void Parser_Cpp::retardToken (statementInfo *const st)
653 {
654 if (st->tokenIndex == 0)
655 st->tokenIndex = (unsigned int) NumTokens - 1;
656 else
657 --st->tokenIndex;
658 setToken (st, TOKEN_NONE);
659 }
660
661 tokenInfo *Parser_Cpp::newToken (void)
662 {
663 tokenInfo *const token = xMalloc (1, tokenInfo);
664 token->name = vStringNew ();
665 initToken (token);
666 return token;
667 }
668
669 void Parser_Cpp::deleteToken (tokenInfo *const token)
670 {
671 if (token != NULL)
672 {
673 vStringDelete (token->name);
674 eFree (token);
675 }
676 }
677
678 const char *Parser_Cpp::accessString (const accessType access)
679 {
680 const char *const names [] = {
681 "?", "local", "private", "protected", "public", "default"
682 };
683 Assert (sizeof (names) / sizeof (names [0]) == ACCESS_COUNT);
684 Assert ((int) access < ACCESS_COUNT);
685 return names [(int) access];
686 }
687
688 const char *Parser_Cpp::implementationString (const impType imp)
689 {
690 static const char *const names [] ={
691 "?", "abstract", "virtual", "pure virtual"
692 };
693 Assert (sizeof (names) / sizeof (names [0]) == IMP_COUNT);
694 Assert ((int) imp < IMP_COUNT);
695 return names [(int) imp];
696 }
697
698 /*
699 * Debugging functions
700 */
701
702 #ifdef DEBUG
703
704 #define boolString(c) ((c) ? "TRUE" : "FALSE")
705
706 const char *Parser_Cpp::tokenString (const tokenType type)
707 {
708 static const char *const names [] = {
709 "none", "args", "}", "{", "colon", "comma", "double colon", "keyword",
710 "name", "package", "paren-name", "semicolon", "specifier"
711 };
712 Assert (sizeof (names) / sizeof (names [0]) == TOKEN_COUNT);
713 Assert ((int) type < TOKEN_COUNT);
714 return names [(int) type];
715 }
716
717 const char *Parser_Cpp::scopeString (const tagScope scope)
718 {
719 static const char *const names [] = {
720 "global", "static", "extern", "friend", "typedef"
721 };
722 Assert (sizeof (names) / sizeof (names [0]) == SCOPE_COUNT);
723 Assert ((int) scope < SCOPE_COUNT);
724 return names [(int) scope];
725 }
726
727 const char *Parser_Cpp::declString (const declType declaration)
728 {
729 static const char *const names [] = {
730 "?", "base", "class", "enum", "event", "function", "ignore",
731 "interface", "namespace", "no mangle", "package", "program",
732 "struct", "task", "union",
733 };
734 Assert (sizeof (names) / sizeof (names [0]) == DECL_COUNT);
735 Assert ((int) declaration < DECL_COUNT);
736 return names [(int) declaration];
737 }
738
739 const char *Parser_Cpp::keywordString (const keywordId keyword)
740 {
741 const size_t count = sizeof (KeywordTable) / sizeof (KeywordTable [0]);
742 const char *name = "none";
743 size_t i;
744 for (i = 0 ; i < count ; ++i)
745 {
746 const keywordDesc *p = &KeywordTable [i];
747 if (p->id == keyword)
748 {
749 name = p->name;
750 break;
751 }
752 }
753 return name;
754 }
755
756 void Parser_Cpp::printTockenInfo(tokenInfo *const token)
757 {
758 if (isType (token, TOKEN_NAME))
759 fprintf(stderr, "type: %-12s: %-13s line: %lu\n",
760 tokenString (token->type), vStringValue (token->name),
761 token->lineNumber);
762
763 else if (isType (token, TOKEN_KEYWORD))
764 fprintf(stderr, "type: %-12s: %-13s line: %lu\n",
765 tokenString (token->type), keywordString (token->keyword),
766 token->lineNumber);
767
768 else
769 fprintf(stderr, "type: %-12s line: %lu\n",
770 tokenString (token->type), token->lineNumber);
771 }
772
773 void Parser_Cpp::printStatementInfo (const statementInfo *const st)
774 {
775 unsigned int i;
776 fprintf(stderr, "scope: %s decl: %s gotName: %s gotParenName: %s\n",
777 scopeString (st->scope), declString (st->declaration),
778 boolString (st->gotName), boolString (st->gotParenName));
779 fprintf(stderr, "haveQualifyingName: %s\n", boolString (st->haveQualifyingName));
780 fprintf(stderr, "access: %s default: %s\n", accessString (st->member.access),
781 accessString (st->member.accessDefault));
782 fprintf (stderr, "token : ");
783 printTockenInfo(activeToken (st));
784 for (i = 1 ; i < (unsigned int) NumTokens ; ++i)
785 {
786 fprintf(stderr, "prev %u : ", i);
787 printTockenInfo(prevToken (st, i));
788 }
789 fprintf(stderr, "context: ");
790 printTockenInfo(st->context);
791 fprintf(stderr, "------------------\n");
792 fprintf(stderr, "parent set=%s\n", boolString (st->parent != NULL));
793 }
794
795 #endif
796
797 /*
798 * Statement management
799 */
800
801 boolean Parser_Cpp::isContextualKeyword (const tokenInfo *const token)
802 {
803 boolean result;
804 switch (token->keyword)
805 {
806 case KEYWORD_CLASS:
807 case KEYWORD_ENUM:
808 case KEYWORD_INTERFACE:
809 case KEYWORD_NAMESPACE:
810 case KEYWORD_STRUCT:
811 case KEYWORD_UNION:
812 result = true;
813 break;
814
815 default: result = false; break;
816 }
817 return result;
818 }
819
820 boolean Parser_Cpp::isContextualStatement (const statementInfo *const st)
821 {
822 boolean result = false;
823 if (st != NULL) switch (st->declaration)
824 {
825 case DECL_CLASS:
826 case DECL_ENUM:
827 case DECL_INTERFACE:
828 case DECL_NAMESPACE:
829 case DECL_STRUCT:
830 case DECL_UNION:
831 result = true;
832 break;
833
834 default: result = false; break;
835 }
836 return result;
837 }
838
839 boolean Parser_Cpp::isMember (const statementInfo *const st)
840 {
841 boolean result;
842 if (isType (st->context, TOKEN_NAME))
843 result = true;
844 else
845 result = (boolean)
846 (st->parent != NULL && isContextualStatement (st->parent));
847 return result;
848 }
849
850 void Parser_Cpp::initMemberInfo (statementInfo *const st)
851 {
852 accessType accessDefault = ACCESS_UNDEFINED;
853
854 if (st->parent != NULL) switch (st->parent->declaration)
855 {
856 case DECL_ENUM:
857 accessDefault = (isLanguage (Lang_java) ? ACCESS_PUBLIC : ACCESS_UNDEFINED);
858 break;
859 case DECL_NAMESPACE:
860 accessDefault = ACCESS_UNDEFINED;
861 break;
862
863 case DECL_CLASS:
864 if (isLanguage (Lang_java))
865 accessDefault = ACCESS_DEFAULT;
866 else
867 accessDefault = ACCESS_PRIVATE;
868 break;
869
870 case DECL_INTERFACE:
871 case DECL_STRUCT:
872 case DECL_UNION:
873 accessDefault = ACCESS_PUBLIC;
874 break;
875
876 default: break;
877 }
878 st->member.accessDefault = accessDefault;
879 st->member.access = accessDefault;
880 }
881
882 void Parser_Cpp::reinitStatement (statementInfo *const st, const boolean partial)
883 {
884 unsigned int i;
885
886 if (! partial)
887 {
888 st->scope = SCOPE_GLOBAL;
889 if (isContextualStatement (st->parent))
890 st->declaration = DECL_BASE;
891 else
892 st->declaration = DECL_NONE;
893 }
894 st->gotParenName = false;
895 st->isPointer = false;
896 st->inFunction = false;
897 st->assignment = false;
898 st->notVariable = false;
899 st->implementation = IMP_DEFAULT;
900 st->gotArgs = false;
901 st->gotName = false;
902 st->haveQualifyingName = false;
903 st->tokenIndex = 0;
904
905 if (st->parent != NULL)
906 st->inFunction = st->parent->inFunction;
907
908 for (i = 0 ; i < (unsigned int) NumTokens ; ++i)
909 initToken (st->token [i]);
910
911 initToken (st->context);
912
913 /* Keep the block name, so that a variable following after a comma will
914 * still have the structure name.
915 */
916 if (! partial)
917 initToken (st->blockName);
918
919 vStringClear (st->parentClasses);
920
921 /* Init member info.
922 */
923 if (! partial)
924 st->member.access = st->member.accessDefault;
925 }
926
927 void Parser_Cpp::initStatement (statementInfo *const st, statementInfo *const parent)
928 {
929 st->parent = parent;
930 initMemberInfo (st);
931 reinitStatement (st, false);
932 }
933
934 /*
935 * Tag generation functions
936 */
937 cKind Parser_Cpp::cTagKind (const tagType type)
938 {
939 cKind result = CK_UNDEFINED;
940 switch (type)
941 {
942 case TAG_CLASS: result = CK_CLASS; break;
943 case TAG_ENUM: result = CK_ENUMERATION; break;
944 case TAG_ENUMERATOR: result = CK_ENUMERATOR; break;
945 case TAG_FUNCTION: result = CK_FUNCTION; break;
946 case TAG_LOCAL: result = CK_LOCAL; break;
947 case TAG_MEMBER: result = CK_MEMBER; break;
948 case TAG_NAMESPACE: result = CK_NAMESPACE; break;
949 case TAG_PROTOTYPE: result = CK_PROTOTYPE; break;
950 case TAG_STRUCT: result = CK_STRUCT; break;
951 case TAG_TYPEDEF: result = CK_TYPEDEF; break;
952 case TAG_UNION: result = CK_UNION; break;
953 case TAG_VARIABLE: result = CK_VARIABLE; break;
954 case TAG_EXTERN_VAR: result = CK_EXTERN_VARIABLE; break;
955
956 default: Assert ("Bad C tag type" == NULL); break;
957 }
958 return result;
959 }
960
961 csharpKind Parser_Cpp::csharpTagKind (const tagType type)
962 {
963 csharpKind result = CSK_UNDEFINED;
964 switch (type)
965 {
966 case TAG_CLASS: result = CSK_CLASS; break;
967 case TAG_ENUM: result = CSK_ENUMERATION; break;
968 case TAG_ENUMERATOR: result = CSK_ENUMERATOR; break;
969 case TAG_EVENT: result = CSK_EVENT; break;
970 case TAG_FIELD: result = CSK_FIELD ; break;
971 case TAG_INTERFACE: result = CSK_INTERFACE; break;
972 case TAG_LOCAL: result = CSK_LOCAL; break;
973 case TAG_METHOD: result = CSK_METHOD; break;
974 case TAG_NAMESPACE: result = CSK_NAMESPACE; break;
975 case TAG_PROPERTY: result = CSK_PROPERTY; break;
976 case TAG_STRUCT: result = CSK_STRUCT; break;
977 case TAG_TYPEDEF: result = CSK_TYPEDEF; break;
978
979 default: Assert ("Bad C# tag type" == NULL); break;
980 }
981 return result;
982 }
983
984 javaKind Parser_Cpp::javaTagKind (const tagType type)
985 {
986 javaKind result = JK_UNDEFINED;
987 switch (type)
988 {
989 case TAG_CLASS: result = JK_CLASS; break;
990 case TAG_ENUM: result = JK_ENUM; break;
991 case TAG_ENUMERATOR: result = JK_ENUM_CONSTANT; break;
992 case TAG_FIELD: result = JK_FIELD; break;
993 case TAG_INTERFACE: result = JK_INTERFACE; break;
994 case TAG_LOCAL: result = JK_LOCAL; break;
995 case TAG_METHOD: result = JK_METHOD; break;
996 case TAG_PACKAGE: result = JK_PACKAGE; break;
997
998 default: Assert ("Bad Java tag type" == NULL); break;
999 }
1000 return result;
1001 }
1002
1003 veraKind Parser_Cpp::veraTagKind (const tagType type) {
1004 veraKind result = VK_UNDEFINED;
1005 switch (type)
1006 {
1007 case TAG_CLASS: result = VK_CLASS; break;
1008 case TAG_ENUM: result = VK_ENUMERATION; break;
1009 case TAG_ENUMERATOR: result = VK_ENUMERATOR; break;
1010 case TAG_FUNCTION: result = VK_FUNCTION; break;
1011 case TAG_LOCAL: result = VK_LOCAL; break;
1012 case TAG_MEMBER: result = VK_MEMBER; break;
1013 case TAG_PROGRAM: result = VK_PROGRAM; break;
1014 case TAG_PROTOTYPE: result = VK_PROTOTYPE; break;
1015 case TAG_TASK: result = VK_TASK; break;
1016 case TAG_TYPEDEF: result = VK_TYPEDEF; break;
1017 case TAG_VARIABLE: result = VK_VARIABLE; break;
1018 case TAG_EXTERN_VAR: result = VK_EXTERN_VARIABLE; break;
1019
1020 default: Assert ("Bad Vera tag type" == NULL); break;
1021 }
1022 return result;
1023 }
1024
1025 const char *Parser_Cpp::tagName (const tagType type)
1026 {
1027 const char* result;
1028 if (isLanguage (Lang_csharp))
1029 result = CsharpKinds [csharpTagKind (type)].name;
1030 else if (isLanguage (Lang_java))
1031 result = JavaKinds [javaTagKind (type)].name;
1032 else if (isLanguage (Lang_vera))
1033 result = VeraKinds [veraTagKind (type)].name;
1034 else
1035 result = CKinds [cTagKind (type)].name;
1036 return result;
1037 }
1038
1039 int Parser_Cpp::tagLetter (const tagType type)
1040 {
1041 int result;
1042 if (isLanguage (Lang_csharp))
1043 result = CsharpKinds [csharpTagKind (type)].letter;
1044 else if (isLanguage (Lang_java))
1045 result = JavaKinds [javaTagKind (type)].letter;
1046 else if (isLanguage (Lang_vera))
1047 result = VeraKinds [veraTagKind (type)].letter;
1048 else
1049 result = CKinds [cTagKind (type)].letter;
1050 return result;
1051 }
1052
1053 boolean Parser_Cpp::includeTag (const tagType type, const boolean isFileScope)
1054 {
1055 boolean result;
1056 if (isFileScope && false /*! Option.include.fileScope*/)
1057 result = false;
1058 else if (isLanguage (Lang_csharp))
1059 result = CsharpKinds [csharpTagKind (type)].enabled;
1060 else if (isLanguage (Lang_java))
1061 result = JavaKinds [javaTagKind (type)].enabled;
1062 else if (isLanguage (Lang_vera))
1063 result = VeraKinds [veraTagKind (type)].enabled;
1064 else
1065 result = CKinds [cTagKind (type)].enabled;
1066 return result;
1067 }
1068
1069 tagType Parser_Cpp::declToTagType (const declType declaration)
1070 {
1071 tagType type = TAG_UNDEFINED;
1072
1073 switch (declaration)
1074 {
1075 case DECL_CLASS: type = TAG_CLASS; break;
1076 case DECL_ENUM: type = TAG_ENUM; break;
1077 case DECL_EVENT: type = TAG_EVENT; break;
1078 case DECL_FUNCTION: type = TAG_FUNCTION; break;
1079 case DECL_INTERFACE: type = TAG_INTERFACE; break;
1080 case DECL_NAMESPACE: type = TAG_NAMESPACE; break;
1081 case DECL_PROGRAM: type = TAG_PROGRAM; break;
1082 case DECL_TASK: type = TAG_TASK; break;
1083 case DECL_STRUCT: type = TAG_STRUCT; break;
1084 case DECL_UNION: type = TAG_UNION; break;
1085
1086 default: Assert ("Unexpected declaration" == NULL); break;
1087 }
1088 return type;
1089 }
1090
1091 const char* Parser_Cpp::accessField (const statementInfo *const st)
1092 {
1093 const char* result = NULL;
1094 if (isLanguage (Lang_cpp) && st->scope == SCOPE_FRIEND)
1095 result = "friend";
1096 else if (st->member.access != ACCESS_UNDEFINED)
1097 result = accessString (st->member.access);
1098 return result;
1099 }
1100
1101 void Parser_Cpp::addContextSeparator (vString *const scope)
1102 {
1103 if (isLanguage (Lang_c) || isLanguage (Lang_cpp))
1104 vStringCatS (scope, "::");
1105 else if (isLanguage (Lang_java) || isLanguage (Lang_csharp))
1106 vStringCatS (scope, ".");
1107 }
1108
1109
1110 //void Parser_Cpp::addOtherFields (tagEntryInfo* const tag, const tagType type,
1111 // const statementInfo *const st,
1112 // vString *const scope, vString *const typeRef)
1113 //{
1114 // /* For selected tag types, append an extension flag designating the
1115 // * parent object in which the tag is defined.
1116 // */
1117 // switch (type)
1118 // {
1119 // default: break;
1120 //
1121 // case TAG_FUNCTION:
1122 // case TAG_METHOD:
1123 // case TAG_PROTOTYPE:
1124 // if (vStringLength (Signature) > 0)
1125 // tag->extensionFields.signature = vStringValue (Signature);
1126 // case TAG_CLASS:
1127 // case TAG_ENUM:
1128 // case TAG_ENUMERATOR:
1129 // case TAG_EVENT:
1130 // case TAG_FIELD:
1131 // case TAG_INTERFACE:
1132 // case TAG_MEMBER:
1133 // case TAG_NAMESPACE:
1134 // case TAG_PROPERTY:
1135 // case TAG_STRUCT:
1136 // case TAG_TASK:
1137 // case TAG_TYPEDEF:
1138 // case TAG_UNION:
1139 // if (vStringLength (scope) > 0 &&
1140 // (isMember (st) || st->parent->declaration == DECL_NAMESPACE))
1141 // {
1142 // if (isType (st->context, TOKEN_NAME))
1143 // tag->extensionFields.scope [0] = tagName (TAG_CLASS);
1144 // else
1145 // tag->extensionFields.scope [0] =
1146 // tagName (declToTagType (parentDecl (st)));
1147 // tag->extensionFields.scope [1] = vStringValue (scope);
1148 // }
1149 // if ((type == TAG_CLASS || type == TAG_INTERFACE ||
1150 // type == TAG_STRUCT) && vStringLength (st->parentClasses) > 0)
1151 // {
1152 //
1153 // tag->extensionFields.inheritance =
1154 // vStringValue (st->parentClasses);
1155 // }
1156 // if (st->implementation != IMP_DEFAULT &&
1157 // (isLanguage (Lang_cpp) || isLanguage (Lang_csharp) ||
1158 // isLanguage (Lang_java)))
1159 // {
1160 // tag->extensionFields.implementation =
1161 // implementationString (st->implementation);
1162 // }
1163 // if (isMember (st))
1164 // {
1165 // tag->extensionFields.access = accessField (st);
1166 // }
1167 // break;
1168 // }
1169 //
1170 // /* Add typename info, type of the tag and name of struct/union/etc. */
1171 // if ((type == TAG_TYPEDEF || type == TAG_VARIABLE || type == TAG_MEMBER)
1172 // && isContextualStatement(st))
1173 // {
1174 // char *p;
1175 //
1176 // tag->extensionFields.typeRef [0] =
1177 // tagName (declToTagType (st->declaration));
1178 // p = vStringValue (st->blockName->name);
1179 //
1180 // /* If there was no {} block get the name from the token before the
1181 // * name (current token is ';' or ',', previous token is the name).
1182 // */
1183 // if (p == NULL || *p == '\0')
1184 // {
1185 // tokenInfo *const prev2 = prevToken (st, 2);
1186 // if (isType (prev2, TOKEN_NAME))
1187 // p = vStringValue (prev2->name);
1188 // }
1189 //
1190 // /* Prepend the scope name if there is one. */
1191 // if (vStringLength (scope) > 0)
1192 // {
1193 // vStringCopy(typeRef, scope);
1194 // addContextSeparator (typeRef);
1195 // vStringCatS(typeRef, p);
1196 // p = vStringValue (typeRef);
1197 // }
1198 // tag->extensionFields.typeRef [1] = p;
1199 // }
1200 //}
1201
1202
1203 void Parser_Cpp::findScopeHierarchy (vString *const string, const statementInfo *const st)
1204 {
1205 vStringClear (string);
1206
1207 if (isType (st->context, TOKEN_NAME)) {
1208 vStringCopy (string, st->context->name);
1209 }
1210
1211 if (st->parent != NULL)
1212 {
1213 vString *temp = vStringNew ();
1214 const statementInfo *s;
1215 for (s = st->parent ; s != NULL ; s = s->parent)
1216 {
1217 if (isContextualStatement (s) ||
1218 s->declaration == DECL_NAMESPACE ||
1219 s->declaration == DECL_PROGRAM)
1220 {
1221 vStringCopy (temp, string);
1222 vStringClear (string);
1223 Assert (isType (s->blockName, TOKEN_NAME));
1224
1225 if (isType (s->context, TOKEN_NAME) &&
1226 vStringLength (s->context->name) > 0)
1227 {
1228
1229 vStringCat (string, s->context->name);
1230 addContextSeparator (string);
1231 }
1232
1233 vStringCat (string, s->blockName->name);
1234
1235 if (vStringLength (temp) > 0)
1236 addContextSeparator (string);
1237
1238 vStringCat (string, temp);
1239 }
1240 }
1241 vStringDelete (temp);
1242 }
1243 }
1244
1245
1246 //void Parser_Cpp::makeExtraTagEntry (const tagType type, tagEntryInfo *const e,
1247 // vString *const scope)
1248 //{
1249 // if (Option.include.qualifiedTags &&
1250 // scope != NULL && vStringLength (scope) > 0)
1251 // {
1252 // vString *const scopedName = vStringNew ();
1253 //
1254 // if (type != TAG_ENUMERATOR)
1255 // vStringCopy (scopedName, scope);
1256 // else
1257 // {
1258 // /* remove last component (i.e. enumeration name) from scope */
1259 // const char* const sc = vStringValue (scope);
1260 // const char* colon = strrchr (sc, ':');
1261 // if (colon != NULL)
1262 // {
1263 // while (*colon == ':' && colon > sc)
1264 // --colon;
1265 // vStringNCopy (scopedName, scope, colon + 1 - sc);
1266 // }
1267 // }
1268 // if (vStringLength (scopedName) > 0)
1269 // {
1270 // addContextSeparator (scopedName);
1271 // vStringCatS (scopedName, e->name);
1272 // e->name = vStringValue (scopedName);
1273 // makeTagEntry (e);
1274 // }
1275 // vStringDelete (scopedName);
1276 // }
1277 //}
1278
1279
1280 #ifdef DEBUG
1281 /*****************************************************************************
1282 *
1283 *****************************************************************************/
1284 QString Parser_Cpp::tagTypeToStr(const tagType type) {
1285 switch (type) {
1286 case TAG_UNDEFINED: return "TAG_UNDEFINED";
1287 case TAG_CLASS: return "TAG_CLASS"; /* class name */
1288 case TAG_ENUM: return "TAG_ENUM"; /* enumeration name */
1289 case TAG_ENUMERATOR: return "TAG_ENUMERATOR"; /* enumerator (enumeration value) */
1290 case TAG_EVENT: return "TAG_EVENT"; /* event */
1291 case TAG_FIELD: return "TAG_FIELD"; /* field (Java) */
1292 case TAG_FUNCTION: return "TAG_FUNCTION"; /* function definition */
1293 case TAG_INTERFACE: return "TAG_INTERFACE"; /* interface declaration */
1294 case TAG_LOCAL: return "TAG_LOCAL"; /* local variable definition */
1295 case TAG_MEMBER: return "TAG_MEMBER"; /* structure, class or interface member */
1296 case TAG_METHOD: return "TAG_METHOD"; /* method declaration */
1297 case TAG_NAMESPACE: return "TAG_NAMESPACE"; /* namespace name */
1298 case TAG_PACKAGE: return "TAG_PACKAGE"; /* package name */
1299 case TAG_PROGRAM: return "TAG_PROGRAM"; /* program name */
1300 case TAG_PROPERTY: return "TAG_PROPERTY"; /* property name */
1301 case TAG_PROTOTYPE: return "TAG_PROTOTYPE"; /* function prototype or declaration */
1302 case TAG_STRUCT: return "TAG_STRUCT"; /* structure name */
1303 case TAG_TASK: return "TAG_TASK"; /* task name */
1304 case TAG_TYPEDEF: return "TAG_TYPEDEF"; /* typedef name */
1305 case TAG_UNION: return "TAG_UNION"; /* union name */
1306 case TAG_VARIABLE: return "TAG_VARIABLE"; /* variable definition */
1307 case TAG_EXTERN_VAR: return "TAG_EXTERN_VAR"; /* external variable declaration */
1308 case TAG_COUNT: return "TAG_COUNT"; /* mus */
1309 default: return "Unknown tagType";
1310 }
1311 }
1312 #endif
1313
1314
1315 /*****************************************************************************
1316 *
1317 *****************************************************************************/
1318 Symbol::SymbolType Parser_Cpp::declToSymbolType (const declType declaration)
1319 {
1320 Symbol::SymbolType type = Symbol::SymbolUnknown;
1321
1322 switch (declaration)
1323 {
1324 case DECL_CLASS: type = Symbol::SymbolClass; break;
1325 case DECL_FUNCTION: type = Symbol::SymbolFunc; break;
1326 case DECL_STRUCT: type = Symbol::SymbolStruct; break;
1327 // case DECL_UNION: type = Symbol::SymbolUnknown; break;
1328 // case DECL_ENUM: type = TAG_ENUM; break;
1329 // case DECL_EVENT: type = TAG_EVENT; break;
1330 // case DECL_INTERFACE: type = TAG_INTERFACE; break;
1331 case DECL_NAMESPACE: type = Symbol::SymbolNamespace; break;
1332 // case DECL_PROGRAM: type = TAG_PROGRAM; break;
1333 // case DECL_TASK: type = TAG_TASK; break;
1334
1335 default: Assert ("Unexpected declaration" == NULL); break;
1336 }
1337 return type;
1338 }
1339
1340
1341 /*****************************************************************************
1342 *
1343 *****************************************************************************/
1344 Symbol *Parser_Cpp::getParent(const statementInfo *const st) {
1345 Symbol *result = mSymbols;
1346
1347 QList<const statementInfo*> list;
1348
1349 const statementInfo *s;
1350 for (s = st->parent ; s != NULL ; s = s->parent) {
1351 if (isContextualStatement (s) ||
1352 s->declaration == DECL_NAMESPACE ||
1353 s->declaration == DECL_PROGRAM)
1354 {
1355 list.prepend(s);
1356 }
1357 }
1358
1359 Symbol *prev = mSymbols;
1360 result = mSymbols;
1361 for(int i=0; i<list.count(); ++i) {
1362 s = list.at(i);
1363 QString name = vStringToQString(s->blockName->name);
1364 Symbol::SymbolType type = declToSymbolType(s == NULL ? DECL_NONE : s->declaration);
1365
1366 result = prev->find(name, type);
1367 if (!result) {
1368 result = new Symbol(type, name, prev);
1369 }
1370
1371 prev = result;
1372 }
1373
1374
1375
1376 if (isType (st->context, TOKEN_NAME)) {
1377 QString name = vStringToQString(st->context->name);
1378 prev = result;
1379 result = prev->find(name);
1380 if (!result)
1381 result = new Symbol(Symbol::SymbolClass, vStringToQString(st->context->name), prev);
1382 }
1383
1384
1385
1386 return result;
1387 }
1388
1389
1390 /*****************************************************************************
1391 *
1392 *****************************************************************************/
1393 void Parser_Cpp::makeTag (const tokenInfo *const token,
1394 const statementInfo *const st,
1395 boolean isFileScope, const tagType type)
1396 {
1397 Q_UNUSED(isFileScope);
1398
1399 if ( type == TAG_METHOD || type == TAG_FUNCTION )
1400
1401 {
1402 QString name = vStringToQString(token->name);
1403 Symbol *symbol = NULL;
1404 Symbol *parent = getParent(st);
1405
1406
1407 symbol = new Symbol(Symbol::SymbolFunc, name, parent);
1408 symbol->setDetailedText(name + ' ' + vStringToQString(Signature));
1409 symbol->setLine(token->lineNumber);
1410
1411 Symbol *proto = parent->find(name, Symbol::SymbolPrototype);
1412
1413 if (proto) {
1414 proto->setParent(NULL);
1415 symbol->setRelatedSymbol(proto);
1416 }
1417
1418 return;
1419 }
1420
1421
1422 Symbol *symbol = NULL;
1423 QString name = vStringToQString(token->name);
1424
1425 switch (type) {
1426
1427 case TAG_MEMBER: /* structure, class or interface member */
1428 break;
1429
1430 case TAG_STRUCT: /* structure name */
1431 symbol = new Symbol(Symbol::SymbolStruct, name);
1432 break;
1433
1434 case TAG_CLASS: /* class name */
1435 symbol = new Symbol(Symbol::SymbolClass, name);
1436 break;
1437
1438 case TAG_METHOD: /* method declaration */
1439 symbol = new Symbol(Symbol::SymbolFunc, name);
1440 symbol->setDetailedText(name + vStringToQString(Signature));
1441 break;
1442
1443 case TAG_FUNCTION: /* function definition */
1444 symbol = new Symbol(Symbol::SymbolFunc, name);
1445 symbol->setDetailedText(name + vStringToQString(Signature));
1446 break;
1447
1448 case TAG_PROTOTYPE: /* function prototype or declaration */
1449 symbol = new Symbol(Symbol::SymbolPrototype, name);
1450 symbol->setDetailedText(name + vStringToQString(Signature));
1451 break;
1452
1453 case TAG_NAMESPACE: /* namespace name */
1454 symbol = new Symbol(Symbol::SymbolNamespace, name);
1455 break;
1456
1457 default:
1458 #ifdef DEBUG
1459 qDebug() << QString("Token '%1' have unknown type '%2'.").arg(vStringToQString(token->name)).arg(tagTypeToStr(type));
1460 #endif
1461 break;
1462 }
1463
1464
1465 if (symbol) {
1466 Symbol *parent = getParent(st);
1467 symbol->setParent(parent);
1468 symbol->setLine(token->lineNumber);
1469
1470
1471 // vString *scope = vStringNew ();
1472 //findScopeHierarchy (scope, st);
1473 //vStringDelete (scope);
1474
1475 }
1476
1477
1478
1479 // TAG_CLASS, /* class name */
1480 // TAG_ENUM, /* enumeration name */
1481 // TAG_ENUMERATOR, /* enumerator (enumeration value) */
1482 // TAG_EVENT, /* event */
1483 // TAG_FIELD, /* field (Java) */
1484 // TAG_FUNCTION, /* function definition */
1485 // TAG_INTERFACE, /* interface declaration */
1486 // TAG_LOCAL, /* local variable definition */
1487 // TAG_MEMBER, /* structure, class or interface member */
1488
1489
1490 // TAG_PACKAGE, /* package name */
1491 // TAG_PROGRAM, /* program name */
1492 // TAG_PROPERTY, /* property name */
1493 // TAG_PROTOTYPE, /* function prototype or declaration */
1494 // TAG_STRUCT, /* structure name */
1495 // TAG_TASK, /* task name */
1496 // TAG_TYPEDEF, /* typedef name */
1497 // TAG_UNION, /* union name */
1498 // TAG_VARIABLE, /* variable definition */
1499 // TAG_EXTERN_VAR, /* external variable declaration */
1500 // TAG_COUNT /* must be last */
1501
1502
1503 #if 0
1504 /* Nothing is really of file scope when it appears in a header file.
1505 */
1506 isFileScope = (boolean) (isFileScope && ! isHeaderFile ());
1507
1508 if (isType (token, TOKEN_NAME) && vStringLength (token->name) > 0 &&
1509 includeTag (type, isFileScope))
1510 {
1511 vString *scope = vStringNew ();
1512 /* Use "typeRef" to store the typename from addOtherFields() until
1513 * it's used in makeTagEntry().
1514 */
1515 vString *typeRef = vStringNew ();
1516 tagEntryInfo e;
1517
1518 initTagEntry (&e, vStringValue (token->name));
1519
1520 e.lineNumber = token->lineNumber;
1521 e.filePosition= token->filePosition;
1522 e.isFileScope = isFileScope;
1523 e.kindName = tagName (type);
1524 e.kind = tagLetter (type);
1525
1526 findScopeHierarchy (scope, st);
1527 addOtherFields (&e, type, st, scope, typeRef);
1528
1529 makeTagEntry (&e);
1530 makeExtraTagEntry (type, &e, scope);
1531 vStringDelete (scope);
1532 vStringDelete (typeRef);
1533 }
1534 #endif
1535 }
1536
1537 boolean Parser_Cpp::isValidTypeSpecifier (const declType declaration)
1538 {
1539 boolean result;
1540 switch (declaration)
1541 {
1542 case DECL_BASE:
1543 case DECL_CLASS:
1544 case DECL_ENUM:
1545 case DECL_EVENT:
1546 case DECL_STRUCT:
1547 case DECL_UNION:
1548 result = true;
1549 break;
1550
1551 default:
1552 result = false;
1553 break;
1554 }
1555 return result;
1556 }
1557
1558 void Parser_Cpp::qualifyEnumeratorTag (const statementInfo *const st,
1559 const tokenInfo *const nameToken)
1560 {
1561 if (isType (nameToken, TOKEN_NAME))
1562 makeTag (nameToken, st, true, TAG_ENUMERATOR);
1563 }
1564
1565 void Parser_Cpp::qualifyFunctionTag (const statementInfo *const st,
1566 const tokenInfo *const nameToken)
1567 {
1568 if (isType (nameToken, TOKEN_NAME))
1569 {
1570 tagType type;
1571 const boolean isFileScope =
1572 (boolean) (st->member.access == ACCESS_PRIVATE ||
1573 (!isMember (st) && st->scope == SCOPE_STATIC));
1574 if (isLanguage (Lang_java) || isLanguage (Lang_csharp))
1575 type = TAG_METHOD;
1576 else if (isLanguage (Lang_vera) && st->declaration == DECL_TASK)
1577 type = TAG_TASK;
1578 else
1579 type = TAG_FUNCTION;
1580 makeTag (nameToken, st, isFileScope, type);
1581 }
1582 }
1583
1584 void Parser_Cpp::qualifyFunctionDeclTag (const statementInfo *const st,
1585 const tokenInfo *const nameToken)
1586 {
1587 if (! isType (nameToken, TOKEN_NAME))
1588 ;
1589 else if (isLanguage (Lang_java) || isLanguage (Lang_csharp))
1590 qualifyFunctionTag (st, nameToken);
1591 else if (st->scope == SCOPE_TYPEDEF)
1592 makeTag (nameToken, st, true, TAG_TYPEDEF);
1593 else if (isValidTypeSpecifier (st->declaration) && ! isLanguage (Lang_csharp))
1594 makeTag (nameToken, st, true, TAG_PROTOTYPE);
1595 }
1596
1597 void Parser_Cpp::qualifyCompoundTag (const statementInfo *const st,
1598 const tokenInfo *const nameToken)
1599 {
1600 if (isType (nameToken, TOKEN_NAME))
1601 {
1602 const tagType type = declToTagType (st->declaration);
1603 const boolean fileScoped = (boolean)
1604 (!(isLanguage (Lang_java) ||
1605 isLanguage (Lang_csharp) ||
1606 isLanguage (Lang_vera)));
1607
1608 if (type != TAG_UNDEFINED)
1609 makeTag (nameToken, st, fileScoped, type);
1610 }
1611 }
1612
1613 void Parser_Cpp::qualifyBlockTag (statementInfo *const st,
1614 const tokenInfo *const nameToken)
1615 {
1616 switch (st->declaration)
1617 {
1618 case DECL_CLASS:
1619 case DECL_ENUM:
1620 case DECL_INTERFACE:
1621 case DECL_NAMESPACE:
1622 case DECL_PROGRAM:
1623 case DECL_STRUCT:
1624 case DECL_UNION:
1625 qualifyCompoundTag (st, nameToken);
1626 break;
1627 default: break;
1628 }
1629 }
1630
1631 void Parser_Cpp::qualifyVariableTag (const statementInfo *const st,
1632 const tokenInfo *const nameToken)
1633 {
1634 /* We have to watch that we do not interpret a declaration of the
1635 * form "struct tag;" as a variable definition. In such a case, the
1636 * token preceding the name will be a keyword.
1637 */
1638 if (! isType (nameToken, TOKEN_NAME))
1639 ;
1640 else if (st->scope == SCOPE_TYPEDEF)
1641 makeTag (nameToken, st, true, TAG_TYPEDEF);
1642 else if (st->declaration == DECL_EVENT)
1643 makeTag (nameToken, st, (boolean) (st->member.access == ACCESS_PRIVATE),
1644 TAG_EVENT);
1645 else if (st->declaration == DECL_PACKAGE)
1646 makeTag (nameToken, st, false, TAG_PACKAGE);
1647 else if (isValidTypeSpecifier (st->declaration))
1648 {
1649 if (st->notVariable)
1650 ;
1651 else if (isMember (st))
1652 {
1653 if (isLanguage (Lang_java) || isLanguage (Lang_csharp))
1654 makeTag (nameToken, st,
1655 (boolean) (st->member.access == ACCESS_PRIVATE), TAG_FIELD);
1656 else if (st->scope == SCOPE_GLOBAL || st->scope == SCOPE_STATIC)
1657 makeTag (nameToken, st, true, TAG_MEMBER);
1658 }
1659 else
1660 {
1661 if (st->scope == SCOPE_EXTERN || ! st->haveQualifyingName)
1662 makeTag (nameToken, st, false, TAG_EXTERN_VAR);
1663 else if (st->inFunction)
1664 makeTag (nameToken, st, (boolean) (st->scope == SCOPE_STATIC),
1665 TAG_LOCAL);
1666 else
1667 makeTag (nameToken, st, (boolean) (st->scope == SCOPE_STATIC),
1668 TAG_VARIABLE);
1669 }
1670 }
1671 }
1672
1673 /*
1674 * Parsing functions
1675 */
1676
1677 int Parser_Cpp::skipToOneOf (const char *const chars)
1678 {
1679
1680 int c;
1681 do
1682 c = cppGetc ();
1683 while (c != EOF && c != '\0' && strchr (chars, c) == NULL);
1684 return c;
1685 }
1686
1687 /* Skip to the next non-white character.
1688 */
1689 int Parser_Cpp::skipToNonWhite (void)
1690 {
1691 boolean found = false;
1692 int c;
1693
1694 //#if 0
1695 // do
1696 // c =cppGetc ();
1697 // while (isspace (c));
1698 //#else
1699 while (1)
1700 {
1701 c = cppGetc ();
1702 if (isspace (c))
1703 found = true;
1704 else
1705 break;
1706 }
1707 if (CollectingSignature && found)
1708 vStringPut (Signature, ' ');
1709 //#endif
1710
1711 return c;
1712 }
1713
1714 /* Skips to the next brace in column 1. This is intended for cases where
1715 * preprocessor constructs result in unbalanced braces.
1716 */
1717 void Parser_Cpp::skipToFormattedBraceMatch (void)
1718 {
1719 int c, next;
1720
1721 c = cppGetc ();
1722 next = cppGetc ();
1723 while (c != EOF && (c != '\n' || next != '}'))
1724 {
1725 c = next;
1726 next = cppGetc ();
1727 }
1728 }
1729
1730 /* Skip to the matching character indicated by the pair string. If skipping
1731 * to a matching brace and any brace is found within a different level of a
1732 * #if conditional statement while brace formatting is in effect, we skip to
1733 * the brace matched by its formatting. It is assumed that we have already
1734 * read the character which starts the group (i.e. the first character of
1735 * "pair").
1736 */
1737 void Parser_Cpp::skipToMatch (const char *const pair)
1738 {
1739 const boolean braceMatching = (boolean) (strcmp ("{}", pair) == 0);
1740 const boolean braceFormatting = (boolean) (isBraceFormat () && braceMatching);
1741 const unsigned int initialLevel = getDirectiveNestLevel ();
1742 const int begin = pair [0], end = pair [1];
1743 //const unsigned long inputLineNumber = getInputLineNumber ();
1744 int matchLevel = 1;
1745 int c = '\0';
1746
1747 while (matchLevel > 0 && (c = skipToNonWhite ()) != EOF)
1748 {
1749 if (CollectingSignature)
1750 vStringPut (Signature, c);
1751 if (c == begin)
1752 {
1753 ++matchLevel;
1754 if (braceFormatting && getDirectiveNestLevel () != initialLevel)
1755 {
1756 skipToFormattedBraceMatch ();
1757 break;
1758 }
1759 }
1760 else if (c == end)
1761 {
1762 --matchLevel;
1763 if (braceFormatting && getDirectiveNestLevel () != initialLevel)
1764 {
1765 skipToFormattedBraceMatch ();
1766 break;
1767 }
1768 }
1769 }
1770 if (c == EOF)
1771 {
1772 verbose ("%s: failed to find match for '%c' at line %lu\n",
1773 getInputFileName (), begin, inputLineNumber);
1774 if (braceMatching)
1775 longjmp (Exception, (int) ExceptionBraceFormattingError);
1776 else
1777 longjmp (Exception, (int) ExceptionFormattingError);
1778 }
1779 }
1780
1781 void Parser_Cpp::skipParens (void)
1782 {
1783 const int c = skipToNonWhite ();
1784
1785 if (c == '(')
1786 skipToMatch ("()");
1787 else
1788 cppUngetc (c);
1789 }
1790
1791 void Parser_Cpp::skipBraces (void)
1792 {
1793 const int c = skipToNonWhite ();
1794
1795 if (c == '{')
1796 skipToMatch ("{}");
1797 else
1798 cppUngetc (c);
1799 }
1800
1801 keywordId Parser_Cpp::analyzeKeyword (const char *const name)
1802 {
1803 const keywordId id = (keywordId) keywords.lookupKeyword(name, language());//getSourceLanguage ());
1804 return id;
1805 }
1806
1807 void Parser_Cpp::analyzeIdentifier (tokenInfo *const token)
1808 {
1809 //char *const name = vStringValue (token->name);
1810 const char *replacement = NULL;
1811 boolean parensToo = false;
1812
1813 if (isLanguage (Lang_java) || true /* ! isIgnoreToken (name, &parensToo, &replacement)*/)
1814 {
1815 if (replacement != NULL)
1816 token->keyword = analyzeKeyword (replacement);
1817 else
1818 token->keyword = analyzeKeyword (vStringValue (token->name));
1819
1820 if (token->keyword == KEYWORD_NONE)
1821 token->type = TOKEN_NAME;
1822 else
1823 token->type = TOKEN_KEYWORD;
1824
1825 }
1826 else
1827 {
1828 initToken (token);
1829 if (parensToo)
1830 {
1831 int c = skipToNonWhite ();
1832
1833 if (c == '(')
1834 skipToMatch ("()");
1835 }
1836 }
1837 }
1838
1839 void Parser_Cpp::readIdentifier (tokenInfo *const token, const int firstChar)
1840 {
1841 vString *const name = token->name;
1842 int c = firstChar;
1843 boolean first = true;
1844
1845 initToken (token);
1846
1847 /* Bug #1585745: strangely, C++ destructors allow whitespace between
1848 * the ~ and the class name. */
1849 if (isLanguage (Lang_cpp) && firstChar == '~')
1850 {
1851 vStringPut (name, c);
1852 c = skipToNonWhite ();
1853 }
1854
1855 do
1856 {
1857 vStringPut (name, c);
1858 if (CollectingSignature)
1859 {
1860 if (!first)
1861 vStringPut (Signature, c);
1862 first = false;
1863 }
1864 c = cppGetc ();
1865 } while (isident (c) || ((isLanguage (Lang_java) || isLanguage (Lang_csharp)) && (isHighChar (c) || c == '.')));
1866 vStringTerminate (name);
1867 cppUngetc (c); /* unget non-identifier character */
1868
1869 analyzeIdentifier (token);
1870 }
1871
1872 void Parser_Cpp::readPackageName (tokenInfo *const token, const int firstChar)
1873 {
1874 vString *const name = token->name;
1875 int c = firstChar;
1876
1877 initToken (token);
1878
1879 while (isident (c) || c == '.')
1880 {
1881 vStringPut (name, c);
1882 c = cppGetc ();
1883 }
1884 vStringTerminate (name);
1885 cppUngetc (c); /* unget non-package character */
1886 }
1887
1888 void Parser_Cpp::readPackageOrNamespace (statementInfo *const st, const declType declaration)
1889 {
1890 st->declaration = declaration;
1891
1892 if (declaration == DECL_NAMESPACE && !isLanguage (Lang_csharp))
1893 {
1894 /* In C++ a namespace is specified one level at a time. */
1895 return;
1896 }
1897 else
1898 {
1899 /* In C#, a namespace can also be specified like a Java package name. */
1900 tokenInfo *const token = activeToken (st);
1901 Assert (isType (token, TOKEN_KEYWORD));
1902 readPackageName (token, skipToNonWhite ());
1903 token->type = TOKEN_NAME;
1904 st->gotName = true;
1905 st->haveQualifyingName = true;
1906 }
1907 }
1908
1909 void Parser_Cpp::processName (statementInfo *const st)
1910 {
1911 Assert (isType (activeToken (st), TOKEN_NAME));
1912 if (st->gotName && st->declaration == DECL_NONE)
1913 st->declaration = DECL_BASE;
1914 st->gotName = true;
1915 st->haveQualifyingName = true;
1916 }
1917
1918 void Parser_Cpp::readOperator (statementInfo *const st)
1919 {
1920 const char *const acceptable = "+-*/%^&|~!=<>,[]";
1921 const tokenInfo* const prev = prevToken (st,1);
1922 tokenInfo *const token = activeToken (st);
1923 vString *const name = token->name;
1924 int c = skipToNonWhite ();
1925
1926 /* When we arrive here, we have the keyword "operator" in 'name'.
1927 */
1928 if (isType (prev, TOKEN_KEYWORD) && (prev->keyword == KEYWORD_ENUM ||
1929 prev->keyword == KEYWORD_STRUCT || prev->keyword == KEYWORD_UNION))
1930 ; /* ignore "operator" keyword if preceded by these keywords */
1931 else if (c == '(')
1932 {
1933 /* Verify whether this is a valid function call (i.e. "()") operator.
1934 */
1935 if (cppGetc () == ')')
1936 {
1937 vStringPut (name, ' '); /* always separate operator from keyword */
1938 c = skipToNonWhite ();
1939 if (c == '(')
1940 vStringCatS (name, "()");
1941 }
1942 else
1943 {
1944 skipToMatch ("()");
1945 c = cppGetc ();
1946 }
1947 }
1948 else if (isident1 (c))
1949 {
1950 /* Handle "new" and "delete" operators, and conversion functions
1951 * (per 13.3.1.1.2 [2] of the C++ spec).
1952 */
1953 boolean whiteSpace = true; /* default causes insertion of space */
1954 do
1955 {
1956 if (isspace (c))
1957 whiteSpace = true;
1958 else
1959 {
1960 if (whiteSpace)
1961 {
1962 vStringPut (name, ' ');
1963 whiteSpace = false;
1964 }
1965 vStringPut (name, c);
1966 }
1967 c = cppGetc ();
1968 } while (! isOneOf (c, "(;") && c != EOF);
1969 vStringTerminate (name);
1970 }
1971 else if (isOneOf (c, acceptable))
1972 {
1973 vStringPut (name, ' '); /* always separate operator from keyword */
1974 do
1975 {
1976 vStringPut (name, c);
1977 c = cppGetc ();
1978 } while (isOneOf (c, acceptable));
1979 vStringTerminate (name);
1980 }
1981
1982 cppUngetc (c);
1983
1984 token->type = TOKEN_NAME;
1985 token->keyword = KEYWORD_NONE;
1986 processName (st);
1987 }
1988
1989 void Parser_Cpp::copyToken (tokenInfo *const dest, const tokenInfo *const src)
1990 {
1991 dest->type = src->type;
1992 dest->keyword = src->keyword;
1993 // dest->filePosition = src->filePosition;
1994 dest->lineNumber = src->lineNumber;
1995 vStringCopy (dest->name, src->name);
1996 }
1997
1998 void Parser_Cpp::setAccess (statementInfo *const st, const accessType access)
1999 {
2000 if (isMember (st))
2001 {
2002 if (isLanguage (Lang_cpp))
2003 {
2004 int c = skipToNonWhite ();
2005
2006 if (c == ':')
2007 reinitStatement (st, false);
2008 else
2009 cppUngetc (c);
2010
2011 st->member.accessDefault = access;
2012 }
2013 st->member.access = access;
2014 }
2015 }
2016
2017 void Parser_Cpp::discardTypeList (tokenInfo *const token)
2018 {
2019 int c = skipToNonWhite ();
2020 while (isident1 (c))
2021 {
2022 readIdentifier (token, c);
2023 c = skipToNonWhite ();
2024 if (c == '.' || c == ',')
2025 c = skipToNonWhite ();
2026 }
2027 cppUngetc (c);
2028 }
2029
2030 void Parser_Cpp::addParentClass (statementInfo *const st, tokenInfo *const token)
2031 {
2032 if (vStringLength (token->name) > 0 &&
2033 vStringLength (st->parentClasses) > 0)
2034 {
2035 vStringPut (st->parentClasses, ',');
2036 }
2037 vStringCat (st->parentClasses, token->name);
2038 }
2039
2040 void Parser_Cpp::readParents (statementInfo *const st, const int qualifier)
2041 {
2042 tokenInfo *const token = newToken ();
2043 tokenInfo *const parent = newToken ();
2044 int c;
2045
2046 do
2047 {
2048 c = skipToNonWhite ();
2049 if (isident1 (c))
2050 {
2051 readIdentifier (token, c);
2052 if (isType (token, TOKEN_NAME))
2053 vStringCat (parent->name, token->name);
2054 else
2055 {
2056 addParentClass (st, parent);
2057 initToken (parent);
2058 }
2059 }
2060 else if (c == qualifier)
2061 vStringPut (parent->name, c);
2062 else if (c == '<')
2063 skipToMatch ("<>");
2064 else if (isType (token, TOKEN_NAME))
2065 {
2066 addParentClass (st, parent);
2067 initToken (parent);
2068 }
2069 } while (c != '{' && c != EOF);
2070 cppUngetc (c);
2071 deleteToken (parent);
2072 deleteToken (token);
2073 }
2074
2075 void Parser_Cpp::skipStatement (statementInfo *const st)
2076 {
2077 st->declaration = DECL_IGNORE;
2078 skipToOneOf (";");
2079 }
2080
2081 void Parser_Cpp::processInterface (statementInfo *const st)
2082 {
2083 st->declaration = DECL_INTERFACE;
2084 }
2085
2086 void Parser_Cpp::processToken (tokenInfo *const token, statementInfo *const st)
2087 {
2088 switch (token->keyword) /* is it a reserved word? */
2089 {
2090 default: break;
2091
2092 case KEYWORD_NONE: processName (st); break;
2093 case KEYWORD_ABSTRACT: st->implementation = IMP_ABSTRACT; break;
2094 case KEYWORD_ATTRIBUTE: skipParens (); initToken (token); break;
2095 case KEYWORD_BIND: st->declaration = DECL_BASE; break;
2096 case KEYWORD_BIT: st->declaration = DECL_BASE; break;
2097 case KEYWORD_CATCH: skipParens (); skipBraces (); break;
2098 case KEYWORD_CHAR: st->declaration = DECL_BASE; break;
2099 case KEYWORD_CLASS: st->declaration = DECL_CLASS; break;
2100 case KEYWORD_CONST: st->declaration = DECL_BASE; break;
2101 case KEYWORD_DOUBLE: st->declaration = DECL_BASE; break;
2102 case KEYWORD_ENUM: st->declaration = DECL_ENUM; break;
2103 case KEYWORD_EXTENDS: readParents (st, '.');
2104 setToken (st, TOKEN_NONE); break;
2105 case KEYWORD_FLOAT: st->declaration = DECL_BASE; break;
2106 case KEYWORD_FUNCTION: st->declaration = DECL_BASE; break;
2107 case KEYWORD_FRIEND: st->scope = SCOPE_FRIEND; break;
2108 case KEYWORD_GOTO: skipStatement (st); break;
2109 case KEYWORD_IMPLEMENTS:readParents (st, '.');
2110 setToken (st, TOKEN_NONE); break;
2111 case KEYWORD_IMPORT: skipStatement (st); break;
2112 case KEYWORD_INT: st->declaration = DECL_BASE; break;
2113 case KEYWORD_INTEGER: st->declaration = DECL_BASE; break;
2114 case KEYWORD_INTERFACE: processInterface (st); break;
2115 case KEYWORD_LOCAL: setAccess (st, ACCESS_LOCAL); break;
2116 case KEYWORD_LONG: st->declaration = DECL_BASE; break;
2117 case KEYWORD_OPERATOR: readOperator (st); break;
2118 case KEYWORD_PRIVATE: setAccess (st, ACCESS_PRIVATE); break;
2119 case KEYWORD_PROGRAM: st->declaration = DECL_PROGRAM; break;
2120 case KEYWORD_PROTECTED: setAccess (st, ACCESS_PROTECTED); break;
2121 case KEYWORD_PUBLIC: setAccess (st, ACCESS_PUBLIC); break;
2122 case KEYWORD_RETURN: skipStatement (st); break;
2123 case KEYWORD_SHORT: st->declaration = DECL_BASE; break;
2124 case KEYWORD_SIGNED: st->declaration = DECL_BASE; break;
2125 case KEYWORD_STRING: st->declaration = DECL_BASE; break;
2126 case KEYWORD_STRUCT: st->declaration = DECL_STRUCT; break;
2127 case KEYWORD_TASK: st->declaration = DECL_TASK; break;
2128 case KEYWORD_THROWS: discardTypeList (token); break;
2129 case KEYWORD_UNION: st->declaration = DECL_UNION; break;
2130 case KEYWORD_UNSIGNED: st->declaration = DECL_BASE; break;
2131 case KEYWORD_USING: skipStatement (st); break;
2132 case KEYWORD_VOID: st->declaration = DECL_BASE; break;
2133 case KEYWORD_VOLATILE: st->declaration = DECL_BASE; break;
2134 case KEYWORD_VIRTUAL: st->implementation = IMP_VIRTUAL; break;
2135 case KEYWORD_WCHAR_T: st->declaration = DECL_BASE; break;
2136
2137 case KEYWORD_NAMESPACE: readPackageOrNamespace (st, DECL_NAMESPACE); break;
2138 case KEYWORD_PACKAGE: readPackageOrNamespace (st, DECL_PACKAGE); break;
2139
2140 case KEYWORD_EVENT:
2141 if (isLanguage (Lang_csharp))
2142 st->declaration = DECL_EVENT;
2143 break;
2144
2145 case KEYWORD_TYPEDEF:
2146 reinitStatement (st, false);
2147 st->scope = SCOPE_TYPEDEF;
2148 break;
2149
2150 case KEYWORD_EXTERN:
2151 if (! isLanguage (Lang_csharp) || !st->gotName)
2152 {
2153 reinitStatement (st, false);
2154 st->scope = SCOPE_EXTERN;
2155 st->declaration = DECL_BASE;
2156 }
2157 break;
2158
2159 case KEYWORD_STATIC:
2160 if (! (isLanguage (Lang_java) || isLanguage (Lang_csharp)))
2161 {
2162 reinitStatement (st, false);
2163 st->scope = SCOPE_STATIC;
2164 st->declaration = DECL_BASE;
2165 }
2166 break;
2167
2168 case KEYWORD_FOR:
2169 case KEYWORD_FOREACH:
2170 case KEYWORD_IF:
2171 case KEYWORD_SWITCH:
2172 case KEYWORD_WHILE:
2173 {
2174 int c = skipToNonWhite ();
2175 if (c == '(')
2176 skipToMatch ("()");
2177 break;
2178 }
2179 }
2180 }
2181
2182 /*
2183 * Parenthesis handling functions
2184 */
2185
2186 void Parser_Cpp::restartStatement (statementInfo *const st)
2187 {
2188 tokenInfo *const save = newToken ();
2189 tokenInfo *token = activeToken (st);
2190
2191 copyToken (save, token);
2192 DebugStatement ( if (debug (DEBUG_PARSE)) printf ("<ES>");)
2193 reinitStatement (st, false);
2194 token = activeToken (st);
2195 copyToken (token, save);
2196 deleteToken (save);
2197 processToken (token, st);
2198 }
2199
2200 /* Skips over a the mem-initializer-list of a ctor-initializer, defined as:
2201 *
2202 * mem-initializer-list:
2203 * mem-initializer, mem-initializer-list
2204 *
2205 * mem-initializer:
2206 * [::] [nested-name-spec] class-name (...)
2207 * identifier
2208 */
2209 void Parser_Cpp::skipMemIntializerList (tokenInfo *const token)
2210 {
2211 int c;
2212
2213 do
2214 {
2215 c = skipToNonWhite ();
2216 while (isident1 (c) || c == ':')
2217 {
2218 if (c != ':')
2219 readIdentifier (token, c);
2220 c = skipToNonWhite ();
2221 }
2222 if (c == '<')
2223 {
2224 skipToMatch ("<>");
2225 c = skipToNonWhite ();
2226 }
2227 if (c == '(')
2228 {
2229 skipToMatch ("()");
2230 c = skipToNonWhite ();
2231 }
2232 } while (c == ',');
2233 cppUngetc (c);
2234 }
2235
2236 void Parser_Cpp::skipMacro (statementInfo *const st)
2237 {
2238 tokenInfo *const prev2 = prevToken (st, 2);
2239
2240 if (isType (prev2, TOKEN_NAME))
2241 retardToken (st);
2242 skipToMatch ("()");
2243 }
2244
2245 /* Skips over characters following the parameter list. This will be either
2246 * non-ANSI style function declarations or C++ stuff. Our choices:
2247 *
2248 * C (K&R):
2249 * int func ();
2250 * int func (one, two) int one; float two; {...}
2251 * C (ANSI):
2252 * int func (int one, float two);
2253 * int func (int one, float two) {...}
2254 * C++:
2255 * int foo (...) [const|volatile] [throw (...)];
2256 * int foo (...) [const|volatile] [throw (...)] [ctor-initializer] {...}
2257 * int foo (...) [const|volatile] [throw (...)] try [ctor-initializer] {...}
2258 * catch (...) {...}
2259 */
2260 boolean Parser_Cpp::skipPostArgumentStuff (
2261 statementInfo *const st, parenInfo *const info)
2262 {
2263 tokenInfo *const token = activeToken (st);
2264 unsigned int parameters = info->parameterCount;
2265 unsigned int elementCount = 0;
2266 boolean restart = false;
2267 boolean end = false;
2268 int c = skipToNonWhite ();
2269
2270 do
2271 {
2272 switch (c)
2273 {
2274 case ')': break;
2275 case ':': skipMemIntializerList (token);break; /* ctor-initializer */
2276 case '[': skipToMatch ("[]"); break;
2277 case '=': cppUngetc (c); end = true; break;
2278 case '{': cppUngetc (c); end = true; break;
2279 case '}': cppUngetc (c); end = true; break;
2280
2281 case '(':
2282 if (elementCount > 0)
2283 ++elementCount;
2284 skipToMatch ("()");
2285 break;
2286
2287 case ';':
2288 if (parameters == 0 || elementCount < 2)
2289 {
2290 cppUngetc (c);
2291 end = true;
2292 }
2293 else if (--parameters == 0)
2294 end = true;
2295 break;
2296
2297 default:
2298 if (isident1 (c))
2299 {
2300 readIdentifier (token, c);
2301 switch (token->keyword)
2302 {
2303 case KEYWORD_ATTRIBUTE: skipParens (); break;
2304 case KEYWORD_THROW: skipParens (); break;
2305 case KEYWORD_TRY: break;
2306
2307 case KEYWORD_CONST:
2308 case KEYWORD_VOLATILE:
2309 if (vStringLength (Signature) > 0)
2310 {
2311 vStringPut (Signature, ' ');
2312 vStringCat (Signature, token->name);
2313 }
2314 break;
2315
2316 case KEYWORD_CATCH:
2317 case KEYWORD_CLASS:
2318 case KEYWORD_EXPLICIT:
2319 case KEYWORD_EXTERN:
2320 case KEYWORD_FRIEND:
2321 case KEYWORD_INLINE:
2322 case KEYWORD_MUTABLE:
2323 case KEYWORD_NAMESPACE:
2324 case KEYWORD_NEW:
2325 case KEYWORD_NEWCOV:
2326 case KEYWORD_OPERATOR:
2327 case KEYWORD_OVERLOAD:
2328 case KEYWORD_PRIVATE:
2329 case KEYWORD_PROTECTED:
2330 case KEYWORD_PUBLIC:
2331 case KEYWORD_STATIC:
2332 case KEYWORD_TEMPLATE:
2333 case KEYWORD_TYPEDEF:
2334 case KEYWORD_TYPENAME:
2335 case KEYWORD_USING:
2336 case KEYWORD_VIRTUAL:
2337 /* Never allowed within parameter declarations. */
2338 restart = true;
2339 end = true;
2340 break;
2341
2342 default:
2343 if (isType (token, TOKEN_NONE))
2344 ;
2345 else if (info->isKnrParamList && info->parameterCount > 0)
2346 ++elementCount;
2347 else
2348 {
2349 /* If we encounter any other identifier immediately
2350 * following an empty parameter list, this is almost
2351 * certainly one of those Microsoft macro "thingies"
2352 * that the automatic source code generation sticks
2353 * in. Terminate the current statement.
2354 */
2355 restart = true;
2356 end = true;
2357 }
2358 break;
2359 }
2360 }
2361 }
2362 if (! end)
2363 {
2364 c = skipToNonWhite ();
2365 if (c == EOF)
2366 end = true;
2367 }
2368 } while (! end);
2369
2370 if (restart)
2371 restartStatement (st);
2372 else
2373 setToken (st, TOKEN_NONE);
2374
2375 return (boolean) (c != EOF);
2376 }
2377
2378 void Parser_Cpp::skipJavaThrows (statementInfo *const st)
2379 {
2380 tokenInfo *const token = activeToken (st);
2381 int c = skipToNonWhite ();
2382
2383 if (isident1 (c))
2384 {
2385 readIdentifier (token, c);
2386 if (token->keyword == KEYWORD_THROWS)
2387 {
2388 do
2389 {
2390 c = skipToNonWhite ();
2391 if (isident1 (c))
2392 {
2393 readIdentifier (token, c);
2394 c = skipToNonWhite ();
2395 }
2396 } while (c == '.' || c == ',');
2397 }
2398 }
2399 cppUngetc (c);
2400 setToken (st, TOKEN_NONE);
2401 }
2402
2403 void Parser_Cpp::analyzePostParens (statementInfo *const st, parenInfo *const info)
2404 {
2405 //const unsigned long inputLineNumber = getInputLineNumber ();
2406 int c = skipToNonWhite ();
2407
2408 cppUngetc (c);
2409 if (isOneOf (c, "{;,="))
2410 ;
2411 else if (isLanguage (Lang_java))
2412 skipJavaThrows (st);
2413 else
2414 {
2415 if (! skipPostArgumentStuff (st, info))
2416 {
2417 verbose (
2418 "%s: confusing argument declarations beginning at line %lu\n",
2419 getInputFileName (), inputLineNumber);
2420 longjmp (Exception, (int) ExceptionFormattingError);
2421 }
2422 }
2423 }
2424
2425 boolean Parser_Cpp::languageSupportsGenerics (void)
2426 {
2427 return (boolean) (isLanguage (Lang_cpp) || isLanguage (Lang_csharp) ||
2428 isLanguage (Lang_java));
2429 }
2430
2431 void Parser_Cpp::processAngleBracket (void)
2432 {
2433 int c = cppGetc ();
2434 if (c == '>') {
2435 /* already found match for template */
2436 } else if (languageSupportsGenerics () && c != '<' && c != '=') {
2437 /* this is a template */
2438 cppUngetc (c);
2439 skipToMatch ("<>");
2440 } else if (c == '<') {
2441 /* skip "<<" or "<<=". */
2442 c = cppGetc ();
2443 if (c != '=') {
2444 cppUngetc (c);
2445 }
2446 } else {
2447 cppUngetc (c);
2448 }
2449 }
2450
2451 void Parser_Cpp::parseJavaAnnotation (statementInfo *const st)
2452 {
2453 /*
2454 * @Override
2455 * @Target(ElementType.METHOD)
2456 * @SuppressWarnings(value = "unchecked")
2457 *
2458 * But watch out for "@interface"!
2459 */
2460 tokenInfo *const token = activeToken (st);
2461
2462 int c = skipToNonWhite ();
2463 readIdentifier (token, c);
2464 if (token->keyword == KEYWORD_INTERFACE)
2465 {
2466 /* Oops. This was actually "@interface" defining a new annotation. */
2467 processInterface (st);
2468 }
2469 else
2470 {
2471 /* Bug #1691412: skip any annotation arguments. */
2472 skipParens ();
2473 }
2474 }
2475
2476 int Parser_Cpp::parseParens (statementInfo *const st, parenInfo *const info)
2477 {
2478 tokenInfo *const token = activeToken (st);
2479 unsigned int identifierCount = 0;
2480 unsigned int depth = 1;
2481 boolean firstChar = true;
2482 int nextChar = '\0';
2483
2484 CollectingSignature = true;
2485 vStringClear (Signature);
2486 vStringPut (Signature, '(');
2487 info->parameterCount = 1;
2488 do
2489 {
2490 int c = skipToNonWhite ();
2491 vStringPut (Signature, c);
2492
2493 switch (c)
2494 {
2495 case '&':
2496 case '*':
2497 info->isPointer = true;
2498 info->isKnrParamList = false;
2499 if (identifierCount == 0)
2500 info->isParamList = false;
2501 initToken (token);
2502 break;
2503
2504 case ':':
2505 info->isKnrParamList = false;
2506 break;
2507
2508 case '.':
2509 info->isNameCandidate = false;
2510 c = cppGetc ();
2511 if (c != '.')
2512 {
2513 cppUngetc (c);
2514 info->isKnrParamList = false;
2515 }
2516 else
2517 {
2518 c =cppGetc ();
2519 if (c != '.')
2520 {
2521 cppUngetc (c);
2522 info->isKnrParamList = false;
2523 }
2524 else
2525 vStringCatS (Signature, "..."); /* variable arg list */
2526 }
2527 break;
2528
2529 case ',':
2530 info->isNameCandidate = false;
2531 if (info->isKnrParamList)
2532 {
2533 ++info->parameterCount;
2534 identifierCount = 0;
2535 }
2536 break;
2537
2538 case '=':
2539 info->isKnrParamList = false;
2540 info->isNameCandidate = false;
2541 if (firstChar)
2542 {
2543 info->isParamList = false;
2544 skipMacro (st);
2545 depth = 0;
2546 }
2547 break;
2548
2549 case '[':
2550 info->isKnrParamList = false;
2551 skipToMatch ("[]");
2552 break;
2553
2554 case '<':
2555 info->isKnrParamList = false;
2556 processAngleBracket ();
2557 break;
2558
2559 case ')':
2560 if (firstChar)
2561 info->parameterCount = 0;
2562 --depth;
2563 break;
2564
2565 case '(':
2566 info->isKnrParamList = false;
2567 if (firstChar)
2568 {
2569 info->isNameCandidate = false;
2570 cppUngetc (c);
2571 vStringClear (Signature);
2572 skipMacro (st);
2573 depth = 0;
2574 vStringChop (Signature);
2575 }
2576 else if (isType (token, TOKEN_PAREN_NAME))
2577 {
2578 c = skipToNonWhite ();
2579 if (c == '*') /* check for function pointer */
2580 {
2581 skipToMatch ("()");
2582 c = skipToNonWhite ();
2583 if (c == '(')
2584 skipToMatch ("()");
2585 else
2586 cppUngetc (c);
2587 }
2588 else
2589 {
2590 cppUngetc (c);
2591 cppUngetc ('(');
2592 info->nestedArgs = true;
2593 }
2594 }
2595 else
2596 ++depth;
2597 break;
2598
2599 default:
2600 if (c == '@' && isLanguage (Lang_java))
2601 {
2602 parseJavaAnnotation(st);
2603 }
2604 else if (isident1 (c))
2605 {
2606 if (++identifierCount > 1)
2607 info->isKnrParamList = false;
2608 readIdentifier (token, c);
2609 if (isType (token, TOKEN_NAME) && info->isNameCandidate)
2610 token->type = TOKEN_PAREN_NAME;
2611 else if (isType (token, TOKEN_KEYWORD))
2612 {
2613 if (token->keyword != KEYWORD_CONST &&
2614 token->keyword != KEYWORD_VOLATILE)
2615 {
2616 info->isKnrParamList = false;
2617 info->isNameCandidate = false;
2618 }
2619 }
2620 }
2621 else
2622 {
2623 info->isParamList = false;
2624 info->isKnrParamList = false;
2625 info->isNameCandidate = false;
2626 info->invalidContents = true;
2627 }
2628 break;
2629 }
2630 firstChar = false;
2631 } while (! info->nestedArgs && depth > 0 &&
2632 (info->isKnrParamList || info->isNameCandidate));
2633
2634 if (! info->nestedArgs) while (depth > 0)
2635 {
2636 skipToMatch ("()");
2637 --depth;
2638 }
2639
2640 if (! info->isNameCandidate)
2641 initToken (token);
2642
2643 vStringTerminate (Signature);
2644 if (info->isKnrParamList)
2645 vStringClear (Signature);
2646 CollectingSignature = false;
2647 return nextChar;
2648 }
2649
2650 void Parser_Cpp::initParenInfo (parenInfo *const info)
2651 {
2652 info->isPointer = false;
2653 info->isParamList = true;
2654 info->isKnrParamList = isLanguage (Lang_c);
2655 info->isNameCandidate = true;
2656 info->invalidContents = false;
2657 info->nestedArgs = false;
2658 info->parameterCount = 0;
2659 }
2660
2661 void Parser_Cpp::analyzeParens (statementInfo *const st)
2662 {
2663 tokenInfo *const prev = prevToken (st, 1);
2664
2665 if (st->inFunction && ! st->assignment)
2666 st->notVariable = true;
2667 if (! isType (prev, TOKEN_NONE)) /* in case of ignored enclosing macros */
2668 {
2669 tokenInfo *const token = activeToken (st);
2670 parenInfo info;
2671 int c;
2672
2673 initParenInfo (&info);
2674 parseParens (st, &info);
2675 c = skipToNonWhite ();
2676 cppUngetc (c);
2677 if (info.invalidContents)
2678 reinitStatement (st, false);
2679 else if (info.isNameCandidate && isType (token, TOKEN_PAREN_NAME) &&
2680 ! st->gotParenName &&
2681 (! info.isParamList || ! st->haveQualifyingName ||
2682 c == '(' ||
2683 (c == '=' && st->implementation != IMP_VIRTUAL) ||
2684 (st->declaration == DECL_NONE && isOneOf (c, ",;"))))
2685 {
2686 token->type = TOKEN_NAME;
2687 processName (st);
2688 st->gotParenName = true;
2689 if (! (c == '(' && info.nestedArgs))
2690 st->isPointer = info.isPointer;
2691 }
2692 else if (! st->gotArgs && info.isParamList)
2693 {
2694 st->gotArgs = true;
2695 setToken (st, TOKEN_ARGS);
2696 advanceToken (st);
2697 if (st->scope != SCOPE_TYPEDEF)
2698 analyzePostParens (st, &info);
2699 }
2700 else
2701 setToken (st, TOKEN_NONE);
2702 }
2703 }
2704
2705 /*
2706 * Token parsing functions
2707 */
2708
2709 void Parser_Cpp::addContext (statementInfo *const st, const tokenInfo* const token)
2710 {
2711 if (isType (token, TOKEN_NAME))
2712 {
2713 if (vStringLength (st->context->name) > 0)
2714 {
2715 if (isLanguage (Lang_c) || isLanguage (Lang_cpp))
2716 vStringCatS (st->context->name, "::");
2717 else if (isLanguage (Lang_java) || isLanguage (Lang_csharp))
2718 vStringCatS (st->context->name, ".");
2719 }
2720 vStringCat (st->context->name, token->name);
2721 st->context->type = TOKEN_NAME;
2722 }
2723 }
2724
2725 boolean Parser_Cpp::inheritingDeclaration (declType decl)
2726 {
2727 /* C# supports inheritance for enums. C++0x will too, but not yet. */
2728 if (decl == DECL_ENUM)
2729 {
2730 return (boolean) (isLanguage (Lang_csharp));
2731 }
2732 return (boolean) (
2733 decl == DECL_CLASS ||
2734 decl == DECL_STRUCT ||
2735 decl == DECL_INTERFACE);
2736 }
2737
2738 void Parser_Cpp::processColon (statementInfo *const st)
2739 {
2740 int c = (isLanguage (Lang_cpp) ?cppGetc () : skipToNonWhite ());
2741 const boolean doubleColon = (boolean) (c == ':');
2742
2743 if (doubleColon)
2744 {
2745 setToken (st, TOKEN_DOUBLE_COLON);
2746 st->haveQualifyingName = false;
2747 }
2748 else
2749 {
2750 cppUngetc (c);
2751 if ((isLanguage (Lang_cpp) || isLanguage (Lang_csharp)) &&
2752 inheritingDeclaration (st->declaration))
2753 {
2754 readParents (st, ':');
2755 }
2756 else if (parentDecl (st) == DECL_STRUCT)
2757 {
2758 c = skipToOneOf (",;");
2759 if (c == ',')
2760 setToken (st, TOKEN_COMMA);
2761 else if (c == ';')
2762 setToken (st, TOKEN_SEMICOLON);
2763 }
2764 else
2765 {
2766 const tokenInfo *const prev = prevToken (st, 1);
2767 const tokenInfo *const prev2 = prevToken (st, 2);
2768 if (prev->keyword == KEYWORD_DEFAULT ||
2769 prev2->keyword == KEYWORD_CASE ||
2770 st->parent != NULL)
2771 {
2772 reinitStatement (st, false);
2773 }
2774 }
2775 }
2776 }
2777
2778 /* Skips over any initializing value which may follow an '=' character in a
2779 * variable definition.
2780 */
2781 int Parser_Cpp::skipInitializer (statementInfo *const st)
2782 {
2783 boolean done = false;
2784 int c;
2785
2786 while (! done)
2787 {
2788 c = skipToNonWhite ();
2789
2790 if (c == EOF)
2791 longjmp (Exception, (int) ExceptionFormattingError);
2792 else switch (c)
2793 {
2794 case ',':
2795 case ';': done = true; break;
2796
2797 case '0':
2798 if (st->implementation == IMP_VIRTUAL)
2799 st->implementation = IMP_PURE_VIRTUAL;
2800 break;
2801
2802 case '[': skipToMatch ("[]"); break;
2803 case '(': skipToMatch ("()"); break;
2804 case '{': skipToMatch ("{}"); break;
2805 case '<': processAngleBracket(); break;
2806
2807 case '}':
2808 if (insideEnumBody (st))
2809 done = true;
2810 else if (! isBraceFormat ())
2811 {
2812 verbose ("%s: unexpected closing brace at line %lu\n",
2813 getInputFileName (), getInputLineNumber ());
2814 longjmp (Exception, (int) ExceptionBraceFormattingError);
2815 }
2816 break;
2817
2818 default: break;
2819 }
2820 }
2821 return c;
2822 }
2823
2824 void Parser_Cpp::processInitializer (statementInfo *const st)
2825 {
2826 const boolean inEnumBody = insideEnumBody (st);
2827 int c =cppGetc ();
2828
2829 if (c != '=')
2830 {
2831 cppUngetc (c);
2832 c = skipInitializer (st);
2833 st->assignment = true;
2834 if (c == ';')
2835 setToken (st, TOKEN_SEMICOLON);
2836 else if (c == ',')
2837 setToken (st, TOKEN_COMMA);
2838 else if (c == '}' && inEnumBody)
2839 {
2840 cppUngetc (c);
2841 setToken (st, TOKEN_COMMA);
2842 }
2843 if (st->scope == SCOPE_EXTERN)
2844 st->scope = SCOPE_GLOBAL;
2845 }
2846 }
2847
2848 void Parser_Cpp::parseIdentifier (statementInfo *const st, const int c)
2849 {
2850 tokenInfo *const token = activeToken (st);
2851
2852 readIdentifier (token, c);
2853
2854 if (! isType (token, TOKEN_NONE))
2855 processToken (token, st);
2856 }
2857
2858 void Parser_Cpp::parseGeneralToken (statementInfo *const st, const int c)
2859 {
2860 const tokenInfo *const prev = prevToken (st, 1);
2861
2862 if (isident1 (c) || (isLanguage (Lang_java) && isHighChar (c)))
2863 {
2864 parseIdentifier (st, c);
2865 if (isType (st->context, TOKEN_NAME) &&
2866 isType (activeToken (st), TOKEN_NAME) && isType (prev, TOKEN_NAME))
2867 {
2868 initToken (st->context);
2869 }
2870 }
2871 else if (c == '.' || c == '-')
2872 {
2873 if (! st->assignment)
2874 st->notVariable = true;
2875 if (c == '-')
2876 {
2877 int c2 =cppGetc ();
2878 if (c2 != '>')
2879 cppUngetc (c2);
2880 }
2881 }
2882 else if (c == '!' || c == '>')
2883 {
2884 int c2 =cppGetc ();
2885 if (c2 != '=')
2886 cppUngetc (c2);
2887 }
2888 else if (c == '@' && isLanguage (Lang_java))
2889 {
2890 parseJavaAnnotation (st);
2891 }
2892 else if (isExternCDecl (st, c))
2893 {
2894 st->declaration = DECL_NOMANGLE;
2895 st->scope = SCOPE_GLOBAL;
2896 }
2897 }
2898
2899 /* Reads characters from the pre-processor and assembles tokens, setting
2900 * the current statement state.
2901 */
2902 void Parser_Cpp::nextToken (statementInfo *const st)
2903 {
2904 tokenInfo *token;
2905 do
2906 {
2907 int c = skipToNonWhite ();
2908
2909 switch (c)
2910 {
2911 case EOF: longjmp (Exception, (int) ExceptionEOF); break;
2912 case '(': analyzeParens (st); break;
2913 case '<': processAngleBracket (); break;
2914 case '*': st->haveQualifyingName = false; break;
2915 case ',': setToken (st, TOKEN_COMMA); break;
2916 case ':': processColon (st); break;
2917 case ';': setToken (st, TOKEN_SEMICOLON); break;
2918 case '=': processInitializer (st); break;
2919 case '[': skipToMatch ("[]"); break;
2920 case '{': setToken (st, TOKEN_BRACE_OPEN); break;
2921 case '}': setToken (st, TOKEN_BRACE_CLOSE); break;
2922 default: parseGeneralToken (st, c); break;
2923 }
2924 token = activeToken (st);
2925 } while (isType (token, TOKEN_NONE));
2926 }
2927
2928 /*
2929 * Scanning support functions
2930 */
2931
2932
2933
2934 statementInfo *Parser_Cpp::newStatement (statementInfo *const parent)
2935 {
2936 statementInfo *const st = xMalloc (1, statementInfo);
2937 unsigned int i;
2938
2939 for (i = 0 ; i < (unsigned int) NumTokens ; ++i)
2940 st->token [i] = newToken ();
2941
2942 st->context = newToken ();
2943 st->blockName = newToken ();
2944 st->parentClasses = vStringNew ();
2945
2946 initStatement (st, parent);
2947 CurrentStatement = st;
2948
2949 return st;
2950 }
2951
2952 void Parser_Cpp::deleteStatement (void)
2953 {
2954 statementInfo *const st = CurrentStatement;
2955 statementInfo *const parent = st->parent;
2956 unsigned int i;
2957
2958 for (i = 0 ; i < (unsigned int) NumTokens ; ++i)
2959 {
2960 deleteToken (st->token [i]); st->token [i] = NULL;
2961 }
2962 deleteToken (st->blockName); st->blockName = NULL;
2963 deleteToken (st->context); st->context = NULL;
2964 vStringDelete (st->parentClasses); st->parentClasses = NULL;
2965 eFree (st);
2966 CurrentStatement = parent;
2967 }
2968
2969 void Parser_Cpp::deleteAllStatements (void)
2970 {
2971 while (CurrentStatement != NULL)
2972 deleteStatement ();
2973 }
2974
2975 boolean Parser_Cpp::isStatementEnd (const statementInfo *const st)
2976 {
2977 const tokenInfo *const token = activeToken (st);
2978 boolean isEnd;
2979
2980 if (isType (token, TOKEN_SEMICOLON))
2981 isEnd = true;
2982 else if (isType (token, TOKEN_BRACE_CLOSE))
2983 /* Java and C# do not require semicolons to end a block. Neither do C++
2984 * namespaces. All other blocks require a semicolon to terminate them.
2985 */
2986 isEnd = (boolean) (isLanguage (Lang_java) || isLanguage (Lang_csharp) ||
2987 ! isContextualStatement (st));
2988 else
2989 isEnd = false;
2990
2991 return isEnd;
2992 }
2993
2994 void Parser_Cpp::checkStatementEnd (statementInfo *const st)
2995 {
2996 const tokenInfo *const token = activeToken (st);
2997
2998 if (isType (token, TOKEN_COMMA))
2999 reinitStatement (st, true);
3000 else if (isStatementEnd (st))
3001 {
3002 DebugStatement ( if (debug (DEBUG_PARSE)) printf ("<ES>"); )
3003 reinitStatement (st, false);
3004 cppEndStatement ();
3005 }
3006 else
3007 {
3008 cppBeginStatement ();
3009 advanceToken (st);
3010 }
3011 }
3012
3013 void Parser_Cpp::nest (statementInfo *const st, const unsigned int nestLevel)
3014 {
3015 switch (st->declaration)
3016 {
3017 case DECL_CLASS:
3018 case DECL_ENUM:
3019 case DECL_INTERFACE:
3020 case DECL_NAMESPACE:
3021 case DECL_NOMANGLE:
3022 case DECL_STRUCT:
3023 case DECL_UNION:
3024 createTags (nestLevel, st);
3025 break;
3026
3027 case DECL_FUNCTION:
3028 case DECL_TASK:
3029 st->inFunction = true;
3030 /* fall through */
3031 default:
3032 if (includeTag (TAG_LOCAL, false))
3033 createTags (nestLevel, st);
3034 else
3035 skipToMatch ("{}");
3036 break;
3037 }
3038 advanceToken (st);
3039 setToken (st, TOKEN_BRACE_CLOSE);
3040 }
3041
3042 void Parser_Cpp::tagCheck (statementInfo *const st)
3043 {
3044 const tokenInfo *const token = activeToken (st);
3045 const tokenInfo *const prev = prevToken (st, 1);
3046 const tokenInfo *const prev2 = prevToken (st, 2);
3047
3048 switch (token->type)
3049 {
3050 case TOKEN_NAME:
3051 if (insideEnumBody (st))
3052 qualifyEnumeratorTag (st, token);
3053 break;
3054 //#if 0
3055 // case TOKEN_PACKAGE:
3056 // if (st->haveQualifyingName)
3057 // makeTag (token, st, false, TAG_PACKAGE);
3058 // break;
3059 //#endif
3060 case TOKEN_BRACE_OPEN:
3061 if (isType (prev, TOKEN_ARGS))
3062 {
3063 if (st->haveQualifyingName)
3064 {
3065 if (! isLanguage (Lang_vera))
3066 st->declaration = DECL_FUNCTION;
3067 if (isType (prev2, TOKEN_NAME))
3068 copyToken (st->blockName, prev2);
3069 qualifyFunctionTag (st, prev2);
3070 }
3071 }
3072 else if (isContextualStatement (st) ||
3073 st->declaration == DECL_NAMESPACE ||
3074 st->declaration == DECL_PROGRAM)
3075 {
3076 if (isType (prev, TOKEN_NAME))
3077 copyToken (st->blockName, prev);
3078 else
3079 {
3080 /* For an anonymous struct or union we use a unique ID
3081 * a number, so that the members can be found.
3082 */
3083 char buf [20]; /* length of "_anon" + digits + null */
3084 sprintf (buf, "__anon%d", ++AnonymousID);
3085 vStringCopyS (st->blockName->name, buf);
3086 st->blockName->type = TOKEN_NAME;
3087 st->blockName->keyword = KEYWORD_NONE;
3088 }
3089 qualifyBlockTag (st, prev);
3090 }
3091 else if (isLanguage (Lang_csharp))
3092 makeTag (prev, st, false, TAG_PROPERTY);
3093 break;
3094
3095 case TOKEN_SEMICOLON:
3096 case TOKEN_COMMA:
3097 if (insideEnumBody (st))
3098 ;
3099 else if (isType (prev, TOKEN_NAME))
3100 {
3101 if (isContextualKeyword (prev2))
3102 makeTag (prev, st, true, TAG_EXTERN_VAR);
3103 else
3104 qualifyVariableTag (st, prev);
3105 }
3106 else if (isType (prev, TOKEN_ARGS) && isType (prev2, TOKEN_NAME))
3107 {
3108 if (st->isPointer)
3109 qualifyVariableTag (st, prev2);
3110 else
3111 qualifyFunctionDeclTag (st, prev2);
3112 }
3113 if (isLanguage (Lang_java) && token->type == TOKEN_SEMICOLON && insideEnumBody (st))
3114 {
3115 /* In Java, after an initial enum-like part,
3116 * a semicolon introduces a class-like part.
3117 * See Bug #1730485 for the full rationale. */
3118 st->parent->declaration = DECL_CLASS;
3119 }
3120 break;
3121
3122 default: break;
3123 }
3124 }
3125
3126 /* Parses the current file and decides whether to write out and tags that
3127 * are discovered.
3128 */
3129 void Parser_Cpp::createTags (const unsigned int nestLevel,
3130 statementInfo *const parent)
3131 {
3132 statementInfo *const st = newStatement (parent);
3133
3134 DebugStatement ( if (nestLevel > 0) debugParseNest (true, nestLevel); )
3135 while (true)
3136 {
3137 tokenInfo *token;
3138
3139 nextToken (st);
3140 token = activeToken(st);
3141
3142 if (isType (token, TOKEN_BRACE_CLOSE))
3143 {
3144 if (nestLevel > 0)
3145 break;
3146 else
3147 {
3148 verbose ("%s: unexpected closing brace at line %lu\n",
3149 getInputFileName (), getInputLineNumber ());
3150 longjmp (Exception, (int) ExceptionBraceFormattingError);
3151 }
3152 }
3153 else if (isType (token, TOKEN_DOUBLE_COLON))
3154 {
3155 addContext (st, prevToken (st, 1));
3156 advanceToken (st);
3157 }
3158 else
3159 {
3160 tagCheck (st);
3161 if (isType (token, TOKEN_BRACE_OPEN))
3162 nest (st, nestLevel + 1);
3163 checkStatementEnd (st);
3164 }
3165 }
3166 deleteStatement ();
3167 DebugStatement ( if (nestLevel > 0) debugParseNest (false, nestLevel - 1); )
3168 }
3169
3170 boolean Parser_Cpp::findCTags (const unsigned int passCount)
3171 {
3172 exception_t exception;
3173 boolean retry;
3174
3175 Assert (passCount < 3);
3176 cppInit ((boolean) (passCount > 1), isLanguage (Lang_csharp));
3177 Signature = vStringNew ();
3178
3179 exception = (exception_t) setjmp (Exception);
3180 retry = false;
3181 if (exception == ExceptionNone) {
3182 createTags (0, NULL);
3183 }
3184 else
3185 {
3186 deleteAllStatements ();
3187 if (exception == ExceptionBraceFormattingError && passCount == 1)
3188 {
3189 retry = true;
3190 verbose ("%s: retrying file with fallback brace matching algorithm\n",
3191 getInputFileName ());
3192 }
3193 }
3194 vStringDelete (Signature);
3195 cppTerminate ();
3196
3197 return retry;
3198 }
3199
3200 void Parser_Cpp::buildKeywordHash (const langType language, unsigned int idx)
3201 {
3202 const size_t count = sizeof (KeywordTable) / sizeof (KeywordTable [0]);
3203 size_t i;
3204 for (i = 0 ; i < count ; ++i)
3205 {
3206 const keywordDesc* const p = &KeywordTable [i];
3207 if (p->isValid [idx])
3208 keywords.addKeyword (p->name, language, (int) p->id);
3209 }
3210 }
3211
3212 void Parser_Cpp::initializeCParser (const langType language)
3213 {
3214 Lang_c = language;
3215 buildKeywordHash (language, 0);
3216 }
3217
3218 void Parser_Cpp::initializeCppParser (const langType language)
3219 {
3220 Lang_cpp = language;
3221 buildKeywordHash (language, 1);
3222 }
3223
3224 void Parser_Cpp::initializeCsharpParser (const langType language)
3225 {
3226 Lang_csharp = language;
3227 buildKeywordHash (language, 2);
3228 }
3229
3230 void Parser_Cpp::initializeJavaParser (const langType language)
3231 {
3232 Lang_java = language;
3233 buildKeywordHash (language, 3);
3234 }
3235
3236 void Parser_Cpp::initializeVeraParser (const langType language)
3237 {
3238 Lang_vera = language;
3239 buildKeywordHash (language, 4);
3240 }
3241
3242
3243 /*****************************************************************************
3244 *****************************************************************************/
3245 void Parser_Cpp::parse() {
3246
3247 switch (language()) {
3248 case LanguageC: initializeCParser(language()); break;
3249 case LanguageCpp: initializeCppParser(language()); break;
3250 case LanguageCsharp: initializeCsharpParser(language()); break;
3251 case LanguageJava: initializeJavaParser(language()); break;
3252 case LanguageVera: initializeVeraParser(language()); break;
3253 default: return;
3254 }
3255
3256
3257
3258 int passCount=1;
3259
3260 while (findCTags(passCount)) {
3261 resetText();
3262 passCount++;
3263 }
3264
3265 }
3266
3267 #endif // PARSER_CPP