clang  10.0.0svn
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 
13 #include "clang/Basic/TokenKinds.h"
14 #include "llvm/Support/ErrorHandling.h"
15 using namespace clang;
16 
17 static 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 
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 ANNOTATION(X) case annot_ ## X: return true;
52 #include "clang/Basic/TokenKinds.def"
53  default:
54  break;
55  }
56  return false;
57 }
58 
60  switch (Kind) {
61 #define PRAGMA_ANNOTATION(X) case annot_ ## X: return true;
62 #include "clang/Basic/TokenKinds.def"
63  default:
64  break;
65  }
66  return false;
67 }
static const char *const TokNames[]
Definition: TokenKinds.cpp:17
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:40
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:31
Kind
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
Definition: TokenKinds.cpp:49
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
Dataflow Directional Tag Classes.
Defines the clang::TokenKind enum and support functions.
bool isPragmaAnnotation(TokenKind K)
Return true if this is an annotation token representing a pragma.
Definition: TokenKinds.cpp:59
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Definition: TokenKinds.cpp:24