15 #ifndef LLVM_CLANG_LEX_MACROINFO_H 16 #define LLVM_CLANG_LEX_MACROINFO_H 21 #include "llvm/ADT/ArrayRef.h" 22 #include "llvm/ADT/FoldingSet.h" 23 #include "llvm/ADT/PointerIntPair.h" 24 #include "llvm/ADT/SmallVector.h" 25 #include "llvm/Support/Allocator.h" 31 class DefMacroDirective;
59 unsigned NumParameters = 0;
65 mutable unsigned DefinitionLength;
66 mutable bool IsDefinitionLengthCached : 1;
69 bool IsFunctionLike : 1;
76 bool IsC99Varargs : 1;
82 bool IsGNUVarargs : 1;
89 bool IsBuiltinMacro : 1;
92 bool HasCommaPasting : 1;
110 bool IsAllowRedefinitionsWithoutWarning : 1;
113 bool IsWarnIfUnused : 1;
116 bool UsedForHeaderGuard : 1;
134 if (IsDefinitionLengthCached)
135 return DefinitionLength;
136 return getDefinitionLengthSlow(SM);
147 bool Syntactically)
const;
157 IsAllowRedefinitionsWithoutWarning = Val;
166 llvm::BumpPtrAllocator &PPAllocator) {
167 assert(ParameterList ==
nullptr && NumParameters == 0 &&
168 "Parameter list already set!");
172 NumParameters = List.size();
173 ParameterList = PPAllocator.Allocate<
IdentifierInfo *>(List.size());
174 std::copy(List.begin(), List.end(), ParameterList);
208 bool isVariadic()
const {
return IsC99Varargs | IsGNUVarargs; }
227 return IsAllowRedefinitionsWithoutWarning;
237 assert(Tok < ReplacementTokens.size() &&
"Invalid token #");
238 return ReplacementTokens[
Tok];
251 !IsDefinitionLengthCached &&
252 "Changing replacement tokens after definition length got calculated");
253 ReplacementTokens.push_back(Tok);
262 assert(IsDisabled &&
"Cannot enable an already-enabled macro!");
267 assert(!IsDisabled &&
"Cannot disable an already-disabled macro!");
318 : Loc(Loc), MDKind(K), IsFromPCH(
false), IsPublic(
true) {}
342 bool IsPublic =
true;
348 : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
357 return const_cast<DefInfo *
>(
this)->getMacroInfo();
365 bool isValid()
const {
return DefDirective !=
nullptr; }
368 explicit operator bool()
const {
return isValid(); }
370 inline DefInfo getPreviousDefinition();
373 return const_cast<DefInfo *
>(
this)->getPreviousDefinition();
387 return !Def.isUndefined();
412 assert(MI &&
"MacroInfo is null");
422 return MD->
getKind() == MD_Define;
433 assert(UndefLoc.
isValid() &&
"Invalid UndefLoc!");
437 return MD->
getKind() == MD_Undefine;
456 return MD->
getKind() == MD_Visibility;
465 return DefDirective->getLocation();
471 return DefDirective->getInfo();
476 if (
isInvalid() || DefDirective->getPrevious() ==
nullptr)
478 return DefDirective->getPrevious()->getDefinition();
501 unsigned NumOverriddenBy = 0;
504 unsigned NumOverrides;
508 : II(II), Macro(Macro), OwningModule(OwningModule),
509 NumOverrides(Overrides.size()) {
510 std::copy(Overrides.begin(), Overrides.end(),
520 return Profile(ID, OwningModule, II);
525 ID.AddPointer(OwningModule);
548 return overrides_begin() + NumOverrides;
552 return llvm::makeArrayRef(overrides_begin(), overrides_end());
565 llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
572 : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
575 explicit operator bool()
const {
576 return getLocalDirective() || !ModuleMacros.empty();
581 if (!ModuleMacros.empty())
582 return ModuleMacros.back()->getMacroInfo();
583 if (
auto *MD = getLocalDirective())
584 return MD->getMacroInfo();
589 bool isAmbiguous()
const {
return LatestLocalAndAmbiguous.getInt(); }
594 return LatestLocalAndAmbiguous.getPointer();
601 if (
auto *MD = getLocalDirective())
602 F(MD->getMacroInfo());
603 for (
auto *MM : getModuleMacros())
604 F(MM->getMacroInfo());
610 #endif // LLVM_CLANG_LEX_MACROINFO_H
param_iterator param_begin() const
void AddTokenToBody(const Token &Tok)
Add the specified token to the replacement text for the macro.
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
Module * getOwningModule() const
Get the ID of the module that exports this macro.
static ClassTemplateDecl * getDefinition(ClassTemplateDecl *D)
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
bool isEnabled() const
Return true if this macro is enabled.
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)
void setIsWarnIfUnused(bool val)
Set the value of the IsWarnIfUnused flag.
tokens_iterator tokens_begin() const
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
bool isFromPCH() const
Return true if the macro directive was loaded from a PCH file.
const DefInfo getPreviousDefinition() const
One of these records is kept for each identifier that is lexed.
Represents a macro directive exported by a module.
overrides_iterator overrides_end() const
A directive for a defined macro or a macro imported from a module.
bool hasCommaPasting() const
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.
param_iterator param_end() const
const Token & getReplacementToken(unsigned Tok) const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
MacroDirective * getPrevious()
Get previous definition of the macro with the same name.
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
overrides_iterator overrides_begin() const
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
DefMacroDirective(MacroInfo *MI)
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
SmallVectorImpl< Token >::const_iterator tokens_iterator
void setUsedForHeaderGuard(bool Val)
DefInfo getPreviousDefinition()
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
bool isAllowRedefinitionsWithoutWarning() const
Return true if this macro can be redefined without warning.
bool isPublic() const
Determine whether this macro is part of the public API of its module.
unsigned getNumParams() const
void setHasCommaPasting()
const DefMacroDirective * getDirective() const
SourceLocation getLocation() const
static bool classof(const VisibilityMacroDirective *)
const DefInfo getDefinition() const
bool isObjectLike() const
SourceLocation getUndefLocation() const
unsigned MDKind
MacroDirective kind.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
void setIsFunctionLike()
Function/Object-likeness.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Encodes a location in the source.
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
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)
bool isC99Varargs() const
const MacroInfo * getMacroInfo() const
static bool isInvalid(LocType Loc, bool *Invalid)
Dataflow Directional Tag Classes.
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
bool isFunctionLike() const
DefMacroDirective * getDirective()
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
VisibilityMacroDirective(SourceLocation Loc, bool Public)
MacroInfo * getMacroInfo()
tokens_iterator tokens_end() const
SourceLocation getLocation() const
IdentifierInfo * getName() const
Get the name of the macro.
ArrayRef< ModuleMacro * > overrides() const
Encapsulates the data about a macro definition (e.g.
int getParameterNum(const IdentifierInfo *Arg) const
Return the parameter number of the specified identifier, or -1 if the identifier is not a formal para...
const MacroInfo * getInfo() const
The data for the macro definition.
MacroInfo * getMacroInfo() const
Get definition for this exported #define, or nullptr if this represents a #undef. ...
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
bool tokens_empty() const
static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule, IdentifierInfo *II)
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
unsigned getDefinitionLength(const SourceManager &SM) const
Get length in characters of the macro definition.
Defines the clang::SourceLocation class and associated facilities.
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...
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
ArrayRef< Token > tokens() const
static bool classof(const DefMacroDirective *)
static bool classof(const MacroDirective *)
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
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()
bool isGNUVarargs() const
unsigned IsFromPCH
True if the macro directive was loaded from a PCH file.
void forAllDefinitions(Fn F) const
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
const MacroInfo * getMacroInfo() const
void setParameterList(ArrayRef< IdentifierInfo *> List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the parameter list for this macro.
MacroDefinition(DefMacroDirective *MD, ArrayRef< ModuleMacro *> MMs, bool IsAmbiguous)
void Profile(llvm::FoldingSetNodeID &ID) const
This class handles loading and caching of source files into memory.
static bool classof(const MacroDirective *MD)
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
UndefMacroDirective(SourceLocation UndefLoc)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
static bool classof(const MacroDirective *MD)
ArrayRef< const IdentifierInfo * > params() const