1//===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief Defines the clang::TokenKind enum and support functions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
16#define LLVM_CLANG_BASIC_TOKENKINDS_H
17
18#include "llvm/Support/Compiler.h"
19
20namespace clang {
21
22namespace tok {
23
24/// \brief Provides a simple uniform namespace for tokens from all C languages.
25enum TokenKind : unsigned short {
26#define TOK(X) X,
27#include "clang/Basic/TokenKinds.def"
28  NUM_TOKENS
29};
30
31/// \brief Provides a namespace for preprocessor keywords which start with a
32/// '#' at the beginning of the line.
33enum PPKeywordKind {
34#define PPKEYWORD(X) pp_##X,
35#include "clang/Basic/TokenKinds.def"
36  NUM_PP_KEYWORDS
37};
38
39/// \brief Provides a namespace for Objective-C keywords which start with
40/// an '@'.
41enum ObjCKeywordKind {
42#define OBJC1_AT_KEYWORD(X) objc_##X,
43#define OBJC2_AT_KEYWORD(X) objc_##X,
44#include "clang/Basic/TokenKinds.def"
45  NUM_OBJC_KEYWORDS
46};
47
48/// \brief Defines the possible values of an on-off-switch (C99 6.10.6p2).
49enum OnOffSwitch {
50  OOS_ON, OOS_OFF, OOS_DEFAULT
51};
52
53/// \brief Determines the name of a token as used within the front end.
54///
55/// The name of a token will be an internal name (such as "l_square")
56/// and should not be used as part of diagnostic messages.
57const char *getTokenName(TokenKind Kind) LLVM_READNONE;
58
59/// \brief Determines the spelling of simple punctuation tokens like
60/// '!' or '%', and returns NULL for literal and annotation tokens.
61///
62/// This routine only retrieves the "simple" spelling of the token,
63/// and will not produce any alternative spellings (e.g., a
64/// digraph). For the actual spelling of a given Token, use
65/// Preprocessor::getSpelling().
66const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
67
68/// \brief Determines the spelling of simple keyword and contextual keyword
69/// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
70const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
71
72/// \brief Return true if this is a raw identifier or an identifier kind.
73inline bool isAnyIdentifier(TokenKind K) {
74  return (K == tok::identifier) || (K == tok::raw_identifier);
75}
76
77/// \brief Return true if this is a C or C++ string-literal (or
78/// C++11 user-defined-string-literal) token.
79inline bool isStringLiteral(TokenKind K) {
80  return K == tok::string_literal || K == tok::wide_string_literal ||
81         K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
82         K == tok::utf32_string_literal;
83}
84
85/// \brief Return true if this is a "literal" kind, like a numeric
86/// constant, string, etc.
87inline bool isLiteral(TokenKind K) {
88  return K == tok::numeric_constant || K == tok::char_constant ||
89         K == tok::wide_char_constant || K == tok::utf8_char_constant ||
90         K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
91         isStringLiteral(K) || K == tok::angle_string_literal;
92}
93
94/// \brief Return true if this is any of tok::annot_* kinds.
95inline bool isAnnotation(TokenKind K) {
96#define ANNOTATION(NAME) \
97  if (K == tok::annot_##NAME) \
98    return true;
99#include "clang/Basic/TokenKinds.def"
100  return false;
101}
102
103}  // end namespace tok
104}  // end namespace clang
105
106#endif
107