xref: /netbsd-src/external/apache2/llvm/dist/clang/include/clang/Basic/TokenKinds.h (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
17330f729Sjoerg //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg ///
97330f729Sjoerg /// \file
107330f729Sjoerg /// Defines the clang::TokenKind enum and support functions.
117330f729Sjoerg ///
127330f729Sjoerg //===----------------------------------------------------------------------===//
137330f729Sjoerg 
147330f729Sjoerg #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
157330f729Sjoerg #define LLVM_CLANG_BASIC_TOKENKINDS_H
167330f729Sjoerg 
17*e038c9c4Sjoerg #include "llvm/ADT/DenseMapInfo.h"
187330f729Sjoerg #include "llvm/Support/Compiler.h"
197330f729Sjoerg 
207330f729Sjoerg namespace clang {
217330f729Sjoerg 
227330f729Sjoerg namespace tok {
237330f729Sjoerg 
247330f729Sjoerg /// Provides a simple uniform namespace for tokens from all C languages.
257330f729Sjoerg enum TokenKind : unsigned short {
267330f729Sjoerg #define TOK(X) X,
277330f729Sjoerg #include "clang/Basic/TokenKinds.def"
287330f729Sjoerg   NUM_TOKENS
297330f729Sjoerg };
307330f729Sjoerg 
317330f729Sjoerg /// Provides a namespace for preprocessor keywords which start with a
327330f729Sjoerg /// '#' at the beginning of the line.
337330f729Sjoerg enum PPKeywordKind {
347330f729Sjoerg #define PPKEYWORD(X) pp_##X,
357330f729Sjoerg #include "clang/Basic/TokenKinds.def"
367330f729Sjoerg   NUM_PP_KEYWORDS
377330f729Sjoerg };
387330f729Sjoerg 
397330f729Sjoerg /// Provides a namespace for Objective-C keywords which start with
407330f729Sjoerg /// an '@'.
417330f729Sjoerg enum ObjCKeywordKind {
427330f729Sjoerg #define OBJC_AT_KEYWORD(X) objc_##X,
437330f729Sjoerg #include "clang/Basic/TokenKinds.def"
447330f729Sjoerg   NUM_OBJC_KEYWORDS
457330f729Sjoerg };
467330f729Sjoerg 
477330f729Sjoerg /// Defines the possible values of an on-off-switch (C99 6.10.6p2).
487330f729Sjoerg enum OnOffSwitch {
497330f729Sjoerg   OOS_ON, OOS_OFF, OOS_DEFAULT
507330f729Sjoerg };
517330f729Sjoerg 
527330f729Sjoerg /// Determines the name of a token as used within the front end.
537330f729Sjoerg ///
547330f729Sjoerg /// The name of a token will be an internal name (such as "l_square")
557330f729Sjoerg /// and should not be used as part of diagnostic messages.
567330f729Sjoerg const char *getTokenName(TokenKind Kind) LLVM_READNONE;
577330f729Sjoerg 
587330f729Sjoerg /// Determines the spelling of simple punctuation tokens like
597330f729Sjoerg /// '!' or '%', and returns NULL for literal and annotation tokens.
607330f729Sjoerg ///
617330f729Sjoerg /// This routine only retrieves the "simple" spelling of the token,
627330f729Sjoerg /// and will not produce any alternative spellings (e.g., a
637330f729Sjoerg /// digraph). For the actual spelling of a given Token, use
647330f729Sjoerg /// Preprocessor::getSpelling().
657330f729Sjoerg const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
667330f729Sjoerg 
677330f729Sjoerg /// Determines the spelling of simple keyword and contextual keyword
687330f729Sjoerg /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
697330f729Sjoerg const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
707330f729Sjoerg 
717330f729Sjoerg /// Return true if this is a raw identifier or an identifier kind.
isAnyIdentifier(TokenKind K)727330f729Sjoerg inline bool isAnyIdentifier(TokenKind K) {
737330f729Sjoerg   return (K == tok::identifier) || (K == tok::raw_identifier);
747330f729Sjoerg }
757330f729Sjoerg 
767330f729Sjoerg /// Return true if this is a C or C++ string-literal (or
777330f729Sjoerg /// C++11 user-defined-string-literal) token.
isStringLiteral(TokenKind K)787330f729Sjoerg inline bool isStringLiteral(TokenKind K) {
797330f729Sjoerg   return K == tok::string_literal || K == tok::wide_string_literal ||
807330f729Sjoerg          K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
817330f729Sjoerg          K == tok::utf32_string_literal;
827330f729Sjoerg }
837330f729Sjoerg 
847330f729Sjoerg /// Return true if this is a "literal" kind, like a numeric
857330f729Sjoerg /// constant, string, etc.
isLiteral(TokenKind K)867330f729Sjoerg inline bool isLiteral(TokenKind K) {
877330f729Sjoerg   return K == tok::numeric_constant || K == tok::char_constant ||
887330f729Sjoerg          K == tok::wide_char_constant || K == tok::utf8_char_constant ||
897330f729Sjoerg          K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
907330f729Sjoerg          isStringLiteral(K) || K == tok::header_name;
917330f729Sjoerg }
927330f729Sjoerg 
937330f729Sjoerg /// Return true if this is any of tok::annot_* kinds.
947330f729Sjoerg bool isAnnotation(TokenKind K);
957330f729Sjoerg 
967330f729Sjoerg /// Return true if this is an annotation token representing a pragma.
977330f729Sjoerg bool isPragmaAnnotation(TokenKind K);
987330f729Sjoerg 
997330f729Sjoerg } // end namespace tok
1007330f729Sjoerg } // end namespace clang
1017330f729Sjoerg 
102*e038c9c4Sjoerg namespace llvm {
103*e038c9c4Sjoerg template <> struct DenseMapInfo<clang::tok::PPKeywordKind> {
104*e038c9c4Sjoerg   static inline clang::tok::PPKeywordKind getEmptyKey() {
105*e038c9c4Sjoerg     return clang::tok::PPKeywordKind::pp_not_keyword;
106*e038c9c4Sjoerg   }
107*e038c9c4Sjoerg   static inline clang::tok::PPKeywordKind getTombstoneKey() {
108*e038c9c4Sjoerg     return clang::tok::PPKeywordKind::NUM_PP_KEYWORDS;
109*e038c9c4Sjoerg   }
110*e038c9c4Sjoerg   static unsigned getHashValue(const clang::tok::PPKeywordKind &Val) {
111*e038c9c4Sjoerg     return static_cast<unsigned>(Val);
112*e038c9c4Sjoerg   }
113*e038c9c4Sjoerg   static bool isEqual(const clang::tok::PPKeywordKind &LHS,
114*e038c9c4Sjoerg                       const clang::tok::PPKeywordKind &RHS) {
115*e038c9c4Sjoerg     return LHS == RHS;
116*e038c9c4Sjoerg   }
117*e038c9c4Sjoerg };
118*e038c9c4Sjoerg } // namespace llvm
119*e038c9c4Sjoerg 
1207330f729Sjoerg #endif
121