assert(!Tokens.empty());
58 if(Current->
isNot(tok::identifier))
62 if(Current->
is(tok::l_paren)) {
67 if(!parseExpansion())
75assert(Current->
is(tok::l_paren));
77 while(Current->
is(tok::identifier)) {
78Def.
Params.push_back(Current);
81 if(Current->
isNot(tok::comma))
85 if(Current->
isNot(tok::r_paren))
91 boolparseExpansion() {
92 if(!Current->
isOneOf(tok::equal, tok::eof))
94 if(Current->
is(tok::equal))
101 while(Current->
isNot(tok::eof)) {
102Def.
Body.push_back(Current);
105Def.
Body.push_back(Current);
109 if(Pos + 1 < Tokens.size())
111Current = Tokens[Pos];
116FormatToken *Current =
nullptr;
118ArrayRef<FormatToken *> Tokens;
122 conststd::vector<std::string> &Macros,
SourceManager&SourceMgr,
124llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
126: SourceMgr(SourceMgr), Style(Style), Allocator(Allocator),
127IdentTable(IdentTable) {
128 for(
conststd::string &Macro : Macros)
129parseDefinition(Macro);
134voidMacroExpander::parseDefinition(
conststd::string &Macro) {
136llvm::MemoryBuffer::getMemBufferCopy(Macro,
"<scratch space>"));
139Allocator, IdentTable);
140 const autoTokens = Lex.lex();
141 if(!Tokens.empty()) {
142DefinitionParser
Parser(Tokens);
143 autoDefinition =
Parser.parse();
144 if(Definition.ObjectLike) {
145ObjectLike[Definition.Name] = std::move(Definition);
147FunctionLike[Definition.Name][Definition.Params.size()] =
148std::move(Definition);
154 returnFunctionLike.contains(Name) || ObjectLike.contains(Name);
158 returnObjectLike.contains(Name);
162 autoit = FunctionLike.find(Name);
163 returnit != FunctionLike.end() && it->second.contains(Arity);
168std::optional<ArgsList> OptionalArgs)
const{
170assert(
hasArity(
ID->TokenText, OptionalArgs->size()));
174? FunctionLike.find(
ID->TokenText)
175->second.find(OptionalArgs.value().size())
177: ObjectLike.find(
ID->TokenText)->second;
181llvm::StringSet<> ExpandedArgs;
185Tok->MacroCtx->ExpandedFrom.push_back(
ID);
191 autoexpandArgument = [&](
FormatToken*Tok) ->
bool{
194 if(Tok->isNot(tok::identifier))
196 if(!ExpandedArgs.insert(Tok->TokenText).second)
198 autoI = Def.
ArgMap.find(Tok->TokenText);
199 if(I == Def.
ArgMap.end())
204 if(I->getValue() >= Args.size())
221 if(expandArgument(Tok))
232assert(
Result.size() >= 1 &&
Result.back()->is(tok::eof));
233 if(
Result.size() > 1) {
234++
Result[0]->MacroCtx->StartOfExpansion;
235++
Result[
Result.size() - 2]->MacroCtx->EndOfExpansion;
238 Result[0]->MacroCtx->StartOfExpansion = 1;
239 Result[0]->MacroCtx->EndOfExpansion = 1;
Contains functions for text encoding manipulation.
This file contains FormatTokenLexer, which tokenizes a source file into a token stream suitable for C...
This file contains the declaration of the FormatToken, a wrapper around Token with additional informa...
Various functions to configurably format source code.
This file contains the main building blocks of macro support in clang-format.
Defines the clang::Preprocessor interface.
Defines the clang::TokenKind enum and support functions.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements an efficient mapping from strings to IdentifierInfo nodes.
Parser - This implements a parser for the C family of languages.
This class handles loading and caching of source files into memory.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
MacroExpander::Definition parse()
DefinitionParser(ArrayRef< FormatToken * > Tokens)
bool objectLike(StringRef Name) const
Returns whetherh there is an object-like overload, i.e.
SmallVector< FormatToken *, 8 > expand(FormatToken *ID, std::optional< ArgsList > OptionalArgs) const
Returns the expanded stream of format tokens for ID, where each element in Args is a positional argum...
ArrayRef< SmallVector< FormatToken *, 8 > > ArgsList
bool hasArity(StringRef Name, unsigned Arity) const
Returns whether macro Name provides an overload with the given arity.
MacroExpander(const std::vector< std::string > &Macros, SourceManager &SourceMgr, const FormatStyle &Style, llvm::SpecificBumpPtrAllocator< FormatToken > &Allocator, IdentifierTable &IdentTable)
Construct a macro expander from a set of macro definitions.
bool defined(StringRef Name) const
Returns whether any macro Name is defined, regardless of overloads.
@ MR_Hidden
The token was expanded from a macro definition, and is not visible as part of the macro call.
@ MR_ExpandedArg
The token was expanded from a macro argument when formatting the expanded token sequence.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
The FormatStyle is used to configure the formatting to follow specific guidelines.
A wrapper around a Token storing information about the whitespace characters preceding it.
StringRef TokenText
The raw text of the token.
unsigned Finalized
If true, this token has been fully formatted (indented and potentially re-formatted inside),...
std::optional< MacroExpansion > MacroCtx
bool is(tok::TokenKind Kind) const
bool isOneOf(A K1, B K2) const
void copyFrom(const FormatToken &Tok)
SmallVector< FormatToken *, 8 > Params
SmallVector< FormatToken *, 8 > Body
llvm::StringMap< size_t > ArgMap
Contains information on the token's role in a macro expansion.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4