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) {
150 if (IsC99Varargs || IsGNUVarargs) {
151 if (NumArguments && IsC99Varargs) Out <<
", ";
158 for (
const Token &Tok : ReplacementTokens) {
161 if (First || Tok.hasLeadingSpace())
167 else if (Tok.isLiteral() && Tok.getLiteralData())
168 Out << StringRef(Tok.getLiteralData(), Tok.getLength());
169 else if (
auto *II = Tok.getIdentifierInfo())
170 Out << II->getName();
172 Out << Tok.getName();
182 return DefInfo(DefMD, UndefLoc,
183 !isPublic.hasValue() || isPublic.getValue());
186 UndefLoc = UndefMD->getLocation();
191 if (!isPublic.hasValue())
195 return DefInfo(
nullptr, UndefLoc,
196 !isPublic.hasValue() || isPublic.getValue());
201 assert(L.
isValid() &&
"SourceLocation is invalid.");
203 if (Def.getLocation().isInvalid() ||
205 return (!Def.isUndefined() ||
213 llvm::raw_ostream &Out = llvm::errs();
216 case MD_Define: Out <<
"DefMacroDirective";
break;
217 case MD_Undefine: Out <<
"UndefMacroDirective";
break;
218 case MD_Visibility: Out <<
"VisibilityMacroDirective";
break;
223 Out <<
" prev " << Prev;
226 if (isa<VisibilityMacroDirective>(
this))
227 Out << (
IsPublic ?
" public" :
" private");
229 if (
auto *DMD = dyn_cast<DefMacroDirective>(
this)) {
230 if (
auto *Info = DMD->getInfo()) {
243 llvm::alignOf<ModuleMacro>());
244 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.
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
detail::InMemoryDirectory::const_iterator I
DefInfo getPreviousDefinition()
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
IdentifierInfo *const * arg_iterator
Arguments - The list of arguments for a function-like macro.
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() 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.
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.
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