clang 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
clang::MacroArgs Class Referencefinal

MacroArgs - An instance of this class captures information about the formal arguments specified to a function-like macro invocation. More...

#include "clang/Lex/MacroArgs.h"

Inheritance diagram for clang::MacroArgs:
Inheritance graph
[legend]

Public Member Functions

void destroy (Preprocessor &PP)
 destroy - Destroy and deallocate the memory for this object.
 
bool ArgNeedsPreexpansion (const Token *ArgTok, Preprocessor &PP) const
 ArgNeedsPreexpansion - If we can prove that the argument won't be affected by pre-expansion, return false.
 
const TokengetUnexpArgument (unsigned Arg) const
 getUnexpArgument - Return a pointer to the first token of the unexpanded token list for the specified formal.
 
const std::vector< Token > & getPreExpArgument (unsigned Arg, Preprocessor &PP)
 getPreExpArgument - Return the pre-expanded form of the specified argument.
 
unsigned getNumMacroArguments () const
 getNumMacroArguments - Return the number of arguments the invoked macro expects.
 
bool isVarargsElidedUse () const
 isVarargsElidedUse - Return true if this is a C99 style varargs macro invocation and there was no argument specified for the "..." argument.
 
bool invokedWithVariadicArgument (const MacroInfo *const MI, Preprocessor &PP)
 Returns true if the macro was defined with a variadic (ellipsis) parameter AND was invoked with at least one token supplied as a variadic argument (after pre-expansion).
 
MacroArgsdeallocate ()
 deallocate - This should only be called by the Preprocessor when managing its freelist.
 

Static Public Member Functions

static MacroArgscreate (const MacroInfo *MI, ArrayRef< Token > UnexpArgTokens, bool VarargsElided, Preprocessor &PP)
 MacroArgs ctor function - Create a new MacroArgs object with the specified macro and argument info.
 
static unsigned getArgLength (const Token *ArgPtr)
 getArgLength - Given a pointer to an expanded or unexpanded argument, return the number of tokens, not counting the EOF, that make up the argument.
 
static Token StringifyArgument (const Token *ArgToks, Preprocessor &PP, bool Charify, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd)
 StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of tokens into the literal string token that should be produced by the C # preprocessor operator.
 

Detailed Description

MacroArgs - An instance of this class captures information about the formal arguments specified to a function-like macro invocation.

Definition at line 29 of file MacroArgs.h.

Member Function Documentation

◆ ArgNeedsPreexpansion()

bool MacroArgs::ArgNeedsPreexpansion ( const Token ArgTok,
Preprocessor PP 
) const

ArgNeedsPreexpansion - If we can prove that the argument won't be affected by pre-expansion, return false.

Otherwise, conservatively return true.

Definition at line 146 of file MacroArgs.cpp.

References clang::Token::getIdentifierInfo(), and clang::Token::isNot().

◆ create()

MacroArgs * MacroArgs::create ( const MacroInfo MI,
ArrayRef< Token UnexpArgTokens,
bool  VarargsElided,
Preprocessor PP 
)
static

MacroArgs ctor function - Create a new MacroArgs object with the specified macro and argument info.

MacroArgs ctor function - This destroys the vector passed in.

Definition at line 24 of file MacroArgs.cpp.

References clang::MacroInfo::getNumParams(), clang::MacroInfo::isFunctionLike(), and clang::Result.

◆ deallocate()

MacroArgs * MacroArgs::deallocate ( )

deallocate - This should only be called by the Preprocessor when managing its freelist.

Definition at line 91 of file MacroArgs.cpp.

◆ destroy()

void MacroArgs::destroy ( Preprocessor PP)

destroy - Destroy and deallocate the memory for this object.

Definition at line 78 of file MacroArgs.cpp.

◆ getArgLength()

unsigned MacroArgs::getArgLength ( const Token ArgPtr)
static

getArgLength - Given a pointer to an expanded or unexpanded argument, return the number of tokens, not counting the EOF, that make up the argument.

Definition at line 108 of file MacroArgs.cpp.

References clang::Token::isNot().

Referenced by getPreExpArgument().

◆ getNumMacroArguments()

unsigned clang::MacroArgs::getNumMacroArguments ( ) const
inline

getNumMacroArguments - Return the number of arguments the invoked macro expects.

Definition at line 95 of file MacroArgs.h.

Referenced by getPreExpArgument(), getUnexpArgument(), and invokedWithVariadicArgument().

◆ getPreExpArgument()

const std::vector< Token > & MacroArgs::getPreExpArgument ( unsigned  Arg,
Preprocessor PP 
)

getPreExpArgument - Return the pre-expanded form of the specified argument.

Definition at line 161 of file MacroArgs.cpp.

References getArgLength(), getNumMacroArguments(), getUnexpArgument(), clang::Preprocessor::Lex(), clang::Preprocessor::RemoveTopOfLexerStack(), and clang::Result.

Referenced by invokedWithVariadicArgument().

◆ getUnexpArgument()

const Token * MacroArgs::getUnexpArgument ( unsigned  Arg) const

getUnexpArgument - Return a pointer to the first token of the unexpanded token list for the specified formal.

getUnexpArgument - Return the unexpanded tokens for the specified formal.

Definition at line 118 of file MacroArgs.cpp.

References getNumMacroArguments(), and clang::Result.

Referenced by getPreExpArgument().

◆ invokedWithVariadicArgument()

bool MacroArgs::invokedWithVariadicArgument ( const MacroInfo *const  MI,
Preprocessor PP 
)

Returns true if the macro was defined with a variadic (ellipsis) parameter AND was invoked with at least one token supplied as a variadic argument (after pre-expansion).

#define F(a) a
#define V(a, ...) __VA_OPT__(a)
F() <-- returns false on this invocation.
V(,a) <-- returns true on this invocation.
V(,) <-- returns false on this invocation.
V(,F()) <-- returns false on this invocation.
const internal::MapAnyOfMatcher< CallExpr, CXXConstructExpr > invocation
Matches function calls and constructor calls.

Definition at line 136 of file MacroArgs.cpp.

References getNumMacroArguments(), getPreExpArgument(), and clang::MacroInfo::isVariadic().

◆ isVarargsElidedUse()

bool clang::MacroArgs::isVarargsElidedUse ( ) const
inline

isVarargsElidedUse - Return true if this is a C99 style varargs macro invocation and there was no argument specified for the "..." argument.

If the argument was specified (even empty) or this isn't a C99 style varargs function, or if in strict mode and the C99 varargs macro had only a ... argument, this returns false.

Definition at line 102 of file MacroArgs.h.

◆ StringifyArgument()

Token MacroArgs::StringifyArgument ( const Token ArgToks,
Preprocessor PP,
bool  Charify,
SourceLocation  ExpansionLocStart,
SourceLocation  ExpansionLocEnd 
)
static

StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of tokens into the literal string token that should be produced by the C # preprocessor operator.

If Charify is true, then it should be turned into a character literal for the Microsoft charize (#@) extension.

Definition at line 208 of file MacroArgs.cpp.

References clang::Preprocessor::CodeCompleteNaturalLanguage(), clang::Preprocessor::CreateString(), clang::Preprocessor::Diag(), clang::Token::getKind(), clang::Token::getLength(), clang::Preprocessor::getSpelling(), clang::Token::hasLeadingSpace(), clang::Invalid, clang::Token::is(), clang::Token::isAtStartOfLine(), clang::Token::isNot(), clang::tok::isStringLiteral(), memcpy(), clang::Result, clang::Token::setKind(), clang::Token::startToken(), and clang::Lexer::Stringify().


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