Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:51

0001 //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// Defines the clang::TokenKind enum and support functions.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
0015 #define LLVM_CLANG_BASIC_TOKENKINDS_H
0016 
0017 #include "llvm/ADT/DenseMapInfo.h"
0018 #include "llvm/Support/Compiler.h"
0019 
0020 namespace clang {
0021 
0022 namespace tok {
0023 
0024 /// Provides a simple uniform namespace for tokens from all C languages.
0025 enum TokenKind : unsigned short {
0026 #define TOK(X) X,
0027 #include "clang/Basic/TokenKinds.def"
0028   NUM_TOKENS
0029 };
0030 
0031 /// Provides a namespace for preprocessor keywords which start with a
0032 /// '#' at the beginning of the line.
0033 enum PPKeywordKind {
0034 #define PPKEYWORD(X) pp_##X,
0035 #include "clang/Basic/TokenKinds.def"
0036   NUM_PP_KEYWORDS
0037 };
0038 
0039 /// Provides a namespace for Objective-C keywords which start with
0040 /// an '@'.
0041 enum ObjCKeywordKind {
0042 #define OBJC_AT_KEYWORD(X) objc_##X,
0043 #include "clang/Basic/TokenKinds.def"
0044   NUM_OBJC_KEYWORDS
0045 };
0046 
0047 /// Provides a namespace for notable identifers such as float_t and
0048 /// double_t.
0049 enum NotableIdentifierKind {
0050 #define NOTABLE_IDENTIFIER(X) X,
0051 #include "clang/Basic/TokenKinds.def"
0052   NUM_NOTABLE_IDENTIFIERS
0053 };
0054 
0055 /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
0056 enum OnOffSwitch {
0057   OOS_ON, OOS_OFF, OOS_DEFAULT
0058 };
0059 
0060 /// Determines the name of a token as used within the front end.
0061 ///
0062 /// The name of a token will be an internal name (such as "l_square")
0063 /// and should not be used as part of diagnostic messages.
0064 const char *getTokenName(TokenKind Kind) LLVM_READNONE;
0065 
0066 /// Determines the spelling of simple punctuation tokens like
0067 /// '!' or '%', and returns NULL for literal and annotation tokens.
0068 ///
0069 /// This routine only retrieves the "simple" spelling of the token,
0070 /// and will not produce any alternative spellings (e.g., a
0071 /// digraph). For the actual spelling of a given Token, use
0072 /// Preprocessor::getSpelling().
0073 const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
0074 
0075 /// Determines the spelling of simple keyword and contextual keyword
0076 /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
0077 const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
0078 
0079 /// Returns the spelling of preprocessor keywords, such as "else".
0080 const char *getPPKeywordSpelling(PPKeywordKind Kind) LLVM_READNONE;
0081 
0082 /// Return true if this is a raw identifier or an identifier kind.
0083 inline bool isAnyIdentifier(TokenKind K) {
0084   return (K == tok::identifier) || (K == tok::raw_identifier);
0085 }
0086 
0087 /// Return true if this is a C or C++ string-literal (or
0088 /// C++11 user-defined-string-literal) token.
0089 inline bool isStringLiteral(TokenKind K) {
0090   return K == tok::string_literal || K == tok::wide_string_literal ||
0091          K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
0092          K == tok::utf32_string_literal;
0093 }
0094 
0095 /// Return true if this is a "literal" kind, like a numeric
0096 /// constant, string, etc.
0097 inline bool isLiteral(TokenKind K) {
0098   return K == tok::numeric_constant || K == tok::char_constant ||
0099          K == tok::wide_char_constant || K == tok::utf8_char_constant ||
0100          K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
0101          isStringLiteral(K) || K == tok::header_name || K == tok::binary_data;
0102 }
0103 
0104 /// Return true if this is any of tok::annot_* kinds.
0105 bool isAnnotation(TokenKind K);
0106 
0107 /// Return true if this is an annotation token representing a pragma.
0108 bool isPragmaAnnotation(TokenKind K);
0109 
0110 inline constexpr bool isRegularKeywordAttribute(TokenKind K) {
0111   return (false
0112 #define KEYWORD_ATTRIBUTE(X, ...) || (K == tok::kw_##X)
0113 #include "clang/Basic/RegularKeywordAttrInfo.inc"
0114   );
0115 }
0116 
0117 } // end namespace tok
0118 } // end namespace clang
0119 
0120 namespace llvm {
0121 template <> struct DenseMapInfo<clang::tok::PPKeywordKind> {
0122   static inline clang::tok::PPKeywordKind getEmptyKey() {
0123     return clang::tok::PPKeywordKind::pp_not_keyword;
0124   }
0125   static inline clang::tok::PPKeywordKind getTombstoneKey() {
0126     return clang::tok::PPKeywordKind::NUM_PP_KEYWORDS;
0127   }
0128   static unsigned getHashValue(const clang::tok::PPKeywordKind &Val) {
0129     return static_cast<unsigned>(Val);
0130   }
0131   static bool isEqual(const clang::tok::PPKeywordKind &LHS,
0132                       const clang::tok::PPKeywordKind &RHS) {
0133     return LHS == RHS;
0134   }
0135 };
0136 } // namespace llvm
0137 
0138 #endif