14#ifndef LLVM_CLANG_LEX_MACROINFO_H
15#define LLVM_CLANG_LEX_MACROINFO_H
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/FoldingSet.h"
22#include "llvm/ADT/PointerIntPair.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/Support/Allocator.h"
30class DefMacroDirective;
58 const Token *ReplacementTokens =
nullptr;
61 unsigned NumParameters = 0;
64 unsigned NumReplacementTokens = 0;
67 mutable unsigned DefinitionLength;
68 mutable bool IsDefinitionLengthCached : 1;
71 bool IsFunctionLike : 1;
78 bool IsC99Varargs : 1;
84 bool IsGNUVarargs : 1;
91 bool IsBuiltinMacro : 1;
94 bool HasCommaPasting : 1;
112 bool IsAllowRedefinitionsWithoutWarning : 1;
115 bool IsWarnIfUnused : 1;
118 bool UsedForHeaderGuard : 1;
135 if (IsDefinitionLengthCached)
136 return DefinitionLength;
137 return getDefinitionLengthSlow(
SM);
148 bool Syntactically)
const;
158 IsAllowRedefinitionsWithoutWarning = Val;
167 llvm::BumpPtrAllocator &PPAllocator) {
168 assert(ParameterList ==
nullptr && NumParameters == 0 &&
169 "Parameter list already set!");
173 NumParameters = List.size();
174 ParameterList = PPAllocator.Allocate<
IdentifierInfo *>(List.size());
175 std::copy(List.begin(), List.end(), ParameterList);
209 bool isVariadic()
const {
return IsC99Varargs || IsGNUVarargs; }
228 return IsAllowRedefinitionsWithoutWarning;
238 assert(Tok < NumReplacementTokens &&
"Invalid token #");
239 return ReplacementTokens[Tok];
246 return ReplacementTokens + NumReplacementTokens;
255 assert(ReplacementTokens ==
nullptr && NumReplacementTokens == 0 &&
256 "Token list already allocated!");
257 NumReplacementTokens = NumTokens;
258 Token *NewReplacementTokens = PPAllocator.Allocate<
Token>(NumTokens);
259 ReplacementTokens = NewReplacementTokens;
265 !IsDefinitionLengthCached &&
266 "Changing replacement tokens after definition length got calculated");
267 assert(ReplacementTokens ==
nullptr && NumReplacementTokens == 0 &&
268 "Token list already set!");
272 NumReplacementTokens = Tokens.size();
273 Token *NewReplacementTokens = PPAllocator.Allocate<
Token>(Tokens.size());
274 std::copy(Tokens.begin(), Tokens.end(), NewReplacementTokens);
275 ReplacementTokens = NewReplacementTokens;
284 assert(IsDisabled &&
"Cannot enable an already-enabled macro!");
289 assert(!IsDisabled &&
"Cannot disable an already-disabled macro!");
328 LLVM_PREFERRED_TYPE(
Kind)
332 LLVM_PREFERRED_TYPE(
bool)
339 LLVM_PREFERRED_TYPE(
bool)
367 bool IsPublic =
true;
373 : DefDirective(DefDirective), UndefLoc(UndefLoc), IsPublic(
isPublic) {}
390 bool isValid()
const {
return DefDirective !=
nullptr; }
412 return !Def.isUndefined();
438 assert(MI &&
"MacroInfo is null");
459 assert(UndefLoc.
isValid() &&
"Invalid UndefLoc!");
497 return DefDirective->getInfo();
502 if (
isInvalid() || DefDirective->getPrevious() ==
nullptr)
504 return DefDirective->getPrevious()->getDefinition();
527 unsigned NumOverriddenBy = 0;
530 unsigned NumOverrides;
534 : II(II), Macro(Macro), OwningModule(OwningModule),
535 NumOverrides(Overrides.size()) {
536 std::copy(Overrides.begin(), Overrides.end(),
546 return Profile(
ID, OwningModule, II);
551 ID.AddPointer(OwningModule);
574 return overrides_begin() + NumOverrides;
591 llvm::PointerIntPair<DefMacroDirective *, 1, bool> LatestLocalAndAmbiguous;
598 : LatestLocalAndAmbiguous(MD, IsAmbiguous), ModuleMacros(MMs) {}
601 explicit operator bool()
const {
602 return getLocalDirective() || !ModuleMacros.empty();
607 if (!ModuleMacros.empty())
608 return ModuleMacros.back()->getMacroInfo();
609 if (
auto *MD = getLocalDirective())
610 return MD->getMacroInfo();
615 bool isAmbiguous()
const {
return LatestLocalAndAmbiguous.getInt(); }
620 return LatestLocalAndAmbiguous.getPointer();
627 if (
auto *MD = getLocalDirective())
628 F(MD->getMacroInfo());
629 for (
auto *MM : getModuleMacros())
630 F(MM->getMacroInfo());
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
static bool isInvalid(LocType Loc, bool *Invalid)
A directive for a defined macro or a macro imported from a module.
static bool classof(const MacroDirective *MD)
static bool classof(const DefMacroDirective *)
const MacroInfo * getInfo() const
The data for the macro definition.
DefMacroDirective(MacroInfo *MI)
DefMacroDirective(MacroInfo *MI, SourceLocation Loc)
One of these records is kept for each identifier that is lexed.
A description of the current definition of a macro.
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
DefMacroDirective * getLocalDirective() const
Get the latest non-imported, non-#undef'd macro definition for this macro.
ArrayRef< ModuleMacro * > getModuleMacros() const
Get the active module macros for this macro.
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
MacroDefinition(DefMacroDirective *MD, ArrayRef< ModuleMacro * > MMs, bool IsAmbiguous)
MacroDefinition()=default
void forAllDefinitions(Fn F) const
const DefInfo getPreviousDefinition() const
DefMacroDirective * getDirective()
DefInfo(DefMacroDirective *DefDirective, SourceLocation UndefLoc, bool isPublic)
DefInfo getPreviousDefinition()
MacroInfo * getMacroInfo()
const MacroInfo * getMacroInfo() const
SourceLocation getUndefLocation() const
const DefMacroDirective * getDirective() const
SourceLocation getLocation() const
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
MacroDirective * Previous
Previous macro directive for the same identifier, or nullptr.
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
const MacroInfo * getMacroInfo() const
const DefInfo findDirectiveAtLoc(SourceLocation L, const SourceManager &SM) const
Find macro definition active in the specified source location.
unsigned IsPublic
Whether the macro has public visibility (when described in a module).
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
unsigned IsFromPCH
True if the macro directive was loaded from a PCH file.
SourceLocation getLocation() const
static bool classof(const MacroDirective *)
unsigned MDKind
MacroDirective kind.
MacroInfo * getMacroInfo()
const DefInfo getDefinition() const
bool isFromPCH() const
Return true if the macro directive was loaded from a PCH file.
MacroDirective * getPrevious()
Get previous definition of the macro with the same name.
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
Encapsulates the data about a macro definition (e.g.
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
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 isUsed() const
Return false if this macro is defined in the main file and has not yet been used.
bool isC99Varargs() const
bool isFunctionLike() const
const_tokens_iterator tokens_begin() const
bool isAllowRedefinitionsWithoutWarning() const
Return true if this macro can be redefined without warning.
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
void setUsedForHeaderGuard(bool Val)
void setHasCommaPasting()
param_iterator param_begin() const
const_tokens_iterator tokens_end() const
ArrayRef< const IdentifierInfo * > params() const
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
unsigned getNumParams() const
const Token & getReplacementToken(unsigned Tok) const
void setDefinitionEndLoc(SourceLocation EndLoc)
Set the location of the last token in the macro.
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
void setTokens(ArrayRef< Token > Tokens, llvm::BumpPtrAllocator &PPAllocator)
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
void setParameterList(ArrayRef< IdentifierInfo * > List, llvm::BumpPtrAllocator &PPAllocator)
Set the specified list of identifiers as the parameter list for this macro.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
bool tokens_empty() const
unsigned getDefinitionLength(const SourceManager &SM) const
Get length in characters of the macro definition.
llvm::MutableArrayRef< Token > allocateTokens(unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator)
bool hasCommaPasting() const
void setIsFunctionLike()
Function/Object-likeness.
bool isObjectLike() const
param_iterator param_end() const
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
ArrayRef< Token > tokens() const
void setIsWarnIfUnused(bool val)
Set the value of the IsWarnIfUnused flag.
int getParameterNum(const IdentifierInfo *Arg) const
Return the parameter number of the specified identifier, or -1 if the identifier is not a formal para...
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
bool isGNUVarargs() const
void setIsC99Varargs()
Varargs querying methods. This can only be set for function-like macros.
bool isEnabled() const
Return true if this macro is enabled.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
void setIsBuiltinMacro(bool Val=true)
Set or clear the isBuiltinMacro flag.
Represents a macro directive exported by a module.
const IdentifierInfo * getName() const
Get the name of the macro.
MacroInfo * getMacroInfo() const
Get definition for this exported #define, or nullptr if this represents a #undef.
overrides_iterator overrides_begin() const
ArrayRef< ModuleMacro * > overrides() const
static void Profile(llvm::FoldingSetNodeID &ID, Module *OwningModule, const IdentifierInfo *II)
unsigned getNumOverridingMacros() const
Get the number of macros that override this one.
void Profile(llvm::FoldingSetNodeID &ID) const
Module * getOwningModule() const
Get the ID of the module that exports this macro.
ModuleMacro *const * overrides_iterator
Iterators over the overridden module IDs.
overrides_iterator overrides_end() const
Describes a module or submodule.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
Token - This structure provides full information about a lexed token.
A directive for an undefined macro.
static bool classof(const UndefMacroDirective *)
static bool classof(const MacroDirective *MD)
UndefMacroDirective(SourceLocation UndefLoc)
A directive for setting the module visibility of a macro.
VisibilityMacroDirective(SourceLocation Loc, bool Public)
static bool classof(const MacroDirective *MD)
static bool classof(const VisibilityMacroDirective *)
bool isPublic() const
Determine whether this macro is part of the public API of its module.
The JSON file list parser is used to communicate input to InstallAPI.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Other
Other implicit parameter.