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