1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_LEX_PREPROCESSOR_H |
15 | #define LLVM_CLANG_LEX_PREPROCESSOR_H |
16 | |
17 | #include "clang/Basic/Builtins.h" |
18 | #include "clang/Basic/Diagnostic.h" |
19 | #include "clang/Basic/IdentifierTable.h" |
20 | #include "clang/Basic/LLVM.h" |
21 | #include "clang/Basic/LangOptions.h" |
22 | #include "clang/Basic/Module.h" |
23 | #include "clang/Basic/SourceLocation.h" |
24 | #include "clang/Basic/SourceManager.h" |
25 | #include "clang/Basic/TokenKinds.h" |
26 | #include "clang/Lex/Lexer.h" |
27 | #include "clang/Lex/MacroInfo.h" |
28 | #include "clang/Lex/ModuleLoader.h" |
29 | #include "clang/Lex/ModuleMap.h" |
30 | #include "clang/Lex/PPCallbacks.h" |
31 | #include "clang/Lex/Token.h" |
32 | #include "clang/Lex/TokenLexer.h" |
33 | #include "llvm/ADT/ArrayRef.h" |
34 | #include "llvm/ADT/DenseMap.h" |
35 | #include "llvm/ADT/FoldingSet.h" |
36 | #include "llvm/ADT/None.h" |
37 | #include "llvm/ADT/Optional.h" |
38 | #include "llvm/ADT/PointerUnion.h" |
39 | #include "llvm/ADT/STLExtras.h" |
40 | #include "llvm/ADT/SmallPtrSet.h" |
41 | #include "llvm/ADT/SmallVector.h" |
42 | #include "llvm/ADT/StringRef.h" |
43 | #include "llvm/ADT/TinyPtrVector.h" |
44 | #include "llvm/ADT/iterator_range.h" |
45 | #include "llvm/Support/Allocator.h" |
46 | #include "llvm/Support/Casting.h" |
47 | #include "llvm/Support/Registry.h" |
48 | #include <cassert> |
49 | #include <cstddef> |
50 | #include <cstdint> |
51 | #include <memory> |
52 | #include <map> |
53 | #include <string> |
54 | #include <utility> |
55 | #include <vector> |
56 | |
57 | namespace llvm { |
58 | |
59 | template<unsigned InternalLen> class SmallString; |
60 | |
61 | } |
62 | |
63 | namespace clang { |
64 | |
65 | class CodeCompletionHandler; |
66 | class CommentHandler; |
67 | class DirectoryEntry; |
68 | class DirectoryLookup; |
69 | class ExternalPreprocessorSource; |
70 | class FileEntry; |
71 | class FileManager; |
72 | class ; |
73 | class MacroArgs; |
74 | class PragmaHandler; |
75 | class PragmaNamespace; |
76 | class PreprocessingRecord; |
77 | class PreprocessorLexer; |
78 | class PreprocessorOptions; |
79 | class ScratchBuffer; |
80 | class TargetInfo; |
81 | |
82 | |
83 | |
84 | class TokenValue { |
85 | tok::TokenKind Kind; |
86 | IdentifierInfo *II; |
87 | |
88 | public: |
89 | TokenValue(tok::TokenKind Kind) : Kind(Kind), II(nullptr) { |
90 | (0) . __assert_fail ("Kind != tok..raw_identifier && \"Raw identifiers are not supported.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 90, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind != tok::raw_identifier && "Raw identifiers are not supported."); |
91 | (0) . __assert_fail ("Kind != tok..identifier && \"Identifiers should be created by TokenValue(IdentifierInfo *)\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 92, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind != tok::identifier && |
92 | (0) . __assert_fail ("Kind != tok..identifier && \"Identifiers should be created by TokenValue(IdentifierInfo *)\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 92, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Identifiers should be created by TokenValue(IdentifierInfo *)"); |
93 | (0) . __assert_fail ("!tok..isLiteral(Kind) && \"Literals are not supported.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 93, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!tok::isLiteral(Kind) && "Literals are not supported."); |
94 | (0) . __assert_fail ("!tok..isAnnotation(Kind) && \"Annotations are not supported.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 94, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!tok::isAnnotation(Kind) && "Annotations are not supported."); |
95 | } |
96 | |
97 | TokenValue(IdentifierInfo *II) : Kind(tok::identifier), II(II) {} |
98 | |
99 | bool operator==(const Token &Tok) const { |
100 | return Tok.getKind() == Kind && |
101 | (!II || II == Tok.getIdentifierInfo()); |
102 | } |
103 | }; |
104 | |
105 | |
106 | enum MacroUse { |
107 | |
108 | MU_Other = 0, |
109 | |
110 | |
111 | MU_Define = 1, |
112 | |
113 | |
114 | MU_Undef = 2 |
115 | }; |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | class Preprocessor { |
124 | friend class VAOptDefinitionContext; |
125 | friend class VariadicMacroScopeGuard; |
126 | |
127 | std::shared_ptr<PreprocessorOptions> PPOpts; |
128 | DiagnosticsEngine *Diags; |
129 | LangOptions &LangOpts; |
130 | const TargetInfo *Target = nullptr; |
131 | const TargetInfo *AuxTarget = nullptr; |
132 | FileManager &FileMgr; |
133 | SourceManager &SourceMgr; |
134 | std::unique_ptr<ScratchBuffer> ScratchBuf; |
135 | HeaderSearch &; |
136 | ModuleLoader &TheModuleLoader; |
137 | |
138 | |
139 | ExternalPreprocessorSource *ExternalSource; |
140 | |
141 | |
142 | |
143 | llvm::BumpPtrAllocator BP; |
144 | |
145 | |
146 | IdentifierInfo *Ident__LINE__, *Ident__FILE__; |
147 | IdentifierInfo *Ident__DATE__, *Ident__TIME__; |
148 | IdentifierInfo *Ident__INCLUDE_LEVEL__; |
149 | IdentifierInfo *Ident__BASE_FILE__; |
150 | IdentifierInfo *Ident__TIMESTAMP__; |
151 | IdentifierInfo *Ident__COUNTER__; |
152 | IdentifierInfo *Ident_Pragma, *Ident__pragma; |
153 | IdentifierInfo *Ident__identifier; |
154 | IdentifierInfo *Ident__VA_ARGS__; |
155 | IdentifierInfo *Ident__VA_OPT__; |
156 | IdentifierInfo *Ident__has_feature; |
157 | IdentifierInfo *Ident__has_extension; |
158 | IdentifierInfo *Ident__has_builtin; |
159 | IdentifierInfo *Ident__has_attribute; |
160 | IdentifierInfo *Ident__has_include; |
161 | IdentifierInfo *Ident__has_include_next; |
162 | IdentifierInfo *Ident__has_warning; |
163 | IdentifierInfo *Ident__is_identifier; |
164 | IdentifierInfo *Ident__building_module; |
165 | IdentifierInfo *Ident__MODULE__; |
166 | IdentifierInfo *Ident__has_cpp_attribute; |
167 | IdentifierInfo *Ident__has_c_attribute; |
168 | IdentifierInfo *Ident__has_declspec; |
169 | IdentifierInfo *Ident__is_target_arch; |
170 | IdentifierInfo *Ident__is_target_vendor; |
171 | IdentifierInfo *Ident__is_target_os; |
172 | IdentifierInfo *Ident__is_target_environment; |
173 | |
174 | |
175 | Token* ArgMacro; |
176 | |
177 | SourceLocation DATELoc, TIMELoc; |
178 | |
179 | |
180 | unsigned CounterValue = 0; |
181 | |
182 | enum { |
183 | |
184 | MaxAllowedIncludeStackDepth = 200 |
185 | }; |
186 | |
187 | |
188 | bool : 1; |
189 | bool : 1; |
190 | bool SuppressIncludeNotFoundError : 1; |
191 | |
192 | |
193 | bool InMacroArgs : 1; |
194 | |
195 | |
196 | bool : 1; |
197 | |
198 | |
199 | bool DisableMacroExpansion : 1; |
200 | |
201 | |
202 | |
203 | bool MacroExpansionInDirectivesOverride : 1; |
204 | |
205 | class ResetMacroExpansionHelper; |
206 | |
207 | |
208 | mutable bool ReadMacrosFromExternalSource : 1; |
209 | |
210 | |
211 | bool PragmasEnabled : 1; |
212 | |
213 | |
214 | bool PreprocessedOutput : 1; |
215 | |
216 | |
217 | bool ParsingIfOrElifDirective; |
218 | |
219 | |
220 | bool InMacroArgPreExpansion; |
221 | |
222 | |
223 | |
224 | mutable IdentifierTable Identifiers; |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | SelectorTable Selectors; |
236 | |
237 | |
238 | Builtin::Context BuiltinInfo; |
239 | |
240 | |
241 | |
242 | std::unique_ptr<PragmaNamespace> PragmaHandlers; |
243 | |
244 | |
245 | |
246 | std::unique_ptr<PragmaNamespace> PragmaHandlersBackup; |
247 | |
248 | |
249 | |
250 | std::vector<CommentHandler *> CommentHandlers; |
251 | |
252 | |
253 | |
254 | bool IncrementalProcessing = false; |
255 | |
256 | |
257 | TranslationUnitKind TUKind; |
258 | |
259 | |
260 | CodeCompletionHandler *CodeComplete = nullptr; |
261 | |
262 | |
263 | const FileEntry *CodeCompletionFile = nullptr; |
264 | |
265 | |
266 | unsigned CodeCompletionOffset = 0; |
267 | |
268 | |
269 | |
270 | SourceLocation CodeCompletionLoc; |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | SourceLocation CodeCompletionFileLoc; |
277 | |
278 | |
279 | |
280 | SourceLocation ModuleImportLoc; |
281 | |
282 | |
283 | SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> ModuleImportPath; |
284 | |
285 | |
286 | bool LastTokenWasAt = false; |
287 | |
288 | |
289 | |
290 | bool ModuleImportExpectsIdentifier = false; |
291 | |
292 | |
293 | |
294 | SourceLocation PragmaARCCFCodeAuditedLoc; |
295 | |
296 | |
297 | |
298 | SourceLocation PragmaAssumeNonNullLoc; |
299 | |
300 | |
301 | bool CodeCompletionReached = false; |
302 | |
303 | |
304 | |
305 | IdentifierInfo *CodeCompletionII = nullptr; |
306 | |
307 | |
308 | SourceRange CodeCompletionTokenRange; |
309 | |
310 | |
311 | |
312 | |
313 | const DirectoryEntry *MainFileDir = nullptr; |
314 | |
315 | |
316 | |
317 | |
318 | |
319 | |
320 | std::pair<int, bool> SkipMainFilePreamble; |
321 | |
322 | |
323 | |
324 | bool HasReachedMaxIncludeDepth = false; |
325 | |
326 | public: |
327 | struct PreambleSkipInfo { |
328 | SourceLocation HashTokenLoc; |
329 | SourceLocation IfTokenLoc; |
330 | bool FoundNonSkipPortion; |
331 | bool FoundElse; |
332 | SourceLocation ElseLoc; |
333 | |
334 | PreambleSkipInfo(SourceLocation HashTokenLoc, SourceLocation IfTokenLoc, |
335 | bool FoundNonSkipPortion, bool FoundElse, |
336 | SourceLocation ElseLoc) |
337 | : HashTokenLoc(HashTokenLoc), IfTokenLoc(IfTokenLoc), |
338 | FoundNonSkipPortion(FoundNonSkipPortion), FoundElse(FoundElse), |
339 | ElseLoc(ElseLoc) {} |
340 | }; |
341 | |
342 | private: |
343 | friend class ASTReader; |
344 | friend class MacroArgs; |
345 | |
346 | class PreambleConditionalStackStore { |
347 | enum State { |
348 | Off = 0, |
349 | Recording = 1, |
350 | Replaying = 2, |
351 | }; |
352 | |
353 | public: |
354 | PreambleConditionalStackStore() = default; |
355 | |
356 | void startRecording() { ConditionalStackState = Recording; } |
357 | void startReplaying() { ConditionalStackState = Replaying; } |
358 | bool isRecording() const { return ConditionalStackState == Recording; } |
359 | bool isReplaying() const { return ConditionalStackState == Replaying; } |
360 | |
361 | ArrayRef<PPConditionalInfo> getStack() const { |
362 | return ConditionalStack; |
363 | } |
364 | |
365 | void doneReplaying() { |
366 | ConditionalStack.clear(); |
367 | ConditionalStackState = Off; |
368 | } |
369 | |
370 | void setStack(ArrayRef<PPConditionalInfo> s) { |
371 | if (!isRecording() && !isReplaying()) |
372 | return; |
373 | ConditionalStack.clear(); |
374 | ConditionalStack.append(s.begin(), s.end()); |
375 | } |
376 | |
377 | bool hasRecordedPreamble() const { return !ConditionalStack.empty(); } |
378 | |
379 | bool reachedEOFWhileSkipping() const { return SkipInfo.hasValue(); } |
380 | |
381 | void clearSkipInfo() { SkipInfo.reset(); } |
382 | |
383 | llvm::Optional<PreambleSkipInfo> SkipInfo; |
384 | |
385 | private: |
386 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
387 | State ConditionalStackState = Off; |
388 | } PreambleConditionalStack; |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | std::unique_ptr<Lexer> CurLexer; |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | PreprocessorLexer *CurPPLexer = nullptr; |
401 | |
402 | |
403 | |
404 | |
405 | |
406 | |
407 | const DirectoryLookup *CurDirLookup = nullptr; |
408 | |
409 | |
410 | |
411 | |
412 | std::unique_ptr<TokenLexer> CurTokenLexer; |
413 | |
414 | |
415 | enum CurLexerKind { |
416 | CLK_Lexer, |
417 | CLK_TokenLexer, |
418 | CLK_CachingLexer, |
419 | CLK_LexAfterModuleImport |
420 | } CurLexerKind = CLK_Lexer; |
421 | |
422 | |
423 | |
424 | Module *CurLexerSubmodule = nullptr; |
425 | |
426 | |
427 | |
428 | |
429 | struct IncludeStackInfo { |
430 | enum CurLexerKind CurLexerKind; |
431 | Module *TheSubmodule; |
432 | std::unique_ptr<Lexer> TheLexer; |
433 | PreprocessorLexer *ThePPLexer; |
434 | std::unique_ptr<TokenLexer> TheTokenLexer; |
435 | const DirectoryLookup *TheDirLookup; |
436 | |
437 | |
438 | |
439 | IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule, |
440 | std::unique_ptr<Lexer> &&TheLexer, |
441 | PreprocessorLexer *ThePPLexer, |
442 | std::unique_ptr<TokenLexer> &&TheTokenLexer, |
443 | const DirectoryLookup *TheDirLookup) |
444 | : CurLexerKind(std::move(CurLexerKind)), |
445 | TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)), |
446 | ThePPLexer(std::move(ThePPLexer)), |
447 | TheTokenLexer(std::move(TheTokenLexer)), |
448 | TheDirLookup(std::move(TheDirLookup)) {} |
449 | }; |
450 | std::vector<IncludeStackInfo> IncludeMacroStack; |
451 | |
452 | |
453 | |
454 | std::unique_ptr<PPCallbacks> Callbacks; |
455 | |
456 | struct MacroExpandsInfo { |
457 | Token Tok; |
458 | MacroDefinition MD; |
459 | SourceRange Range; |
460 | |
461 | MacroExpandsInfo(Token Tok, MacroDefinition MD, SourceRange Range) |
462 | : Tok(Tok), MD(MD), Range(Range) {} |
463 | }; |
464 | SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks; |
465 | |
466 | |
467 | struct ModuleMacroInfo { |
468 | |
469 | MacroDirective *MD; |
470 | |
471 | |
472 | llvm::TinyPtrVector<ModuleMacro *> ActiveModuleMacros; |
473 | |
474 | |
475 | |
476 | unsigned ActiveModuleMacrosGeneration = 0; |
477 | |
478 | |
479 | bool IsAmbiguous = false; |
480 | |
481 | |
482 | llvm::TinyPtrVector<ModuleMacro *> OverriddenMacros; |
483 | |
484 | ModuleMacroInfo(MacroDirective *MD) : MD(MD) {} |
485 | }; |
486 | |
487 | |
488 | class MacroState { |
489 | mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *> State; |
490 | |
491 | ModuleMacroInfo *getModuleInfo(Preprocessor &PP, |
492 | const IdentifierInfo *II) const { |
493 | if (II->isOutOfDate()) |
494 | PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II)); |
495 | |
496 | |
497 | if (!II->hasMacroDefinition() || |
498 | (!PP.getLangOpts().Modules && |
499 | !PP.getLangOpts().ModulesLocalVisibility) || |
500 | !PP.CurSubmoduleState->VisibleModules.getGeneration()) |
501 | return nullptr; |
502 | |
503 | auto *Info = State.dyn_cast<ModuleMacroInfo*>(); |
504 | if (!Info) { |
505 | Info = new (PP.getPreprocessorAllocator()) |
506 | ModuleMacroInfo(State.get<MacroDirective *>()); |
507 | State = Info; |
508 | } |
509 | |
510 | if (PP.CurSubmoduleState->VisibleModules.getGeneration() != |
511 | Info->ActiveModuleMacrosGeneration) |
512 | PP.updateModuleMacroInfo(II, *Info); |
513 | return Info; |
514 | } |
515 | |
516 | public: |
517 | MacroState() : MacroState(nullptr) {} |
518 | MacroState(MacroDirective *MD) : State(MD) {} |
519 | |
520 | MacroState(MacroState &&O) noexcept : State(O.State) { |
521 | O.State = (MacroDirective *)nullptr; |
522 | } |
523 | |
524 | MacroState &operator=(MacroState &&O) noexcept { |
525 | auto S = O.State; |
526 | O.State = (MacroDirective *)nullptr; |
527 | State = S; |
528 | return *this; |
529 | } |
530 | |
531 | ~MacroState() { |
532 | if (auto *Info = State.dyn_cast<ModuleMacroInfo*>()) |
533 | Info->~ModuleMacroInfo(); |
534 | } |
535 | |
536 | MacroDirective *getLatest() const { |
537 | if (auto *Info = State.dyn_cast<ModuleMacroInfo*>()) |
538 | return Info->MD; |
539 | return State.get<MacroDirective*>(); |
540 | } |
541 | |
542 | void setLatest(MacroDirective *MD) { |
543 | if (auto *Info = State.dyn_cast<ModuleMacroInfo*>()) |
544 | Info->MD = MD; |
545 | else |
546 | State = MD; |
547 | } |
548 | |
549 | bool isAmbiguous(Preprocessor &PP, const IdentifierInfo *II) const { |
550 | auto *Info = getModuleInfo(PP, II); |
551 | return Info ? Info->IsAmbiguous : false; |
552 | } |
553 | |
554 | ArrayRef<ModuleMacro *> |
555 | getActiveModuleMacros(Preprocessor &PP, const IdentifierInfo *II) const { |
556 | if (auto *Info = getModuleInfo(PP, II)) |
557 | return Info->ActiveModuleMacros; |
558 | return None; |
559 | } |
560 | |
561 | MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc, |
562 | SourceManager &SourceMgr) const { |
563 | |
564 | if (auto *Latest = getLatest()) |
565 | return Latest->findDirectiveAtLoc(Loc, SourceMgr); |
566 | return {}; |
567 | } |
568 | |
569 | void overrideActiveModuleMacros(Preprocessor &PP, IdentifierInfo *II) { |
570 | if (auto *Info = getModuleInfo(PP, II)) { |
571 | Info->OverriddenMacros.insert(Info->OverriddenMacros.end(), |
572 | Info->ActiveModuleMacros.begin(), |
573 | Info->ActiveModuleMacros.end()); |
574 | Info->ActiveModuleMacros.clear(); |
575 | Info->IsAmbiguous = false; |
576 | } |
577 | } |
578 | |
579 | ArrayRef<ModuleMacro*> getOverriddenMacros() const { |
580 | if (auto *Info = State.dyn_cast<ModuleMacroInfo*>()) |
581 | return Info->OverriddenMacros; |
582 | return None; |
583 | } |
584 | |
585 | void setOverriddenMacros(Preprocessor &PP, |
586 | ArrayRef<ModuleMacro *> Overrides) { |
587 | auto *Info = State.dyn_cast<ModuleMacroInfo*>(); |
588 | if (!Info) { |
589 | if (Overrides.empty()) |
590 | return; |
591 | Info = new (PP.getPreprocessorAllocator()) |
592 | ModuleMacroInfo(State.get<MacroDirective *>()); |
593 | State = Info; |
594 | } |
595 | Info->OverriddenMacros.clear(); |
596 | Info->OverriddenMacros.insert(Info->OverriddenMacros.end(), |
597 | Overrides.begin(), Overrides.end()); |
598 | Info->ActiveModuleMacrosGeneration = 0; |
599 | } |
600 | }; |
601 | |
602 | |
603 | |
604 | |
605 | |
606 | |
607 | using MacroMap = llvm::DenseMap<const IdentifierInfo *, MacroState>; |
608 | |
609 | struct SubmoduleState; |
610 | |
611 | |
612 | struct BuildingSubmoduleInfo { |
613 | |
614 | Module *M; |
615 | |
616 | |
617 | SourceLocation ImportLoc; |
618 | |
619 | |
620 | bool IsPragma; |
621 | |
622 | |
623 | SubmoduleState *OuterSubmoduleState; |
624 | |
625 | |
626 | unsigned OuterPendingModuleMacroNames; |
627 | |
628 | BuildingSubmoduleInfo(Module *M, SourceLocation ImportLoc, bool IsPragma, |
629 | SubmoduleState *OuterSubmoduleState, |
630 | unsigned OuterPendingModuleMacroNames) |
631 | : M(M), ImportLoc(ImportLoc), IsPragma(IsPragma), |
632 | OuterSubmoduleState(OuterSubmoduleState), |
633 | OuterPendingModuleMacroNames(OuterPendingModuleMacroNames) {} |
634 | }; |
635 | SmallVector<BuildingSubmoduleInfo, 8> BuildingSubmoduleStack; |
636 | |
637 | |
638 | struct SubmoduleState { |
639 | |
640 | MacroMap Macros; |
641 | |
642 | |
643 | VisibleModuleSet VisibleModules; |
644 | |
645 | |
646 | |
647 | }; |
648 | std::map<Module *, SubmoduleState> Submodules; |
649 | |
650 | |
651 | SubmoduleState NullSubmoduleState; |
652 | |
653 | |
654 | |
655 | SubmoduleState *CurSubmoduleState; |
656 | |
657 | |
658 | llvm::FoldingSet<ModuleMacro> ModuleMacros; |
659 | |
660 | |
661 | llvm::SmallVector<const IdentifierInfo *, 32> PendingModuleMacroNames; |
662 | |
663 | |
664 | |
665 | llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro *>> |
666 | LeafModuleMacros; |
667 | |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | |
677 | using WarnUnusedMacroLocsTy = llvm::SmallPtrSet<SourceLocation, 32>; |
678 | WarnUnusedMacroLocsTy WarnUnusedMacroLocs; |
679 | |
680 | |
681 | |
682 | MacroArgs *MacroArgCache = nullptr; |
683 | |
684 | |
685 | |
686 | llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>> |
687 | PragmaPushMacroInfo; |
688 | |
689 | |
690 | unsigned NumDirectives = 0; |
691 | unsigned NumDefined = 0; |
692 | unsigned NumUndefined = 0; |
693 | unsigned NumPragma = 0; |
694 | unsigned NumIf = 0; |
695 | unsigned NumElse = 0; |
696 | unsigned NumEndif = 0; |
697 | unsigned NumEnteredSourceFiles = 0; |
698 | unsigned MaxIncludeStackDepth = 0; |
699 | unsigned NumMacroExpanded = 0; |
700 | unsigned NumFnMacroExpanded = 0; |
701 | unsigned NumBuiltinMacroExpanded = 0; |
702 | unsigned NumFastMacroExpanded = 0; |
703 | unsigned NumTokenPaste = 0; |
704 | unsigned NumFastTokenPaste = 0; |
705 | unsigned NumSkipped = 0; |
706 | |
707 | |
708 | |
709 | std::string Predefines; |
710 | |
711 | |
712 | FileID PredefinesFileID; |
713 | |
714 | |
715 | FileID ; |
716 | |
717 | |
718 | bool SkippingUntilPragmaHdrStop = false; |
719 | |
720 | |
721 | bool = false; |
722 | |
723 | |
724 | |
725 | enum { TokenLexerCacheSize = 8 }; |
726 | unsigned NumCachedTokenLexers; |
727 | std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize]; |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | SmallVector<Token, 16> MacroExpandedTokens; |
736 | std::vector<std::pair<TokenLexer *, size_t>> MacroExpandingLexersStack; |
737 | |
738 | |
739 | |
740 | |
741 | |
742 | |
743 | PreprocessingRecord *Record = nullptr; |
744 | |
745 | |
746 | using CachedTokensTy = SmallVector<Token, 1>; |
747 | |
748 | |
749 | |
750 | CachedTokensTy CachedTokens; |
751 | |
752 | |
753 | |
754 | |
755 | |
756 | |
757 | CachedTokensTy::size_type CachedLexPos = 0; |
758 | |
759 | |
760 | |
761 | |
762 | |
763 | |
764 | std::vector<CachedTokensTy::size_type> BacktrackPositions; |
765 | |
766 | struct MacroInfoChain { |
767 | MacroInfo MI; |
768 | MacroInfoChain *Next; |
769 | }; |
770 | |
771 | |
772 | |
773 | MacroInfoChain *MIChainHead = nullptr; |
774 | |
775 | void updateOutOfDateIdentifier(IdentifierInfo &II) const; |
776 | |
777 | public: |
778 | Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts, |
779 | DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM, |
780 | HeaderSearch &, ModuleLoader &TheModuleLoader, |
781 | IdentifierInfoLookup *IILookup = nullptr, |
782 | bool = false, |
783 | TranslationUnitKind TUKind = TU_Complete); |
784 | |
785 | ~Preprocessor(); |
786 | |
787 | |
788 | |
789 | |
790 | |
791 | |
792 | |
793 | void Initialize(const TargetInfo &Target, |
794 | const TargetInfo *AuxTarget = nullptr); |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | void InitializeForModelFile(); |
803 | |
804 | |
805 | void FinalizeForModelFile(); |
806 | |
807 | |
808 | |
809 | PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; } |
810 | |
811 | DiagnosticsEngine &getDiagnostics() const { return *Diags; } |
812 | void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; } |
813 | |
814 | const LangOptions &getLangOpts() const { return LangOpts; } |
815 | const TargetInfo &getTargetInfo() const { return *Target; } |
816 | const TargetInfo *getAuxTargetInfo() const { return AuxTarget; } |
817 | FileManager &getFileManager() const { return FileMgr; } |
818 | SourceManager &getSourceManager() const { return SourceMgr; } |
819 | HeaderSearch &() const { return HeaderInfo; } |
820 | |
821 | IdentifierTable &getIdentifierTable() { return Identifiers; } |
822 | const IdentifierTable &getIdentifierTable() const { return Identifiers; } |
823 | SelectorTable &getSelectorTable() { return Selectors; } |
824 | Builtin::Context &getBuiltinInfo() { return BuiltinInfo; } |
825 | llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; } |
826 | |
827 | void setExternalSource(ExternalPreprocessorSource *Source) { |
828 | ExternalSource = Source; |
829 | } |
830 | |
831 | ExternalPreprocessorSource *getExternalSource() const { |
832 | return ExternalSource; |
833 | } |
834 | |
835 | |
836 | ModuleLoader &getModuleLoader() const { return TheModuleLoader; } |
837 | |
838 | bool hadModuleLoaderFatalFailure() const { |
839 | return TheModuleLoader.HadFatalFailure; |
840 | } |
841 | |
842 | |
843 | bool isParsingIfOrElifDirective() const { |
844 | return ParsingIfOrElifDirective; |
845 | } |
846 | |
847 | |
848 | void (bool , bool ) { |
849 | this->KeepComments = KeepComments | KeepMacroComments; |
850 | this->KeepMacroComments = KeepMacroComments; |
851 | } |
852 | |
853 | bool () const { return KeepComments; } |
854 | |
855 | void setPragmasEnabled(bool Enabled) { PragmasEnabled = Enabled; } |
856 | bool getPragmasEnabled() const { return PragmasEnabled; } |
857 | |
858 | void SetSuppressIncludeNotFoundError(bool Suppress) { |
859 | SuppressIncludeNotFoundError = Suppress; |
860 | } |
861 | |
862 | bool GetSuppressIncludeNotFoundError() { |
863 | return SuppressIncludeNotFoundError; |
864 | } |
865 | |
866 | |
867 | |
868 | void setPreprocessedOutput(bool IsPreprocessedOutput) { |
869 | PreprocessedOutput = IsPreprocessedOutput; |
870 | } |
871 | |
872 | |
873 | |
874 | bool isPreprocessedOutput() const { return PreprocessedOutput; } |
875 | |
876 | |
877 | bool isCurrentLexer(const PreprocessorLexer *L) const { |
878 | return CurPPLexer == L; |
879 | } |
880 | |
881 | |
882 | |
883 | |
884 | |
885 | PreprocessorLexer *getCurrentLexer() const { return CurPPLexer; } |
886 | |
887 | |
888 | |
889 | |
890 | |
891 | PreprocessorLexer *getCurrentFileLexer() const; |
892 | |
893 | |
894 | |
895 | Module *getCurrentLexerSubmodule() const { return CurLexerSubmodule; } |
896 | |
897 | |
898 | FileID getPredefinesFileID() const { return PredefinesFileID; } |
899 | |
900 | |
901 | |
902 | |
903 | |
904 | |
905 | PPCallbacks *getPPCallbacks() const { return Callbacks.get(); } |
906 | void addPPCallbacks(std::unique_ptr<PPCallbacks> C) { |
907 | if (Callbacks) |
908 | C = llvm::make_unique<PPChainedCallbacks>(std::move(C), |
909 | std::move(Callbacks)); |
910 | Callbacks = std::move(C); |
911 | } |
912 | |
913 | |
914 | bool isMacroDefined(StringRef Id) { |
915 | return isMacroDefined(&Identifiers.get(Id)); |
916 | } |
917 | bool isMacroDefined(const IdentifierInfo *II) { |
918 | return II->hasMacroDefinition() && |
919 | (!getLangOpts().Modules || (bool)getMacroDefinition(II)); |
920 | } |
921 | |
922 | |
923 | |
924 | |
925 | bool isMacroDefinedInLocalModule(const IdentifierInfo *II, Module *M) { |
926 | if (!II->hasMacroDefinition()) |
927 | return false; |
928 | auto I = Submodules.find(M); |
929 | if (I == Submodules.end()) |
930 | return false; |
931 | auto J = I->second.Macros.find(II); |
932 | if (J == I->second.Macros.end()) |
933 | return false; |
934 | auto *MD = J->second.getLatest(); |
935 | return MD && MD->isDefined(); |
936 | } |
937 | |
938 | MacroDefinition getMacroDefinition(const IdentifierInfo *II) { |
939 | if (!II->hasMacroDefinition()) |
940 | return {}; |
941 | |
942 | MacroState &S = CurSubmoduleState->Macros[II]; |
943 | auto *MD = S.getLatest(); |
944 | while (MD && isa<VisibilityMacroDirective>(MD)) |
945 | MD = MD->getPrevious(); |
946 | return MacroDefinition(dyn_cast_or_null<DefMacroDirective>(MD), |
947 | S.getActiveModuleMacros(*this, II), |
948 | S.isAmbiguous(*this, II)); |
949 | } |
950 | |
951 | MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II, |
952 | SourceLocation Loc) { |
953 | if (!II->hadMacroDefinition()) |
954 | return {}; |
955 | |
956 | MacroState &S = CurSubmoduleState->Macros[II]; |
957 | MacroDirective::DefInfo DI; |
958 | if (auto *MD = S.getLatest()) |
959 | DI = MD->findDirectiveAtLoc(Loc, getSourceManager()); |
960 | |
961 | return MacroDefinition(DI.getDirective(), |
962 | S.getActiveModuleMacros(*this, II), |
963 | S.isAmbiguous(*this, II)); |
964 | } |
965 | |
966 | |
967 | |
968 | MacroDirective *getLocalMacroDirective(const IdentifierInfo *II) const { |
969 | if (!II->hasMacroDefinition()) |
970 | return nullptr; |
971 | |
972 | auto *MD = getLocalMacroDirectiveHistory(II); |
973 | if (!MD || MD->getDefinition().isUndefined()) |
974 | return nullptr; |
975 | |
976 | return MD; |
977 | } |
978 | |
979 | const MacroInfo *getMacroInfo(const IdentifierInfo *II) const { |
980 | return const_cast<Preprocessor*>(this)->getMacroInfo(II); |
981 | } |
982 | |
983 | MacroInfo *getMacroInfo(const IdentifierInfo *II) { |
984 | if (!II->hasMacroDefinition()) |
985 | return nullptr; |
986 | if (auto MD = getMacroDefinition(II)) |
987 | return MD.getMacroInfo(); |
988 | return nullptr; |
989 | } |
990 | |
991 | |
992 | |
993 | |
994 | |
995 | |
996 | MacroDirective *getLocalMacroDirectiveHistory(const IdentifierInfo *II) const; |
997 | |
998 | |
999 | void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD); |
1000 | DefMacroDirective *appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, |
1001 | SourceLocation Loc) { |
1002 | DefMacroDirective *MD = AllocateDefMacroDirective(MI, Loc); |
1003 | appendMacroDirective(II, MD); |
1004 | return MD; |
1005 | } |
1006 | DefMacroDirective *appendDefMacroDirective(IdentifierInfo *II, |
1007 | MacroInfo *MI) { |
1008 | return appendDefMacroDirective(II, MI, MI->getDefinitionLoc()); |
1009 | } |
1010 | |
1011 | |
1012 | void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, |
1013 | MacroDirective *MD); |
1014 | |
1015 | |
1016 | ModuleMacro *addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, |
1017 | ArrayRef<ModuleMacro *> Overrides, bool &IsNew); |
1018 | ModuleMacro *getModuleMacro(Module *Mod, IdentifierInfo *II); |
1019 | |
1020 | |
1021 | ArrayRef<ModuleMacro*> getLeafModuleMacros(const IdentifierInfo *II) const { |
1022 | if (II->isOutOfDate()) |
1023 | updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II)); |
1024 | auto I = LeafModuleMacros.find(II); |
1025 | if (I != LeafModuleMacros.end()) |
1026 | return I->second; |
1027 | return None; |
1028 | } |
1029 | |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | using macro_iterator = MacroMap::const_iterator; |
1035 | |
1036 | macro_iterator macro_begin(bool IncludeExternalMacros = true) const; |
1037 | macro_iterator macro_end(bool IncludeExternalMacros = true) const; |
1038 | |
1039 | llvm::iterator_range<macro_iterator> |
1040 | macros(bool IncludeExternalMacros = true) const { |
1041 | macro_iterator begin = macro_begin(IncludeExternalMacros); |
1042 | macro_iterator end = macro_end(IncludeExternalMacros); |
1043 | return llvm::make_range(begin, end); |
1044 | } |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | StringRef getLastMacroWithSpelling(SourceLocation Loc, |
1052 | ArrayRef<TokenValue> Tokens) const; |
1053 | |
1054 | const std::string &getPredefines() const { return Predefines; } |
1055 | |
1056 | |
1057 | |
1058 | |
1059 | void setPredefines(const char *P) { Predefines = P; } |
1060 | void setPredefines(StringRef P) { Predefines = P; } |
1061 | |
1062 | |
1063 | |
1064 | IdentifierInfo *getIdentifierInfo(StringRef Name) const { |
1065 | return &Identifiers.get(Name); |
1066 | } |
1067 | |
1068 | |
1069 | |
1070 | |
1071 | |
1072 | void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler); |
1073 | void AddPragmaHandler(PragmaHandler *Handler) { |
1074 | AddPragmaHandler(StringRef(), Handler); |
1075 | } |
1076 | |
1077 | |
1078 | |
1079 | |
1080 | |
1081 | |
1082 | void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler); |
1083 | void RemovePragmaHandler(PragmaHandler *Handler) { |
1084 | RemovePragmaHandler(StringRef(), Handler); |
1085 | } |
1086 | |
1087 | |
1088 | void IgnorePragmas(); |
1089 | |
1090 | |
1091 | void addCommentHandler(CommentHandler *Handler); |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | void removeCommentHandler(CommentHandler *Handler); |
1097 | |
1098 | |
1099 | void setCodeCompletionHandler(CodeCompletionHandler &Handler) { |
1100 | CodeComplete = &Handler; |
1101 | } |
1102 | |
1103 | |
1104 | CodeCompletionHandler *getCodeCompletionHandler() const { |
1105 | return CodeComplete; |
1106 | } |
1107 | |
1108 | |
1109 | void clearCodeCompletionHandler() { |
1110 | CodeComplete = nullptr; |
1111 | } |
1112 | |
1113 | |
1114 | |
1115 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
1116 | |
1117 | |
1118 | |
1119 | void CodeCompleteNaturalLanguage(); |
1120 | |
1121 | |
1122 | void setCodeCompletionIdentifierInfo(IdentifierInfo *Filter) { |
1123 | CodeCompletionII = Filter; |
1124 | } |
1125 | |
1126 | |
1127 | |
1128 | void setCodeCompletionTokenRange(const SourceLocation Start, |
1129 | const SourceLocation End) { |
1130 | CodeCompletionTokenRange = {Start, End}; |
1131 | } |
1132 | SourceRange getCodeCompletionTokenRange() const { |
1133 | return CodeCompletionTokenRange; |
1134 | } |
1135 | |
1136 | |
1137 | StringRef getCodeCompletionFilter() { |
1138 | if (CodeCompletionII) |
1139 | return CodeCompletionII->getName(); |
1140 | return {}; |
1141 | } |
1142 | |
1143 | |
1144 | |
1145 | PreprocessingRecord *getPreprocessingRecord() const { return Record; } |
1146 | |
1147 | |
1148 | |
1149 | void createPreprocessingRecord(); |
1150 | |
1151 | |
1152 | bool (const FileEntry *FE); |
1153 | |
1154 | |
1155 | bool (); |
1156 | |
1157 | |
1158 | bool (); |
1159 | |
1160 | |
1161 | bool creatingPCHWithPragmaHdrStop(); |
1162 | |
1163 | |
1164 | bool usingPCHWithPragmaHdrStop(); |
1165 | |
1166 | |
1167 | |
1168 | void SkipTokensWhileUsingPCH(); |
1169 | |
1170 | |
1171 | |
1172 | void HandleSkippedDirectiveWhileUsingPCH(Token &Result, |
1173 | SourceLocation HashLoc); |
1174 | |
1175 | |
1176 | |
1177 | void EnterMainSourceFile(); |
1178 | |
1179 | |
1180 | void EndSourceFile(); |
1181 | |
1182 | |
1183 | |
1184 | |
1185 | |
1186 | bool EnterSourceFile(FileID FID, const DirectoryLookup *Dir, |
1187 | SourceLocation Loc); |
1188 | |
1189 | |
1190 | |
1191 | |
1192 | |
1193 | |
1194 | |
1195 | void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro, |
1196 | MacroArgs *Args); |
1197 | |
1198 | |
1199 | |
1200 | |
1201 | |
1202 | |
1203 | |
1204 | |
1205 | |
1206 | |
1207 | |
1208 | |
1209 | private: |
1210 | void EnterTokenStream(const Token *Toks, unsigned NumToks, |
1211 | bool DisableMacroExpansion, bool OwnsTokens); |
1212 | |
1213 | public: |
1214 | void EnterTokenStream(std::unique_ptr<Token[]> Toks, unsigned NumToks, |
1215 | bool DisableMacroExpansion) { |
1216 | EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true); |
1217 | } |
1218 | |
1219 | void EnterTokenStream(ArrayRef<Token> Toks, bool DisableMacroExpansion) { |
1220 | EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false); |
1221 | } |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | |
1227 | void RemoveTopOfLexerStack(); |
1228 | |
1229 | |
1230 | |
1231 | |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | |
1237 | |
1238 | |
1239 | |
1240 | |
1241 | |
1242 | void EnableBacktrackAtThisPos(); |
1243 | |
1244 | |
1245 | void CommitBacktrackedTokens(); |
1246 | |
1247 | struct CachedTokensRange { |
1248 | CachedTokensTy::size_type Begin, End; |
1249 | }; |
1250 | |
1251 | private: |
1252 | |
1253 | |
1254 | Optional<CachedTokensRange> CachedTokenRangeToErase; |
1255 | |
1256 | public: |
1257 | |
1258 | |
1259 | CachedTokensRange LastCachedTokenRange(); |
1260 | |
1261 | |
1262 | |
1263 | void EraseCachedTokens(CachedTokensRange TokenRange); |
1264 | |
1265 | |
1266 | |
1267 | void Backtrack(); |
1268 | |
1269 | |
1270 | |
1271 | bool isBacktrackEnabled() const { return !BacktrackPositions.empty(); } |
1272 | |
1273 | |
1274 | void Lex(Token &Result); |
1275 | |
1276 | |
1277 | bool (Token &Result, bool AllowMacroExpansion = true); |
1278 | |
1279 | void LexAfterModuleImport(Token &Result); |
1280 | |
1281 | void makeModuleVisible(Module *M, SourceLocation Loc); |
1282 | |
1283 | SourceLocation getModuleImportLoc(Module *M) const { |
1284 | return CurSubmoduleState->VisibleModules.getImportLoc(M); |
1285 | } |
1286 | |
1287 | |
1288 | |
1289 | |
1290 | bool LexStringLiteral(Token &Result, std::string &String, |
1291 | const char *DiagnosticTag, bool AllowMacroExpansion) { |
1292 | if (AllowMacroExpansion) |
1293 | Lex(Result); |
1294 | else |
1295 | LexUnexpandedToken(Result); |
1296 | return FinishLexStringLiteral(Result, String, DiagnosticTag, |
1297 | AllowMacroExpansion); |
1298 | } |
1299 | |
1300 | |
1301 | |
1302 | bool FinishLexStringLiteral(Token &Result, std::string &String, |
1303 | const char *DiagnosticTag, |
1304 | bool AllowMacroExpansion); |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | |
1311 | void (Token &Result) { |
1312 | do |
1313 | Lex(Result); |
1314 | while (Result.getKind() == tok::comment); |
1315 | } |
1316 | |
1317 | |
1318 | void LexUnexpandedToken(Token &Result) { |
1319 | |
1320 | bool OldVal = DisableMacroExpansion; |
1321 | DisableMacroExpansion = true; |
1322 | |
1323 | Lex(Result); |
1324 | |
1325 | |
1326 | DisableMacroExpansion = OldVal; |
1327 | } |
1328 | |
1329 | |
1330 | |
1331 | void LexUnexpandedNonComment(Token &Result) { |
1332 | do |
1333 | LexUnexpandedToken(Result); |
1334 | while (Result.getKind() == tok::comment); |
1335 | } |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value); |
1341 | |
1342 | |
1343 | void SetMacroExpansionOnlyInDirectives() { |
1344 | DisableMacroExpansion = true; |
1345 | MacroExpansionInDirectivesOverride = true; |
1346 | } |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | |
1352 | |
1353 | |
1354 | |
1355 | const Token &LookAhead(unsigned N) { |
1356 | if (CachedLexPos + N < CachedTokens.size()) |
1357 | return CachedTokens[CachedLexPos+N]; |
1358 | else |
1359 | return PeekAhead(N+1); |
1360 | } |
1361 | |
1362 | |
1363 | |
1364 | |
1365 | |
1366 | |
1367 | void RevertCachedTokens(unsigned N) { |
1368 | (0) . __assert_fail ("isBacktrackEnabled() && \"Should only be called when tokens are cached for backtracking\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1369, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isBacktrackEnabled() && |
1369 | (0) . __assert_fail ("isBacktrackEnabled() && \"Should only be called when tokens are cached for backtracking\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1369, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Should only be called when tokens are cached for backtracking"); |
1370 | (0) . __assert_fail ("signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back()) && \"Should revert tokens up to the last backtrack position, not more\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1371, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back()) |
1371 | (0) . __assert_fail ("signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back()) && \"Should revert tokens up to the last backtrack position, not more\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1371, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> && "Should revert tokens up to the last backtrack position, not more"); |
1372 | (0) . __assert_fail ("signed(CachedLexPos) - signed(N) >= 0 && \"Corrupted backtrack positions ?\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1373, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(signed(CachedLexPos) - signed(N) >= 0 && |
1373 | (0) . __assert_fail ("signed(CachedLexPos) - signed(N) >= 0 && \"Corrupted backtrack positions ?\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1373, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Corrupted backtrack positions ?"); |
1374 | CachedLexPos -= N; |
1375 | } |
1376 | |
1377 | |
1378 | |
1379 | |
1380 | |
1381 | void EnterToken(const Token &Tok) { |
1382 | EnterCachingLexMode(); |
1383 | CachedTokens.insert(CachedTokens.begin()+CachedLexPos, Tok); |
1384 | } |
1385 | |
1386 | |
1387 | |
1388 | |
1389 | |
1390 | |
1391 | |
1392 | |
1393 | |
1394 | void AnnotateCachedTokens(const Token &Tok) { |
1395 | (0) . __assert_fail ("Tok.isAnnotation() && \"Expected annotation token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1395, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Tok.isAnnotation() && "Expected annotation token"); |
1396 | if (CachedLexPos != 0 && isBacktrackEnabled()) |
1397 | AnnotatePreviousCachedTokens(Tok); |
1398 | } |
1399 | |
1400 | |
1401 | |
1402 | SourceLocation getLastCachedTokenLocation() const { |
1403 | assert(CachedLexPos != 0); |
1404 | return CachedTokens[CachedLexPos-1].getLastLoc(); |
1405 | } |
1406 | |
1407 | |
1408 | |
1409 | bool IsPreviousCachedToken(const Token &Tok) const; |
1410 | |
1411 | |
1412 | |
1413 | |
1414 | |
1415 | |
1416 | void ReplacePreviousCachedToken(ArrayRef<Token> NewToks); |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | void ReplaceLastTokenWithAnnotation(const Token &Tok) { |
1427 | (0) . __assert_fail ("Tok.isAnnotation() && \"Expected annotation token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1427, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Tok.isAnnotation() && "Expected annotation token"); |
1428 | if (CachedLexPos != 0 && isBacktrackEnabled()) |
1429 | CachedTokens[CachedLexPos-1] = Tok; |
1430 | } |
1431 | |
1432 | |
1433 | void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, |
1434 | void *AnnotationVal); |
1435 | |
1436 | |
1437 | |
1438 | void TypoCorrectToken(const Token &Tok) { |
1439 | (0) . __assert_fail ("Tok.getIdentifierInfo() && \"Expected identifier token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1439, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Tok.getIdentifierInfo() && "Expected identifier token"); |
1440 | if (CachedLexPos != 0 && isBacktrackEnabled()) |
1441 | CachedTokens[CachedLexPos-1] = Tok; |
1442 | } |
1443 | |
1444 | |
1445 | |
1446 | void recomputeCurLexerKind(); |
1447 | |
1448 | |
1449 | bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; } |
1450 | |
1451 | |
1452 | void enableIncrementalProcessing(bool value = true) { |
1453 | IncrementalProcessing = value; |
1454 | } |
1455 | |
1456 | |
1457 | |
1458 | |
1459 | |
1460 | |
1461 | |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | |
1470 | bool SetCodeCompletionPoint(const FileEntry *File, |
1471 | unsigned Line, unsigned Column); |
1472 | |
1473 | |
1474 | bool isCodeCompletionEnabled() const { return CodeCompletionFile != nullptr; } |
1475 | |
1476 | |
1477 | |
1478 | |
1479 | |
1480 | SourceLocation getCodeCompletionLoc() const { return CodeCompletionLoc; } |
1481 | |
1482 | |
1483 | |
1484 | |
1485 | |
1486 | SourceLocation getCodeCompletionFileLoc() const { |
1487 | return CodeCompletionFileLoc; |
1488 | } |
1489 | |
1490 | |
1491 | |
1492 | bool isCodeCompletionReached() const { return CodeCompletionReached; } |
1493 | |
1494 | |
1495 | void setCodeCompletionReached() { |
1496 | (0) . __assert_fail ("isCodeCompletionEnabled() && \"Code-completion not enabled!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1496, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isCodeCompletionEnabled() && "Code-completion not enabled!"); |
1497 | CodeCompletionReached = true; |
1498 | |
1499 | getDiagnostics().setSuppressAllDiagnostics(true); |
1500 | } |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | |
1506 | SourceLocation getPragmaARCCFCodeAuditedLoc() const { |
1507 | return PragmaARCCFCodeAuditedLoc; |
1508 | } |
1509 | |
1510 | |
1511 | |
1512 | void setPragmaARCCFCodeAuditedLoc(SourceLocation Loc) { |
1513 | PragmaARCCFCodeAuditedLoc = Loc; |
1514 | } |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | |
1520 | SourceLocation getPragmaAssumeNonNullLoc() const { |
1521 | return PragmaAssumeNonNullLoc; |
1522 | } |
1523 | |
1524 | |
1525 | |
1526 | void setPragmaAssumeNonNullLoc(SourceLocation Loc) { |
1527 | PragmaAssumeNonNullLoc = Loc; |
1528 | } |
1529 | |
1530 | |
1531 | |
1532 | void setMainFileDir(const DirectoryEntry *Dir) { |
1533 | MainFileDir = Dir; |
1534 | } |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | |
1541 | |
1542 | void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine) { |
1543 | SkipMainFilePreamble.first = Bytes; |
1544 | SkipMainFilePreamble.second = StartOfLine; |
1545 | } |
1546 | |
1547 | |
1548 | |
1549 | |
1550 | DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const { |
1551 | return Diags->Report(Loc, DiagID); |
1552 | } |
1553 | |
1554 | DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const { |
1555 | return Diags->Report(Tok.getLocation(), DiagID); |
1556 | } |
1557 | |
1558 | |
1559 | |
1560 | |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | StringRef getSpelling(SourceLocation loc, |
1566 | SmallVectorImpl<char> &buffer, |
1567 | bool *invalid = nullptr) const { |
1568 | return Lexer::getSpelling(loc, buffer, SourceMgr, LangOpts, invalid); |
1569 | } |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | |
1579 | std::string getSpelling(const Token &Tok, bool *Invalid = nullptr) const { |
1580 | return Lexer::getSpelling(Tok, SourceMgr, LangOpts, Invalid); |
1581 | } |
1582 | |
1583 | |
1584 | |
1585 | |
1586 | |
1587 | |
1588 | |
1589 | |
1590 | |
1591 | |
1592 | |
1593 | |
1594 | |
1595 | unsigned getSpelling(const Token &Tok, const char *&Buffer, |
1596 | bool *Invalid = nullptr) const { |
1597 | return Lexer::getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid); |
1598 | } |
1599 | |
1600 | |
1601 | |
1602 | |
1603 | |
1604 | StringRef getSpelling(const Token &Tok, |
1605 | SmallVectorImpl<char> &Buffer, |
1606 | bool *Invalid = nullptr) const; |
1607 | |
1608 | |
1609 | |
1610 | bool getRawToken(SourceLocation Loc, Token &Result, |
1611 | bool IgnoreWhiteSpace = false) { |
1612 | return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace); |
1613 | } |
1614 | |
1615 | |
1616 | |
1617 | char |
1618 | getSpellingOfSingleCharacterNumericConstant(const Token &Tok, |
1619 | bool *Invalid = nullptr) const { |
1620 | (0) . __assert_fail ("Tok.is(tok..numeric_constant) && Tok.getLength() == 1 && \"Called on unsupported token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1621, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::numeric_constant) && |
1621 | (0) . __assert_fail ("Tok.is(tok..numeric_constant) && Tok.getLength() == 1 && \"Called on unsupported token\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1621, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> Tok.getLength() == 1 && "Called on unsupported token"); |
1622 | (0) . __assert_fail ("!Tok.needsCleaning() && \"Token can't need cleaning with length 1\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1622, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!Tok.needsCleaning() && "Token can't need cleaning with length 1"); |
1623 | |
1624 | |
1625 | if (const char *D = Tok.getLiteralData()) |
1626 | return *D; |
1627 | |
1628 | |
1629 | |
1630 | return *SourceMgr.getCharacterData(Tok.getLocation(), Invalid); |
1631 | } |
1632 | |
1633 | |
1634 | |
1635 | |
1636 | |
1637 | |
1638 | |
1639 | |
1640 | |
1641 | StringRef getImmediateMacroName(SourceLocation Loc) { |
1642 | return Lexer::getImmediateMacroName(Loc, SourceMgr, getLangOpts()); |
1643 | } |
1644 | |
1645 | |
1646 | |
1647 | |
1648 | |
1649 | |
1650 | void CreateString(StringRef Str, Token &Tok, |
1651 | SourceLocation ExpansionLocStart = SourceLocation(), |
1652 | SourceLocation ExpansionLocEnd = SourceLocation()); |
1653 | |
1654 | |
1655 | |
1656 | |
1657 | SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length); |
1658 | |
1659 | |
1660 | |
1661 | |
1662 | |
1663 | |
1664 | |
1665 | |
1666 | |
1667 | |
1668 | |
1669 | |
1670 | |
1671 | |
1672 | |
1673 | |
1674 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0) { |
1675 | return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, LangOpts); |
1676 | } |
1677 | |
1678 | |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | bool isAtStartOfMacroExpansion(SourceLocation loc, |
1684 | SourceLocation *MacroBegin = nullptr) const { |
1685 | return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts, |
1686 | MacroBegin); |
1687 | } |
1688 | |
1689 | |
1690 | |
1691 | |
1692 | |
1693 | |
1694 | bool isAtEndOfMacroExpansion(SourceLocation loc, |
1695 | SourceLocation *MacroEnd = nullptr) const { |
1696 | return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd); |
1697 | } |
1698 | |
1699 | |
1700 | void DumpToken(const Token &Tok, bool DumpFlags = false) const; |
1701 | void DumpLocation(SourceLocation Loc) const; |
1702 | void DumpMacro(const MacroInfo &MI) const; |
1703 | void dumpMacroInfo(const IdentifierInfo *II); |
1704 | |
1705 | |
1706 | |
1707 | SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, |
1708 | unsigned Char) const { |
1709 | return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, LangOpts); |
1710 | } |
1711 | |
1712 | |
1713 | |
1714 | |
1715 | |
1716 | void IncrementPasteCounter(bool isFast) { |
1717 | if (isFast) |
1718 | ++NumFastTokenPaste; |
1719 | else |
1720 | ++NumTokenPaste; |
1721 | } |
1722 | |
1723 | void PrintStats(); |
1724 | |
1725 | size_t getTotalMemory() const; |
1726 | |
1727 | |
1728 | |
1729 | |
1730 | void HandleMicrosoftCommentPaste(Token &Tok); |
1731 | |
1732 | |
1733 | |
1734 | |
1735 | |
1736 | |
1737 | |
1738 | |
1739 | IdentifierInfo *LookUpIdentifierInfo(Token &Identifier) const; |
1740 | |
1741 | private: |
1742 | llvm::DenseMap<IdentifierInfo*,unsigned> PoisonReasons; |
1743 | |
1744 | public: |
1745 | |
1746 | |
1747 | |
1748 | |
1749 | void SetPoisonReason(IdentifierInfo *II, unsigned DiagID); |
1750 | |
1751 | |
1752 | void HandlePoisonedIdentifier(Token & Identifier); |
1753 | |
1754 | void MaybeHandlePoisonedIdentifier(Token & Identifier) { |
1755 | if(IdentifierInfo * II = Identifier.getIdentifierInfo()) { |
1756 | if(II->isPoisoned()) { |
1757 | HandlePoisonedIdentifier(Identifier); |
1758 | } |
1759 | } |
1760 | } |
1761 | |
1762 | private: |
1763 | |
1764 | |
1765 | |
1766 | IdentifierInfo *Ident__exception_code, |
1767 | *Ident___exception_code, |
1768 | *Ident_GetExceptionCode; |
1769 | |
1770 | IdentifierInfo *Ident__exception_info, |
1771 | *Ident___exception_info, |
1772 | *Ident_GetExceptionInfo; |
1773 | |
1774 | IdentifierInfo *Ident__abnormal_termination, |
1775 | *Ident___abnormal_termination, |
1776 | *Ident_AbnormalTermination; |
1777 | |
1778 | const char *getCurLexerEndPos(); |
1779 | void (const Module &Mod); |
1780 | |
1781 | public: |
1782 | void PoisonSEHIdentifiers(bool Poison = true); |
1783 | |
1784 | |
1785 | |
1786 | |
1787 | |
1788 | |
1789 | |
1790 | |
1791 | |
1792 | bool HandleIdentifier(Token &Identifier); |
1793 | |
1794 | |
1795 | |
1796 | |
1797 | |
1798 | |
1799 | bool HandleEndOfFile(Token &Result, bool isEndOfMacro = false); |
1800 | |
1801 | |
1802 | |
1803 | bool HandleEndOfTokenLexer(Token &Result); |
1804 | |
1805 | |
1806 | |
1807 | |
1808 | |
1809 | |
1810 | void HandleDirective(Token &Result); |
1811 | |
1812 | |
1813 | |
1814 | |
1815 | |
1816 | |
1817 | void CheckEndOfDirective(const char *DirType, bool EnableMacros = false); |
1818 | |
1819 | |
1820 | |
1821 | SourceRange DiscardUntilEndOfDirective(); |
1822 | |
1823 | |
1824 | |
1825 | bool SawDateOrTime() const { |
1826 | return DATELoc != SourceLocation() || TIMELoc != SourceLocation(); |
1827 | } |
1828 | unsigned getCounterValue() const { return CounterValue; } |
1829 | void setCounterValue(unsigned V) { CounterValue = V; } |
1830 | |
1831 | |
1832 | Module *getCurrentModule(); |
1833 | |
1834 | |
1835 | MacroInfo *AllocateMacroInfo(SourceLocation L); |
1836 | |
1837 | |
1838 | |
1839 | |
1840 | |
1841 | |
1842 | |
1843 | |
1844 | |
1845 | |
1846 | bool GetIncludeFilenameSpelling(SourceLocation Loc,StringRef &Buffer); |
1847 | |
1848 | |
1849 | |
1850 | |
1851 | |
1852 | const FileEntry *(SourceLocation FilenameLoc, StringRef Filename, |
1853 | bool isAngled, const DirectoryLookup *FromDir, |
1854 | const FileEntry *FromFile, |
1855 | const DirectoryLookup *&CurDir, |
1856 | SmallVectorImpl<char> *SearchPath, |
1857 | SmallVectorImpl<char> *RelativePath, |
1858 | ModuleMap::KnownHeader *SuggestedModule, |
1859 | bool *IsMapped, bool *IsFrameworkFound, |
1860 | bool SkipCache = false); |
1861 | |
1862 | |
1863 | |
1864 | |
1865 | |
1866 | |
1867 | const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; } |
1868 | |
1869 | |
1870 | bool isInPrimaryFile() const; |
1871 | |
1872 | |
1873 | |
1874 | bool LexOnOffSwitch(tok::OnOffSwitch &Result); |
1875 | |
1876 | bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, |
1877 | bool *ShadowFlag = nullptr); |
1878 | |
1879 | void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma); |
1880 | Module *LeaveSubmodule(bool ForPragma); |
1881 | |
1882 | private: |
1883 | friend void TokenLexer::ExpandFunctionArguments(); |
1884 | |
1885 | void PushIncludeMacroStack() { |
1886 | (0) . __assert_fail ("CurLexerKind != CLK_CachingLexer && \"cannot push a caching lexer\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 1886, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer"); |
1887 | IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule, |
1888 | std::move(CurLexer), CurPPLexer, |
1889 | std::move(CurTokenLexer), CurDirLookup); |
1890 | CurPPLexer = nullptr; |
1891 | } |
1892 | |
1893 | void PopIncludeMacroStack() { |
1894 | CurLexer = std::move(IncludeMacroStack.back().TheLexer); |
1895 | CurPPLexer = IncludeMacroStack.back().ThePPLexer; |
1896 | CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer); |
1897 | CurDirLookup = IncludeMacroStack.back().TheDirLookup; |
1898 | CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule; |
1899 | CurLexerKind = IncludeMacroStack.back().CurLexerKind; |
1900 | IncludeMacroStack.pop_back(); |
1901 | } |
1902 | |
1903 | void PropagateLineStartLeadingSpaceInfo(Token &Result); |
1904 | |
1905 | |
1906 | |
1907 | bool needModuleMacros() const; |
1908 | |
1909 | |
1910 | |
1911 | void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info); |
1912 | |
1913 | DefMacroDirective *AllocateDefMacroDirective(MacroInfo *MI, |
1914 | SourceLocation Loc); |
1915 | UndefMacroDirective *AllocateUndefMacroDirective(SourceLocation UndefLoc); |
1916 | VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc, |
1917 | bool isPublic); |
1918 | |
1919 | |
1920 | |
1921 | |
1922 | |
1923 | |
1924 | |
1925 | |
1926 | |
1927 | |
1928 | |
1929 | void ReadMacroName(Token &MacroNameTok, MacroUse IsDefineUndef = MU_Other, |
1930 | bool *ShadowFlag = nullptr); |
1931 | |
1932 | |
1933 | |
1934 | |
1935 | |
1936 | |
1937 | |
1938 | |
1939 | |
1940 | |
1941 | MacroInfo *ReadOptionalMacroParameterListAndBody( |
1942 | const Token &MacroNameTok, bool ); |
1943 | |
1944 | |
1945 | |
1946 | |
1947 | |
1948 | bool ReadMacroParameterList(MacroInfo *MI, Token& LastTok); |
1949 | |
1950 | |
1951 | |
1952 | |
1953 | |
1954 | |
1955 | |
1956 | |
1957 | |
1958 | void SkipExcludedConditionalBlock(SourceLocation HashTokenLoc, |
1959 | SourceLocation IfTokenLoc, |
1960 | bool FoundNonSkipPortion, bool FoundElse, |
1961 | SourceLocation ElseLoc = SourceLocation()); |
1962 | |
1963 | |
1964 | |
1965 | struct DirectiveEvalResult { |
1966 | |
1967 | bool Conditional; |
1968 | |
1969 | |
1970 | bool IncludedUndefinedIds; |
1971 | |
1972 | |
1973 | SourceRange ExprRange; |
1974 | }; |
1975 | |
1976 | |
1977 | |
1978 | |
1979 | |
1980 | DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); |
1981 | |
1982 | |
1983 | |
1984 | void RegisterBuiltinPragmas(); |
1985 | |
1986 | |
1987 | void RegisterBuiltinMacros(); |
1988 | |
1989 | |
1990 | |
1991 | |
1992 | bool HandleMacroExpandedIdentifier(Token &Identifier, const MacroDefinition &MD); |
1993 | |
1994 | |
1995 | |
1996 | |
1997 | |
1998 | |
1999 | Token *cacheMacroExpandedTokens(TokenLexer *tokLexer, |
2000 | ArrayRef<Token> tokens); |
2001 | |
2002 | void removeCachedMacroExpandedTokensOfLastLexer(); |
2003 | |
2004 | |
2005 | |
2006 | |
2007 | bool isNextPPTokenLParen(); |
2008 | |
2009 | |
2010 | |
2011 | MacroArgs *ReadMacroCallArgumentList(Token &MacroName, MacroInfo *MI, |
2012 | SourceLocation &MacroEnd); |
2013 | |
2014 | |
2015 | |
2016 | void ExpandBuiltinMacro(Token &Tok); |
2017 | |
2018 | |
2019 | |
2020 | |
2021 | void Handle_Pragma(Token &Tok); |
2022 | |
2023 | |
2024 | |
2025 | void HandleMicrosoft__pragma(Token &Tok); |
2026 | |
2027 | |
2028 | |
2029 | void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir); |
2030 | |
2031 | |
2032 | void setPredefinesFileID(FileID FID) { |
2033 | (0) . __assert_fail ("PredefinesFileID.isInvalid() && \"PredefinesFileID already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Lex/Preprocessor.h", 2033, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(PredefinesFileID.isInvalid() && "PredefinesFileID already set!"); |
2034 | PredefinesFileID = FID; |
2035 | } |
2036 | |
2037 | |
2038 | void (FileID FID); |
2039 | |
2040 | |
2041 | |
2042 | static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) { |
2043 | return L ? !L->isPragmaLexer() : P != nullptr; |
2044 | } |
2045 | |
2046 | static bool IsFileLexer(const IncludeStackInfo& I) { |
2047 | return IsFileLexer(I.TheLexer.get(), I.ThePPLexer); |
2048 | } |
2049 | |
2050 | bool IsFileLexer() const { |
2051 | return IsFileLexer(CurLexer.get(), CurPPLexer); |
2052 | } |
2053 | |
2054 | |
2055 | |
2056 | void CachingLex(Token &Result); |
2057 | |
2058 | bool InCachingLexMode() const { |
2059 | |
2060 | |
2061 | return !CurPPLexer && !CurTokenLexer && !IncludeMacroStack.empty(); |
2062 | } |
2063 | |
2064 | void EnterCachingLexMode(); |
2065 | |
2066 | void ExitCachingLexMode() { |
2067 | if (InCachingLexMode()) |
2068 | RemoveTopOfLexerStack(); |
2069 | } |
2070 | |
2071 | const Token &PeekAhead(unsigned N); |
2072 | void AnnotatePreviousCachedTokens(const Token &Tok); |
2073 | |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | void HandleLineDirective(); |
2079 | void HandleDigitDirective(Token &Tok); |
2080 | void HandleUserDiagnosticDirective(Token &Tok, bool isWarning); |
2081 | void HandleIdentSCCSDirective(Token &Tok); |
2082 | void HandleMacroPublicDirective(Token &Tok); |
2083 | void HandleMacroPrivateDirective(); |
2084 | |
2085 | |
2086 | void HandleIncludeDirective(SourceLocation HashLoc, |
2087 | Token &Tok, |
2088 | const DirectoryLookup *LookupFrom = nullptr, |
2089 | const FileEntry *LookupFromFile = nullptr, |
2090 | bool isImport = false); |
2091 | void HandleIncludeNextDirective(SourceLocation HashLoc, Token &Tok); |
2092 | void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok); |
2093 | void HandleImportDirective(SourceLocation HashLoc, Token &Tok); |
2094 | void HandleMicrosoftImportDirective(Token &Tok); |
2095 | |
2096 | public: |
2097 | |
2098 | |
2099 | |
2100 | static bool checkModuleIsAvailable(const LangOptions &LangOpts, |
2101 | const TargetInfo &TargetInfo, |
2102 | DiagnosticsEngine &Diags, Module *M); |
2103 | |
2104 | |
2105 | |
2106 | |
2107 | |
2108 | Module *getModuleForLocation(SourceLocation Loc); |
2109 | |
2110 | |
2111 | |
2112 | |
2113 | |
2114 | |
2115 | |
2116 | |
2117 | |
2118 | |
2119 | |
2120 | |
2121 | const FileEntry *(SourceLocation IncLoc, |
2122 | Module *M, |
2123 | SourceLocation MLoc); |
2124 | |
2125 | bool isRecordingPreamble() const { |
2126 | return PreambleConditionalStack.isRecording(); |
2127 | } |
2128 | |
2129 | bool hasRecordedPreamble() const { |
2130 | return PreambleConditionalStack.hasRecordedPreamble(); |
2131 | } |
2132 | |
2133 | ArrayRef<PPConditionalInfo> getPreambleConditionalStack() const { |
2134 | return PreambleConditionalStack.getStack(); |
2135 | } |
2136 | |
2137 | void setRecordedPreambleConditionalStack(ArrayRef<PPConditionalInfo> s) { |
2138 | PreambleConditionalStack.setStack(s); |
2139 | } |
2140 | |
2141 | void setReplayablePreambleConditionalStack(ArrayRef<PPConditionalInfo> s, |
2142 | llvm::Optional<PreambleSkipInfo> SkipInfo) { |
2143 | PreambleConditionalStack.startReplaying(); |
2144 | PreambleConditionalStack.setStack(s); |
2145 | PreambleConditionalStack.SkipInfo = SkipInfo; |
2146 | } |
2147 | |
2148 | llvm::Optional<PreambleSkipInfo> getPreambleSkipInfo() const { |
2149 | return PreambleConditionalStack.SkipInfo; |
2150 | } |
2151 | |
2152 | private: |
2153 | |
2154 | |
2155 | void replayPreambleConditionalStack(); |
2156 | |
2157 | |
2158 | void HandleDefineDirective(Token &Tok, bool ); |
2159 | void HandleUndefDirective(); |
2160 | |
2161 | |
2162 | void HandleIfdefDirective(Token &Result, const Token &HashToken, |
2163 | bool isIfndef, bool ReadAnyTokensBeforeDirective); |
2164 | void HandleIfDirective(Token &IfToken, const Token &HashToken, |
2165 | bool ReadAnyTokensBeforeDirective); |
2166 | void HandleEndifDirective(Token &EndifToken); |
2167 | void HandleElseDirective(Token &Result, const Token &HashToken); |
2168 | void HandleElifDirective(Token &ElifToken, const Token &HashToken); |
2169 | |
2170 | |
2171 | void HandlePragmaDirective(SourceLocation IntroducerLoc, |
2172 | PragmaIntroducerKind Introducer); |
2173 | |
2174 | public: |
2175 | void HandlePragmaOnce(Token &OnceTok); |
2176 | void HandlePragmaMark(); |
2177 | void HandlePragmaPoison(); |
2178 | void HandlePragmaSystemHeader(Token &); |
2179 | void HandlePragmaDependency(Token &DependencyTok); |
2180 | void HandlePragmaPushMacro(Token &Tok); |
2181 | void HandlePragmaPopMacro(Token &Tok); |
2182 | void HandlePragmaIncludeAlias(Token &Tok); |
2183 | void HandlePragmaModuleBuild(Token &Tok); |
2184 | void HandlePragmaHdrstop(Token &Tok); |
2185 | IdentifierInfo *ParsePragmaPushOrPopMacro(Token &Tok); |
2186 | |
2187 | |
2188 | |
2189 | bool HandleComment(Token &result, SourceRange ); |
2190 | |
2191 | |
2192 | |
2193 | void markMacroAsUsed(MacroInfo *MI); |
2194 | }; |
2195 | |
2196 | |
2197 | |
2198 | class CommentHandler { |
2199 | public: |
2200 | virtual ~CommentHandler(); |
2201 | |
2202 | |
2203 | |
2204 | virtual bool HandleComment(Preprocessor &PP, SourceRange ) = 0; |
2205 | }; |
2206 | |
2207 | |
2208 | using PragmaHandlerRegistry = llvm::Registry<PragmaHandler>; |
2209 | |
2210 | } |
2211 | |
2212 | #endif |
2213 | |