16 using namespace clang;
20 ParameterList(nullptr),
22 IsDefinitionLengthCached(
false),
23 IsFunctionLike(
false),
26 IsBuiltinMacro(
false),
27 HasCommaPasting(
false),
30 IsAllowRedefinitionsWithoutWarning(
false),
31 IsWarnIfUnused(
false),
32 UsedForHeaderGuard(
false) {
35 unsigned MacroInfo::getDefinitionLengthSlow(
const SourceManager &
SM)
const {
36 assert(!IsDefinitionLengthCached);
37 IsDefinitionLengthCached =
true;
39 if (ReplacementTokens.empty())
40 return (DefinitionLength = 0);
42 const Token &firstToken = ReplacementTokens.front();
43 const Token &lastToken = ReplacementTokens.back();
47 assert((macroStart.
isFileID() || firstToken.
is(tok::comment)) &&
48 "Macro defined in macro?");
49 assert((macroEnd.
isFileID() || lastToken.
is(tok::comment)) &&
50 "Macro defined in macro?");
51 std::pair<FileID, unsigned>
53 std::pair<FileID, unsigned>
55 assert(startInfo.first == endInfo.first &&
56 "Macro definition spanning multiple FileIDs ?");
57 assert(startInfo.second <= endInfo.second);
58 DefinitionLength = endInfo.second - startInfo.second;
59 DefinitionLength += lastToken.
getLength();
61 return DefinitionLength;
72 bool Syntactically)
const {
73 bool Lexically = !Syntactically;
76 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 (UsedForHeaderGuard) Out <<
" header_guard";
142 Out <<
"\n #define <macro>";
143 if (IsFunctionLike) {
145 for (
unsigned I = 0;
I != NumParameters; ++
I) {
149 if (IsC99Varargs || IsGNUVarargs) {
150 if (NumParameters && IsC99Varargs) Out <<
", ";
157 for (
const Token &Tok : ReplacementTokens) {
160 if (First || Tok.hasLeadingSpace())
166 else if (Tok.isLiteral() && Tok.getLiteralData())
167 Out << StringRef(Tok.getLiteralData(), Tok.getLength());
168 else if (
auto *II = Tok.getIdentifierInfo())
169 Out << II->getName();
171 Out << Tok.getName();
181 return DefInfo(DefMD, UndefLoc,
182 !isPublic.hasValue() || isPublic.getValue());
185 UndefLoc = UndefMD->getLocation();
190 if (!isPublic.hasValue())
194 return DefInfo(
nullptr, UndefLoc,
195 !isPublic.hasValue() || isPublic.getValue());
200 assert(L.
isValid() &&
"SourceLocation is invalid.");
202 if (Def.getLocation().isInvalid() ||
204 return (!Def.isUndefined() ||
212 llvm::raw_ostream &Out = llvm::errs();
215 case MD_Define: Out <<
"DefMacroDirective";
break;
216 case MD_Undefine: Out <<
"UndefMacroDirective";
break;
217 case MD_Visibility: Out <<
"VisibilityMacroDirective";
break;
222 Out <<
" prev " << Prev;
225 if (isa<VisibilityMacroDirective>(
this))
226 Out << (
IsPublic ?
" public" :
" private");
228 if (
auto *DMD = dyn_cast<DefMacroDirective>(
this)) {
229 if (
auto *Info = DMD->getInfo()) {
243 return new (Mem)
ModuleMacro(OwningModule, II, Macro, Overrides);
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
llvm::BumpPtrAllocator & getPreprocessorAllocator()
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
param_iterator param_begin() const
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const
Find macro definition active in the specified source location.
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
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
One of these records is kept for each identifier that is lexed.
Represents a macro directive exported by a module.
A directive for a defined macro or a macro imported from a module.
Token - This structure provides full information about a lexed token.
Describes a module or submodule.
A directive for setting the module visibility of a macro.
static ModuleMacro * create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides)
tok::TokenKind getKind() const
unsigned getNumParams() const
detail::InMemoryDirectory::const_iterator I
param_iterator param_end() const
DefInfo getPreviousDefinition()
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
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.
Defines the clang::Preprocessor interface.
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. ...
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.
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
bool isGNUVarargs() const
detail::InMemoryDirectory::const_iterator E
bool isFunctionLike() const
Encapsulates the data about a macro definition (e.g.
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 IsFromPCH
True if the macro directive was loaded from a PCH file.
int getParameterNum(const IdentifierInfo *Arg) const
Return the parameter number of the specified identifier, or -1 if the identifier is not a formal para...
unsigned getLength() 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