TokenKinds.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- 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 the clang::TokenKind enum and support functions.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
  19. #define LLVM_CLANG_BASIC_TOKENKINDS_H
  20. #include "llvm/ADT/DenseMapInfo.h"
  21. #include "llvm/Support/Compiler.h"
  22. namespace clang {
  23. namespace tok {
  24. /// Provides a simple uniform namespace for tokens from all C languages.
  25. enum TokenKind : unsigned short {
  26. #define TOK(X) X,
  27. #include "clang/Basic/TokenKinds.def"
  28. NUM_TOKENS
  29. };
  30. /// Provides a namespace for preprocessor keywords which start with a
  31. /// '#' at the beginning of the line.
  32. enum PPKeywordKind {
  33. #define PPKEYWORD(X) pp_##X,
  34. #include "clang/Basic/TokenKinds.def"
  35. NUM_PP_KEYWORDS
  36. };
  37. /// Provides a namespace for Objective-C keywords which start with
  38. /// an '@'.
  39. enum ObjCKeywordKind {
  40. #define OBJC_AT_KEYWORD(X) objc_##X,
  41. #include "clang/Basic/TokenKinds.def"
  42. NUM_OBJC_KEYWORDS
  43. };
  44. /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
  45. enum OnOffSwitch {
  46. OOS_ON, OOS_OFF, OOS_DEFAULT
  47. };
  48. /// Determines the name of a token as used within the front end.
  49. ///
  50. /// The name of a token will be an internal name (such as "l_square")
  51. /// and should not be used as part of diagnostic messages.
  52. const char *getTokenName(TokenKind Kind) LLVM_READNONE;
  53. /// Determines the spelling of simple punctuation tokens like
  54. /// '!' or '%', and returns NULL for literal and annotation tokens.
  55. ///
  56. /// This routine only retrieves the "simple" spelling of the token,
  57. /// and will not produce any alternative spellings (e.g., a
  58. /// digraph). For the actual spelling of a given Token, use
  59. /// Preprocessor::getSpelling().
  60. const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
  61. /// Determines the spelling of simple keyword and contextual keyword
  62. /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
  63. const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
  64. /// Return true if this is a raw identifier or an identifier kind.
  65. inline bool isAnyIdentifier(TokenKind K) {
  66. return (K == tok::identifier) || (K == tok::raw_identifier);
  67. }
  68. /// Return true if this is a C or C++ string-literal (or
  69. /// C++11 user-defined-string-literal) token.
  70. inline bool isStringLiteral(TokenKind K) {
  71. return K == tok::string_literal || K == tok::wide_string_literal ||
  72. K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
  73. K == tok::utf32_string_literal;
  74. }
  75. /// Return true if this is a "literal" kind, like a numeric
  76. /// constant, string, etc.
  77. inline bool isLiteral(TokenKind K) {
  78. return K == tok::numeric_constant || K == tok::char_constant ||
  79. K == tok::wide_char_constant || K == tok::utf8_char_constant ||
  80. K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
  81. isStringLiteral(K) || K == tok::header_name;
  82. }
  83. /// Return true if this is any of tok::annot_* kinds.
  84. bool isAnnotation(TokenKind K);
  85. /// Return true if this is an annotation token representing a pragma.
  86. bool isPragmaAnnotation(TokenKind K);
  87. } // end namespace tok
  88. } // end namespace clang
  89. namespace llvm {
  90. template <> struct DenseMapInfo<clang::tok::PPKeywordKind> {
  91. static inline clang::tok::PPKeywordKind getEmptyKey() {
  92. return clang::tok::PPKeywordKind::pp_not_keyword;
  93. }
  94. static inline clang::tok::PPKeywordKind getTombstoneKey() {
  95. return clang::tok::PPKeywordKind::NUM_PP_KEYWORDS;
  96. }
  97. static unsigned getHashValue(const clang::tok::PPKeywordKind &Val) {
  98. return static_cast<unsigned>(Val);
  99. }
  100. static bool isEqual(const clang::tok::PPKeywordKind &LHS,
  101. const clang::tok::PPKeywordKind &RHS) {
  102. return LHS == RHS;
  103. }
  104. };
  105. } // namespace llvm
  106. #endif
  107. #ifdef __GNUC__
  108. #pragma GCC diagnostic pop
  109. #endif