1 //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Defines the clang::TokenKind enum and support functions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
15 #define LLVM_CLANG_BASIC_TOKENKINDS_H
17 #include "llvm/Support/Compiler.h"
23 /// Provides a simple uniform namespace for tokens from all C languages.
24 enum TokenKind : unsigned short {
26 #include "clang/Basic/TokenKinds.def"
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"
38 /// Provides a namespace for Objective-C keywords which start with
40 enum ObjCKeywordKind {
41 #define OBJC_AT_KEYWORD(X) objc_##X,
42 #include "clang/Basic/TokenKinds.def"
46 /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
48 OOS_ON, OOS_OFF, OOS_DEFAULT
51 /// Determines the name of a token as used within the front end.
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;
57 /// Determines the spelling of simple punctuation tokens like
58 /// '!' or '%', and returns NULL for literal and annotation tokens.
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;
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;
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);
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;
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;
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) \
97 #include "clang/Basic/TokenKinds.def"
101 } // end namespace tok
102 } // end namespace clang