class MacroInfo

Declaration

class MacroInfo { /* full declaration omitted */ };

Description

Encapsulates the data about a macro definition (e.g. its tokens). There's an instance of this class for every #define.

Declared at: clang/include/clang/Lex/MacroInfo.h:39

Member Variables

private clang::SourceLocation Location
The location the macro is defined.
private clang::SourceLocation EndLocation
The location of the last token in the macro.
private clang::IdentifierInfo** ParameterList = nullptr
This can be empty, for, e.g. "#define X()". In a C99-style variadic macro, this includes the \c __VA_ARGS__ identifier on the list.
private const clang::Token* ReplacementTokens = nullptr
This is the list of tokens that the macro is defined to.
private unsigned int NumParameters = 0
private unsigned int NumReplacementTokens = 0
private unsigned int DefinitionLength
Length in characters of the macro definition.
private bool IsDefinitionLengthCached
private bool IsFunctionLike
True if this macro is function-like, false if it is object-like.
private bool IsC99Varargs
The __VA_ARGS__ token should be replaced with the contents of "..." in an invocation.
private bool IsGNUVarargs
The "a" identifier in the replacement list will be replaced with all arguments of the macro starting with the specified one.
private bool IsBuiltinMacro
This is the case for builtin macros such as __LINE__, so long as they have not been redefined, but not for regular predefined macros from the "<built-in>" memory buffer (see Preprocessing::getPredefinesFileID).
private bool HasCommaPasting
Whether this macro contains the sequence ", ## __VA_ARGS__"
private bool IsDisabled
This disables recursive expansion, which would be quite bad for things like # define A A.
private bool IsUsed
This is used to emit -Wunused-macros diagnostics.
private bool IsAllowRedefinitionsWithoutWarning
True if this macro can be redefined without emitting a warning.
private bool IsWarnIfUnused
Must warn if the macro is unused at the end of translation unit.
private bool UsedForHeaderGuard
Whether this macro was used as header guard.

Method Overview

Methods

void DisableMacro()

Declared at: clang/include/clang/Lex/MacroInfo.h:289

void EnableMacro()

Declared at: clang/include/clang/Lex/MacroInfo.h:284

MacroInfo(clang::SourceLocation DefLoc)

Declared at: clang/include/clang/Lex/MacroInfo.h:121

Parameters

clang::SourceLocation DefLoc

llvm::MutableArrayRef<Token> allocateTokens(
    unsigned int NumTokens,
    llvm::BumpPtrAllocator& PPAllocator)

Declared at: clang/include/clang/Lex/MacroInfo.h:255

Parameters

unsigned int NumTokens
llvm::BumpPtrAllocator& PPAllocator

void dump() const

Declared at: clang/include/clang/Lex/MacroInfo.h:299

clang::SourceLocation getDefinitionEndLoc() const

Description

Return the location of the last token in the macro.

Declared at: clang/include/clang/Lex/MacroInfo.h:132

unsigned int getDefinitionLength(
    const clang::SourceManager& SM) const

Description

Get length in characters of the macro definition.

Declared at: clang/include/clang/Lex/MacroInfo.h:135

Parameters

const clang::SourceManager& SM

unsigned int getDefinitionLengthSlow(
    const clang::SourceManager& SM) const

Declared at: clang/include/clang/Lex/MacroInfo.h:304

Parameters

const clang::SourceManager& SM

clang::SourceLocation getDefinitionLoc() const

Description

Return the location that the macro was defined at.

Declared at: clang/include/clang/Lex/MacroInfo.h:126

unsigned int getNumParams() const

Declared at: clang/include/clang/Lex/MacroInfo.h:185

unsigned int getNumTokens() const

Description

Return the number of tokens that this macro expands to.

Declared at: clang/include/clang/Lex/MacroInfo.h:236

int getParameterNum(
    const clang::IdentifierInfo* Arg) const

Description

Return the parameter number of the specified identifier, or -1 if the identifier is not a formal parameter identifier.

Declared at: clang/include/clang/Lex/MacroInfo.h:192

Parameters

const clang::IdentifierInfo* Arg

const clang::Token& getReplacementToken(
    unsigned int Tok) const

Declared at: clang/include/clang/Lex/MacroInfo.h:238

Parameters

unsigned int Tok

bool hasCommaPasting() const

Declared at: clang/include/clang/Lex/MacroInfo.h:220

bool isAllowRedefinitionsWithoutWarning() const

Description

Return true if this macro can be redefined without warning.

Declared at: clang/include/clang/Lex/MacroInfo.h:228

bool isBuiltinMacro() const

Description

Return true if this macro requires processing before expansion. This is true only for builtin macro, such as \ __LINE__, whose values are not given by fixed textual expansions. Regular predefined macros from the "<built-in>" buffer are not reported as builtins by this function.

Declared at: clang/include/clang/Lex/MacroInfo.h:218

bool isC99Varargs() const

Declared at: clang/include/clang/Lex/MacroInfo.h:208

bool isEnabled() const

Description

Return true if this macro is enabled. In other words, that we are not currently in an expansion of this macro.

Declared at: clang/include/clang/Lex/MacroInfo.h:282

bool isFunctionLike() const

Declared at: clang/include/clang/Lex/MacroInfo.h:202

bool isGNUVarargs() const

Declared at: clang/include/clang/Lex/MacroInfo.h:209

bool isIdenticalTo(const clang::MacroInfo& Other,
                   clang::Preprocessor& PP,
                   bool Syntactically) const

Description

Return true if the specified macro definition is equal to this macro in spelling, arguments, and whitespace.

Declared at: clang/include/clang/Lex/MacroInfo.h:148

Parameters

const clang::MacroInfo& Other
clang::Preprocessor& PP
bool Syntactically
if true, the macro definitions can be identical even if they use different identifiers for the function macro parameters. Otherwise the comparison is lexical and this implements the rules in C99 6.10.3.

bool isObjectLike() const

Declared at: clang/include/clang/Lex/MacroInfo.h:203

bool isUsed() const

Description

Return false if this macro is defined in the main file and has not yet been used.

Declared at: clang/include/clang/Lex/MacroInfo.h:225

bool isUsedForHeaderGuard() const

Description

Determine whether this macro was used for a header guard.

Declared at: clang/include/clang/Lex/MacroInfo.h:295

bool isVariadic() const

Declared at: clang/include/clang/Lex/MacroInfo.h:210

bool isWarnIfUnused() const

Description

Return true if we should emit a warning if the macro is unused.

Declared at: clang/include/clang/Lex/MacroInfo.h:233

clang::MacroInfo::param_iterator param_begin()
    const

Declared at: clang/include/clang/Lex/MacroInfo.h:183

bool param_empty() const

Declared at: clang/include/clang/Lex/MacroInfo.h:182

clang::MacroInfo::param_iterator param_end() const

Declared at: clang/include/clang/Lex/MacroInfo.h:184

ArrayRef<const clang::IdentifierInfo*> params()
    const

Declared at: clang/include/clang/Lex/MacroInfo.h:186

void setDefinitionEndLoc(
    clang::SourceLocation EndLoc)

Description

Set the location of the last token in the macro.

Declared at: clang/include/clang/Lex/MacroInfo.h:129

Parameters

clang::SourceLocation EndLoc

void setHasCommaPasting()

Declared at: clang/include/clang/Lex/MacroInfo.h:221

void setIsAllowRedefinitionsWithoutWarning(
    bool Val)

Description

Set the value of the IsAllowRedefinitionsWithoutWarning flag.

Declared at: clang/include/clang/Lex/MacroInfo.h:158

Parameters

bool Val

void setIsBuiltinMacro(bool Val = true)

Description

Set or clear the isBuiltinMacro flag.

Declared at: clang/include/clang/Lex/MacroInfo.h:152

Parameters

bool Val = true

void setIsC99Varargs()

Description

Varargs querying methods. This can only be set for function-like macros.

Declared at: clang/include/clang/Lex/MacroInfo.h:206

void setIsFunctionLike()

Description

Function/Object-likeness. Keep track of whether this macro has formal parameters.

Declared at: clang/include/clang/Lex/MacroInfo.h:201

void setIsGNUVarargs()

Declared at: clang/include/clang/Lex/MacroInfo.h:207

void setIsUsed(bool Val)

Description

Set the value of the IsUsed flag.

Declared at: clang/include/clang/Lex/MacroInfo.h:155

Parameters

bool Val

void setIsWarnIfUnused(bool val)

Description

Set the value of the IsWarnIfUnused flag.

Declared at: clang/include/clang/Lex/MacroInfo.h:163

Parameters

bool val

void setParameterList(
    ArrayRef<clang::IdentifierInfo*> List,
    llvm::BumpPtrAllocator& PPAllocator)

Description

Set the specified list of identifiers as the parameter list for this macro.

Declared at: clang/include/clang/Lex/MacroInfo.h:167

Parameters

ArrayRef<clang::IdentifierInfo*> List
llvm::BumpPtrAllocator& PPAllocator

void setTokens(
    ArrayRef<clang::Token> Tokens,
    llvm::BumpPtrAllocator& PPAllocator)

Declared at: clang/include/clang/Lex/MacroInfo.h:264

Parameters

ArrayRef<clang::Token> Tokens
llvm::BumpPtrAllocator& PPAllocator

void setUsedForHeaderGuard(bool Val)

Declared at: clang/include/clang/Lex/MacroInfo.h:297

Parameters

bool Val

ArrayRef<clang::Token> tokens() const

Declared at: clang/include/clang/Lex/MacroInfo.h:250

clang::MacroInfo::const_tokens_iterator
tokens_begin() const

Declared at: clang/include/clang/Lex/MacroInfo.h:245

bool tokens_empty() const

Declared at: clang/include/clang/Lex/MacroInfo.h:249

clang::MacroInfo::const_tokens_iterator
tokens_end() const

Declared at: clang/include/clang/Lex/MacroInfo.h:246

~MacroInfo()

Declared at: clang/include/clang/Lex/MacroInfo.h:122