1193326Sed//===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9239462Sdim/// 10239462Sdim/// \file 11239462Sdim/// \brief Defines the clang::TokenKind enum and support functions. 12239462Sdim/// 13193326Sed//===----------------------------------------------------------------------===// 14193326Sed 15193326Sed#ifndef LLVM_CLANG_TOKENKINDS_H 16193326Sed#define LLVM_CLANG_TOKENKINDS_H 17193326Sed 18193326Sednamespace clang { 19193326Sed 20193326Sednamespace tok { 21193326Sed 22239462Sdim/// \brief Provides a simple uniform namespace for tokens from all C languages. 23193326Sedenum TokenKind { 24193326Sed#define TOK(X) X, 25193326Sed#include "clang/Basic/TokenKinds.def" 26193326Sed NUM_TOKENS 27193326Sed}; 28193326Sed 29239462Sdim/// \brief Provides a namespace for preprocessor keywords which start with a 30239462Sdim/// '#' at the beginning of the line. 31193326Sedenum PPKeywordKind { 32198092Srdivacky#define PPKEYWORD(X) pp_##X, 33193326Sed#include "clang/Basic/TokenKinds.def" 34193326Sed NUM_PP_KEYWORDS 35193326Sed}; 36193326Sed 37239462Sdim/// \brief Provides a namespace for Objective-C keywords which start with 38239462Sdim/// an '@'. 39193326Sedenum ObjCKeywordKind { 40193326Sed#define OBJC1_AT_KEYWORD(X) objc_##X, 41193326Sed#define OBJC2_AT_KEYWORD(X) objc_##X, 42193326Sed#include "clang/Basic/TokenKinds.def" 43193326Sed NUM_OBJC_KEYWORDS 44193326Sed}; 45193326Sed 46239462Sdim/// \brief Defines the possible values of an on-off-switch (C99 6.10.6p2). 47218893Sdimenum OnOffSwitch { 48218893Sdim OOS_ON, OOS_OFF, OOS_DEFAULT 49218893Sdim}; 50218893Sdim 51193326Sed/// \brief Determines the name of a token as used within the front end. 52193326Sed/// 53193326Sed/// The name of a token will be an internal name (such as "l_square") 54193326Sed/// and should not be used as part of diagnostic messages. 55193326Sedconst char *getTokenName(enum TokenKind Kind); 56193326Sed 57193326Sed/// \brief Determines the spelling of simple punctuation tokens like 58193326Sed/// '!' or '%', and returns NULL for literal and annotation tokens. 59193326Sed/// 60193326Sed/// This routine only retrieves the "simple" spelling of the token, 61193326Sed/// and will not produce any alternative spellings (e.g., a 62193326Sed/// digraph). For the actual spelling of a given Token, use 63193326Sed/// Preprocessor::getSpelling(). 64193326Sedconst char *getTokenSimpleSpelling(enum TokenKind Kind); 65193326Sed 66243830Sdim/// \brief Return true if this is a raw identifier or an identifier kind. 67243830Sdiminline bool isAnyIdentifier(TokenKind K) { 68243830Sdim return (K == tok::identifier) || (K == tok::raw_identifier); 69243830Sdim} 70243830Sdim 71249423Sdim/// \brief Return true if this is a C or C++ string-literal (or 72249423Sdim/// C++11 user-defined-string-literal) token. 73249423Sdiminline bool isStringLiteral(TokenKind K) { 74249423Sdim return K == tok::string_literal || K == tok::wide_string_literal || 75249423Sdim K == tok::utf8_string_literal || K == tok::utf16_string_literal || 76249423Sdim K == tok::utf32_string_literal; 77249423Sdim} 78249423Sdim 79243830Sdim/// \brief Return true if this is a "literal" kind, like a numeric 80243830Sdim/// constant, string, etc. 81243830Sdiminline bool isLiteral(TokenKind K) { 82249423Sdim return K == tok::numeric_constant || K == tok::char_constant || 83249423Sdim K == tok::wide_char_constant || K == tok::utf16_char_constant || 84249423Sdim K == tok::utf32_char_constant || isStringLiteral(K) || 85249423Sdim K == tok::angle_string_literal; 86243830Sdim} 87243830Sdim 88243830Sdim/// \brief Return true if this is any of tok::annot_* kinds. 89243830Sdiminline bool isAnnotation(TokenKind K) { 90243830Sdim#define ANNOTATION(NAME) \ 91243830Sdim if (K == tok::annot_##NAME) \ 92243830Sdim return true; 93243830Sdim#include "clang/Basic/TokenKinds.def" 94243830Sdim return false; 95243830Sdim} 96243830Sdim 97193326Sed} // end namespace tok 98193326Sed} // end namespace clang 99193326Sed 100193326Sed#endif 101