clang  14.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  FormatToken *analyzeRight(const SourceManager &SourceMgr,
76  const AdditionalKeywords &Keywords,
78  const std::string &Qualifier,
79  tok::TokenKind QualifierType);
80 
81  FormatToken *analyzeLeft(const SourceManager &SourceMgr,
82  const AdditionalKeywords &Keywords,
84  const std::string &Qualifier,
85  tok::TokenKind QualifierType);
86 
87  // is the Token a simple or qualifier type
88  static bool isQualifierOrType(const FormatToken *Tok,
89  const std::vector<tok::TokenKind> &Qualifiers);
90 
91  // is the Token likely a Macro
92  static bool isPossibleMacro(const FormatToken *Tok);
93 };
94 
95 } // end namespace format
96 } // end namespace clang
97 
98 #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: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
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:145
clang::format::FormatStyle
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:59
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
clang::format::QualifierAlignmentFixer
Definition: QualifierAlignmentFixer.h:28
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::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::LeftRightQualifierAlignmentFixer::analyze
std::pair< tooling::Replacements, unsigned > analyze(TokenAnnotator &Annotator, SmallVectorImpl< AnnotatedLine * > &AnnotatedLines, FormatTokenLexer &Tokens) override
Definition: QualifierAlignmentFixer.cpp:384
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:362
llvm::ArrayRef
Definition: LLVM.h:34
clang
Definition: CalledOnceCheck.h:17
clang::format::TokenAnalyzer
Definition: TokenAnalyzer.h:80
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
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::format::TokenAnalyzer::Style
FormatStyle Style
Definition: TokenAnalyzer.h:96
TokenAnalyzer.h