clang  9.0.0svn
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"
28 };
29 
30 /// Provides a namespace for preprocessor keywords which start with a
31 /// '#' at the beginning of the line.
33 #define PPKEYWORD(X) pp_##X,
34 #include "clang/Basic/TokenKinds.def"
36 };
37 
38 /// Provides a namespace for Objective-C keywords which start with
39 /// an '@'.
41 #define OBJC_AT_KEYWORD(X) objc_##X,
42 #include "clang/Basic/TokenKinds.def"
44 };
45 
46 /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
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 inline bool isAnnotation(TokenKind K) {
94 #define ANNOTATION(NAME) \
95  if (K == tok::annot_##NAME) \
96  return true;
97 #include "clang/Basic/TokenKinds.def"
98  return false;
99 }
100 
101 } // end namespace tok
102 } // end namespace clang
103 
104 #endif
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
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
Definition: TokenKinds.cpp:40
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
Definition: TokenKinds.h:32
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
Definition: TokenKinds.cpp:31
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition: TokenKinds.h:40
Kind
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
Definition: TokenKinds.h:93
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Definition: TokenKinds.h:85
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
Dataflow Directional Tag Classes.
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:47
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Definition: TokenKinds.cpp:24
bool isAnyIdentifier(TokenKind K)
Return true if this is a raw identifier or an identifier kind.
Definition: TokenKinds.h:71