clang API Documentation
00001 //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 /// 00010 /// \file 00011 /// \brief Defines the clang::TokenKind enum and support functions. 00012 /// 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H 00016 #define LLVM_CLANG_BASIC_TOKENKINDS_H 00017 00018 #include "llvm/Support/Compiler.h" 00019 00020 namespace clang { 00021 00022 namespace tok { 00023 00024 /// \brief Provides a simple uniform namespace for tokens from all C languages. 00025 enum TokenKind : unsigned short { 00026 #define TOK(X) X, 00027 #include "clang/Basic/TokenKinds.def" 00028 NUM_TOKENS 00029 }; 00030 00031 /// \brief Provides a namespace for preprocessor keywords which start with a 00032 /// '#' at the beginning of the line. 00033 enum PPKeywordKind { 00034 #define PPKEYWORD(X) pp_##X, 00035 #include "clang/Basic/TokenKinds.def" 00036 NUM_PP_KEYWORDS 00037 }; 00038 00039 /// \brief Provides a namespace for Objective-C keywords which start with 00040 /// an '@'. 00041 enum ObjCKeywordKind { 00042 #define OBJC1_AT_KEYWORD(X) objc_##X, 00043 #define OBJC2_AT_KEYWORD(X) objc_##X, 00044 #include "clang/Basic/TokenKinds.def" 00045 NUM_OBJC_KEYWORDS 00046 }; 00047 00048 /// \brief Defines the possible values of an on-off-switch (C99 6.10.6p2). 00049 enum OnOffSwitch { 00050 OOS_ON, OOS_OFF, OOS_DEFAULT 00051 }; 00052 00053 /// \brief Determines the name of a token as used within the front end. 00054 /// 00055 /// The name of a token will be an internal name (such as "l_square") 00056 /// and should not be used as part of diagnostic messages. 00057 const char *getTokenName(TokenKind Kind) LLVM_READNONE; 00058 00059 /// \brief Determines the spelling of simple punctuation tokens like 00060 /// '!' or '%', and returns NULL for literal and annotation tokens. 00061 /// 00062 /// This routine only retrieves the "simple" spelling of the token, 00063 /// and will not produce any alternative spellings (e.g., a 00064 /// digraph). For the actual spelling of a given Token, use 00065 /// Preprocessor::getSpelling(). 00066 const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE; 00067 00068 /// \brief Determines the spelling of simple keyword and contextual keyword 00069 /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds. 00070 const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE; 00071 00072 /// \brief Return true if this is a raw identifier or an identifier kind. 00073 inline bool isAnyIdentifier(TokenKind K) { 00074 return (K == tok::identifier) || (K == tok::raw_identifier); 00075 } 00076 00077 /// \brief Return true if this is a C or C++ string-literal (or 00078 /// C++11 user-defined-string-literal) token. 00079 inline bool isStringLiteral(TokenKind K) { 00080 return K == tok::string_literal || K == tok::wide_string_literal || 00081 K == tok::utf8_string_literal || K == tok::utf16_string_literal || 00082 K == tok::utf32_string_literal; 00083 } 00084 00085 /// \brief Return true if this is a "literal" kind, like a numeric 00086 /// constant, string, etc. 00087 inline bool isLiteral(TokenKind K) { 00088 return K == tok::numeric_constant || K == tok::char_constant || 00089 K == tok::wide_char_constant || K == tok::utf8_char_constant || 00090 K == tok::utf16_char_constant || K == tok::utf32_char_constant || 00091 isStringLiteral(K) || K == tok::angle_string_literal; 00092 } 00093 00094 /// \brief Return true if this is any of tok::annot_* kinds. 00095 inline bool isAnnotation(TokenKind K) { 00096 #define ANNOTATION(NAME) \ 00097 if (K == tok::annot_##NAME) \ 00098 return true; 00099 #include "clang/Basic/TokenKinds.def" 00100 return false; 00101 } 00102 00103 } // end namespace tok 00104 } // end namespace clang 00105 00106 #endif