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/ADT/DenseMapInfo.h"
18 #include "llvm/Support/Compiler.h"
24 /// Provides a simple uniform namespace for tokens from all C languages.
25 enum TokenKind : unsigned short {
27 #include "clang/Basic/TokenKinds.def"
31 /// Provides a namespace for preprocessor keywords which start with a
32 /// '#' at the beginning of the line.
34 #define PPKEYWORD(X) pp_##X,
35 #include "clang/Basic/TokenKinds.def"
39 /// Provides a namespace for Objective-C keywords which start with
41 enum ObjCKeywordKind {
42 #define OBJC_AT_KEYWORD(X) objc_##X,
43 #include "clang/Basic/TokenKinds.def"
47 /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
49 OOS_ON, OOS_OFF, OOS_DEFAULT
52 /// Determines the name of a token as used within the front end.
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;
58 /// Determines the spelling of simple punctuation tokens like
59 /// '!' or '%', and returns NULL for literal and annotation tokens.
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;
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;
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);
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;
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::header_name;
93 /// Return true if this is any of tok::annot_* kinds.
94 bool isAnnotation(TokenKind K);
96 /// Return true if this is an annotation token representing a pragma.
97 bool isPragmaAnnotation(TokenKind K);
99 } // end namespace tok
100 } // end namespace clang
103 template <> struct DenseMapInfo<clang::tok::PPKeywordKind> {
104 static inline clang::tok::PPKeywordKind getEmptyKey() {
105 return clang::tok::PPKeywordKind::pp_not_keyword;
107 static inline clang::tok::PPKeywordKind getTombstoneKey() {
108 return clang::tok::PPKeywordKind::NUM_PP_KEYWORDS;
110 static unsigned getHashValue(const clang::tok::PPKeywordKind &Val) {
111 return static_cast<unsigned>(Val);
113 static bool isEqual(const clang::tok::PPKeywordKind &LHS,
114 const clang::tok::PPKeywordKind &RHS) {