[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang-tools-extra / clang-tidy / modernize / IntegralLiteralExpressionMatcher.h
blob22893784b07f88f1f9c09cb52fe378fa3ab4a9c9
1 //===--- IntegralLiteralExpressionMatcher.h - clang-tidy ------------------===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRAL_LITERAL_EXPRESSION_MATCHER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_INTEGRAL_LITERAL_EXPRESSION_MATCHER_H
12 #include <clang/Lex/Token.h>
13 #include <llvm/ADT/ArrayRef.h>
15 namespace clang::tidy::modernize {
17 enum class LiteralSize {
18 Unknown = 0,
19 Int,
20 UnsignedInt,
21 Long,
22 UnsignedLong,
23 LongLong,
24 UnsignedLongLong
27 // Parses an array of tokens and returns true if they conform to the rules of
28 // C++ for whole expressions involving integral literals. Follows the operator
29 // precedence rules of C++. Optionally exclude comma operator expressions.
30 class IntegralLiteralExpressionMatcher {
31 public:
32 IntegralLiteralExpressionMatcher(ArrayRef<Token> Tokens, bool CommaAllowed)
33 : Current(Tokens.begin()), End(Tokens.end()), CommaAllowed(CommaAllowed) {
36 bool match();
37 LiteralSize largestLiteralSize() const;
39 private:
40 bool advance();
41 bool consume(tok::TokenKind Kind);
42 template <typename NonTerminalFunctor, typename IsKindFunctor>
43 bool nonTerminalChainedExpr(const NonTerminalFunctor &NonTerminal,
44 const IsKindFunctor &IsKind);
45 template <tok::TokenKind Kind, typename NonTerminalFunctor>
46 bool nonTerminalChainedExpr(const NonTerminalFunctor &NonTerminal);
47 template <tok::TokenKind K1, tok::TokenKind K2, tok::TokenKind... Ks,
48 typename NonTerminalFunctor>
49 bool nonTerminalChainedExpr(const NonTerminalFunctor &NonTerminal);
51 bool unaryOperator();
52 bool unaryExpr();
53 bool multiplicativeExpr();
54 bool additiveExpr();
55 bool shiftExpr();
56 bool compareExpr();
57 bool relationalExpr();
58 bool equalityExpr();
59 bool andExpr();
60 bool exclusiveOrExpr();
61 bool inclusiveOrExpr();
62 bool logicalAndExpr();
63 bool logicalOrExpr();
64 bool conditionalExpr();
65 bool commaExpr();
66 bool expr();
68 ArrayRef<Token>::iterator Current;
69 ArrayRef<Token>::iterator End;
70 LiteralSize LargestSize{LiteralSize::Unknown};
71 bool CommaAllowed;
74 } // namespace clang::tidy::modernize
76 #endif