Debian Codegraph @

plugins/symbolbrowser/symbols/parsers/parserex.h

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 rceived 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 PARSEREX_H
23 #define PARSEREX_H
24 #include "parser.h"
25 #include "vstring.h"
26
27 class ParserEx : public Parser
28 {
29 public:
30 ParserEx();
31 virtual ~ParserEx();
32
33 protected:
34 enum eCharacters {
35 /* white space characters */
36 SPACE = ' ',
37 NEWLINE = '\n',
38 CRETURN = '\r',
39 FORMFEED = '\f',
40 TAB = '\t',
41 VTAB = '\v',
42
43 /* some hard to read characters */
44 DOUBLE_QUOTE = '"',
45 SINGLE_QUOTE = '\'',
46 BACKSLASH = '\\',
47
48 STRING_SYMBOL = ('S' + 0x80),
49 CHAR_SYMBOL = ('C' + 0x80)
50 };
51
52
53 void cppInit (const bool state, const bool hasAtLiteralStrings);
54 void cppTerminate (void);
55
56 bool isBraceFormat (void);
57 unsigned int getDirectiveNestLevel (void);
58 void cppBeginStatement (void);
59 void cppEndStatement (void);
60 void cppUngetc (const int c);
61 int cppGetc (void);
62 int skipOverCComment (void);
63
64
65 /*****************************************************************************
66 Is the character valid as a character of a C identifier?
67 VMS allows '$' in identifiers.
68 *****************************************************************************/
69 bool isident(const char c) const { return (isalnum(c) || (c) == '_' || (c) == '$'); };
70
71 /*****************************************************************************
72 Is the character valid as the first character of a C identifier?
73 C++ allows '~' in destructors. VMS allows '$' in identifiers.
74 *****************************************************************************/
75 bool isident1(const char c) const { return (isalpha(c) || (c) == '_' || (c) == '~' || (c) == '$'); }
76
77 private:
78 enum Comment { COMMENT_NONE, COMMENT_C, COMMENT_CPLUS };
79
80 enum eCppLimits {
81 MaxCppNestingLevel = 20,
82 MaxDirectiveName = 10
83 };
84
85 /* Defines the one nesting level of a preprocessor conditional.
86 */
87 typedef struct sConditionalInfo {
88 bool ignoreAllBranches; /* ignoring parent conditional branch */
89 bool singleBranch; /* choose only one branch */
90 bool branchChosen; /* branch already selected */
91 bool ignoring; /* current ignore state */
92 } conditionalInfo;
93
94 enum eState {
95 DRCTV_NONE, /* no known directive - ignore to end of line */
96 DRCTV_DEFINE, /* "#define" encountered */
97 DRCTV_HASH, /* initial '#' read; determine directive */
98 DRCTV_IF, /* "#if" or "#ifdef" encountered */
99 DRCTV_PRAGMA, /* #pragma encountered */
100 DRCTV_UNDEF /* "#undef" encountered */
101 };
102
103
104 /* Defines the current state of the pre-processor. */
105 int ungetch, ungetch2; /* ungotten characters, if any */
106 bool resolveRequired; /* must resolve if/else/elif/endif branch */
107 bool hasAtLiteralStrings; /* supports @"c:\" strings */
108 struct sDirective {
109 enum eState state; /* current directive being processed */
110 bool accept; /* is a directive syntactically permitted? */
111 vString * name; /* macro name */
112 unsigned int nestLevel; /* level 0 is not used */
113 conditionalInfo ifdef [MaxCppNestingLevel];
114 } directive;
115
116 /* Use brace formatting to detect end of block. */
117 bool BraceFormat;
118
119
120 bool readDirective (int c, char *const name, unsigned int maxLength);
121 void readIdentifier (int c, vString *const name);
122 conditionalInfo *currentConditional (void);
123 bool isIgnore (void);
124 bool setIgnore (const bool ignore);
125 bool isIgnoreBranch (void);
126 void chooseBranch (void);
127 bool pushConditional (const bool firstBranchChosen);
128 bool popConditional (void);
129 void makeDefineTag (const char *const name);
130 void directiveDefine (const int c);
131 void directivePragma (int c);
132 bool directiveIf (const int c);
133 bool directiveHash (const int c);
134 bool handleDirective (const int c);
135 Comment isComment (void);
136 int skipOverCplusComment (void);
137 int skipToEndOfString (bool ignoreBackslash);
138 int skipToEndOfChar (void);
139
140 };
141
142 #endif // PARSEREX_H