TokenKinds.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //===--- TokenKinds.cpp - Token Kinds Support -----------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the TokenKind enum and support functions.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Basic/TokenKinds.h"
  13. #include "llvm/Support/ErrorHandling.h"
  14. using namespace clang;
  15. static const char * const TokNames[] = {
  16. #define TOK(X) #X,
  17. #define KEYWORD(X,Y) #X,
  18. #include "clang/Basic/TokenKinds.def"
  19. nullptr
  20. };
  21. const char *tok::getTokenName(TokenKind Kind) {
  22. if (Kind < tok::NUM_TOKENS)
  23. return TokNames[Kind];
  24. llvm_unreachable("unknown TokenKind");
  25. return nullptr;
  26. }
  27. const char *tok::getPunctuatorSpelling(TokenKind Kind) {
  28. switch (Kind) {
  29. #define PUNCTUATOR(X,Y) case X: return Y;
  30. #include "clang/Basic/TokenKinds.def"
  31. default: break;
  32. }
  33. return nullptr;
  34. }
  35. const char *tok::getKeywordSpelling(TokenKind Kind) {
  36. switch (Kind) {
  37. #define KEYWORD(X,Y) case kw_ ## X: return #X;
  38. #include "clang/Basic/TokenKinds.def"
  39. default: break;
  40. }
  41. return nullptr;
  42. }
  43. const char *tok::getPPKeywordSpelling(tok::PPKeywordKind Kind) {
  44. switch (Kind) {
  45. #define PPKEYWORD(x) case tok::pp_##x: return #x;
  46. #include "clang/Basic/TokenKinds.def"
  47. default: break;
  48. }
  49. return nullptr;
  50. }
  51. bool tok::isAnnotation(TokenKind Kind) {
  52. switch (Kind) {
  53. #define ANNOTATION(X) case annot_ ## X: return true;
  54. #include "clang/Basic/TokenKinds.def"
  55. default:
  56. break;
  57. }
  58. return false;
  59. }
  60. bool tok::isPragmaAnnotation(TokenKind Kind) {
  61. switch (Kind) {
  62. #define PRAGMA_ANNOTATION(X) case annot_ ## X: return true;
  63. #include "clang/Basic/TokenKinds.def"
  64. default:
  65. break;
  66. }
  67. return false;
  68. }