clang 20.0.0git
Public Types | Public Member Functions | Friends | List of all members
clang::MacroInfo Class Reference

Encapsulates the data about a macro definition (e.g. More...

#include "clang/Lex/MacroInfo.h"

Public Types

using param_iterator = IdentifierInfo *const *
 Parameters - The list of parameters for a function-like macro.
 
using const_tokens_iterator = const Token *
 

Public Member Functions

SourceLocation getDefinitionLoc () const
 Return the location that the macro was defined at.
 
void setDefinitionEndLoc (SourceLocation EndLoc)
 Set the location of the last token in the macro.
 
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.
 
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, and whitespace.
 
void setIsBuiltinMacro (bool Val=true)
 Set or clear the isBuiltinMacro flag.
 
void setIsUsed (bool Val)
 Set the value of the IsUsed flag.
 
void setIsAllowRedefinitionsWithoutWarning (bool Val)
 Set the value of the IsAllowRedefinitionsWithoutWarning flag.
 
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.
 
bool param_empty () const
 
param_iterator param_begin () const
 
param_iterator param_end () const
 
unsigned getNumParams () const
 
ArrayRef< const IdentifierInfo * > params () const
 
int getParameterNum (const IdentifierInfo *Arg) const
 Return the parameter number of the specified identifier, or -1 if the identifier is not a formal parameter identifier.
 
void setIsFunctionLike ()
 Function/Object-likeness.
 
bool isFunctionLike () const
 
bool isObjectLike () const
 
void setIsC99Varargs ()
 Varargs querying methods. This can only be set for function-like macros.
 
void setIsGNUVarargs ()
 
bool isC99Varargs () const
 
bool isGNUVarargs () const
 
bool isVariadic () const
 
bool isBuiltinMacro () const
 Return true if this macro requires processing before expansion.
 
bool hasCommaPasting () const
 
void setHasCommaPasting ()
 
bool isUsed () const
 Return false if this macro is defined in the main file and has not yet been used.
 
bool isAllowRedefinitionsWithoutWarning () const
 Return true if this macro can be redefined without warning.
 
bool isWarnIfUnused () const
 Return true if we should emit a warning if the macro is unused.
 
unsigned getNumTokens () const
 Return the number of tokens that this macro expands to.
 
const TokengetReplacementToken (unsigned Tok) const
 
const_tokens_iterator tokens_begin () const
 
const_tokens_iterator tokens_end () const
 
bool tokens_empty () const
 
ArrayRef< Tokentokens () const
 
llvm::MutableArrayRef< TokenallocateTokens (unsigned NumTokens, llvm::BumpPtrAllocator &PPAllocator)
 
void setTokens (ArrayRef< Token > Tokens, llvm::BumpPtrAllocator &PPAllocator)
 
bool isEnabled () const
 Return true if this macro is enabled.
 
void EnableMacro ()
 
void DisableMacro ()
 
bool isUsedForHeaderGuard () const
 Determine whether this macro was used for a header guard.
 
void setUsedForHeaderGuard (bool Val)
 
void dump () const
 

Friends

class Preprocessor
 

Detailed Description

Encapsulates the data about a macro definition (e.g.

its tokens).

There's an instance of this class for every #define.

Definition at line 39 of file MacroInfo.h.

Member Typedef Documentation

◆ const_tokens_iterator

Definition at line 242 of file MacroInfo.h.

◆ param_iterator

Parameters - The list of parameters for a function-like macro.

This can be empty, for, e.g. "#define X()".

Definition at line 180 of file MacroInfo.h.

Member Function Documentation

◆ allocateTokens()

llvm::MutableArrayRef< Token > clang::MacroInfo::allocateTokens ( unsigned  NumTokens,
llvm::BumpPtrAllocator &  PPAllocator 
)
inline

Definition at line 254 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ DisableMacro()

void clang::MacroInfo::DisableMacro ( )
inline

Definition at line 288 of file MacroInfo.h.

Referenced by clang::TokenLexer::Init().

◆ dump()

LLVM_DUMP_METHOD void MacroInfo::dump ( ) const

◆ EnableMacro()

void clang::MacroInfo::EnableMacro ( )
inline

Definition at line 283 of file MacroInfo.h.

◆ getDefinitionEndLoc()

SourceLocation clang::MacroInfo::getDefinitionEndLoc ( ) const
inline

Return the location of the last token in the macro.

Definition at line 131 of file MacroInfo.h.

◆ getDefinitionLength()

unsigned clang::MacroInfo::getDefinitionLength ( const SourceManager SM) const
inline

Get length in characters of the macro definition.

Definition at line 134 of file MacroInfo.h.

References SM.

Referenced by clang::TokenLexer::Init().

◆ getDefinitionLoc()

SourceLocation clang::MacroInfo::getDefinitionLoc ( ) const
inline

Return the location that the macro was defined at.

Definition at line 125 of file MacroInfo.h.

Referenced by clang::Preprocessor::appendDefMacroDirective(), isLanguageDefinedBuiltin(), and clang::Preprocessor::markMacroAsUsed().

◆ getNumParams()

unsigned clang::MacroInfo::getNumParams ( ) const
inline

Definition at line 184 of file MacroInfo.h.

Referenced by clang::MacroArgs::create(), clang::TokenLexer::Init(), and isIdenticalTo().

◆ getNumTokens()

unsigned clang::MacroInfo::getNumTokens ( ) const
inline

Return the number of tokens that this macro expands to.

Definition at line 235 of file MacroInfo.h.

Referenced by clang::Preprocessor::DumpMacro(), isConfigurationPattern(), isIdenticalTo(), and MacroDefinitionEquals().

◆ getParameterNum()

int clang::MacroInfo::getParameterNum ( const IdentifierInfo Arg) const
inline

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

Definition at line 191 of file MacroInfo.h.

References E, param_begin(), and param_end().

Referenced by isIdenticalTo().

◆ getReplacementToken()

const Token & clang::MacroInfo::getReplacementToken ( unsigned  Tok) const
inline

◆ hasCommaPasting()

bool clang::MacroInfo::hasCommaPasting ( ) const
inline

Definition at line 219 of file MacroInfo.h.

◆ isAllowRedefinitionsWithoutWarning()

bool clang::MacroInfo::isAllowRedefinitionsWithoutWarning ( ) const
inline

Return true if this macro can be redefined without warning.

Definition at line 227 of file MacroInfo.h.

◆ isBuiltinMacro()

bool clang::MacroInfo::isBuiltinMacro ( ) const
inline

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.

Definition at line 217 of file MacroInfo.h.

Referenced by DoPrintMacros(), clang::ASTWriter::getMacroID(), clang::ASTWriter::getMacroRef(), and isLanguageDefinedBuiltin().

◆ isC99Varargs()

bool clang::MacroInfo::isC99Varargs ( ) const
inline

◆ isEnabled()

bool clang::MacroInfo::isEnabled ( ) const
inline

Return true if this macro is enabled.

In other words, that we are not currently in an expansion of this macro.

Definition at line 281 of file MacroInfo.h.

◆ isFunctionLike()

bool clang::MacroInfo::isFunctionLike ( ) const
inline

◆ isGNUVarargs()

bool clang::MacroInfo::isGNUVarargs ( ) const
inline

Definition at line 208 of file MacroInfo.h.

Referenced by isIdenticalTo(), and PrintMacroDefinition().

◆ isIdenticalTo()

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

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

Parameters
Syntacticallyif 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.

Definition at line 94 of file MacroInfo.cpp.

References E, clang::Token::getIdentifierInfo(), clang::Token::getKind(), getNumParams(), getNumTokens(), getParameterNum(), clang::Preprocessor::getSpelling(), clang::Token::hasLeadingSpace(), clang::Token::isAtStartOfLine(), isC99Varargs(), isFunctionLike(), isGNUVarargs(), clang::Other, param_begin(), and param_end().

◆ isObjectLike()

bool clang::MacroInfo::isObjectLike ( ) const
inline

◆ isUsed()

bool clang::MacroInfo::isUsed ( ) const
inline

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

Definition at line 224 of file MacroInfo.h.

Referenced by clang::Preprocessor::markMacroAsUsed().

◆ isUsedForHeaderGuard()

bool clang::MacroInfo::isUsedForHeaderGuard ( ) const
inline

Determine whether this macro was used for a header guard.

Definition at line 294 of file MacroInfo.h.

Referenced by AddMacroResults().

◆ isVariadic()

bool clang::MacroInfo::isVariadic ( ) const
inline

◆ isWarnIfUnused()

bool clang::MacroInfo::isWarnIfUnused ( ) const
inline

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

Definition at line 232 of file MacroInfo.h.

Referenced by clang::Preprocessor::markMacroAsUsed().

◆ param_begin()

param_iterator clang::MacroInfo::param_begin ( ) const
inline

◆ param_empty()

bool clang::MacroInfo::param_empty ( ) const
inline

Definition at line 181 of file MacroInfo.h.

Referenced by PrintMacroDefinition().

◆ param_end()

param_iterator clang::MacroInfo::param_end ( ) const
inline

◆ params()

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

Definition at line 185 of file MacroInfo.h.

Referenced by isTrivialSingleTokenExpansion().

◆ setDefinitionEndLoc()

void clang::MacroInfo::setDefinitionEndLoc ( SourceLocation  EndLoc)
inline

Set the location of the last token in the macro.

Definition at line 128 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ setHasCommaPasting()

void clang::MacroInfo::setHasCommaPasting ( )
inline

Definition at line 220 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ setIsAllowRedefinitionsWithoutWarning()

void clang::MacroInfo::setIsAllowRedefinitionsWithoutWarning ( bool  Val)
inline

Set the value of the IsAllowRedefinitionsWithoutWarning flag.

Definition at line 157 of file MacroInfo.h.

Referenced by clang::Preprocessor::HandlePragmaPushMacro().

◆ setIsBuiltinMacro()

void clang::MacroInfo::setIsBuiltinMacro ( bool  Val = true)
inline

Set or clear the isBuiltinMacro flag.

Definition at line 151 of file MacroInfo.h.

Referenced by RegisterBuiltinMacro().

◆ setIsC99Varargs()

void clang::MacroInfo::setIsC99Varargs ( )
inline

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

Definition at line 205 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ setIsFunctionLike()

void clang::MacroInfo::setIsFunctionLike ( )
inline

Function/Object-likeness.

Keep track of whether this macro has formal parameters.

Definition at line 200 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ setIsGNUVarargs()

void clang::MacroInfo::setIsGNUVarargs ( )
inline

Definition at line 206 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ setIsUsed()

void clang::MacroInfo::setIsUsed ( bool  Val)
inline

Set the value of the IsUsed flag.

Definition at line 154 of file MacroInfo.h.

Referenced by clang::Preprocessor::markMacroAsUsed(), and clang::ASTReader::ReadMacroRecord().

◆ setIsWarnIfUnused()

void clang::MacroInfo::setIsWarnIfUnused ( bool  val)
inline

Set the value of the IsWarnIfUnused flag.

Definition at line 162 of file MacroInfo.h.

◆ setParameterList()

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

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

Definition at line 166 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ setTokens()

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

Definition at line 263 of file MacroInfo.h.

◆ setUsedForHeaderGuard()

void clang::MacroInfo::setUsedForHeaderGuard ( bool  Val)
inline

Definition at line 296 of file MacroInfo.h.

Referenced by clang::ASTReader::ReadMacroRecord().

◆ tokens()

ArrayRef< Token > clang::MacroInfo::tokens ( ) const
inline

Definition at line 249 of file MacroInfo.h.

Referenced by dump(), PrintMacroDefinition(), and clang::ento::tryExpandAsInteger().

◆ tokens_begin()

const_tokens_iterator clang::MacroInfo::tokens_begin ( ) const
inline

◆ tokens_empty()

bool clang::MacroInfo::tokens_empty ( ) const
inline

Definition at line 248 of file MacroInfo.h.

Referenced by PrintMacroDefinition().

◆ tokens_end()

const_tokens_iterator clang::MacroInfo::tokens_end ( ) const
inline

Definition at line 245 of file MacroInfo.h.

Referenced by clang::TokenLexer::Init().

Friends And Related Function Documentation

◆ Preprocessor

friend class Preprocessor
friend

Definition at line 301 of file MacroInfo.h.


The documentation for this class was generated from the following files: