clang 8.0.0

TokenKinds.cpp
Go to the documentation of this file.
1 //===--- TokenKinds.cpp - Token Kinds Support -----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the TokenKind enum and support functions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/Basic/TokenKinds.h"
15 #include "llvm/Support/ErrorHandling.h"
16 using namespace clang;
17
18 static const char * const TokNames[] = {
19 #define TOK(X) #X,
20 #define KEYWORD(X,Y) #X,
21 #include "clang/Basic/TokenKinds.def"
22 nullptr
23 };
24
25 const char *tok::getTokenName(TokenKind Kind) {
26 if (Kind < tok::NUM_TOKENS)
27 return TokNames[Kind];
28 llvm_unreachable("unknown TokenKind");
29 return nullptr;
30 }
31
32 const char *tok::getPunctuatorSpelling(TokenKind Kind) {
33 switch (Kind) {
34 #define PUNCTUATOR(X,Y) case X: return Y;
35 #include "clang/Basic/TokenKinds.def"
36 default: break;
37 }
38 return nullptr;
39 }
40
41 const char *tok::getKeywordSpelling(TokenKind Kind) {
42 switch (Kind) {
43 #define KEYWORD(X,Y) case kw_ ## X: return #X;
44 #include "clang/Basic/TokenKinds.def"
45 default: break;
46 }
47 return nullptr;
48 }
TokNames
static const char *const TokNames[]
Definition: TokenKinds.cpp:18
clang::tok::NUM_TOKENS
Definition: TokenKinds.h:28
clang::tok::getKeywordSpelling
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like &#39;int&#39; and &#39;dynamic_cast&#39;...
Definition: TokenKinds.cpp:41
clang::tok::getPunctuatorSpelling
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like &#39;!&#39; or &#39;&#39;, and returns NULL for literal and...
Definition: TokenKinds.cpp:32
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
TokenKinds.h
Defines the clang::TokenKind enum and support functions.
clang::tok::getTokenName
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Definition: TokenKinds.cpp:25