clang 23.0.0git
TokenKinds.cpp
Go to the documentation of this file.
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
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"
21 nullptr
22};
23
24const char *tok::getTokenName(TokenKind Kind) {
25 if (Kind < tok::NUM_TOKENS)
26 return TokNames[Kind];
27 llvm_unreachable("unknown TokenKind");
28 return nullptr;
29}
30
32 switch (Kind) {
33#define PUNCTUATOR(X,Y) case X: return Y;
34#include "clang/Basic/TokenKinds.def"
35 default: break;
36 }
37 return nullptr;
38}
39
41 switch (Kind) {
42#define KEYWORD(X,Y) case kw_ ## X: return #X;
43#include "clang/Basic/TokenKinds.def"
44 default: break;
45 }
46 return nullptr;
47}
48
50 switch (Kind) {
51#define OBJC_AT_KEYWORD(X) \
52 case objc_##X: \
53 return "@" #X;
54#include "clang/Basic/TokenKinds.def"
55 default:
56 break;
57 }
58 return nullptr;
59}
60
62 switch (Kind) {
63#define PPKEYWORD(x) case tok::pp_##x: return #x;
64#include "clang/Basic/TokenKinds.def"
65 default: break;
66 }
67 return nullptr;
68}
69
71 switch (Kind) {
72#define ANNOTATION(X) case annot_ ## X: return true;
73#include "clang/Basic/TokenKinds.def"
74 default:
75 break;
76 }
77 return false;
78}
79
81 switch (Kind) {
82#define PRAGMA_ANNOTATION(X) case annot_ ## X: return true;
83#include "clang/Basic/TokenKinds.def"
84 default:
85 break;
86 }
87 return false;
88}
static const char *const TokNames[]
Defines the clang::TokenKind enum and support functions.
const char * getPPKeywordSpelling(PPKeywordKind Kind) LLVM_READNONE
Returns the spelling of preprocessor keywords, such as "else".
const char * getObjCKeywordSpelling(ObjCKeywordKind Kind) LLVM_READNONE
Determines the spelling of simple Objective-C keyword tokens like '@import'.
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition TokenKinds.h:41
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition TokenKinds.h:25
bool isPragmaAnnotation(TokenKind K)
Return true if this is an annotation token representing a pragma.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
Definition TokenKinds.h:33
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!
The JSON file list parser is used to communicate input to InstallAPI.