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 NumParameters;
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 UsedForHeaderGuard : 1;
127 if (IsDefinitionLengthCached)
128 return DefinitionLength;
129 return getDefinitionLengthSlow(SM);
140 bool Syntactically)
const;
150 IsAllowRedefinitionsWithoutWarning = Val;
159 llvm::BumpPtrAllocator &PPAllocator) {
160 assert(ParameterList ==
nullptr && NumParameters == 0 &&
161 "Parameter list already set!");
165 NumParameters = List.size();
166 ParameterList = PPAllocator.Allocate<
IdentifierInfo *>(List.size());
167 std::copy(List.begin(), List.end(), ParameterList);
201 bool isVariadic()
const {
return IsC99Varargs | IsGNUVarargs; }
220 return IsAllowRedefinitionsWithoutWarning;
231 assert(Tok < ReplacementTokens.size() &&
"Invalid token #");
232 return ReplacementTokens[Tok];
244 !IsDefinitionLengthCached &&
245 "Changing replacement tokens after definition length got calculated");
246 ReplacementTokens.push_back(Tok);
255 assert(IsDisabled &&
"Cannot enable an already-enabled macro!");
260 assert(!IsDisabled &&
"Cannot disable an already-disabled macro!");
341 : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(isPublic) {}
357 bool isValid()
const {
return DefDirective !=
nullptr; }
378 return !Def.isUndefined();
403 assert(MI &&
"MacroInfo is null");
423 assert(UndefLoc.
isValid() &&
"Invalid UndefLoc!");
459 return DefDirective->getInfo();
464 if (
isInvalid() || DefDirective->getPrevious() ==
nullptr)
466 return DefDirective->getPrevious()->getDefinition();
484 unsigned NumOverriddenBy;
486 unsigned NumOverrides;
493 : II(II), Macro(Macro), OwningModule(OwningModule), NumOverriddenBy(0),
494 NumOverrides(Overrides.size()) {
495 std::copy(Overrides.begin(), Overrides.end(),
505 return Profile(ID, OwningModule, II);
509 ID.AddPointer(OwningModule);
527 return overrides_begin() + NumOverrides;
530 return llvm::makeArrayRef(overrides_begin(), overrides_end());
543 llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
550 : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
553 explicit operator bool()
const {
554 return getLocalDirective() || !ModuleMacros.empty();
559 if (!ModuleMacros.empty())
560 return ModuleMacros.back()->getMacroInfo();
561 if (
auto *MD = getLocalDirective())
562 return MD->getMacroInfo();
567 bool isAmbiguous()
const {
return LatestLocalAndAmbiguous.getInt(); }
572 return LatestLocalAndAmbiguous.getPointer();
579 if (
auto *MD = getLocalDirective())
580 F(MD->getMacroInfo());
581 for (
auto *MM : getModuleMacros())
582 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.
param_iterator param_begin() const
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const
Find macro definition active in the specified source location.
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 setParameterList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the parameter list for this macro.
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.
unsigned getDefinitionLength(const SourceManager &SM) const
Get length in characters of the macro definition.
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
unsigned getNumParams() const
detail::InMemoryDirectory::const_iterator I
DefMacroDirective(MacroInfo *MI)
ArrayRef< Token > tokens() const
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
param_iterator param_end() const
void setUsedForHeaderGuard(bool Val)
DefInfo getPreviousDefinition()
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
void setHasCommaPasting()
static bool classof(const VisibilityMacroDirective *)
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
bool isPublic() const
Determine whether this macro is part of the public API of its module.
bool isC99Varargs() const
unsigned MDKind
MacroDirective kind.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
ArrayRef< const IdentifierInfo * > params() const
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.
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
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)
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.
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 getNumOverridingMacros() const
Get the number of macros that override this one.
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.