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,
40 OpenCLCXX,
41 CUDA,
42 RenderScript,
43 HIP,
44 HLSL,
45 ///@}
46};
47StringRef languageToString(Language L);
48
49enum LangFeatures {
50 LineComment = (1 << 0),
51 C99 = (1 << 1),
52 C11 = (1 << 2),
53 C17 = (1 << 3),
54 C23 = (1 << 4),
55 CPlusPlus = (1 << 5),
56 CPlusPlus11 = (1 << 6),
57 CPlusPlus14 = (1 << 7),
58 CPlusPlus17 = (1 << 8),
59 CPlusPlus20 = (1 << 9),
60 CPlusPlus23 = (1 << 10),
61 CPlusPlus26 = (1 << 11),
62 Digraphs = (1 << 12),
63 GNUMode = (1 << 13),
64 HexFloat = (1 << 14),
65 OpenCL = (1 << 15),
66 HLSL = (1 << 16)
67};
68
69/// LangStandard - Information about the properties of a particular language
70/// standard.
71struct LangStandard {
72 enum Kind {
73#define LANGSTANDARD(id, name, lang, desc, features) \
74 lang_##id,
75#include "clang/Basic/LangStandards.def"
76 lang_unspecified
77 };
78
79 const char *ShortName;
80 const char *Description;
81 unsigned Flags;
82 clang::Language Language;
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.
92 clang::Language getLanguage() const { return Language; }
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 /// isCPlusPlus - Language is a C++ variant.
110 bool isCPlusPlus() const { return Flags & CPlusPlus; }
111
112 /// isCPlusPlus11 - Language is a C++11 variant (or later).
113 bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
114
115 /// isCPlusPlus14 - Language is a C++14 variant (or later).
116 bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
117
118 /// isCPlusPlus17 - Language is a C++17 variant (or later).
119 bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
120
121 /// isCPlusPlus20 - Language is a C++20 variant (or later).
122 bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
123
124 /// isCPlusPlus23 - Language is a post-C++23 variant (or later).
125 bool isCPlusPlus23() const { return Flags & CPlusPlus23; }
126
127 /// isCPlusPlus26 - Language is a post-C++26 variant (or later).
128 bool isCPlusPlus26() const { return Flags & CPlusPlus26; }
129
130 /// hasDigraphs - Language supports digraphs.
131 bool hasDigraphs() const { return Flags & Digraphs; }
132
133 /// isGNUMode - Language includes GNU extensions.
134 bool isGNUMode() const { return Flags & GNUMode; }
135
136 /// hasHexFloats - Language supports hexadecimal float constants.
137 bool hasHexFloats() const { return Flags & HexFloat; }
138
139 /// isOpenCL - Language is a OpenCL variant.
140 bool isOpenCL() const { return Flags & OpenCL; }
141
142 static Kind getLangKind(StringRef Name);
143 static Kind getHLSLLangKind(StringRef Name);
144 static const LangStandard &getLangStandardForKind(Kind K);
145 static const LangStandard *getLangStandardForName(StringRef Name);
146};
147
148LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang,
149 const llvm::Triple &T);
150
151} // end namespace clang
152
153#endif
154

source code of clang/include/clang/Basic/LangStandard.h