clang  14.0.0git
QualifierAlignmentFixer.cpp
Go to the documentation of this file.
1 //===--- LeftRightQualifierAlignmentFixer.cpp -------------------*- C++--*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file implements LeftRightQualifierAlignmentFixer, a TokenAnalyzer that
11 /// enforces either left or right const depending on the style.
12 ///
13 //===----------------------------------------------------------------------===//
14 
16 #include "FormatToken.h"
17 #include "llvm/Support/Debug.h"
18 #include "llvm/Support/Regex.h"
19 
20 #include <algorithm>
21 
22 #define DEBUG_TYPE "format-qualifier-alignment-fixer"
23 
24 namespace clang {
25 namespace format {
26 
28  const Environment &Env, const FormatStyle &Style, StringRef &Code,
29  ArrayRef<tooling::Range> Ranges, unsigned FirstStartColumn,
30  unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName)
31  : TokenAnalyzer(Env, Style), Code(Code), Ranges(Ranges),
32  FirstStartColumn(FirstStartColumn), NextStartColumn(NextStartColumn),
33  LastStartColumn(LastStartColumn), FileName(FileName) {
34  std::vector<std::string> LeftOrder;
35  std::vector<std::string> RightOrder;
36  std::vector<tok::TokenKind> ConfiguredQualifierTokens;
37  PrepareLeftRightOrdering(Style.QualifierOrder, LeftOrder, RightOrder,
38  ConfiguredQualifierTokens);
39 
40  // Handle the left and right Alignment Seperately
41  for (const auto &Qualifier : LeftOrder) {
42  Passes.emplace_back(
43  [&, Qualifier, ConfiguredQualifierTokens](const Environment &Env) {
44  return LeftRightQualifierAlignmentFixer(Env, Style, Qualifier,
45  ConfiguredQualifierTokens,
46  /*RightAlign=*/false)
47  .process();
48  });
49  }
50  for (const auto &Qualifier : RightOrder) {
51  Passes.emplace_back(
52  [&, Qualifier, ConfiguredQualifierTokens](const Environment &Env) {
53  return LeftRightQualifierAlignmentFixer(Env, Style, Qualifier,
54  ConfiguredQualifierTokens,
55  /*RightAlign=*/true)
56  .process();
57  });
58  }
59 }
60 
61 std::pair<tooling::Replacements, unsigned> QualifierAlignmentFixer::analyze(
62  TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
63  FormatTokenLexer &Tokens) {
64 
65  auto Env =
66  std::make_unique<Environment>(Code, FileName, Ranges, FirstStartColumn,
67  NextStartColumn, LastStartColumn);
68  llvm::Optional<std::string> CurrentCode = None;
70  for (size_t I = 0, E = Passes.size(); I < E; ++I) {
71  std::pair<tooling::Replacements, unsigned> PassFixes = Passes[I](*Env);
72  auto NewCode = applyAllReplacements(
73  CurrentCode ? StringRef(*CurrentCode) : Code, PassFixes.first);
74  if (NewCode) {
75  Fixes = Fixes.merge(PassFixes.first);
76  if (I + 1 < E) {
77  CurrentCode = std::move(*NewCode);
78  Env = std::make_unique<Environment>(
79  *CurrentCode, FileName,
81  FirstStartColumn, NextStartColumn, LastStartColumn);
82  }
83  }
84  }
85 
86  // Don't make replacements that replace nothing.
87  tooling::Replacements NonNoOpFixes;
88 
89  for (auto I = Fixes.begin(), E = Fixes.end(); I != E; ++I) {
90  StringRef OriginalCode = Code.substr(I->getOffset(), I->getLength());
91 
92  if (!OriginalCode.equals(I->getReplacementText())) {
93  auto Err = NonNoOpFixes.add(*I);
94  if (Err)
95  llvm::errs() << "Error adding replacements : "
96  << llvm::toString(std::move(Err)) << "\n";
97  }
98  }
99  return {NonNoOpFixes, 0};
100 }
101 
102 static void replaceToken(const SourceManager &SourceMgr,
103  tooling::Replacements &Fixes,
104  const CharSourceRange &Range, std::string NewText) {
105  auto Replacement = tooling::Replacement(SourceMgr, Range, NewText);
106  auto Err = Fixes.add(Replacement);
107 
108  if (Err)
109  llvm::errs() << "Error while rearranging Qualifier : "
110  << llvm::toString(std::move(Err)) << "\n";
111 }
112 
113 static void removeToken(const SourceManager &SourceMgr,
114  tooling::Replacements &Fixes,
115  const FormatToken *First) {
116  auto Range = CharSourceRange::getCharRange(First->getStartOfNonWhitespace(),
117  First->Tok.getEndLoc());
118  replaceToken(SourceMgr, Fixes, Range, "");
119 }
120 
121 static void insertQualifierAfter(const SourceManager &SourceMgr,
122  tooling::Replacements &Fixes,
123  const FormatToken *First,
124  const std::string &Qualifier) {
125  FormatToken *Next = First->Next;
126  if (!Next)
127  return;
128  auto Range = CharSourceRange::getCharRange(Next->getStartOfNonWhitespace(),
129  Next->Tok.getEndLoc());
130 
131  std::string NewText = " " + Qualifier + " ";
132  NewText += Next->TokenText;
133  replaceToken(SourceMgr, Fixes, Range, NewText);
134 }
135 
136 static void insertQualifierBefore(const SourceManager &SourceMgr,
137  tooling::Replacements &Fixes,
138  const FormatToken *First,
139  const std::string &Qualifier) {
140  auto Range = CharSourceRange::getCharRange(First->getStartOfNonWhitespace(),
141  First->Tok.getEndLoc());
142 
143  std::string NewText = " " + Qualifier + " ";
144  NewText += First->TokenText;
145 
146  replaceToken(SourceMgr, Fixes, Range, NewText);
147 }
148 
149 static bool endsWithSpace(const std::string &s) {
150  if (s.empty()) {
151  return false;
152  }
153  return isspace(s.back());
154 }
155 
156 static bool startsWithSpace(const std::string &s) {
157  if (s.empty()) {
158  return false;
159  }
160  return isspace(s.front());
161 }
162 
163 static void rotateTokens(const SourceManager &SourceMgr,
164  tooling::Replacements &Fixes, const FormatToken *First,
165  const FormatToken *Last, bool Left) {
166  auto *End = Last;
167  auto *Begin = First;
168  if (!Left) {
169  End = Last->Next;
170  Begin = First->Next;
171  }
172 
173  std::string NewText;
174  // If we are rotating to the left we move the Last token to the front.
175  if (Left) {
176  NewText += Last->TokenText;
177  NewText += " ";
178  }
179 
180  // Then move through the other tokens.
181  auto *Tok = Begin;
182  while (Tok != End) {
183  if (!NewText.empty() && !endsWithSpace(NewText)) {
184  NewText += " ";
185  }
186 
187  NewText += Tok->TokenText;
188  Tok = Tok->Next;
189  }
190 
191  // If we are rotating to the right we move the first token to the back.
192  if (!Left) {
193  if (!NewText.empty() && !startsWithSpace(NewText)) {
194  NewText += " ";
195  }
196  NewText += First->TokenText;
197  }
198 
199  auto Range = CharSourceRange::getCharRange(First->getStartOfNonWhitespace(),
200  Last->Tok.getEndLoc());
201 
202  replaceToken(SourceMgr, Fixes, Range, NewText);
203 }
204 
206  const SourceManager &SourceMgr, const AdditionalKeywords &Keywords,
207  tooling::Replacements &Fixes, FormatToken *Tok,
208  const std::string &Qualifier, tok::TokenKind QualifierType) {
209  // We only need to think about streams that begin with a qualifier.
210  if (!Tok->is(QualifierType))
211  return Tok;
212  // Don't concern yourself if nothing follows the qualifier.
213  if (!Tok->Next)
214  return Tok;
216  return Tok;
217 
218  FormatToken *Qual = Tok->Next;
219  FormatToken *LastQual = Qual;
220  while (Qual && isQualifierOrType(Qual, ConfiguredQualifierTokens)) {
221  LastQual = Qual;
222  Qual = Qual->Next;
223  }
224  if (LastQual && Qual != LastQual) {
225  rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
226  Tok = LastQual;
227  } else if (Tok->startsSequence(QualifierType, tok::identifier,
228  TT_TemplateOpener)) {
229  // Read from the TemplateOpener to
230  // TemplateCloser as in const ArrayRef<int> a; const ArrayRef<int> &a;
231  FormatToken *EndTemplate = Tok->Next->Next->MatchingParen;
232  if (EndTemplate) {
233  // Move to the end of any template class members e.g.
234  // `Foo<int>::iterator`.
235  if (EndTemplate->startsSequence(TT_TemplateCloser, tok::coloncolon,
236  tok::identifier))
237  EndTemplate = EndTemplate->Next->Next;
238  }
239  if (EndTemplate && EndTemplate->Next &&
240  !EndTemplate->Next->isOneOf(tok::equal, tok::l_paren)) {
241  insertQualifierAfter(SourceMgr, Fixes, EndTemplate, Qualifier);
242  // Remove the qualifier.
243  removeToken(SourceMgr, Fixes, Tok);
244  return Tok;
245  }
246  } else if (Tok->startsSequence(QualifierType, tok::identifier)) {
247  FormatToken *Next = Tok->Next;
248  // The case `const Foo` -> `Foo const`
249  // The case `const Foo *` -> `Foo const *`
250  // The case `const Foo &` -> `Foo const &`
251  // The case `const Foo &&` -> `Foo const &&`
252  // The case `const std::Foo &&` -> `std::Foo const &&`
253  // The case `const std::Foo<T> &&` -> `std::Foo<T> const &&`
254  while (Next && Next->isOneOf(tok::identifier, tok::coloncolon)) {
255  Next = Next->Next;
256  }
257  if (Next && Next->is(TT_TemplateOpener)) {
258  Next = Next->MatchingParen;
259  // Move to the end of any template class members e.g.
260  // `Foo<int>::iterator`.
261  if (Next && Next->startsSequence(TT_TemplateCloser, tok::coloncolon,
262  tok::identifier)) {
263  Next = Next->Next->Next;
264  return Tok;
265  }
266  assert(Next && "Missing template opener");
267  Next = Next->Next;
268  }
269  if (Next && Next->isOneOf(tok::star, tok::amp, tok::ampamp) &&
270  !Tok->Next->isOneOf(Keywords.kw_override, Keywords.kw_final)) {
271  if (Next->Previous && !Next->Previous->is(QualifierType)) {
272  insertQualifierAfter(SourceMgr, Fixes, Next->Previous, Qualifier);
273  removeToken(SourceMgr, Fixes, Tok);
274  }
275  return Next;
276  }
277  }
278 
279  return Tok;
280 }
281 
283  const SourceManager &SourceMgr, const AdditionalKeywords &Keywords,
284  tooling::Replacements &Fixes, FormatToken *Tok,
285  const std::string &Qualifier, tok::TokenKind QualifierType) {
286  // if Tok is an identifier and possibly a macro then don't convert.
288  return Tok;
289 
290  FormatToken *Qual = Tok;
291  FormatToken *LastQual = Qual;
292  while (Qual && isQualifierOrType(Qual, ConfiguredQualifierTokens)) {
293  LastQual = Qual;
294  Qual = Qual->Next;
295  if (Qual && Qual->is(QualifierType))
296  break;
297  }
298 
299  if (!Qual) {
300  return Tok;
301  }
302 
303  if (LastQual && Qual != LastQual && Qual->is(QualifierType)) {
304  rotateTokens(SourceMgr, Fixes, Tok, Qual, /*Left=*/true);
305  Tok = Qual->Next;
306  } else if (Tok->startsSequence(tok::identifier, QualifierType)) {
307  if (Tok->Next->Next && Tok->Next->Next->isOneOf(tok::identifier, tok::star,
308  tok::amp, tok::ampamp)) {
309  // Don't swap `::iterator const` to `::const iterator`.
310  if (!Tok->Previous ||
311  (Tok->Previous && !Tok->Previous->is(tok::coloncolon))) {
312  rotateTokens(SourceMgr, Fixes, Tok, Tok->Next, /*Left=*/true);
313  Tok = Tok->Next;
314  }
315  }
316  }
317  if (Tok->is(TT_TemplateOpener) && Tok->Next &&
318  (Tok->Next->is(tok::identifier) || Tok->Next->isSimpleTypeSpecifier()) &&
319  Tok->Next->Next && Tok->Next->Next->is(QualifierType)) {
320  rotateTokens(SourceMgr, Fixes, Tok->Next, Tok->Next->Next, /*Left=*/true);
321  }
322  if (Tok->startsSequence(tok::identifier) && Tok->Next) {
323  if (Tok->Previous &&
324  Tok->Previous->isOneOf(tok::star, tok::ampamp, tok::amp)) {
325  return Tok;
326  }
327  FormatToken *Next = Tok->Next;
328  // The case `std::Foo<T> const` -> `const std::Foo<T> &&`
329  while (Next && Next->isOneOf(tok::identifier, tok::coloncolon))
330  Next = Next->Next;
331  if (Next && Next->Previous &&
332  Next->Previous->startsSequence(tok::identifier, TT_TemplateOpener)) {
333  // Read from to the end of the TemplateOpener to
334  // TemplateCloser const ArrayRef<int> a; const ArrayRef<int> &a;
335  assert(Next->MatchingParen && "Missing template closer");
336  Next = Next->MatchingParen->Next;
337 
338  // Move to the end of any template class members e.g.
339  // `Foo<int>::iterator`.
340  if (Next && Next->startsSequence(tok::coloncolon, tok::identifier))
341  Next = Next->Next->Next;
342  if (Next && Next->is(QualifierType)) {
343  // Remove the const.
344  insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
345  removeToken(SourceMgr, Fixes, Next);
346  return Next;
347  }
348  }
349  if (Next && Next->Next &&
350  Next->Next->isOneOf(tok::amp, tok::ampamp, tok::star)) {
351  if (Next->is(QualifierType)) {
352  // Remove the qualifier.
353  insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
354  removeToken(SourceMgr, Fixes, Next);
355  return Next;
356  }
357  }
358  }
359  return Tok;
360 }
361 
363  const std::string &Qualifier) {
364  // Don't let 'type' be an identifier, but steal typeof token.
365  return llvm::StringSwitch<tok::TokenKind>(Qualifier)
366  .Case("type", tok::kw_typeof)
367  .Case("const", tok::kw_const)
368  .Case("volatile", tok::kw_volatile)
369  .Case("static", tok::kw_static)
370  .Case("inline", tok::kw_inline)
371  .Case("constexpr", tok::kw_constexpr)
372  .Case("restrict", tok::kw_restrict)
373  .Default(tok::identifier);
374 }
375 
377  const Environment &Env, const FormatStyle &Style,
378  const std::string &Qualifier,
379  const std::vector<tok::TokenKind> &QualifierTokens, bool RightAlign)
380  : TokenAnalyzer(Env, Style), Qualifier(Qualifier), RightAlign(RightAlign),
381  ConfiguredQualifierTokens(QualifierTokens) {}
382 
383 std::pair<tooling::Replacements, unsigned>
385  TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
386  FormatTokenLexer &Tokens) {
387  tooling::Replacements Fixes;
388  const AdditionalKeywords &Keywords = Tokens.getKeywords();
389  const SourceManager &SourceMgr = Env.getSourceManager();
390  AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
391 
392  tok::TokenKind QualifierToken = getTokenFromQualifier(Qualifier);
393  assert(QualifierToken != tok::identifier && "Unrecognised Qualifier");
394 
395  for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
396  FormatToken *First = AnnotatedLines[I]->First;
397  const auto *Last = AnnotatedLines[I]->Last;
398 
399  for (auto *Tok = First; Tok && Tok != Last && Tok->Next; Tok = Tok->Next) {
400  if (Tok->is(tok::comment))
401  continue;
402  if (RightAlign)
403  Tok = analyzeRight(SourceMgr, Keywords, Fixes, Tok, Qualifier,
404  QualifierToken);
405  else
406  Tok = analyzeLeft(SourceMgr, Keywords, Fixes, Tok, Qualifier,
407  QualifierToken);
408  }
409  }
410  return {Fixes, 0};
411 }
412 
414  const std::vector<std::string> &Order, std::vector<std::string> &LeftOrder,
415  std::vector<std::string> &RightOrder,
416  std::vector<tok::TokenKind> &Qualifiers) {
417 
418  // Depending on the position of type in the order you need
419  // To iterate forward or backward through the order list as qualifier
420  // can push through each other.
421  // The Order list must define the position of "type" to signify
422  assert(llvm::is_contained(Order, "type") &&
423  "QualifierOrder must contain type");
424  // Split the Order list by type and reverse the left side.
425 
426  bool left = true;
427  for (const auto &s : Order) {
428  if (s == "type") {
429  left = false;
430  continue;
431  }
432 
433  tok::TokenKind QualifierToken =
435  if (QualifierToken != tok::kw_typeof && QualifierToken != tok::identifier) {
436  Qualifiers.push_back(QualifierToken);
437  }
438 
439  if (left)
440  // Reverse the order for left aligned items.
441  LeftOrder.insert(LeftOrder.begin(), s);
442  else
443  RightOrder.push_back(s);
444  }
445 }
446 
448  const FormatToken *Tok, const std::vector<tok::TokenKind> &specifiedTypes) {
449  return Tok && (Tok->isSimpleTypeSpecifier() || Tok->is(tok::kw_auto) ||
450  llvm::is_contained(specifiedTypes, Tok->Tok.getKind()));
451 }
452 
453 // If a token is an identifier and it's upper case, it could
454 // be a macro and hence we need to be able to ignore it.
456  if (!Tok)
457  return false;
458  if (!Tok->is(tok::identifier))
459  return false;
460  if (Tok->TokenText.upper() == Tok->TokenText.str())
461  return true;
462  return false;
463 }
464 
465 } // namespace format
466 } // namespace clang
clang::format::QualifierAlignmentFixer::PrepareLeftRightOrdering
static void PrepareLeftRightOrdering(const std::vector< std::string > &Order, std::vector< std::string > &LeftOrder, std::vector< std::string > &RightOrder, std::vector< tok::TokenKind > &Qualifiers)
Definition: QualifierAlignmentFixer.cpp:413
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::format::TokenAnalyzer::Env
const Environment & Env
Definition: TokenAnalyzer.h:98
clang::format::QualifierAlignmentFixer::analyze
std::pair< tooling::Replacements, unsigned > analyze(TokenAnnotator &Annotator, SmallVectorImpl< AnnotatedLine * > &AnnotatedLines, FormatTokenLexer &Tokens) override
Definition: QualifierAlignmentFixer.cpp:61
clang::format::LeftRightQualifierAlignmentFixer
Definition: QualifierAlignmentFixer.h:55
clang::format::insertQualifierAfter
static void insertQualifierAfter(const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First, const std::string &Qualifier)
Definition: QualifierAlignmentFixer.cpp:121
clang::tooling::Replacements
Maintains a set of replacements that are conflict-free.
Definition: Replacement.h:209
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:145
clang::format::FormatStyle
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:59
clang::format::FormatToken::TokenText
StringRef TokenText
The raw text of the token.
Definition: FormatToken.h:227
clang::format::FormatToken
A wrapper around a Token storing information about the whitespace characters preceding it.
Definition: FormatToken.h:210
clang::format::AdditionalKeywords
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...
Definition: FormatToken.h:841
llvm::Optional< std::string >
clang::ComparisonCategoryType::First
@ First
clang::format::endsWithSpace
static bool endsWithSpace(const std::string &s)
Definition: QualifierAlignmentFixer.cpp:149
clang::format::TokenAnalyzer::process
std::pair< tooling::Replacements, unsigned > process()
Definition: TokenAnalyzer.cpp:65
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::format::QualifierAlignmentFixer::QualifierAlignmentFixer
QualifierAlignmentFixer(const Environment &Env, const FormatStyle &Style, StringRef &Code, ArrayRef< tooling::Range > Ranges, unsigned FirstStartColumn, unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName)
Definition: QualifierAlignmentFixer.cpp:27
clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft
FormatToken * analyzeLeft(const SourceManager &SourceMgr, const AdditionalKeywords &Keywords, tooling::Replacements &Fixes, FormatToken *Tok, const std::string &Qualifier, tok::TokenKind QualifierType)
Definition: QualifierAlignmentFixer.cpp:282
clang::format::LeftRightQualifierAlignmentFixer::isPossibleMacro
static bool isPossibleMacro(const FormatToken *Tok)
Definition: QualifierAlignmentFixer.cpp:455
clang::CharSourceRange::getCharRange
static CharSourceRange getCharRange(SourceRange R)
Definition: SourceLocation.h:267
clang::format::FormatToken::Previous
FormatToken * Previous
The previous token in the unwrapped line.
Definition: FormatToken.h:430
clang::format::FormatToken::Tok
Token Tok
The Token.
Definition: FormatToken.h:221
clang::format::TokenAnalyzer::AffectedRangeMgr
AffectedRangeManager AffectedRangeMgr
Definition: TokenAnalyzer.h:100
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::format::LeftRightQualifierAlignmentFixer::analyzeRight
FormatToken * analyzeRight(const SourceManager &SourceMgr, const AdditionalKeywords &Keywords, tooling::Replacements &Fixes, FormatToken *Tok, const std::string &Qualifier, tok::TokenKind QualifierType)
Definition: QualifierAlignmentFixer.cpp:205
clang::format::Environment
Definition: TokenAnalyzer.h:36
clang::format::TokenAnnotator
Determines extra information about the tokens comprising an UnwrappedLine.
Definition: TokenAnnotator.h:158
clang::format::LeftRightQualifierAlignmentFixer::LeftRightQualifierAlignmentFixer
LeftRightQualifierAlignmentFixer(const Environment &Env, const FormatStyle &Style, const std::string &Qualifier, const std::vector< tok::TokenKind > &ConfiguredQualifierTokens, bool RightAlign)
Definition: QualifierAlignmentFixer.cpp:376
clang::format::replaceToken
static void replaceToken(const SourceManager &SourceMgr, tooling::Replacements &Fixes, const CharSourceRange &Range, std::string NewText)
Definition: QualifierAlignmentFixer.cpp:102
clang::format::rotateTokens
static void rotateTokens(const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First, const FormatToken *Last, bool Left)
Definition: QualifierAlignmentFixer.cpp:163
clang::format::LeftRightQualifierAlignmentFixer::analyze
std::pair< tooling::Replacements, unsigned > analyze(TokenAnnotator &Annotator, SmallVectorImpl< AnnotatedLine * > &AnnotatedLines, FormatTokenLexer &Tokens) override
Definition: QualifierAlignmentFixer.cpp:384
clang::format::FormatStyle::QualifierOrder
std::vector< std::string > QualifierOrder
The order in which the qualifiers appear.
Definition: Format.h:1930
clang::tooling::Replacements::end
const_iterator end() const
Definition: Replacement.h:280
clang::tooling::calculateRangesAfterReplacements
std::vector< Range > calculateRangesAfterReplacements(const Replacements &Replaces, const std::vector< Range > &Ranges)
Calculates the new ranges after Replaces are applied.
Definition: Replacement.cpp:510
clang::format::FormatToken::startsSequence
bool startsSequence(A K1, Ts... Tokens) const
true if this token starts a sequence with the given tokens in order, following the Next pointers,...
Definition: FormatToken.h:489
clang::tooling::Replacements::begin
const_iterator begin() const
Definition: Replacement.h:278
clang::format::Environment::getSourceManager
const SourceManager & getSourceManager() const
Definition: TokenAnalyzer.h:49
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::format::removeToken
static void removeToken(const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First)
Definition: QualifierAlignmentFixer.cpp:113
clang::format::LeftRightQualifierAlignmentFixer::getTokenFromQualifier
static tok::TokenKind getTokenFromQualifier(const std::string &Qualifier)
Definition: QualifierAlignmentFixer.cpp:362
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
llvm::ArrayRef
Definition: LLVM.h:34
clang::tooling::Replacement
A text replacement.
Definition: Replacement.h:83
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:255
clang::format::FormatToken::is
bool is(tok::TokenKind Kind) const
Definition: FormatToken.h:452
clang::format::FormatToken::isOneOf
bool isOneOf(A K1, B K2) const
Definition: FormatToken.h:464
clang::format::insertQualifierBefore
static void insertQualifierBefore(const SourceManager &SourceMgr, tooling::Replacements &Fixes, const FormatToken *First, const std::string &Qualifier)
Definition: QualifierAlignmentFixer.cpp:136
clang
Definition: CalledOnceCheck.h:17
clang::format::FormatToken::isSimpleTypeSpecifier
bool isSimpleTypeSpecifier() const
Determine whether the token is a simple-type-specifier.
Definition: FormatToken.cpp:39
QualifierAlignmentFixer.h
clang::format::TokenAnalyzer
Definition: TokenAnalyzer.h:80
clang::format::startsWithSpace
static bool startsWithSpace(const std::string &s)
Definition: QualifierAlignmentFixer.cpp:156
clang::ComparisonCategoryType::Last
@ Last
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:315
clang::format::FormatTokenLexer
Definition: FormatTokenLexer.h:38
clang::format::LeftRightQualifierAlignmentFixer::isQualifierOrType
static bool isQualifierOrType(const FormatToken *Tok, const std::vector< tok::TokenKind > &Qualifiers)
Definition: QualifierAlignmentFixer.cpp:447
clang::tooling::Replacements::merge
LLVM_NODISCARD Replacements merge(const Replacements &Replaces) const
Merges Replaces into the current replacements.
Definition: Replacement.cpp:443
clang::tooling::Replacements::add
llvm::Error add(const Replacement &R)
Adds a new replacement R to the current set of replacements.
Definition: Replacement.cpp:245
FormatToken.h
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::format::FormatToken::Next
FormatToken * Next
The next token in the unwrapped line.
Definition: FormatToken.h:433
clang::tooling::applyAllReplacements
bool applyAllReplacements(const Replacements &Replaces, Rewriter &Rewrite)
Apply all replacements in Replaces to the Rewriter Rewrite.
Definition: Replacement.cpp:567
clang::format::AffectedRangeManager::computeAffectedLines
bool computeAffectedLines(SmallVectorImpl< AnnotatedLine * > &Lines)
Definition: AffectedRangeManager.cpp:22
clang::format::FormatToken::MatchingParen
FormatToken * MatchingParen
If this is a bracket, this points to the matching one.
Definition: FormatToken.h:427
clang::format::TokenAnalyzer::Style
FormatStyle Style
Definition: TokenAnalyzer.h:96