1 //===--- LeftRightQualifierAlignmentFixer.h ------------------------------*- C++
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
8 //===----------------------------------------------------------------------===//
11 /// This file declares LeftRightQualifierAlignmentFixer, a TokenAnalyzer that
12 /// enforces either east or west const depending on the style.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
17 #define LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
19 #include "TokenAnalyzer.h"
24 typedef std::function
<std::pair
<tooling::Replacements
, unsigned>(
28 class QualifierAlignmentFixer
: public TokenAnalyzer
{
29 // Left to Right ordering requires multiple passes
30 SmallVector
<AnalyzerPass
, 8> Passes
;
32 ArrayRef
<tooling::Range
> Ranges
;
33 unsigned FirstStartColumn
;
34 unsigned NextStartColumn
;
35 unsigned LastStartColumn
;
39 QualifierAlignmentFixer(const Environment
&Env
, const FormatStyle
&Style
,
40 StringRef
&Code
, ArrayRef
<tooling::Range
> Ranges
,
41 unsigned FirstStartColumn
, unsigned NextStartColumn
,
42 unsigned LastStartColumn
, StringRef FileName
);
44 std::pair
<tooling::Replacements
, unsigned>
45 analyze(TokenAnnotator
&Annotator
,
46 SmallVectorImpl
<AnnotatedLine
*> &AnnotatedLines
,
47 FormatTokenLexer
&Tokens
) override
;
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
);
55 class LeftRightQualifierAlignmentFixer
: public TokenAnalyzer
{
56 std::string Qualifier
;
58 SmallVector
<tok::TokenKind
, 8> QualifierTokens
;
59 std::vector
<tok::TokenKind
> ConfiguredQualifierTokens
;
62 LeftRightQualifierAlignmentFixer(
63 const Environment
&Env
, const FormatStyle
&Style
,
64 const std::string
&Qualifier
,
65 const std::vector
<tok::TokenKind
> &ConfiguredQualifierTokens
,
68 std::pair
<tooling::Replacements
, unsigned>
69 analyze(TokenAnnotator
&Annotator
,
70 SmallVectorImpl
<AnnotatedLine
*> &AnnotatedLines
,
71 FormatTokenLexer
&Tokens
) override
;
73 static tok::TokenKind
getTokenFromQualifier(const std::string
&Qualifier
);
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
);
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
);
89 // Is the Token a simple or qualifier type
90 static bool isQualifierOrType(const FormatToken
*Tok
);
92 isConfiguredQualifierOrType(const FormatToken
*Tok
,
93 const std::vector
<tok::TokenKind
> &Qualifiers
);
95 // Is the Token likely a Macro
96 static bool isPossibleMacro(const FormatToken
*Tok
);
99 } // end namespace format
100 } // end namespace clang