1 //===--- LangStandards.cpp - Language Standard Definitions ----------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "clang/Basic/LangStandard.h"
10 #include "clang/Config/config.h"
11 #include "llvm/ADT/StringSwitch.h"
12 #include "llvm/Support/ErrorHandling.h"
13 #include "llvm/TargetParser/Triple.h"
14 using namespace clang
;
16 StringRef
clang::languageToString(Language L
) {
18 case Language::Unknown
:
22 case Language::LLVM_IR
:
30 case Language::ObjCXX
:
31 return "Objective-C++";
32 case Language::OpenCL
:
34 case Language::OpenCLCXX
:
38 case Language::RenderScript
:
39 return "RenderScript";
46 llvm_unreachable("unhandled language kind");
49 #define LANGSTANDARD(id, name, lang, desc, features) \
50 static const LangStandard Lang_##id = {name, desc, features, Language::lang};
51 #include "clang/Basic/LangStandards.def"
53 const LangStandard
&LangStandard::getLangStandardForKind(Kind K
) {
55 case lang_unspecified
:
56 llvm::report_fatal_error("getLangStandardForKind() on unspecified kind");
57 #define LANGSTANDARD(id, name, lang, desc, features) \
58 case lang_##id: return Lang_##id;
59 #include "clang/Basic/LangStandards.def"
61 llvm_unreachable("Invalid language kind!");
64 LangStandard::Kind
LangStandard::getLangKind(StringRef Name
) {
65 return llvm::StringSwitch
<Kind
>(Name
)
66 #define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id)
67 #define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id)
68 #include "clang/Basic/LangStandards.def"
69 .Default(lang_unspecified
);
72 const LangStandard
*LangStandard::getLangStandardForName(StringRef Name
) {
73 Kind K
= getLangKind(Name
);
74 if (K
== lang_unspecified
)
77 return &getLangStandardForKind(K
);
80 LangStandard::Kind
clang::getDefaultLanguageStandard(clang::Language Lang
,
81 const llvm::Triple
&T
) {
83 case Language::Unknown
:
84 case Language::LLVM_IR
:
85 llvm_unreachable("Invalid input kind!");
86 case Language::OpenCL
:
87 return LangStandard::lang_opencl12
;
88 case Language::OpenCLCXX
:
89 return LangStandard::lang_openclcpp10
;
92 // The PS4 uses C99 as the default C standard.
94 return LangStandard::lang_gnu99
;
95 return LangStandard::lang_gnu17
;
97 return LangStandard::lang_gnu11
;
99 case Language::ObjCXX
:
102 return LangStandard::lang_gnucxx17
;
103 case Language::RenderScript
:
104 return LangStandard::lang_c99
;
106 return LangStandard::lang_hlsl2021
;
108 llvm_unreachable("unhandled Language kind!");