clang  15.0.0git
Classes | Public Types | Public Member Functions | List of all members
clang::format::MacroExpander Class Reference

Takes a set of macro definitions as strings and allows expanding calls to those macros. More...

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/Format/Macros.h"

Classes

struct  Definition
 
class  DefinitionParser
 

Public Types

using ArgsList = llvm::ArrayRef< llvm::SmallVector< FormatToken *, 8 > >
 

Public Member Functions

 MacroExpander (const std::vector< std::string > &Macros, clang::SourceManager &SourceMgr, const FormatStyle &Style, llvm::SpecificBumpPtrAllocator< FormatToken > &Allocator, IdentifierTable &IdentTable)
 Construct a macro expander from a set of macro definitions. More...
 
 ~MacroExpander ()
 
bool defined (llvm::StringRef Name) const
 Returns whether a macro Name is defined. More...
 
bool objectLike (llvm::StringRef Name) const
 Returns whether the macro has no arguments and should not consume subsequent parentheses. More...
 
llvm::SmallVector< FormatToken *, 8 > expand (FormatToken *ID, ArgsList Args) const
 Returns the expanded stream of format tokens for ID, where each element in Args is a positional argument to the macro call. More...
 

Detailed Description

Takes a set of macro definitions as strings and allows expanding calls to those macros.

For example: Definition: A(x, y)=x + y Call : A(int a = 1, 2) Expansion : int a = 1 + 2

Expansion does not check arity of the definition. If fewer arguments than expected are provided, the remaining parameters are considered empty: Call : A(a) Expansion: a + If more arguments than expected are provided, they will be discarded.

The expander does not support:

Furthermore, only a single expansion of each macro argument is supported, so that we cannot get conflicting formatting decisions from different expansions. Definition: A(x)=x+x Call : A(id) Expansion : id+x

Definition at line 88 of file Macros.h.

Member Typedef Documentation

◆ ArgsList

Definition at line 90 of file Macros.h.

Constructor & Destructor Documentation

◆ MacroExpander()

clang::format::MacroExpander::MacroExpander ( const std::vector< std::string > &  Macros,
clang::SourceManager SourceMgr,
const FormatStyle Style,
llvm::SpecificBumpPtrAllocator< FormatToken > &  Allocator,
IdentifierTable IdentTable 
)

Construct a macro expander from a set of macro definitions.

Macro definitions must be encoded as UTF-8.

Each entry in Macros must conform to the following simple macro-definition language: <definition> ::= <id> <expansion> | <id> "(" <params> ")" <expansion> <params> ::= <id-list> | "" <id-list> ::= <id> | <id> "," <params> <expansion> ::= "=" <tail> | <eof> <tail> ::= <tok> <tail> | <eof>

Macros that cannot be parsed will be silently discarded.

Definition at line 121 of file MacroExpander.cpp.

◆ ~MacroExpander()

clang::format::MacroExpander::~MacroExpander ( )
default

Member Function Documentation

◆ defined()

bool clang::format::MacroExpander::defined ( llvm::StringRef  Name) const

Returns whether a macro Name is defined.

Definition at line 148 of file MacroExpander.cpp.

Referenced by expand().

◆ expand()

llvm::SmallVector< FormatToken *, 8 > clang::format::MacroExpander::expand ( FormatToken ID,
ArgsList  Args 
) const

Returns the expanded stream of format tokens for ID, where each element in Args is a positional argument to the macro call.

Definition at line 156 of file MacroExpander.cpp.

References clang::format::MacroExpander::Definition::ArgMap, clang::format::MacroExpander::Definition::Body, clang::format::FormatToken::copyFrom(), defined(), clang::comments::tok::eof, clang::format::FormatToken::MacroCtx, clang::format::MR_ExpandedArg, and clang::format::MR_Hidden.

◆ objectLike()

bool clang::format::MacroExpander::objectLike ( llvm::StringRef  Name) const

Returns whether the macro has no arguments and should not consume subsequent parentheses.

Definition at line 152 of file MacroExpander.cpp.


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