clang 20.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 {
24 Unknown,
25
26 /// Assembly: we accept this only so that we can preprocess it.
27 Asm,
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).
31 CIR,
32 LLVM_IR,
33
34 ///@{ Languages that the frontend can parse and compile.
35 C,
36 CXX,
37 ObjC,
38 ObjCXX,
39 OpenCL,
41 CUDA,
42 HIP,
43 HLSL,
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 Digraphs = (1 << 13),
63 GNUMode = (1 << 14),
64 HexFloat = (1 << 15),
65 OpenCL = (1 << 16),
66 HLSL = (1 << 17)
67};
68
69/// LangStandard - Information about the properties of a particular language
70/// standard.
72 enum Kind {
73#define LANGSTANDARD(id, name, lang, desc, features) \
74 lang_##id,
75#include "clang/Basic/LangStandards.def"
77 };
78
79 const char *ShortName;
80 const char *Description;
81 unsigned Flags;
83
84public:
85 /// getName - Get the name of this standard.
86 const char *getName() const { return ShortName; }
87
88 /// getDescription - Get the description of this standard.
89 const char *getDescription() const { return Description; }
90
91 /// Get the language that this standard describes.
93
94 /// Language supports '//' comments.
95 bool hasLineComments() const { return Flags & LineComment; }
96
97 /// isC99 - Language is a superset of C99.
98 bool isC99() const { return Flags & C99; }
99
100 /// isC11 - Language is a superset of C11.
101 bool isC11() const { return Flags & C11; }
102
103 /// isC17 - Language is a superset of C17.
104 bool isC17() const { return Flags & C17; }
105
106 /// isC23 - Language is a superset of C23.
107 bool isC23() const { return Flags & C23; }
108
109 /// isC2y - Language is a superset of C2y.
110 bool isC2y() const { return Flags & C2y; }
111
112 /// isCPlusPlus - Language is a C++ variant.
113 bool isCPlusPlus() const { return Flags & CPlusPlus; }
114
115 /// isCPlusPlus11 - Language is a C++11 variant (or later).
116 bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
117
118 /// isCPlusPlus14 - Language is a C++14 variant (or later).
119 bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
120
121 /// isCPlusPlus17 - Language is a C++17 variant (or later).
122 bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
123
124 /// isCPlusPlus20 - Language is a C++20 variant (or later).
125 bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
126
127 /// isCPlusPlus23 - Language is a post-C++23 variant (or later).
128 bool isCPlusPlus23() const { return Flags & CPlusPlus23; }
129
130 /// isCPlusPlus26 - Language is a post-C++26 variant (or later).
131 bool isCPlusPlus26() const { return Flags & CPlusPlus26; }
132
133 /// hasDigraphs - Language supports digraphs.
134 bool hasDigraphs() const { return Flags & Digraphs; }
135
136 /// hasRawStringLiterals - Language supports R"()" raw string literals.
137 bool hasRawStringLiterals() const {
138 // GCC supports raw string literals in C99 and later, but not in C++
139 // before C++11.
140 return isCPlusPlus11() || (!isCPlusPlus() && isC99() && isGNUMode());
141 }
142
143 /// isGNUMode - Language includes GNU extensions.
144 bool isGNUMode() const { return Flags & GNUMode; }
145
146 /// hasHexFloats - Language supports hexadecimal float constants.
147 bool hasHexFloats() const { return Flags & HexFloat; }
148
149 /// isOpenCL - Language is a OpenCL variant.
150 bool isOpenCL() const { return Flags & OpenCL; }
151
152 static Kind getLangKind(StringRef Name);
153 static Kind getHLSLLangKind(StringRef Name);
155 static const LangStandard *getLangStandardForName(StringRef Name);
156};
157
159 const llvm::Triple &T);
160
161} // end namespace clang
162
163#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.
LangFeatures
Definition: LangStandard.h:48
@ GNUMode
Definition: LangStandard.h:63
@ OpenCL
Definition: LangStandard.h:65
@ CPlusPlus23
Definition: LangStandard.h:60
@ CPlusPlus20
Definition: LangStandard.h:59
@ LineComment
Definition: LangStandard.h:49
@ CPlusPlus
Definition: LangStandard.h:55
@ CPlusPlus11
Definition: LangStandard.h:56
@ CPlusPlus14
Definition: LangStandard.h:57
@ HexFloat
Definition: LangStandard.h:64
@ CPlusPlus26
Definition: LangStandard.h:61
@ Digraphs
Definition: LangStandard.h:62
@ CPlusPlus17
Definition: LangStandard.h:58
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.
Definition: LangStandard.h:23
@ 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)
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
LangStandard - Information about the properties of a particular language standard.
Definition: LangStandard.h:71
bool isCPlusPlus20() const
isCPlusPlus20 - Language is a C++20 variant (or later).
Definition: LangStandard.h:125
bool isCPlusPlus() const
isCPlusPlus - Language is a C++ variant.
Definition: LangStandard.h:113
bool hasRawStringLiterals() const
hasRawStringLiterals - Language supports R"()" raw string literals.
Definition: LangStandard.h:137
const char * Description
Definition: LangStandard.h:80
bool hasHexFloats() const
hasHexFloats - Language supports hexadecimal float constants.
Definition: LangStandard.h:147
bool isC11() const
isC11 - Language is a superset of C11.
Definition: LangStandard.h:101
static const LangStandard * getLangStandardForName(StringRef Name)
bool isCPlusPlus17() const
isCPlusPlus17 - Language is a C++17 variant (or later).
Definition: LangStandard.h:122
bool hasDigraphs() const
hasDigraphs - Language supports digraphs.
Definition: LangStandard.h:134
clang::Language getLanguage() const
Get the language that this standard describes.
Definition: LangStandard.h:92
bool isCPlusPlus14() const
isCPlusPlus14 - Language is a C++14 variant (or later).
Definition: LangStandard.h:119
static Kind getHLSLLangKind(StringRef Name)
const char * getDescription() const
getDescription - Get the description of this standard.
Definition: LangStandard.h:89
bool isC17() const
isC17 - Language is a superset of C17.
Definition: LangStandard.h:104
bool isCPlusPlus26() const
isCPlusPlus26 - Language is a post-C++26 variant (or later).
Definition: LangStandard.h:131
bool isC2y() const
isC2y - Language is a superset of C2y.
Definition: LangStandard.h:110
const char * ShortName
Definition: LangStandard.h:79
bool isCPlusPlus11() const
isCPlusPlus11 - Language is a C++11 variant (or later).
Definition: LangStandard.h:116
bool isC23() const
isC23 - Language is a superset of C23.
Definition: LangStandard.h:107
clang::Language Language
Definition: LangStandard.h:82
static const LangStandard & getLangStandardForKind(Kind K)
bool isOpenCL() const
isOpenCL - Language is a OpenCL variant.
Definition: LangStandard.h:150
const char * getName() const
getName - Get the name of this standard.
Definition: LangStandard.h:86
bool hasLineComments() const
Language supports '//' comments.
Definition: LangStandard.h:95
bool isCPlusPlus23() const
isCPlusPlus23 - Language is a post-C++23 variant (or later).
Definition: LangStandard.h:128
bool isGNUMode() const
isGNUMode - Language includes GNU extensions.
Definition: LangStandard.h:144
static Kind getLangKind(StringRef Name)
bool isC99() const
isC99 - Language is a superset of C99.
Definition: LangStandard.h:98