Lines Matching +full:clang +full:- +full:format
1 //===--- MacroExpander.cpp - Format C++ code --------------------*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
20 #include "clang/Basic/TokenKinds.h"
21 #include "clang/Format/Format.h"
22 #include "clang/Lex/HeaderSearch.h"
23 #include "clang/Lex/HeaderSearchOptions.h"
24 #include "clang/Lex/Lexer.h"
25 #include "clang/Lex/ModuleLoader.h"
26 #include "clang/Lex/Preprocessor.h"
27 #include "clang/Lex/PreprocessorOptions.h"
31 namespace clang { namespace
32 namespace format { namespace
41 // x -> 0
42 // y -> 1
56 // Returns an empty definition object with a null-Name on error.
58 if (Current->isNot(tok::identifier)) in parse()
60 Def.Name = Current->TokenText; in parse()
62 if (Current->is(tok::l_paren)) { in parse()
75 assert(Current->is(tok::l_paren)); in parseParams()
77 while (Current->is(tok::identifier)) { in parseParams()
79 Def.ArgMap[Def.Params.back()->TokenText] = Def.Params.size() - 1; in parseParams()
81 if (Current->isNot(tok::comma)) in parseParams()
85 if (Current->isNot(tok::r_paren)) in parseParams()
92 if (!Current->isOneOf(tok::equal, tok::eof)) in parseExpansion()
94 if (Current->is(tok::equal)) in parseExpansion()
101 while (Current->isNot(tok::eof)) { in parseTail()
112 Current->Finalized = true; in nextToken()
137 FileID FID = SourceMgr.createFileID(Buffers.back()->getMemBufferRef()); in parseDefinition()
163 return it != FunctionLike.end() && it->second.contains(Arity); in hasArity()
170 assert(hasArity(ID->TokenText, OptionalArgs->size())); in expand()
172 assert(objectLike(ID->TokenText)); in expand()
174 ? FunctionLike.find(ID->TokenText) in expand()
175 ->second.find(OptionalArgs.value().size()) in expand()
176 ->second in expand()
177 : ObjectLike.find(ID->TokenText)->second; in expand()
185 Tok->MacroCtx->ExpandedFrom.push_back(ID); in expand()
191 auto expandArgument = [&](FormatToken *Tok) -> bool { in expand()
194 if (Tok->isNot(tok::identifier) || ExpandedArgs.contains(Tok->TokenText)) in expand()
196 ExpandedArgs.insert(Tok->TokenText); in expand()
197 auto I = Def.ArgMap.find(Tok->TokenText); in expand()
203 if (I->getValue() >= Args.size()) in expand()
205 for (FormatToken *Arg : Args[I->getValue()]) { in expand()
211 if (!Arg->MacroCtx) in expand()
212 Arg->MacroCtx = MacroExpansion(MR_ExpandedArg); in expand()
225 New->copyFrom(*Tok); in expand()
226 assert(!New->MacroCtx); in expand()
228 New->MacroCtx = MacroExpansion(MR_Hidden); in expand()
231 assert(Result.size() >= 1 && Result.back()->is(tok::eof)); in expand()
233 ++Result[0]->MacroCtx->StartOfExpansion; in expand()
234 ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion; in expand()
239 } // namespace format
240 } // namespace clang