1 //===--- IntegralLiteralExpressionMatcher.h - clang-tidy ------------------===//
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 //===----------------------------------------------------------------------===//
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
{
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
{
32 IntegralLiteralExpressionMatcher(ArrayRef
<Token
> Tokens
, bool CommaAllowed
)
33 : Current(Tokens
.begin()), End(Tokens
.end()), CommaAllowed(CommaAllowed
) {
37 LiteralSize
largestLiteralSize() const;
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
);
53 bool multiplicativeExpr();
57 bool relationalExpr();
60 bool exclusiveOrExpr();
61 bool inclusiveOrExpr();
62 bool logicalAndExpr();
64 bool conditionalExpr();
68 ArrayRef
<Token
>::iterator Current
;
69 ArrayRef
<Token
>::iterator End
;
70 LiteralSize LargestSize
{LiteralSize::Unknown
};
74 } // namespace clang::tidy::modernize