1 1.1 joerg //===--- OperatorPrecedence.cpp ---------------------------------*- C++ -*-===// 2 1.1 joerg // 3 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 1.1 joerg // See https://llvm.org/LICENSE.txt for license information. 5 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 1.1 joerg // 7 1.1 joerg //===----------------------------------------------------------------------===// 8 1.1 joerg /// 9 1.1 joerg /// \file 10 1.1 joerg /// Defines and computes precedence levels for binary/ternary operators. 11 1.1 joerg /// 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg #include "clang/Basic/OperatorPrecedence.h" 14 1.1 joerg 15 1.1 joerg namespace clang { 16 1.1 joerg 17 1.1 joerg prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, 18 1.1 joerg bool CPlusPlus11) { 19 1.1 joerg switch (Kind) { 20 1.1 joerg case tok::greater: 21 1.1 joerg // C++ [temp.names]p3: 22 1.1 joerg // [...] When parsing a template-argument-list, the first 23 1.1 joerg // non-nested > is taken as the ending delimiter rather than a 24 1.1 joerg // greater-than operator. [...] 25 1.1 joerg if (GreaterThanIsOperator) 26 1.1 joerg return prec::Relational; 27 1.1 joerg return prec::Unknown; 28 1.1 joerg 29 1.1 joerg case tok::greatergreater: 30 1.1 joerg // C++11 [temp.names]p3: 31 1.1 joerg // 32 1.1 joerg // [...] Similarly, the first non-nested >> is treated as two 33 1.1 joerg // consecutive but distinct > tokens, the first of which is 34 1.1 joerg // taken as the end of the template-argument-list and completes 35 1.1 joerg // the template-id. [...] 36 1.1 joerg if (GreaterThanIsOperator || !CPlusPlus11) 37 1.1 joerg return prec::Shift; 38 1.1 joerg return prec::Unknown; 39 1.1 joerg 40 1.1 joerg default: return prec::Unknown; 41 1.1 joerg case tok::comma: return prec::Comma; 42 1.1 joerg case tok::equal: 43 1.1 joerg case tok::starequal: 44 1.1 joerg case tok::slashequal: 45 1.1 joerg case tok::percentequal: 46 1.1 joerg case tok::plusequal: 47 1.1 joerg case tok::minusequal: 48 1.1 joerg case tok::lesslessequal: 49 1.1 joerg case tok::greatergreaterequal: 50 1.1 joerg case tok::ampequal: 51 1.1 joerg case tok::caretequal: 52 1.1 joerg case tok::pipeequal: return prec::Assignment; 53 1.1 joerg case tok::question: return prec::Conditional; 54 1.1 joerg case tok::pipepipe: return prec::LogicalOr; 55 1.1 joerg case tok::caretcaret: 56 1.1 joerg case tok::ampamp: return prec::LogicalAnd; 57 1.1 joerg case tok::pipe: return prec::InclusiveOr; 58 1.1 joerg case tok::caret: return prec::ExclusiveOr; 59 1.1 joerg case tok::amp: return prec::And; 60 1.1 joerg case tok::exclaimequal: 61 1.1 joerg case tok::equalequal: return prec::Equality; 62 1.1 joerg case tok::lessequal: 63 1.1 joerg case tok::less: 64 1.1 joerg case tok::greaterequal: return prec::Relational; 65 1.1 joerg case tok::spaceship: return prec::Spaceship; 66 1.1 joerg case tok::lessless: return prec::Shift; 67 1.1 joerg case tok::plus: 68 1.1 joerg case tok::minus: return prec::Additive; 69 1.1 joerg case tok::percent: 70 1.1 joerg case tok::slash: 71 1.1 joerg case tok::star: return prec::Multiplicative; 72 1.1 joerg case tok::periodstar: 73 1.1 joerg case tok::arrowstar: return prec::PointerToMember; 74 1.1 joerg } 75 1.1 joerg } 76 1.1 joerg 77 1.1 joerg } // namespace clang 78