[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / lib / Format / QualifierAlignmentFixer.h
blob3c908316a303f6d96d2a328ac6788498783ae80f
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 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
17 #define LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
19 #include "TokenAnalyzer.h"
21 namespace clang {
22 namespace format {
24 typedef std::function<std::pair<tooling::Replacements, unsigned>(
25 const Environment &)>
26 AnalyzerPass;
28 class QualifierAlignmentFixer : public TokenAnalyzer {
29 // Left to Right ordering requires multiple passes
30 SmallVector<AnalyzerPass, 8> Passes;
31 StringRef &Code;
32 ArrayRef<tooling::Range> Ranges;
33 unsigned FirstStartColumn;
34 unsigned NextStartColumn;
35 unsigned LastStartColumn;
36 StringRef FileName;
38 public:
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;
57 bool RightAlign;
58 SmallVector<tok::TokenKind, 8> QualifierTokens;
59 std::vector<tok::TokenKind> ConfiguredQualifierTokens;
61 public:
62 LeftRightQualifierAlignmentFixer(
63 const Environment &Env, const FormatStyle &Style,
64 const std::string &Qualifier,
65 const std::vector<tok::TokenKind> &ConfiguredQualifierTokens,
66 bool RightAlign);
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);
91 static bool
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
102 #endif