| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef PPTRACE_PPCALLBACKSTRACKER_H |
| 22 |
#define PPTRACE_PPCALLBACKSTRACKER_H |
| 23 |
|
| 24 |
#include "clang/Lex/PPCallbacks.h" |
| 25 |
#include "clang/Lex/Preprocessor.h" |
| 26 |
#include "clang/Basic/SourceManager.h" |
| 27 |
#include "llvm/ADT/ArrayRef.h" |
| 28 |
#include "llvm/ADT/SmallSet.h" |
| 29 |
#include "llvm/ADT/StringMap.h" |
| 30 |
#include "llvm/ADT/StringRef.h" |
| 31 |
#include "llvm/Support/GlobPattern.h" |
| 32 |
#include <string> |
| 33 |
#include <vector> |
| 34 |
|
| 35 |
namespace clang { |
| 36 |
namespace pp_trace { |
| 37 |
|
| 38 |
|
| 39 |
struct Argument { |
| 40 |
std::string Name; |
| 41 |
std::string Value; |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
class CallbackCall { |
| 47 |
public: |
| 48 |
CallbackCall(llvm::StringRef Name) : Name(Name) {} |
| 49 |
CallbackCall() = default; |
| 50 |
|
| 51 |
std::string Name; |
| 52 |
std::vector<Argument> Arguments; |
| 53 |
}; |
| 54 |
|
| 55 |
using FilterType = std::vector<std::pair<llvm::GlobPattern, bool>>; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
class PPCallbacksTracker : public PPCallbacks { |
| 75 |
public: |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
PPCallbacksTracker(const FilterType &Filters, |
| 82 |
std::vector<CallbackCall> &CallbackCalls, |
| 83 |
Preprocessor &PP); |
| 84 |
|
| 85 |
~PPCallbacksTracker() override; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
void FileChanged(SourceLocation Loc, PPCallbacks::FileChangeReason Reason, |
| 90 |
SrcMgr::CharacteristicKind FileType, |
| 91 |
FileID PrevFID = FileID()) override; |
| 92 |
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, |
| 93 |
SrcMgr::CharacteristicKind FileType) override; |
| 94 |
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, |
| 95 |
llvm::StringRef FileName, bool IsAngled, |
| 96 |
CharSourceRange FilenameRange, |
| 97 |
OptionalFileEntryRef File, llvm::StringRef SearchPath, |
| 98 |
llvm::StringRef RelativePath, const Module *Imported, |
| 99 |
SrcMgr::CharacteristicKind FileType) override; |
| 100 |
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, |
| 101 |
const Module *Imported) override; |
| 102 |
void EndOfMainFile() override; |
| 103 |
void Ident(SourceLocation Loc, llvm::StringRef str) override; |
| 104 |
void PragmaDirective(SourceLocation Loc, |
| 105 |
PragmaIntroducerKind Introducer) override; |
| 106 |
void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, |
| 107 |
llvm::StringRef Str) override; |
| 108 |
void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name, |
| 109 |
llvm::StringRef Value) override; |
| 110 |
void PragmaDebug(SourceLocation Loc, llvm::StringRef DebugType) override; |
| 111 |
void PragmaMessage(SourceLocation Loc, llvm::StringRef Namespace, |
| 112 |
PPCallbacks::PragmaMessageKind Kind, |
| 113 |
llvm::StringRef Str) override; |
| 114 |
void PragmaDiagnosticPush(SourceLocation Loc, |
| 115 |
llvm::StringRef Namespace) override; |
| 116 |
void PragmaDiagnosticPop(SourceLocation Loc, |
| 117 |
llvm::StringRef Namespace) override; |
| 118 |
void PragmaDiagnostic(SourceLocation Loc, llvm::StringRef Namespace, |
| 119 |
diag::Severity mapping, llvm::StringRef Str) override; |
| 120 |
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, |
| 121 |
SourceLocation StateLoc, unsigned State) override; |
| 122 |
void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, |
| 123 |
llvm::ArrayRef<int> Ids) override; |
| 124 |
void PragmaWarningPush(SourceLocation Loc, int Level) override; |
| 125 |
void PragmaWarningPop(SourceLocation Loc) override; |
| 126 |
void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override; |
| 127 |
void PragmaExecCharsetPop(SourceLocation Loc) override; |
| 128 |
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, |
| 129 |
SourceRange Range, const MacroArgs *Args) override; |
| 130 |
void MacroDefined(const Token &MacroNameTok, |
| 131 |
const MacroDirective *MD) override; |
| 132 |
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, |
| 133 |
const MacroDirective *Undef) override; |
| 134 |
void Defined(const Token &MacroNameTok, const MacroDefinition &MD, |
| 135 |
SourceRange Range) override; |
| 136 |
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override; |
| 137 |
void If(SourceLocation Loc, SourceRange ConditionRange, |
| 138 |
ConditionValueKind ConditionValue) override; |
| 139 |
void Elif(SourceLocation Loc, SourceRange ConditionRange, |
| 140 |
ConditionValueKind ConditionValue, SourceLocation IfLoc) override; |
| 141 |
void Ifdef(SourceLocation Loc, const Token &MacroNameTok, |
| 142 |
const MacroDefinition &MD) override; |
| 143 |
void Ifndef(SourceLocation Loc, const Token &MacroNameTok, |
| 144 |
const MacroDefinition &MD) override; |
| 145 |
void Else(SourceLocation Loc, SourceLocation IfLoc) override; |
| 146 |
void Endif(SourceLocation Loc, SourceLocation IfLoc) override; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
void beginCallback(const char *Name); |
| 152 |
|
| 153 |
|
| 154 |
void append(const char *Str); |
| 155 |
|
| 156 |
|
| 157 |
void appendArgument(const char *Name, bool Value); |
| 158 |
|
| 159 |
|
| 160 |
void appendArgument(const char *Name, int Value); |
| 161 |
|
| 162 |
|
| 163 |
void appendArgument(const char *Name, const char *Value); |
| 164 |
|
| 165 |
|
| 166 |
void appendArgument(const char *Name, llvm::StringRef Value); |
| 167 |
|
| 168 |
|
| 169 |
void appendArgument(const char *Name, const std::string &Value); |
| 170 |
|
| 171 |
|
| 172 |
void appendArgument(const char *Name, const Token &Value); |
| 173 |
|
| 174 |
|
| 175 |
void appendArgument(const char *Name, int Value, const char *const Strings[]); |
| 176 |
|
| 177 |
|
| 178 |
void appendArgument(const char *Name, FileID Value); |
| 179 |
|
| 180 |
|
| 181 |
void appendArgument(const char *Name, OptionalFileEntryRef Value); |
| 182 |
void appendArgument(const char *Name, FileEntryRef Value); |
| 183 |
|
| 184 |
|
| 185 |
void appendArgument(const char *Name, SourceLocation Value); |
| 186 |
|
| 187 |
|
| 188 |
void appendArgument(const char *Name, SourceRange Value); |
| 189 |
|
| 190 |
|
| 191 |
void appendArgument(const char *Name, CharSourceRange Value); |
| 192 |
|
| 193 |
|
| 194 |
void appendArgument(const char *Name, ModuleIdPath Value); |
| 195 |
|
| 196 |
|
| 197 |
void appendArgument(const char *Name, const IdentifierInfo *Value); |
| 198 |
|
| 199 |
|
| 200 |
void appendArgument(const char *Name, const MacroDirective *Value); |
| 201 |
|
| 202 |
|
| 203 |
void appendArgument(const char *Name, const MacroDefinition &Value); |
| 204 |
|
| 205 |
|
| 206 |
void appendArgument(const char *Name, const MacroArgs *Value); |
| 207 |
|
| 208 |
|
| 209 |
void appendArgument(const char *Name, const Module *Value); |
| 210 |
|
| 211 |
|
| 212 |
void appendQuotedArgument(const char *Name, const std::string &Value); |
| 213 |
|
| 214 |
|
| 215 |
void appendFilePathArgument(const char *Name, llvm::StringRef Value); |
| 216 |
|
| 217 |
|
| 218 |
llvm::StringRef getSourceString(CharSourceRange Range); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
std::vector<CallbackCall> &CallbackCalls; |
| 224 |
|
| 225 |
|
| 226 |
const FilterType &Filters; |
| 227 |
|
| 228 |
|
| 229 |
llvm::StringMap<bool> CallbackIsEnabled; |
| 230 |
|
| 231 |
|
| 232 |
bool DisableTrace; |
| 233 |
|
| 234 |
Preprocessor &PP; |
| 235 |
}; |
| 236 |
|
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
#endif |