clang: lib/CodeGen/MacroPPCallbacks.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
18
19using namespace clang;
20
21void MacroPPCallbacks::writeMacroDefinition(const IdentifierInfo &II,
24 raw_ostream &Value) {
26
28 Name << '(';
31 for (; AI + 1 != E; ++AI) {
32 Name << (*AI)->getName();
33 Name << ',';
34 }
35
36
37 if ((*AI)->getName() == "__VA_ARGS__")
38 Name << "...";
39 else
40 Name << (*AI)->getName();
41 }
42
44
45 Name << "...";
46
47 Name << ')';
48 }
49
51 bool First = true;
52 for (const auto &T : MI.tokens()) {
53 if ( && T.hasLeadingSpace())
55
58 }
59}
60
62 : Gen(Gen), PP(PP), Status(NoScope) {}
63
64
65
66
67
68
69
70
71
72
73
74
75
76llvm::DIMacroFile *MacroPPCallbacks::getCurrentScope() {
77 if (Status == MainFileScope || Status == CommandLineIncludeScope)
78 return Scopes.back();
79 return nullptr;
80}
81
83 if (Status == MainFileScope || EnteredCommandLineIncludeFiles)
84 return Loc;
85
86
87
89}
90
91void MacroPPCallbacks::updateStatusToNextScope() {
92 switch (Status) {
93 case NoScope:
94 Status = InitializedScope;
95 break;
96 case InitializedScope:
97 Status = BuiltinScope;
98 break;
99 case BuiltinScope:
100 Status = CommandLineIncludeScope;
101 break;
102 case CommandLineIncludeScope:
103 Status = MainFileScope;
104 break;
105 case MainFileScope:
106 llvm_unreachable("There is no next scope, already in the final scope");
107 }
108}
109
111 SourceLocation LineLoc = getCorrectLocation(LastHashLoc);
112 switch (Status) {
113 case NoScope:
114 updateStatusToNextScope();
115 break;
116 case InitializedScope:
117 updateStatusToNextScope();
118 return;
119 case BuiltinScope:
121 return;
122 updateStatusToNextScope();
123 [[fallthrough]];
124 case CommandLineIncludeScope:
125 EnteredCommandLineIncludeFiles++;
126 break;
127 case MainFileScope:
128 break;
129 }
130
132 LineLoc, Loc));
133}
134
136 switch (Status) {
137 default:
138 llvm_unreachable("Do not expect to exit a file from current scope");
139 case BuiltinScope:
141
142 Status = MainFileScope;
143 return;
144 case CommandLineIncludeScope:
145 if (!EnteredCommandLineIncludeFiles) {
146 updateStatusToNextScope();
147 return;
148 }
149 EnteredCommandLineIncludeFiles--;
150 break;
151 case MainFileScope:
152 break;
153 }
154
155 Scopes.pop_back();
156}
157
161
163 FileEntered(Loc);
165 FileExited(Loc);
166}
167
171 StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule,
173
174
175 LastHashLoc = HashLoc;
176}
177
182 std::string NameBuffer, ValueBuffer;
183 llvm::raw_string_ostream Name(NameBuffer);
184 llvm::raw_string_ostream Value(ValueBuffer);
187 llvm::dwarf::DW_MACINFO_define, location,
188 NameBuffer, ValueBuffer);
189}
190
197 llvm::dwarf::DW_MACINFO_undef, location,
198 Id->getName(), "");
199}
llvm::MachO::FileType FileType
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines the clang::Preprocessor interface.
Represents a character-granular source range.
llvm::DIMacroFile * CreateTempMacroFile(llvm::DIMacroFile *Parent, SourceLocation LineLoc, SourceLocation FileLoc)
Create debug info for a file referenced by an #include directive.
llvm::DIMacro * CreateMacro(llvm::DIMacroFile *Parent, unsigned MType, SourceLocation LineLoc, StringRef Name, StringRef Value)
Create debug info for a macro defined by a #define directive or a macro undefined by a #undef directi...
The primary public interface to the Clang code generator.
CodeGen::CGDebugInfo * getCGDebugInfo()
Return debug info code generator.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
A description of the current definition of a macro.
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
const MacroInfo * getMacroInfo() const
Encapsulates the data about a macro definition (e.g.
bool isFunctionLike() const
param_iterator param_begin() const
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
param_iterator param_end() const
ArrayRef< Token > tokens() const
bool isGNUVarargs() const
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
Hook called whenever a macro #undef is seen.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever a directive (#xxx) is processed.
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
Hook called whenever a macro definition is seen.
void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID()) override
Callback invoked whenever a source file is entered or exited.
MacroPPCallbacks(CodeGenerator *Gen, Preprocessor &PP)
Describes a module or submodule.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
SourceManager & getSourceManager() const
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
Encodes a location in the source.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a file.
bool isWrittenInCommandLineFile(SourceLocation Loc) const
Returns whether Loc is located in a file.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T