19 using namespace clang;
21 void MacroPPCallbacks::writeMacroDefinition(
const IdentifierInfo &II,
31 for (; AI + 1 != E; ++AI) {
32 Name << (*AI)->getName();
37 if ((*AI)->getName() ==
"__VA_ARGS__")
40 Name << (*AI)->getName();
52 for (
const auto &T : MI.
tokens()) {
53 if (!First && T.hasLeadingSpace())
62 : Gen(Gen), PP(PP), Status(NoScope) {}
76 llvm::DIMacroFile *MacroPPCallbacks::getCurrentScope() {
77 if (Status == MainFileScope || Status == CommandLineIncludeScope)
83 if (Status == MainFileScope || EnteredCommandLineIncludeFiles)
93 return Filename.equals(
"<built-in>");
98 return Filename.equals(
"<command line>");
101 void MacroPPCallbacks::updateStatusToNextScope() {
104 Status = InitializedScope;
106 case InitializedScope:
107 Status = BuiltinScope;
110 Status = CommandLineIncludeScope;
112 case CommandLineIncludeScope:
113 Status = MainFileScope;
116 llvm_unreachable(
"There is no next scope, already in the final scope");
124 updateStatusToNextScope();
126 case InitializedScope:
127 updateStatusToNextScope();
132 updateStatusToNextScope();
134 case CommandLineIncludeScope:
135 EnteredCommandLineIncludeFiles++;
148 llvm_unreachable(
"Do not expect to exit a file from current scope");
152 Status = MainFileScope;
154 case CommandLineIncludeScope:
155 if (!EnteredCommandLineIncludeFiles) {
156 updateStatusToNextScope();
159 EnteredCommandLineIncludeFiles--;
181 StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
185 LastHashLoc = HashLoc;
192 std::string NameBuffer, ValueBuffer;
193 llvm::raw_string_ostream Name(NameBuffer);
194 llvm::raw_string_ostream
Value(ValueBuffer);
197 llvm::dwarf::DW_MACINFO_define, location,
198 Name.str(), Value.str());
207 llvm::dwarf::DW_MACINFO_undef, location,
param_iterator param_begin() const
A description of the current definition of a macro.
static bool isCommandLineFile(SourceManager &SM, SourceLocation Loc)
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
static bool isBuiltinFile(SourceManager &SM, SourceLocation Loc)
One of these records is kept for each identifier that is lexed.
Token - This structure provides full information about a lexed token.
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...
Describes a module or submodule.
param_iterator param_end() 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 ...
The primary public interface to the Clang code generator.
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID=FileID()) override
Callback invoked whenever a source file is entered or exited.
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.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
SourceManager & getSourceManager() const
const char * getFilename() const
Return the presumed filename of this location.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Encodes a location in the source.
IdentifierInfo * getIdentifierInfo() const
Cached information about one file (either on disk or in the virtual file system). ...
const MacroInfo * getMacroInfo() const
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef) override
Hook called whenever a macro #undef is seen.
StringRef getName() const
Return the actual identifier string.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
bool isFunctionLike() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
Encapsulates the data about a macro definition (e.g.
void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override
Hook called whenever a macro definition is seen.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever a directive (#xxx) is processed.
ArrayRef< Token > tokens() const
bool isGNUVarargs() const
MacroPPCallbacks(CodeGenerator *Gen, Preprocessor &PP)
CodeGen::CGDebugInfo * getCGDebugInfo()
Return debug info code generator.
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.