[libc][docgen] simplify posix links (#119595)
[llvm-project.git] / clang / lib / Format / QualifierAlignmentFixer.h
bloba0a0d597ebf30c64a1a73812bc62694425f891ab
1 //===--- QualifierAlignmentFixer.h -------------------------------*- C++-*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file declares QualifierAlignmentFixer, a TokenAnalyzer that
11 /// enforces either east or west const depending on the style.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
16 #define LLVM_CLANG_LIB_FORMAT_QUALIFIERALIGNMENTFIXER_H
18 #include "TokenAnalyzer.h"
20 namespace clang {
21 namespace format {
23 typedef std::function<std::pair<tooling::Replacements, unsigned>(
24 const Environment &)>
25 AnalyzerPass;
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 // Is the Token a simple or qualifier type
36 bool isQualifierOrType(const FormatToken *Tok, const LangOptions &LangOpts);
37 bool isConfiguredQualifierOrType(const FormatToken *Tok,
38 const std::vector<tok::TokenKind> &Qualifiers,
39 const LangOptions &LangOpts);
41 // Is the Token likely a Macro
42 bool isPossibleMacro(const FormatToken *Tok);
44 class LeftRightQualifierAlignmentFixer : public TokenAnalyzer {
45 std::string Qualifier;
46 bool RightAlign;
47 SmallVector<tok::TokenKind, 8> QualifierTokens;
48 std::vector<tok::TokenKind> ConfiguredQualifierTokens;
50 public:
51 LeftRightQualifierAlignmentFixer(
52 const Environment &Env, const FormatStyle &Style,
53 const std::string &Qualifier,
54 const std::vector<tok::TokenKind> &ConfiguredQualifierTokens,
55 bool RightAlign);
57 std::pair<tooling::Replacements, unsigned>
58 analyze(TokenAnnotator &Annotator,
59 SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
60 FormatTokenLexer &Tokens) override;
62 static tok::TokenKind getTokenFromQualifier(const std::string &Qualifier);
64 void fixQualifierAlignment(SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
65 FormatTokenLexer &Tokens,
66 tooling::Replacements &Fixes);
68 const FormatToken *analyzeRight(const SourceManager &SourceMgr,
69 const AdditionalKeywords &Keywords,
70 tooling::Replacements &Fixes,
71 const FormatToken *Tok,
72 const std::string &Qualifier,
73 tok::TokenKind QualifierType);
75 const FormatToken *analyzeLeft(const SourceManager &SourceMgr,
76 const AdditionalKeywords &Keywords,
77 tooling::Replacements &Fixes,
78 const FormatToken *Tok,
79 const std::string &Qualifier,
80 tok::TokenKind QualifierType);
83 } // end namespace format
84 } // end namespace clang
86 #endif