]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/TokenKinds.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / TokenKinds.h
1 //===--- TokenKinds.h - Enum values for C Token Kinds -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Defines the clang::TokenKind enum and support functions.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_BASIC_TOKENKINDS_H
15 #define LLVM_CLANG_BASIC_TOKENKINDS_H
16
17 #include "llvm/Support/Compiler.h"
18
19 namespace clang {
20
21 namespace tok {
22
23 /// Provides a simple uniform namespace for tokens from all C languages.
24 enum TokenKind : unsigned short {
25 #define TOK(X) X,
26 #include "clang/Basic/TokenKinds.def"
27   NUM_TOKENS
28 };
29
30 /// Provides a namespace for preprocessor keywords which start with a
31 /// '#' at the beginning of the line.
32 enum PPKeywordKind {
33 #define PPKEYWORD(X) pp_##X,
34 #include "clang/Basic/TokenKinds.def"
35   NUM_PP_KEYWORDS
36 };
37
38 /// Provides a namespace for Objective-C keywords which start with
39 /// an '@'.
40 enum ObjCKeywordKind {
41 #define OBJC_AT_KEYWORD(X) objc_##X,
42 #include "clang/Basic/TokenKinds.def"
43   NUM_OBJC_KEYWORDS
44 };
45
46 /// 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 /// 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(TokenKind Kind) LLVM_READNONE;
56
57 /// 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 *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
65
66 /// Determines the spelling of simple keyword and contextual keyword
67 /// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
68 const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
69
70 /// Return true if this is a raw identifier or an identifier kind.
71 inline bool isAnyIdentifier(TokenKind K) {
72   return (K == tok::identifier) || (K == tok::raw_identifier);
73 }
74
75 /// Return true if this is a C or C++ string-literal (or
76 /// C++11 user-defined-string-literal) token.
77 inline bool isStringLiteral(TokenKind K) {
78   return K == tok::string_literal || K == tok::wide_string_literal ||
79          K == tok::utf8_string_literal || K == tok::utf16_string_literal ||
80          K == tok::utf32_string_literal;
81 }
82
83 /// Return true if this is a "literal" kind, like a numeric
84 /// constant, string, etc.
85 inline bool isLiteral(TokenKind K) {
86   return K == tok::numeric_constant || K == tok::char_constant ||
87          K == tok::wide_char_constant || K == tok::utf8_char_constant ||
88          K == tok::utf16_char_constant || K == tok::utf32_char_constant ||
89          isStringLiteral(K) || K == tok::header_name;
90 }
91
92 /// Return true if this is any of tok::annot_* kinds.
93 inline bool isAnnotation(TokenKind K) {
94 #define ANNOTATION(NAME) \
95   if (K == tok::annot_##NAME) \
96     return true;
97 #include "clang/Basic/TokenKinds.def"
98   return false;
99 }
100
101 }  // end namespace tok
102 }  // end namespace clang
103
104 #endif