OperatorKinds.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- OperatorKinds.h - C++ Overloaded Operators -------------*- 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 an enumeration for C++ overloaded operators.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_BASIC_OPERATORKINDS_H
  19. #define LLVM_CLANG_BASIC_OPERATORKINDS_H
  20. namespace clang {
  21. /// Enumeration specifying the different kinds of C++ overloaded
  22. /// operators.
  23. enum OverloadedOperatorKind : int {
  24. OO_None, ///< Not an overloaded operator
  25. #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
  26. OO_##Name,
  27. #include "clang/Basic/OperatorKinds.def"
  28. NUM_OVERLOADED_OPERATORS
  29. };
  30. /// Retrieve the spelling of the given overloaded operator, without
  31. /// the preceding "operator" keyword.
  32. const char *getOperatorSpelling(OverloadedOperatorKind Operator);
  33. /// Get the other overloaded operator that the given operator can be rewritten
  34. /// into, if any such operator exists.
  35. inline OverloadedOperatorKind
  36. getRewrittenOverloadedOperator(OverloadedOperatorKind Kind) {
  37. switch (Kind) {
  38. case OO_Less:
  39. case OO_LessEqual:
  40. case OO_Greater:
  41. case OO_GreaterEqual:
  42. return OO_Spaceship;
  43. case OO_ExclaimEqual:
  44. return OO_EqualEqual;
  45. default:
  46. return OO_None;
  47. }
  48. }
  49. /// Determine if this is a compound assignment operator.
  50. inline bool isCompoundAssignmentOperator(OverloadedOperatorKind Kind) {
  51. return Kind >= OO_PlusEqual && Kind <= OO_PipeEqual;
  52. }
  53. } // end namespace clang
  54. #endif
  55. #ifdef __GNUC__
  56. #pragma GCC diagnostic pop
  57. #endif