1 //===--- QualifierAlignmentFixer.h -------------------------------*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file declares QualifierAlignmentFixer, a TokenAnalyzer that
11 /// enforces either east or west const depending on the style.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
16 #define LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
18 #include "TokenAnalyzer.h"
23 typedef std::function
<std::pair
<tooling::Replacements
, unsigned>(
27 void addQualifierAlignmentFixerPasses(const FormatStyle
&Style
,
28 SmallVectorImpl
<AnalyzerPass
> &Passes
);
30 void prepareLeftRightOrderingForQualifierAlignmentFixer(
31 const std::vector
<std::string
> &Order
, std::vector
<std::string
> &LeftOrder
,
32 std::vector
<std::string
> &RightOrder
,
33 std::vector
<tok::TokenKind
> &Qualifiers
);
35 class LeftRightQualifierAlignmentFixer
: public TokenAnalyzer
{
36 std::string Qualifier
;
38 SmallVector
<tok::TokenKind
, 8> QualifierTokens
;
39 std::vector
<tok::TokenKind
> ConfiguredQualifierTokens
;
42 LeftRightQualifierAlignmentFixer(
43 const Environment
&Env
, const FormatStyle
&Style
,
44 const std::string
&Qualifier
,
45 const std::vector
<tok::TokenKind
> &ConfiguredQualifierTokens
,
48 std::pair
<tooling::Replacements
, unsigned>
49 analyze(TokenAnnotator
&Annotator
,
50 SmallVectorImpl
<AnnotatedLine
*> &AnnotatedLines
,
51 FormatTokenLexer
&Tokens
) override
;
53 static tok::TokenKind
getTokenFromQualifier(const std::string
&Qualifier
);
55 const FormatToken
*analyzeRight(const SourceManager
&SourceMgr
,
56 const AdditionalKeywords
&Keywords
,
57 tooling::Replacements
&Fixes
,
58 const FormatToken
*Tok
,
59 const std::string
&Qualifier
,
60 tok::TokenKind QualifierType
);
62 const FormatToken
*analyzeLeft(const SourceManager
&SourceMgr
,
63 const AdditionalKeywords
&Keywords
,
64 tooling::Replacements
&Fixes
,
65 const FormatToken
*Tok
,
66 const std::string
&Qualifier
,
67 tok::TokenKind QualifierType
);
69 // Is the Token a simple or qualifier type
70 static bool isQualifierOrType(const FormatToken
*Tok
);
72 isConfiguredQualifierOrType(const FormatToken
*Tok
,
73 const std::vector
<tok::TokenKind
> &Qualifiers
);
75 // Is the Token likely a Macro
76 static bool isPossibleMacro(const FormatToken
*Tok
);
79 } // end namespace format
80 } // end namespace clang