1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_LEX_PREPROCESSORLEXER_H |
15 | #define LLVM_CLANG_LEX_PREPROCESSORLEXER_H |
16 | |
17 | #include "clang/Lex/MultipleIncludeOpt.h" |
18 | #include "clang/Lex/Token.h" |
19 | #include "clang/Basic/SourceLocation.h" |
20 | #include "llvm/ADT/ArrayRef.h" |
21 | #include "llvm/ADT/SmallVector.h" |
22 | #include <cassert> |
23 | |
24 | namespace clang { |
25 | |
26 | class FileEntry; |
27 | class Preprocessor; |
28 | |
29 | class PreprocessorLexer { |
30 | virtual void anchor(); |
31 | |
32 | protected: |
33 | friend class Preprocessor; |
34 | |
35 | |
36 | Preprocessor *PP = nullptr; |
37 | |
38 | |
39 | const FileID FID; |
40 | |
41 | |
42 | unsigned InitialNumSLocEntries = 0; |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | bool ParsingPreprocessorDirective = false; |
50 | |
51 | |
52 | bool ParsingFilename = false; |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | bool LexingRawMode = false; |
68 | |
69 | |
70 | |
71 | MultipleIncludeOpt MIOpt; |
72 | |
73 | |
74 | |
75 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
76 | |
77 | PreprocessorLexer() : FID() {} |
78 | PreprocessorLexer(Preprocessor *pp, FileID fid); |
79 | virtual ~PreprocessorLexer() = default; |
80 | |
81 | virtual void IndirectLex(Token& Result) = 0; |
82 | |
83 | |
84 | virtual SourceLocation getSourceLocation() = 0; |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | void pushConditionalLevel(SourceLocation DirectiveStart, bool WasSkipping, |
93 | bool FoundNonSkip, bool FoundElse) { |
94 | PPConditionalInfo CI; |
95 | CI.IfLoc = DirectiveStart; |
96 | CI.WasSkipping = WasSkipping; |
97 | CI.FoundNonSkip = FoundNonSkip; |
98 | CI.FoundElse = FoundElse; |
99 | ConditionalStack.push_back(CI); |
100 | } |
101 | void pushConditionalLevel(const PPConditionalInfo &CI) { |
102 | ConditionalStack.push_back(CI); |
103 | } |
104 | |
105 | |
106 | |
107 | |
108 | bool popConditionalLevel(PPConditionalInfo &CI) { |
109 | if (ConditionalStack.empty()) |
110 | return true; |
111 | CI = ConditionalStack.pop_back_val(); |
112 | return false; |
113 | } |
114 | |
115 | |
116 | |
117 | PPConditionalInfo &peekConditionalLevel() { |
118 | (0) . __assert_fail ("!ConditionalStack.empty() && \"No conditionals active!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/PreprocessorLexer.h", 118, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!ConditionalStack.empty() && "No conditionals active!"); |
119 | return ConditionalStack.back(); |
120 | } |
121 | |
122 | unsigned getConditionalStackDepth() const { return ConditionalStack.size(); } |
123 | |
124 | public: |
125 | PreprocessorLexer(const PreprocessorLexer &) = delete; |
126 | PreprocessorLexer &operator=(const PreprocessorLexer &) = delete; |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | void LexIncludeFilename(Token &FilenameTok); |
133 | |
134 | |
135 | |
136 | void setParsingPreprocessorDirective(bool f) { |
137 | ParsingPreprocessorDirective = f; |
138 | } |
139 | |
140 | |
141 | bool isLexingRawMode() const { return LexingRawMode; } |
142 | |
143 | |
144 | Preprocessor *getPP() const { return PP; } |
145 | |
146 | FileID getFileID() const { |
147 | (0) . __assert_fail ("PP && \"PreprocessorLexer..getFileID() should only be used with a Preprocessor\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/PreprocessorLexer.h", 148, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(PP && |
148 | (0) . __assert_fail ("PP && \"PreprocessorLexer..getFileID() should only be used with a Preprocessor\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/PreprocessorLexer.h", 148, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "PreprocessorLexer::getFileID() should only be used with a Preprocessor"); |
149 | return FID; |
150 | } |
151 | |
152 | |
153 | unsigned getInitialNumSLocEntries() const { |
154 | return InitialNumSLocEntries; |
155 | } |
156 | |
157 | |
158 | |
159 | const FileEntry *getFileEntry() const; |
160 | |
161 | |
162 | |
163 | using conditional_iterator = |
164 | SmallVectorImpl<PPConditionalInfo>::const_iterator; |
165 | |
166 | conditional_iterator conditional_begin() const { |
167 | return ConditionalStack.begin(); |
168 | } |
169 | |
170 | conditional_iterator conditional_end() const { |
171 | return ConditionalStack.end(); |
172 | } |
173 | |
174 | void setConditionalLevels(ArrayRef<PPConditionalInfo> CL) { |
175 | ConditionalStack.clear(); |
176 | ConditionalStack.append(CL.begin(), CL.end()); |
177 | } |
178 | }; |
179 | |
180 | } |
181 | |
182 | #endif |
183 | |