]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/include/clang/Basic/TokenKinds.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / include / clang / Basic / TokenKinds.h
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_TOKENKINDS_H
16 #define LLVM_CLANG_TOKENKINDS_H
17
18 namespace clang {
19
20 namespace tok {
21
22 /// \brief Provides a simple uniform namespace for tokens from all C languages.
23 enum TokenKind {
24 #define TOK(X) X,
25 #include "clang/Basic/TokenKinds.def"
26   NUM_TOKENS
27 };
28
29 /// \brief Provides a namespace for preprocessor keywords which start with a
30 /// '#' at the beginning of the line.
31 enum PPKeywordKind {
32 #define PPKEYWORD(X) pp_##X,
33 #include "clang/Basic/TokenKinds.def"
34   NUM_PP_KEYWORDS
35 };
36
37 /// \brief Provides a namespace for Objective-C keywords which start with
38 /// an '@'.
39 enum ObjCKeywordKind {
40 #define OBJC1_AT_KEYWORD(X) objc_##X,
41 #define OBJC2_AT_KEYWORD(X) objc_##X,
42 #include "clang/Basic/TokenKinds.def"
43   NUM_OBJC_KEYWORDS
44 };
45
46 /// \brief Defines the possible values of an on-off-switch (C99 6.10.6p2).
47 enum OnOffSwitch {
48   OOS_ON, OOS_OFF, OOS_DEFAULT
49 };
50
51 /// \brief Determines the name of a token as used within the front end.
52 ///
53 /// The name of a token will be an internal name (such as "l_square")
54 /// and should not be used as part of diagnostic messages.
55 const char *getTokenName(enum TokenKind Kind);
56
57 /// \brief Determines the spelling of simple punctuation tokens like
58 /// '!' or '%', and returns NULL for literal and annotation tokens.
59 ///
60 /// This routine only retrieves the "simple" spelling of the token,
61 /// and will not produce any alternative spellings (e.g., a
62 /// digraph). For the actual spelling of a given Token, use
63 /// Preprocessor::getSpelling().
64 const char *getTokenSimpleSpelling(enum TokenKind Kind);
65
66 /// \brief Return true if this is a raw identifier or an identifier kind.
67 inline bool isAnyIdentifier(TokenKind K) {
68   return (K == tok::identifier) || (K == tok::raw_identifier);
69 }
70
71 /// \brief Return true if this is a C or C++ string-literal (or
72 /// C++11 user-defined-string-literal) token.
73 inline bool isStringLiteral(TokenKind K) {
74   return K == tok::string_literal || K == tok::wide_string_literal ||
75          K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
76          K == tok::utf32_string_literal;
77 }
78
79 /// \brief Return true if this is a "literal" kind, like a numeric
80 /// constant, string, etc.
81 inline bool isLiteral(TokenKind K) {
82   return K == tok::numeric_constant || K == tok::char_constant ||
83          K == tok::wide_char_constant || K == tok::utf16_char_constant ||
84          K == tok::utf32_char_constant || isStringLiteral(K) ||
85          K == tok::angle_string_literal;
86 }
87
88 /// \brief Return true if this is any of tok::annot_* kinds.
89 inline bool isAnnotation(TokenKind K) {
90 #define ANNOTATION(NAME) \
91   if (K == tok::annot_##NAME) \
92     return true;
93 #include "clang/Basic/TokenKinds.def"
94   return false;
95 }
96
97 }  // end namespace tok
98 }  // end namespace clang
99
100 #endif