llvm-project
76 строк · 1.9 Кб
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
13#include "clang/Basic/TokenKinds.h"14#include "llvm/Support/ErrorHandling.h"15using namespace clang;16
17static const char * const TokNames[] = {18#define TOK(X) #X,19#define KEYWORD(X,Y) #X,20#include "clang/Basic/TokenKinds.def"21nullptr22};23
24const char *tok::getTokenName(TokenKind Kind) {25if (Kind < tok::NUM_TOKENS)26return TokNames[Kind];27llvm_unreachable("unknown TokenKind");28return nullptr;29}
30
31const char *tok::getPunctuatorSpelling(TokenKind Kind) {32switch (Kind) {33#define PUNCTUATOR(X,Y) case X: return Y;34#include "clang/Basic/TokenKinds.def"35default: break;36}37return nullptr;38}
39
40const char *tok::getKeywordSpelling(TokenKind Kind) {41switch (Kind) {42#define KEYWORD(X,Y) case kw_ ## X: return #X;43#include "clang/Basic/TokenKinds.def"44default: break;45}46return nullptr;47}
48
49const char *tok::getPPKeywordSpelling(tok::PPKeywordKind Kind) {50switch (Kind) {51#define PPKEYWORD(x) case tok::pp_##x: return #x;52#include "clang/Basic/TokenKinds.def"53default: break;54}55return nullptr;56}
57
58bool tok::isAnnotation(TokenKind Kind) {59switch (Kind) {60#define ANNOTATION(X) case annot_ ## X: return true;61#include "clang/Basic/TokenKinds.def"62default:63break;64}65return false;66}
67
68bool tok::isPragmaAnnotation(TokenKind Kind) {69switch (Kind) {70#define PRAGMA_ANNOTATION(X) case annot_ ## X: return true;71#include "clang/Basic/TokenKinds.def"72default:73break;74}75return false;76}
77