MCPcopy Create free account
hub / github.com/KDAB/codebrowser / PreprocessorCallback

Class PreprocessorCallback

generator/preprocessorcallback.h:35–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33class Annotator;
34
35class PreprocessorCallback : public clang::PPCallbacks {
36 Annotator &annotator;
37 clang::Preprocessor &PP;
38 bool disabled = false; // To prevent recurstion
39 bool seenPragma = false; // To detect _Pragma in expansion
40 bool recoverIncludePath; // If we should try to find the include paths harder
41
42public:
43 PreprocessorCallback(Annotator &fm, clang::Preprocessor &PP, bool recoverIncludePath)
44 : annotator(fm), PP(PP), recoverIncludePath(recoverIncludePath) {}
45
46#if CLANG_VERSION_MAJOR != 3 || CLANG_VERSION_MINOR >= 7
47 using MyMacroDefinition = const clang::MacroDefinition &;
48#else
49 using MyMacroDefinition = const clang::MacroDirective*;
50#endif
51
52 void MacroExpands(const clang::Token& MacroNameTok, MyMacroDefinition MD,
53 clang::SourceRange Range, const clang::MacroArgs *Args) override;
54
55 void MacroDefined(const clang::Token &MacroNameTok, const clang::MacroDirective *MD) override;
56
57 void MacroUndefined(const clang::Token &MacroNameTok, MyMacroDefinition MD
58#if CLANG_VERSION_MAJOR >= 5
59 , const clang::MacroDirective *
60#endif
61 ) override;
62
63 bool FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl<char> &RecoveryPath) override;
64 void InclusionDirective(clang::SourceLocation HashLoc, const clang::Token& IncludeTok, llvm::StringRef FileName,
65 bool IsAngled, clang::CharSourceRange FilenameRange, const clang::FileEntry* File,
66 llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module* Imported) override;
67
68#if CLANG_VERSION_MAJOR == 3 && CLANG_VERSION_MINOR < 5
69 typedef bool ConditionValueKind; // It's an enum in clang 3.5
70#endif
71
72 void PragmaDirective(clang::SourceLocation Loc, clang::PragmaIntroducerKind Introducer) override
73 { seenPragma = true; }
74
75 virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, ConditionValueKind ConditionValue) override
76 { HandlePPCond(Loc, Loc); }
77 virtual void Ifndef(clang::SourceLocation Loc, const clang::Token& MacroNameTok, MyMacroDefinition MD) override
78 { HandlePPCond(Loc, Loc); Defined(MacroNameTok, MD, Loc); }
79 virtual void Ifdef(clang::SourceLocation Loc, const clang::Token& MacroNameTok, MyMacroDefinition MD) override
80 { HandlePPCond(Loc, Loc); Defined(MacroNameTok, MD, Loc); }
81 virtual void Elif(clang::SourceLocation Loc, clang::SourceRange ConditionRange, ConditionValueKind ConditionValue, clang::SourceLocation IfLoc) override {
82 ElifMapping[Loc] = IfLoc;
83 HandlePPCond(Loc, IfLoc);
84 }
85 virtual void Else(clang::SourceLocation Loc, clang::SourceLocation IfLoc) override
86 { HandlePPCond(Loc, IfLoc); }
87 virtual void Endif(clang::SourceLocation Loc, clang::SourceLocation IfLoc) override
88 { HandlePPCond(Loc, IfLoc); }
89
90 virtual void Defined(const clang::Token &MacroNameTok, MyMacroDefinition MD,
91 clang::SourceRange Range) override;
92

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected