OperatorPrecedence.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- OperatorPrecedence.h - Operator precedence levels ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// Defines and computes precedence levels for binary/ternary operators.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_BASIC_OPERATORPRECEDENCE_H
  19. #define LLVM_CLANG_BASIC_OPERATORPRECEDENCE_H
  20. #include "clang/Basic/TokenKinds.h"
  21. namespace clang {
  22. /// PrecedenceLevels - These are precedences for the binary/ternary
  23. /// operators in the C99 grammar. These have been named to relate
  24. /// with the C99 grammar productions. Low precedences numbers bind
  25. /// more weakly than high numbers.
  26. namespace prec {
  27. enum Level {
  28. Unknown = 0, // Not binary operator.
  29. Comma = 1, // ,
  30. Assignment = 2, // =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |=
  31. Conditional = 3, // ?
  32. LogicalOr = 4, // ||
  33. LogicalAnd = 5, // &&
  34. InclusiveOr = 6, // |
  35. ExclusiveOr = 7, // ^
  36. And = 8, // &
  37. Equality = 9, // ==, !=
  38. Relational = 10, // >=, <=, >, <
  39. Spaceship = 11, // <=>
  40. Shift = 12, // <<, >>
  41. Additive = 13, // -, +
  42. Multiplicative = 14, // *, /, %
  43. PointerToMember = 15 // .*, ->*
  44. };
  45. }
  46. /// Return the precedence of the specified binary operator token.
  47. prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
  48. bool CPlusPlus11);
  49. } // end namespace clang
  50. #endif // LLVM_CLANG_BASIC_OPERATORPRECEDENCE_H
  51. #ifdef __GNUC__
  52. #pragma GCC diagnostic pop
  53. #endif