TokenKinds.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. bool tok::isAnnotation(TokenKind Kind) {
  44. switch (Kind) {
  45. #define ANNOTATION(X) case annot_ ## X: return true;
  46. #include "clang/Basic/TokenKinds.def"
  47. default:
  48. break;
  49. }
  50. return false;
  51. }
  52. bool tok::isPragmaAnnotation(TokenKind Kind) {
  53. switch (Kind) {
  54. #define PRAGMA_ANNOTATION(X) case annot_ ## X: return true;
  55. #include "clang/Basic/TokenKinds.def"
  56. default:
  57. break;
  58. }
  59. return false;
  60. }