clang API Documentation

OperatorPrecedence.cpp
Go to the documentation of this file.
00001 //===--- OperatorPrecedence.cpp ---------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Defines and computes precedence levels for binary/ternary operators.
00012 ///
00013 //===----------------------------------------------------------------------===//
00014 #include "clang/Basic/OperatorPrecedence.h"
00015 
00016 namespace clang {
00017 
00018 prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
00019                                bool CPlusPlus11) {
00020   switch (Kind) {
00021   case tok::greater:
00022     // C++ [temp.names]p3:
00023     //   [...] When parsing a template-argument-list, the first
00024     //   non-nested > is taken as the ending delimiter rather than a
00025     //   greater-than operator. [...]
00026     if (GreaterThanIsOperator)
00027       return prec::Relational;
00028     return prec::Unknown;
00029 
00030   case tok::greatergreater:
00031     // C++11 [temp.names]p3:
00032     //
00033     //   [...] Similarly, the first non-nested >> is treated as two
00034     //   consecutive but distinct > tokens, the first of which is
00035     //   taken as the end of the template-argument-list and completes
00036     //   the template-id. [...]
00037     if (GreaterThanIsOperator || !CPlusPlus11)
00038       return prec::Shift;
00039     return prec::Unknown;
00040 
00041   default:                        return prec::Unknown;
00042   case tok::comma:                return prec::Comma;
00043   case tok::equal:
00044   case tok::starequal:
00045   case tok::slashequal:
00046   case tok::percentequal:
00047   case tok::plusequal:
00048   case tok::minusequal:
00049   case tok::lesslessequal:
00050   case tok::greatergreaterequal:
00051   case tok::ampequal:
00052   case tok::caretequal:
00053   case tok::pipeequal:            return prec::Assignment;
00054   case tok::question:             return prec::Conditional;
00055   case tok::pipepipe:             return prec::LogicalOr;
00056   case tok::ampamp:               return prec::LogicalAnd;
00057   case tok::pipe:                 return prec::InclusiveOr;
00058   case tok::caret:                return prec::ExclusiveOr;
00059   case tok::amp:                  return prec::And;
00060   case tok::exclaimequal:
00061   case tok::equalequal:           return prec::Equality;
00062   case tok::lessequal:
00063   case tok::less:
00064   case tok::greaterequal:         return prec::Relational;
00065   case tok::lessless:             return prec::Shift;
00066   case tok::plus:
00067   case tok::minus:                return prec::Additive;
00068   case tok::percent:
00069   case tok::slash:
00070   case tok::star:                 return prec::Multiplicative;
00071   case tok::periodstar:
00072   case tok::arrowstar:            return prec::PointerToMember;
00073   }
00074 }
00075 
00076 }  // namespace clang