16 using namespace clang;
20 ArgumentList(nullptr),
22 IsDefinitionLengthCached(
false),
23 IsFunctionLike(
false),
26 IsBuiltinMacro(
false),
27 HasCommaPasting(
false),
30 IsAllowRedefinitionsWithoutWarning(
false),
31 IsWarnIfUnused(
false),
33 UsedForHeaderGuard(
false) {
37 assert(!IsDefinitionLengthCached);
38 IsDefinitionLengthCached =
true;
40 if (ReplacementTokens.empty())
41 return (DefinitionLength = 0);
43 const Token &firstToken = ReplacementTokens.front();
44 const Token &lastToken = ReplacementTokens.back();
48 assert((macroStart.
isFileID() || firstToken.
is(tok::comment)) &&
49 "Macro defined in macro?");
50 assert((macroEnd.
isFileID() || lastToken.
is(tok::comment)) &&
51 "Macro defined in macro?");
52 std::pair<FileID, unsigned>
54 std::pair<FileID, unsigned>
56 assert(startInfo.first == endInfo.first &&
57 "Macro definition spanning multiple FileIDs ?");
58 assert(startInfo.second <= endInfo.second);
59 DefinitionLength = endInfo.second - startInfo.second;
60 DefinitionLength += lastToken.
getLength();
62 return DefinitionLength;
73 bool Syntactically)
const {
74 bool Lexically = !Syntactically;
77 if (ReplacementTokens.size() != Other.ReplacementTokens.size() ||
88 if (*I != *OI)
return false;
92 for (
unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) {
93 const Token &A = ReplacementTokens[i];
94 const Token &B = Other.ReplacementTokens[i];
130 llvm::raw_ostream &Out = llvm::errs();
133 Out <<
"MacroInfo " <<
this;
134 if (IsBuiltinMacro) Out <<
" builtin";
135 if (IsDisabled) Out <<
" disabled";
136 if (IsUsed) Out <<
" used";
137 if (IsAllowRedefinitionsWithoutWarning)
138 Out <<
" allow_redefinitions_without_warning";
139 if (IsWarnIfUnused) Out <<
" warn_if_unused";
140 if (FromASTFile) Out <<
" imported";
141 if (UsedForHeaderGuard) Out <<
" header_guard";
143 Out <<
"\n #define <macro>";
144 if (IsFunctionLike) {
146 for (
unsigned I = 0; I != NumArguments; ++I) {
148 Out << ArgumentList[I]->
getName();
150 if (IsC99Varargs || IsGNUVarargs) {
151 if (NumArguments && IsC99Varargs) Out <<
", ";
157 for (
const Token &Tok : ReplacementTokens) {
163 else if (Tok.is(tok::identifier))
164 Out << Tok.getIdentifierInfo()->getName();
165 else if (Tok.isLiteral() && Tok.getLiteralData())
166 Out << StringRef(Tok.getLiteralData(), Tok.getLength());
168 Out << Tok.getName();
178 return DefInfo(DefMD, UndefLoc,
179 !isPublic.hasValue() || isPublic.getValue());
182 UndefLoc = UndefMD->getLocation();
187 if (!isPublic.hasValue())
191 return DefInfo(
nullptr, UndefLoc,
192 !isPublic.hasValue() || isPublic.getValue());
197 assert(L.
isValid() &&
"SourceLocation is invalid.");
199 if (Def.getLocation().isInvalid() ||
201 return (!Def.isUndefined() ||
209 llvm::raw_ostream &Out = llvm::errs();
212 case MD_Define: Out <<
"DefMacroDirective";
break;
213 case MD_Undefine: Out <<
"UndefMacroDirective";
break;
214 case MD_Visibility: Out <<
"VisibilityMacroDirective";
break;
219 Out <<
" prev " << Prev;
222 if (isa<VisibilityMacroDirective>(
this))
223 Out << (
IsPublic ?
" public" :
" private");
225 if (
auto *DMD = dyn_cast<DefMacroDirective>(
this)) {
226 if (
auto *Info = DMD->getInfo()) {
239 llvm::alignOf<ModuleMacro>());
240 return new (Mem)
ModuleMacro(OwningModule, II, Macro, Overrides);
bool isAtStartOfLine() const
bool IsFromPCH
True if the macro directive was loaded from a PCH file.
llvm::BumpPtrAllocator & getPreprocessorAllocator()
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const
Find macro definition active in the specified source location. If this macro was not defined there...
Defines the clang::MacroInfo and clang::MacroDirective classes.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
A directive for an undefined macro.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Represents a macro directive exported by a module.
A directive for a defined macro or a macro imported from a module.
Describes a module or submodule.
A directive for setting the module visibility of a macro.
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
static ModuleMacro * create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides)
tok::TokenKind getKind() const
DefInfo getPreviousDefinition()
IdentifierInfo *const * arg_iterator
StringRef getName() const
Return the actual identifier string.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
unsigned getNumArgs() const
Defines the clang::Preprocessor interface.
int getArgumentNum(const IdentifierInfo *Arg) const
Return the argument number of the specified identifier, or -1 if the identifier is not a formal argum...
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
arg_iterator arg_end() const
bool IsPublic
Whether the macro has public visibility (when described in a module).
bool isPublic() const
Determine whether this macro is part of the public API of its module.
bool isC99Varargs() const
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
bool isValid() const
Return true if this is a valid SourceLocation object.
bool is(tok::TokenKind K) const
bool isGNUVarargs() const
bool isFunctionLike() const
Encapsulates the data about a macro definition (e.g. its tokens).
bool isIdenticalTo(const MacroInfo &Other, Preprocessor &PP, bool Syntactically) const
Return true if the specified macro definition is equal to this macro in spelling, arguments...
unsigned getLength() const
arg_iterator arg_begin() const
This class handles loading and caching of source files into memory.
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
IdentifierInfo * getIdentifierInfo() const