clang 8.0.0

TokenKinds.h
Go to the documentation of this file.
1 //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
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 /// \file
11 /// Defines the clang::TokenKind enum and support functions.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
16 #define LLVM_CLANG_BASIC_TOKENKINDS_H
17
18 #include "llvm/Support/Compiler.h"
19
20 namespace clang {
21
22 namespace tok {
23
24 /// Provides a simple uniform namespace for tokens from all C languages.
25 enum TokenKind : unsigned short {
26 #define TOK(X) X,
27 #include "clang/Basic/TokenKinds.def"
28 NUM_TOKENS
29 };
30
31 /// Provides a namespace for preprocessor keywords which start with a
32 /// '#' at the beginning of the line.
33 enum PPKeywordKind {
34 #define PPKEYWORD(X) pp_##X,
35 #include "clang/Basic/TokenKinds.def"
36 NUM_PP_KEYWORDS
37 };
38
39 /// Provides a namespace for Objective-C keywords which start with
40 /// an '@'.
41 enum ObjCKeywordKind {
42 #define OBJC_AT_KEYWORD(X) objc_##X,
43 #include "clang/Basic/TokenKinds.def"
44 NUM_OBJC_KEYWORDS
45 };
46
47 /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
48 enum OnOffSwitch {
49 OOS_ON, OOS_OFF, OOS_DEFAULT
50 };
51
52 /// Determines the name of a token as used within the front end.
53 ///
54 /// The name of a token will be an internal name (such as "l_square")
55 /// and should not be used as part of diagnostic messages.
56 const char *getTokenName(TokenKind Kind) LLVM_READNONE;
57
58 /// Determines the spelling of simple punctuation tokens like
59 /// '!' or '%', and returns NULL for literal and annotation tokens.
60 ///
61 /// This routine only retrieves the "simple" spelling of the token,
62 /// and will not produce any alternative spellings (e.g., a
63 /// digraph). For the actual spelling of a given Token, use
64 /// Preprocessor::getSpelling().
65 const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
66
67 /// Determines the spelling of simple keyword and contextual keyword
68 /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
69 const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
70
71 /// Return true if this is a raw identifier or an identifier kind.
72 inline bool isAnyIdentifier(TokenKind K) {
73 return (K == tok::identifier) || (K == tok::raw_identifier);
74 }
75
76 /// Return true if this is a C or C++ string-literal (or
77 /// C++11 user-defined-string-literal) token.
78 inline bool isStringLiteral(TokenKind K) {
79 return K == tok::string_literal || K == tok::wide_string_literal ||
80 K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
81 K == tok::utf32_string_literal;
82 }
83
84 /// Return true if this is a "literal" kind, like a numeric
85 /// constant, string, etc.
86 inline bool isLiteral(TokenKind K) {
87 return K == tok::numeric_constant || K == tok::char_constant ||
88 K == tok::wide_char_constant || K == tok::utf8_char_constant ||
89 K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
90 isStringLiteral(K) || K == tok::angle_string_literal;
91 }
92
93 /// Return true if this is any of tok::annot_* kinds.
94 inline bool isAnnotation(TokenKind K) {
95 #define ANNOTATION(NAME) \
96 if (K == tok::annot_##NAME) \
97 return true;
98 #include "clang/Basic/TokenKinds.def"
99 return false;
100 }
101
102 } // end namespace tok
103 } // end namespace clang
104
105 #endif
clang::tok::NUM_OBJC_KEYWORDS
Definition: TokenKinds.h:44
clang::tok::isStringLiteral
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
Definition: TokenKinds.h:78
clang::tok::OOS_DEFAULT
Definition: TokenKinds.h:49
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::PPKeywordKind
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a &#39;#&#39; at the beginning of the line...
Definition: TokenKinds.h:33
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
clang::tok::ObjCKeywordKind
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an &#39;@&#39;.
Definition: TokenKinds.h:41
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::tok::isAnnotation
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
Definition: TokenKinds.h:94
clang::tok::isLiteral
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Definition: TokenKinds.h:86
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::tok::OOS_ON
Definition: TokenKinds.h:49
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::tok::OnOffSwitch
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:48
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
clang::tok::OOS_OFF
Definition: TokenKinds.h:49
clang::tok::NUM_PP_KEYWORDS
Definition: TokenKinds.h:36
clang::tok::isAnyIdentifier
bool isAnyIdentifier(TokenKind K)
Return true if this is a raw identifier or an identifier kind.
Definition: TokenKinds.h:72