clang 10.0.0git

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