clang  6.0.0svn
TokenKinds.h
Go to the documentation of this file.
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 
20 namespace clang {
21 
22 namespace tok {
23 
24 /// \brief Provides a simple uniform namespace for tokens from all C languages.
25 enum TokenKind : unsigned short {
26 #define TOK(X) X,
27 #include "clang/Basic/TokenKinds.def"
29 };
30 
31 /// \brief Provides a namespace for preprocessor keywords which start with a
32 /// '#' at the beginning of the line.
34 #define PPKEYWORD(X) pp_##X,
35 #include "clang/Basic/TokenKinds.def"
37 };
38 
39 /// \brief Provides a namespace for Objective-C keywords which start with
40 /// an '@'.
42 #define OBJC1_AT_KEYWORD(X) objc_##X,
43 #define OBJC2_AT_KEYWORD(X) objc_##X,
44 #include "clang/Basic/TokenKinds.def"
46 };
47 
48 /// \brief Defines the possible values of an on-off-switch (C99 6.10.6p2).
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.
57 const 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().
66 const 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.
70 const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
71 
72 /// \brief Return true if this is a raw identifier or an identifier kind.
73 inline 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.
79 inline 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.
87 inline 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.
95 inline 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
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token...
Definition: TokenKinds.h:79
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
Definition: TokenKinds.cpp:41
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
Definition: TokenKinds.h:33
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
Definition: TokenKinds.cpp:32
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
Definition: TokenKinds.h:41
Kind
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
Definition: TokenKinds.h:95
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Definition: TokenKinds.h:87
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
Dataflow Directional Tag Classes.
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:49
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Definition: TokenKinds.cpp:25
bool isAnyIdentifier(TokenKind K)
Return true if this is a raw identifier or an identifier kind.
Definition: TokenKinds.h:73