clang 23.0.0git
LangStandard.h
Go to the documentation of this file.
1//===--- LangStandard.h -----------------------------------------*- 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#ifndef LLVM_CLANG_BASIC_LANGSTANDARD_H
10#define LLVM_CLANG_BASIC_LANGSTANDARD_H
11
12#include "clang/Basic/LLVM.h"
13#include "llvm/ADT/StringRef.h"
14
15namespace llvm {
16class Triple;
17}
18
19namespace clang {
20
21/// The language for the input, used to select and validate the language
22/// standard and possible actions.
23enum class Language : uint8_t {
25
26 /// Assembly: we accept this only so that we can preprocess it.
28
29 /// LLVM IR & CIR: we accept these so that we can run the optimizer on them,
30 /// and compile them to assembly or object code (or LLVM for CIR).
33
34 ///@{ Languages that the frontend can parse and compile.
44 ///@}
45};
46StringRef languageToString(Language L);
47
49 LineComment = (1 << 0),
50 C99 = (1 << 1),
51 C11 = (1 << 2),
52 C17 = (1 << 3),
53 C23 = (1 << 4),
54 C2y = (1 << 5),
55 CPlusPlus = (1 << 6),
56 CPlusPlus11 = (1 << 7),
57 CPlusPlus14 = (1 << 8),
58 CPlusPlus17 = (1 << 9),
59 CPlusPlus20 = (1 << 10),
60 CPlusPlus23 = (1 << 11),
61 CPlusPlus26 = (1 << 12),
62 CPlusPlus29 = (1 << 13),
63 Digraphs = (1 << 14),
64 GNUMode = (1 << 15),
65 HexFloat = (1 << 16),
66 OpenCL = (1 << 17),
67 HLSL = (1 << 18)
68};
69
70/// LangStandard - Information about the properties of a particular language
71/// standard.
73 enum Kind {
74#define LANGSTANDARD(id, name, lang, desc, features, version) lang_##id,
75#include "clang/Basic/LangStandards.def"
77 };
78
79 const char *ShortName;
80 const char *Description;
81 unsigned Flags;
83 std::optional<uint32_t> Version;
84
85public:
86 /// getName - Get the name of this standard.
87 const char *getName() const { return ShortName; }
88
89 /// getDescription - Get the description of this standard.
90 const char *getDescription() const { return Description; }
91
92 /// Get the language that this standard describes.
94
95 /// Get the version code for this language standard.
96 std::optional<uint32_t> getVersion() const { return Version; }
97
98 /// Language supports '//' comments.
99 bool hasLineComments() const { return Flags & LineComment; }
100
101 /// isC99 - Language is a superset of C99.
102 bool isC99() const { return Flags & C99; }
103
104 /// isC11 - Language is a superset of C11.
105 bool isC11() const { return Flags & C11; }
106
107 /// isC17 - Language is a superset of C17.
108 bool isC17() const { return Flags & C17; }
109
110 /// isC23 - Language is a superset of C23.
111 bool isC23() const { return Flags & C23; }
112
113 /// isC2y - Language is a superset of C2y.
114 bool isC2y() const { return Flags & C2y; }
115
116 /// isCPlusPlus - Language is a C++ variant.
117 bool isCPlusPlus() const { return Flags & CPlusPlus; }
118
119 /// isCPlusPlus11 - Language is a C++11 variant (or later).
120 bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
121
122 /// isCPlusPlus14 - Language is a C++14 variant (or later).
123 bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
124
125 /// isCPlusPlus17 - Language is a C++17 variant (or later).
126 bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
127
128 /// isCPlusPlus20 - Language is a C++20 variant (or later).
129 bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
130
131 /// isCPlusPlus23 - Language is a post-C++23 variant (or later).
132 bool isCPlusPlus23() const { return Flags & CPlusPlus23; }
133
134 /// isCPlusPlus26 - Language is a post-C++26 variant (or later).
135 bool isCPlusPlus26() const { return Flags & CPlusPlus26; }
136
137 /// isCPlusPlus29 - Language is a post-C++29 variant (or later).
138 bool isCPlusPlus29() const { return Flags & CPlusPlus29; }
139
140 /// hasDigraphs - Language supports digraphs.
141 bool hasDigraphs() const { return Flags & Digraphs; }
142
143 /// hasRawStringLiterals - Language supports R"()" raw string literals.
144 bool hasRawStringLiterals() const {
145 // GCC supports raw string literals in C99 and later, but not in C++
146 // before C++11.
147 return isCPlusPlus11() || (!isCPlusPlus() && isC99() && isGNUMode());
148 }
149
150 /// allowLiteralDigitSeparator - Language supports literal digit seperator
151 bool allowLiteralDigitSeparator() const { return isCPlusPlus14() || isC23(); }
152
153 /// isGNUMode - Language includes GNU extensions.
154 bool isGNUMode() const { return Flags & GNUMode; }
155
156 /// hasHexFloats - Language supports hexadecimal float constants.
157 bool hasHexFloats() const { return Flags & HexFloat; }
158
159 /// isOpenCL - Language is a OpenCL variant.
160 bool isOpenCL() const { return Flags & OpenCL; }
161
162 static Kind getLangKind(StringRef Name);
163 static Kind getHLSLLangKind(StringRef Name);
164 static const LangStandard &getLangStandardForKind(Kind K);
165 static const LangStandard *getLangStandardForName(StringRef Name);
166};
167
169 const llvm::Triple &T);
170
171} // end namespace clang
172
173#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
The JSON file list parser is used to communicate input to InstallAPI.
@ CPlusPlus23
@ CPlusPlus20
@ LineComment
@ CPlusPlus
@ CPlusPlus11
@ CPlusPlus29
@ CPlusPlus14
@ CPlusPlus26
@ CPlusPlus17
LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang, const llvm::Triple &T)
Language
The language for the input, used to select and validate the language standard and possible actions.
@ CIR
LLVM IR & CIR: we accept these so that we can run the optimizer on them, and compile them to assembly...
@ Asm
Assembly: we accept this only so that we can preprocess it.
StringRef languageToString(Language L)
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
LangStandard - Information about the properties of a particular language standard.
bool isCPlusPlus20() const
isCPlusPlus20 - Language is a C++20 variant (or later).
bool isCPlusPlus() const
isCPlusPlus - Language is a C++ variant.
bool hasRawStringLiterals() const
hasRawStringLiterals - Language supports R"()" raw string literals.
const char * Description
bool hasHexFloats() const
hasHexFloats - Language supports hexadecimal float constants.
std::optional< uint32_t > Version
bool isC11() const
isC11 - Language is a superset of C11.
static const LangStandard * getLangStandardForName(StringRef Name)
bool isCPlusPlus17() const
isCPlusPlus17 - Language is a C++17 variant (or later).
bool hasDigraphs() const
hasDigraphs - Language supports digraphs.
clang::Language getLanguage() const
Get the language that this standard describes.
bool isCPlusPlus14() const
isCPlusPlus14 - Language is a C++14 variant (or later).
static Kind getHLSLLangKind(StringRef Name)
const char * getDescription() const
getDescription - Get the description of this standard.
bool isCPlusPlus29() const
isCPlusPlus29 - Language is a post-C++29 variant (or later).
bool isC17() const
isC17 - Language is a superset of C17.
bool isCPlusPlus26() const
isCPlusPlus26 - Language is a post-C++26 variant (or later).
bool isC2y() const
isC2y - Language is a superset of C2y.
const char * ShortName
bool isCPlusPlus11() const
isCPlusPlus11 - Language is a C++11 variant (or later).
std::optional< uint32_t > getVersion() const
Get the version code for this language standard.
bool isC23() const
isC23 - Language is a superset of C23.
clang::Language Language
static const LangStandard & getLangStandardForKind(Kind K)
bool isOpenCL() const
isOpenCL - Language is a OpenCL variant.
const char * getName() const
getName - Get the name of this standard.
bool hasLineComments() const
Language supports '//' comments.
bool allowLiteralDigitSeparator() const
allowLiteralDigitSeparator - Language supports literal digit seperator
bool isCPlusPlus23() const
isCPlusPlus23 - Language is a post-C++23 variant (or later).
bool isGNUMode() const
isGNUMode - Language includes GNU extensions.
static Kind getLangKind(StringRef Name)
bool isC99() const
isC99 - Language is a superset of C99.