15 #ifndef LLVM_CLANG_LEX_MACROINFO_H
16 #define LLVM_CLANG_LEX_MACROINFO_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/ADT/PointerIntPair.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Support/Allocator.h"
52 unsigned NumArguments;
58 mutable unsigned DefinitionLength;
59 mutable bool IsDefinitionLengthCached : 1;
62 bool IsFunctionLike : 1;
69 bool IsC99Varargs : 1;
75 bool IsGNUVarargs : 1;
82 bool IsBuiltinMacro : 1;
85 bool HasCommaPasting : 1;
103 bool IsAllowRedefinitionsWithoutWarning : 1;
106 bool IsWarnIfUnused : 1;
109 bool FromASTFile : 1;
112 bool UsedForHeaderGuard : 1;
130 if (IsDefinitionLengthCached)
131 return DefinitionLength;
132 return getDefinitionLengthSlow(SM);
143 bool Syntactically)
const;
153 IsAllowRedefinitionsWithoutWarning = Val;
162 llvm::BumpPtrAllocator &PPAllocator) {
163 assert(ArgumentList ==
nullptr && NumArguments == 0 &&
164 "Argument list already set!");
168 NumArguments = List.size();
169 ArgumentList = PPAllocator.Allocate<
IdentifierInfo *>(List.size());
170 std::copy(List.begin(), List.end(), ArgumentList);
204 bool isVariadic()
const {
return IsC99Varargs | IsGNUVarargs; }
223 return IsAllowRedefinitionsWithoutWarning;
234 assert(Tok < ReplacementTokens.size() &&
"Invalid token #");
235 return ReplacementTokens[Tok];
247 !IsDefinitionLengthCached &&
248 "Changing replacement tokens after definition length got calculated");
249 ReplacementTokens.push_back(Tok);
258 assert(IsDisabled &&
"Cannot enable an already-enabled macro!");
263 assert(!IsDisabled &&
"Cannot disable an already-disabled macro!");
280 return *(
const unsigned *)(
this + 1);
290 void setOwningModuleID(
unsigned ID) {
292 *(
unsigned *)(
this + 1) =
ID;
362 : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
378 bool isValid()
const {
return DefDirective !=
nullptr; }
399 return !Def.isUndefined();
424 assert(MI &&
"MacroInfo is null");
444 assert(UndefLoc.
isValid() &&
"Invalid UndefLoc!");
480 return DefDirective->getInfo();
485 if (
isInvalid() || DefDirective->getPrevious() ==
nullptr)
487 return DefDirective->getPrevious()->getDefinition();
505 unsigned NumOverriddenBy;
507 unsigned NumOverrides;
514 : II(II), Macro(Macro), OwningModule(OwningModule), NumOverriddenBy(0),
515 NumOverrides(Overrides.size()) {
516 std::copy(Overrides.begin(), Overrides.end(),
525 void Profile(llvm::FoldingSetNodeID &ID)
const {
526 return Profile(ID, OwningModule, II);
530 ID.AddPointer(OwningModule);
548 return overrides_begin() + NumOverrides;
551 return llvm::makeArrayRef(overrides_begin(), overrides_end());
564 llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
571 : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
574 explicit operator bool()
const {
575 return getLocalDirective() || !ModuleMacros.empty();
580 if (!ModuleMacros.empty())
581 return ModuleMacros.back()->getMacroInfo();
582 if (
auto *MD = getLocalDirective())
583 return MD->getMacroInfo();
588 bool isAmbiguous()
const {
return LatestLocalAndAmbiguous.getInt(); }
593 return LatestLocalAndAmbiguous.getPointer();
600 if (
auto *MD = getLocalDirective())
601 F(MD->getMacroInfo());
602 for (
auto *MM : getModuleMacros())
603 F(MM->getMacroInfo());
ArrayRef< ModuleMacro * > overrides() const
SmallVectorImpl< Token >::const_iterator tokens_iterator
void AddTokenToBody(const Token &Tok)
Add the specified token to the replacement text for the macro.
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const
Find macro definition active in the specified source location.
ArrayRef< const IdentifierInfo * > args() const
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
bool isObjectLike() const
bool hasCommaPasting() const
static bool classof(const UndefMacroDirective *)
A description of the current definition of a macro.
A directive for an undefined macro.
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
void setIsWarnIfUnused(bool val)
Set the value of the IsWarnIfUnused flag.
void Profile(llvm::FoldingSetNodeID &ID) const
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.
bool isEnabled() const
Return true if this macro is enabled.
SourceLocation getLocation() const
MacroInfo * getMacroInfo() const
Get definition for this exported #define, or nullptr if this represents a #undef. ...
Token - This structure provides full information about a lexed token.
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
bool tokens_empty() const
Describes a module or submodule.
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
A directive for setting the module visibility of a macro.
overrides_iterator overrides_begin() const
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
MacroDirective * getPrevious()
Get previous definition of the macro with the same name.
tokens_iterator tokens_begin() const
detail::InMemoryDirectory::const_iterator I
DefMacroDirective(MacroInfo *MI)
ArrayRef< Token > tokens() const
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
void setUsedForHeaderGuard(bool Val)
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.
void setHasCommaPasting()
unsigned getNumArgs() const
static bool classof(const VisibilityMacroDirective *)
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
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...
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular macro info.
unsigned getDefinitionLength(SourceManager &SM) const
Get length in characters of the macro definition.
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
arg_iterator arg_end() const
bool isPublic() const
Determine whether this macro is part of the public API of its module.
void setArgumentList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the argument list for this macro.
bool isC99Varargs() const
unsigned MDKind
MacroDirective kind.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
bool isFromASTFile() const
Determine whether this macro info came from an AST file (such as a precompiled header or module) rath...
void setIsFunctionLike()
Function/Object-likeness.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
overrides_iterator overrides_end() const
Encodes a location in the source.
bool isFromPCH() const
Return true if the macro directive was loaded from a PCH file.
bool isAllowRedefinitionsWithoutWarning() const
Return true if this macro can be redefined without warning.
bool isValid() const
Return true if this is a valid SourceLocation object.
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
void forAllDefinitions(Fn F) const
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
void setIsBuiltinMacro(bool Val=true)
Set or clear the isBuiltinMacro flag.
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc, bool isPublic)
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Module * getOwningModule() const
Get the ID of the module that exports this macro.
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
const Token & getReplacementToken(unsigned Tok) const
static bool isInvalid(LocType Loc, bool *Invalid)
DefMacroDirective * getDirective()
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
bool isGNUVarargs() const
const MacroInfo * getMacroInfo() const
VisibilityMacroDirective(SourceLocation Loc, bool Public)
MacroInfo * getMacroInfo()
MacroDefinition(DefMacroDirective *MD, ArrayRef< ModuleMacro * > MMs, bool IsAmbiguous)
detail::InMemoryDirectory::const_iterator E
SourceLocation getUndefLocation() const
bool isFunctionLike() const
Encapsulates the data about a macro definition (e.g.
const DefInfo getDefinition() const
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...
const DefInfo getPreviousDefinition() const
tokens_iterator tokens_end() const
const MacroInfo * getInfo() const
The data for the macro definition.
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule, IdentifierInfo *II)
static bool classof(const DefMacroDirective *)
static bool classof(const MacroDirective *)
MacroDirective(Kind K, SourceLocation Loc)
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
static bool classof(const MacroDirective *MD)
MacroInfo * getMacroInfo()
unsigned IsFromPCH
True if the macro directive was loaded from a PCH file.
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
arg_iterator arg_begin() const
const MacroInfo * getMacroInfo() const
This class handles loading and caching of source files into memory.
static bool classof(const MacroDirective *MD)
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
UndefMacroDirective(SourceLocation UndefLoc)
SourceLocation getLocation() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
const DefMacroDirective * getDirective() const
static bool classof(const MacroDirective *MD)
MacroDirective * Previous
Previous macro directive for the same identifier, or NULL.