1 //===--- OperatorPrecedence.cpp ---------------------------------*- 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 /// Defines and computes precedence levels for binary/ternary operators.
12 //===----------------------------------------------------------------------===//
13 #include "clang/Basic/OperatorPrecedence.h"
17 prec::Level
getBinOpPrecedence(tok::TokenKind Kind
, bool GreaterThanIsOperator
,
21 // C++ [temp.names]p3:
22 // [...] When parsing a template-argument-list, the first
23 // non-nested > is taken as the ending delimiter rather than a
24 // greater-than operator. [...]
25 if (GreaterThanIsOperator
)
26 return prec::Relational
;
29 case tok::greatergreater
:
30 // C++11 [temp.names]p3:
32 // [...] Similarly, the first non-nested >> is treated as two
33 // consecutive but distinct > tokens, the first of which is
34 // taken as the end of the template-argument-list and completes
35 // the template-id. [...]
36 if (GreaterThanIsOperator
|| !CPlusPlus11
)
40 default: return prec::Unknown
;
41 case tok::comma
: return prec::Comma
;
45 case tok::percentequal
:
48 case tok::lesslessequal
:
49 case tok::greatergreaterequal
:
52 case tok::pipeequal
: return prec::Assignment
;
53 case tok::question
: return prec::Conditional
;
54 case tok::pipepipe
: return prec::LogicalOr
;
55 case tok::ampamp
: return prec::LogicalAnd
;
56 case tok::pipe
: return prec::InclusiveOr
;
57 case tok::caret
: return prec::ExclusiveOr
;
58 case tok::amp
: return prec::And
;
59 case tok::exclaimequal
:
60 case tok::equalequal
: return prec::Equality
;
63 case tok::greaterequal
: return prec::Relational
;
64 case tok::spaceship
: return prec::Spaceship
;
65 case tok::lessless
: return prec::Shift
;
67 case tok::minus
: return prec::Additive
;
70 case tok::star
: return prec::Multiplicative
;
72 case tok::arrowstar
: return prec::PointerToMember
;