clang  16.0.0git
QualifierAlignmentFixer.h
Go to the documentation of this file.
1 //===--- LeftRightQualifierAlignmentFixer.h ------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file declares LeftRightQualifierAlignmentFixer, a TokenAnalyzer that
12 /// enforces either east or west const depending on the style.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
17 #define LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
18 
19 #include "TokenAnalyzer.h"
20 
21 namespace clang {
22 namespace format {
23 
24 typedef std::function<std::pair<tooling::Replacements, unsigned>(
25  const Environment &)>
27 
29  // Left to Right ordering requires multiple passes
31  StringRef &Code;
33  unsigned FirstStartColumn;
34  unsigned NextStartColumn;
35  unsigned LastStartColumn;
36  StringRef FileName;
37 
38 public:
40  StringRef &Code, ArrayRef<tooling::Range> Ranges,
41  unsigned FirstStartColumn, unsigned NextStartColumn,
42  unsigned LastStartColumn, StringRef FileName);
43 
44  std::pair<tooling::Replacements, unsigned>
45  analyze(TokenAnnotator &Annotator,
46  SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
47  FormatTokenLexer &Tokens) override;
48 
49  static void PrepareLeftRightOrdering(const std::vector<std::string> &Order,
50  std::vector<std::string> &LeftOrder,
51  std::vector<std::string> &RightOrder,
52  std::vector<tok::TokenKind> &Qualifiers);
53 };
54 
56  std::string Qualifier;
57  bool RightAlign;
58  SmallVector<tok::TokenKind, 8> QualifierTokens;
59  std::vector<tok::TokenKind> ConfiguredQualifierTokens;
60 
61 public:
63  const Environment &Env, const FormatStyle &Style,
64  const std::string &Qualifier,
65  const std::vector<tok::TokenKind> &ConfiguredQualifierTokens,
66  bool RightAlign);
67 
68  std::pair<tooling::Replacements, unsigned>
69  analyze(TokenAnnotator &Annotator,
70  SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
71  FormatTokenLexer &Tokens) override;
72 
73  static tok::TokenKind getTokenFromQualifier(const std::string &Qualifier);
74 
75  const FormatToken *analyzeRight(const SourceManager &SourceMgr,
76  const AdditionalKeywords &Keywords,
77  tooling::Replacements &Fixes,
78  const FormatToken *Tok,
79  const std::string &Qualifier,
80  tok::TokenKind QualifierType);
81 
82  const FormatToken *analyzeLeft(const SourceManager &SourceMgr,
83  const AdditionalKeywords &Keywords,
84  tooling::Replacements &Fixes,
85  const FormatToken *Tok,
86  const std::string &Qualifier,
87  tok::TokenKind QualifierType);
88 
89  // is the Token a simple or qualifier type
90  static bool isQualifierOrType(const FormatToken *Tok,
91  const std::vector<tok::TokenKind> &Qualifiers);
92 
93  // is the Token likely a Macro
94  static bool isPossibleMacro(const FormatToken *Tok);
95 };
96 
97 } // end namespace format
98 } // end namespace clang
99 
100 #endif
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:465
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:107
llvm::SmallVector< AnalyzerPass, 8 >
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::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:147
clang::format::FormatStyle
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:54
clang::format::FormatToken
A wrapper around a Token storing information about the whitespace characters preceding it.
Definition: FormatToken.h:240
clang::format::AdditionalKeywords
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...
Definition: FormatToken.h:917
clang::format::QualifierAlignmentFixer
Definition: QualifierAlignmentFixer.h:28
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:636
clang::format::LeftRightQualifierAlignmentFixer::analyzeRight
const FormatToken * analyzeRight(const SourceManager &SourceMgr, const AdditionalKeywords &Keywords, tooling::Replacements &Fixes, const FormatToken *Tok, const std::string &Qualifier, tok::TokenKind QualifierType)
Definition: QualifierAlignmentFixer.cpp:206
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::isPossibleMacro
static bool isPossibleMacro(const FormatToken *Tok)
Definition: QualifierAlignmentFixer.cpp:507
clang::format::LeftRightQualifierAlignmentFixer::analyzeLeft
const FormatToken * analyzeLeft(const SourceManager &SourceMgr, const AdditionalKeywords &Keywords, tooling::Replacements &Fixes, const FormatToken *Tok, const std::string &Qualifier, tok::TokenKind QualifierType)
Definition: QualifierAlignmentFixer.cpp:308
clang::format::Environment
Definition: TokenAnalyzer.h:37
clang::format::TokenAnnotator
Determines extra information about the tokens comprising an UnwrappedLine.
Definition: TokenAnnotator.h:168
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:419
clang::format::LeftRightQualifierAlignmentFixer::analyze
std::pair< tooling::Replacements, unsigned > analyze(TokenAnnotator &Annotator, SmallVectorImpl< AnnotatedLine * > &AnnotatedLines, FormatTokenLexer &Tokens) override
Definition: QualifierAlignmentFixer.cpp:427
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::format::AnalyzerPass
std::function< std::pair< tooling::Replacements, unsigned > const Environment &)> AnalyzerPass
Definition: QualifierAlignmentFixer.h:26
clang::format::LeftRightQualifierAlignmentFixer::getTokenFromQualifier
static tok::TokenKind getTokenFromQualifier(const std::string &Qualifier)
Definition: QualifierAlignmentFixer.cpp:405
llvm::ArrayRef
Definition: LLVM.h:34
clang
Definition: CalledOnceCheck.h:17
clang::format::TokenAnalyzer
Definition: TokenAnalyzer.h:88
clang::format::FormatTokenLexer
Definition: FormatTokenLexer.h:39
clang::format::LeftRightQualifierAlignmentFixer::isQualifierOrType
static bool isQualifierOrType(const FormatToken *Tok, const std::vector< tok::TokenKind > &Qualifiers)
Definition: QualifierAlignmentFixer.cpp:499
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::format::TokenAnalyzer::Style
FormatStyle Style
Definition: TokenAnalyzer.h:105
TokenAnalyzer.h