106f32e7eSjoerg //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
206f32e7eSjoerg //
306f32e7eSjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406f32e7eSjoerg // See https://llvm.org/LICENSE.txt for license information.
506f32e7eSjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606f32e7eSjoerg //
706f32e7eSjoerg //===----------------------------------------------------------------------===//
806f32e7eSjoerg ///
906f32e7eSjoerg /// \file
1006f32e7eSjoerg /// Defines the clang::TokenKind enum and support functions.
1106f32e7eSjoerg ///
1206f32e7eSjoerg //===----------------------------------------------------------------------===//
1306f32e7eSjoerg 
1406f32e7eSjoerg #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
1506f32e7eSjoerg #define LLVM_CLANG_BASIC_TOKENKINDS_H
1606f32e7eSjoerg 
17*13fbcb42Sjoerg #include "llvm/ADT/DenseMapInfo.h"
1806f32e7eSjoerg #include "llvm/Support/Compiler.h"
1906f32e7eSjoerg 
2006f32e7eSjoerg namespace clang {
2106f32e7eSjoerg 
2206f32e7eSjoerg namespace tok {
2306f32e7eSjoerg 
2406f32e7eSjoerg /// Provides a simple uniform namespace for tokens from all C languages.
2506f32e7eSjoerg enum TokenKind : unsigned short {
2606f32e7eSjoerg #define TOK(X) X,
2706f32e7eSjoerg #include "clang/Basic/TokenKinds.def"
2806f32e7eSjoerg   NUM_TOKENS
2906f32e7eSjoerg };
3006f32e7eSjoerg 
3106f32e7eSjoerg /// Provides a namespace for preprocessor keywords which start with a
3206f32e7eSjoerg /// '#' at the beginning of the line.
3306f32e7eSjoerg enum PPKeywordKind {
3406f32e7eSjoerg #define PPKEYWORD(X) pp_##X,
3506f32e7eSjoerg #include "clang/Basic/TokenKinds.def"
3606f32e7eSjoerg   NUM_PP_KEYWORDS
3706f32e7eSjoerg };
3806f32e7eSjoerg 
3906f32e7eSjoerg /// Provides a namespace for Objective-C keywords which start with
4006f32e7eSjoerg /// an '@'.
4106f32e7eSjoerg enum ObjCKeywordKind {
4206f32e7eSjoerg #define OBJC_AT_KEYWORD(X) objc_##X,
4306f32e7eSjoerg #include "clang/Basic/TokenKinds.def"
4406f32e7eSjoerg   NUM_OBJC_KEYWORDS
4506f32e7eSjoerg };
4606f32e7eSjoerg 
4706f32e7eSjoerg /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
4806f32e7eSjoerg enum OnOffSwitch {
4906f32e7eSjoerg   OOS_ON, OOS_OFF, OOS_DEFAULT
5006f32e7eSjoerg };
5106f32e7eSjoerg 
5206f32e7eSjoerg /// Determines the name of a token as used within the front end.
5306f32e7eSjoerg ///
5406f32e7eSjoerg /// The name of a token will be an internal name (such as "l_square")
5506f32e7eSjoerg /// and should not be used as part of diagnostic messages.
5606f32e7eSjoerg const char *getTokenName(TokenKind Kind) LLVM_READNONE;
5706f32e7eSjoerg 
5806f32e7eSjoerg /// Determines the spelling of simple punctuation tokens like
5906f32e7eSjoerg /// '!' or '%', and returns NULL for literal and annotation tokens.
6006f32e7eSjoerg ///
6106f32e7eSjoerg /// This routine only retrieves the "simple" spelling of the token,
6206f32e7eSjoerg /// and will not produce any alternative spellings (e.g., a
6306f32e7eSjoerg /// digraph). For the actual spelling of a given Token, use
6406f32e7eSjoerg /// Preprocessor::getSpelling().
6506f32e7eSjoerg const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
6606f32e7eSjoerg 
6706f32e7eSjoerg /// Determines the spelling of simple keyword and contextual keyword
6806f32e7eSjoerg /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
6906f32e7eSjoerg const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
7006f32e7eSjoerg 
7106f32e7eSjoerg /// Return true if this is a raw identifier or an identifier kind.
isAnyIdentifier(TokenKind K)7206f32e7eSjoerg inline bool isAnyIdentifier(TokenKind K) {
7306f32e7eSjoerg   return (K == tok::identifier) || (K == tok::raw_identifier);
7406f32e7eSjoerg }
7506f32e7eSjoerg 
7606f32e7eSjoerg /// Return true if this is a C or C++ string-literal (or
7706f32e7eSjoerg /// C++11 user-defined-string-literal) token.
isStringLiteral(TokenKind K)7806f32e7eSjoerg inline bool isStringLiteral(TokenKind K) {
7906f32e7eSjoerg   return K == tok::string_literal || K == tok::wide_string_literal ||
8006f32e7eSjoerg          K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
8106f32e7eSjoerg          K == tok::utf32_string_literal;
8206f32e7eSjoerg }
8306f32e7eSjoerg 
8406f32e7eSjoerg /// Return true if this is a "literal" kind, like a numeric
8506f32e7eSjoerg /// constant, string, etc.
isLiteral(TokenKind K)8606f32e7eSjoerg inline bool isLiteral(TokenKind K) {
8706f32e7eSjoerg   return K == tok::numeric_constant || K == tok::char_constant ||
8806f32e7eSjoerg          K == tok::wide_char_constant || K == tok::utf8_char_constant ||
8906f32e7eSjoerg          K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
9006f32e7eSjoerg          isStringLiteral(K) || K == tok::header_name;
9106f32e7eSjoerg }
9206f32e7eSjoerg 
9306f32e7eSjoerg /// Return true if this is any of tok::annot_* kinds.
9406f32e7eSjoerg bool isAnnotation(TokenKind K);
9506f32e7eSjoerg 
9606f32e7eSjoerg /// Return true if this is an annotation token representing a pragma.
9706f32e7eSjoerg bool isPragmaAnnotation(TokenKind K);
9806f32e7eSjoerg 
9906f32e7eSjoerg } // end namespace tok
10006f32e7eSjoerg } // end namespace clang
10106f32e7eSjoerg 
102*13fbcb42Sjoerg namespace llvm {
103*13fbcb42Sjoerg template <> struct DenseMapInfo<clang::tok::PPKeywordKind> {
104*13fbcb42Sjoerg   static inline clang::tok::PPKeywordKind getEmptyKey() {
105*13fbcb42Sjoerg     return clang::tok::PPKeywordKind::pp_not_keyword;
106*13fbcb42Sjoerg   }
107*13fbcb42Sjoerg   static inline clang::tok::PPKeywordKind getTombstoneKey() {
108*13fbcb42Sjoerg     return clang::tok::PPKeywordKind::NUM_PP_KEYWORDS;
109*13fbcb42Sjoerg   }
110*13fbcb42Sjoerg   static unsigned getHashValue(const clang::tok::PPKeywordKind &Val) {
111*13fbcb42Sjoerg     return static_cast<unsigned>(Val);
112*13fbcb42Sjoerg   }
113*13fbcb42Sjoerg   static bool isEqual(const clang::tok::PPKeywordKind &LHS,
114*13fbcb42Sjoerg                       const clang::tok::PPKeywordKind &RHS) {
115*13fbcb42Sjoerg     return LHS == RHS;
116*13fbcb42Sjoerg   }
117*13fbcb42Sjoerg };
118*13fbcb42Sjoerg } // namespace llvm
119*13fbcb42Sjoerg 
12006f32e7eSjoerg #endif
121