1 //===--- OperatorPrecedence.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines and computes precedence levels for binary/ternary operators.
13 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/OperatorPrecedence.h"
18 prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
22 // C++ [temp.names]p3:
23 // [...] When parsing a template-argument-list, the first
24 // non-nested > is taken as the ending delimiter rather than a
25 // greater-than operator. [...]
26 if (GreaterThanIsOperator)
27 return prec::Relational;
30 case tok::greatergreater:
31 // C++11 [temp.names]p3:
33 // [...] Similarly, the first non-nested >> is treated as two
34 // consecutive but distinct > tokens, the first of which is
35 // taken as the end of the template-argument-list and completes
36 // the template-id. [...]
37 if (GreaterThanIsOperator || !CPlusPlus11)
41 default: return prec::Unknown;
42 case tok::comma: return prec::Comma;
46 case tok::percentequal:
49 case tok::lesslessequal:
50 case tok::greatergreaterequal:
53 case tok::pipeequal: return prec::Assignment;
54 case tok::question: return prec::Conditional;
55 case tok::pipepipe: return prec::LogicalOr;
56 case tok::ampamp: return prec::LogicalAnd;
57 case tok::pipe: return prec::InclusiveOr;
58 case tok::caret: return prec::ExclusiveOr;
59 case tok::amp: return prec::And;
60 case tok::exclaimequal:
61 case tok::equalequal: return prec::Equality;
64 case tok::greaterequal: return prec::Relational;
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;