Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Basic/TokenKinds.h
Line
Count
Source (jump to first uncovered line)
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/ADT/DenseMapInfo.h"
18
#include "llvm/Support/Compiler.h"
19
20
namespace clang {
21
22
namespace tok {
23
24
/// 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"
28
  NUM_TOKENS
29
};
30
31
/// Provides a namespace for preprocessor keywords which start with a
32
/// '#' at the beginning of the line.
33
enum PPKeywordKind {
34
#define PPKEYWORD(X) pp_##X,
35
#include "clang/Basic/TokenKinds.def"
36
  NUM_PP_KEYWORDS
37
};
38
39
/// Provides a namespace for Objective-C keywords which start with
40
/// an '@'.
41
enum ObjCKeywordKind {
42
#define OBJC_AT_KEYWORD(X) objc_##X,
43
#include "clang/Basic/TokenKinds.def"
44
  NUM_OBJC_KEYWORDS
45
};
46
47
/// Defines the possible values of an on-off-switch (C99 6.10.6p2).
48
enum OnOffSwitch {
49
  OOS_ON, OOS_OFF, OOS_DEFAULT
50
};
51
52
/// Determines the name of a token as used within the front end.
53
///
54
/// The name of a token will be an internal name (such as "l_square")
55
/// and should not be used as part of diagnostic messages.
56
const char *getTokenName(TokenKind Kind) LLVM_READNONE;
57
58
/// Determines the spelling of simple punctuation tokens like
59
/// '!' or '%', and returns NULL for literal and annotation tokens.
60
///
61
/// This routine only retrieves the "simple" spelling of the token,
62
/// and will not produce any alternative spellings (e.g., a
63
/// digraph). For the actual spelling of a given Token, use
64
/// Preprocessor::getSpelling().
65
const char *getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE;
66
67
/// Determines the spelling of simple keyword and contextual keyword
68
/// tokens like 'int' and 'dynamic_cast'. Returns NULL for other token kinds.
69
const char *getKeywordSpelling(TokenKind Kind) LLVM_READNONE;
70
71
/// Returns the spelling of preprocessor keywords, such as "else".
72
const char *getPPKeywordSpelling(PPKeywordKind Kind) LLVM_READNONE;
73
74
/// Return true if this is a raw identifier or an identifier kind.
75
15.3M
inline bool isAnyIdentifier(TokenKind K) {
76
15.3M
  return (K == tok::identifier) || 
(K == tok::raw_identifier)2.02M
;
77
15.3M
}
78
79
/// Return true if this is a C or C++ string-literal (or
80
/// C++11 user-defined-string-literal) token.
81
3.38G
inline bool isStringLiteral(TokenKind K) {
82
3.38G
  return K == tok::string_literal || 
K == tok::wide_string_literal3.29G
||
83
3.38G
         
K == tok::utf8_string_literal3.29G
||
K == tok::utf16_string_literal3.29G
||
84
3.38G
         
K == tok::utf32_string_literal3.29G
;
85
3.38G
}
86
87
/// Return true if this is a "literal" kind, like a numeric
88
/// constant, string, etc.
89
2.89G
inline bool isLiteral(TokenKind K) {
90
2.89G
  return K == tok::numeric_constant || 
K == tok::char_constant2.67G
||
91
2.89G
         
K == tok::wide_char_constant2.67G
||
K == tok::utf8_char_constant2.67G
||
92
2.89G
         
K == tok::utf16_char_constant2.67G
||
K == tok::utf32_char_constant2.67G
||
93
2.89G
         
isStringLiteral(K)2.67G
||
K == tok::header_name2.59G
;
94
2.89G
}
95
96
/// Return true if this is any of tok::annot_* kinds.
97
bool isAnnotation(TokenKind K);
98
99
/// Return true if this is an annotation token representing a pragma.
100
bool isPragmaAnnotation(TokenKind K);
101
102
} // end namespace tok
103
} // end namespace clang
104
105
namespace llvm {
106
template <> struct DenseMapInfo<clang::tok::PPKeywordKind> {
107
0
  static inline clang::tok::PPKeywordKind getEmptyKey() {
108
0
    return clang::tok::PPKeywordKind::pp_not_keyword;
109
0
  }
110
0
  static inline clang::tok::PPKeywordKind getTombstoneKey() {
111
0
    return clang::tok::PPKeywordKind::NUM_PP_KEYWORDS;
112
0
  }
113
0
  static unsigned getHashValue(const clang::tok::PPKeywordKind &Val) {
114
0
    return static_cast<unsigned>(Val);
115
0
  }
116
  static bool isEqual(const clang::tok::PPKeywordKind &LHS,
117
0
                      const clang::tok::PPKeywordKind &RHS) {
118
0
    return LHS == RHS;
119
0
  }
120
};
121
} // namespace llvm
122
123
#endif