clang 20.0.0git
LangStandards.cpp
Go to the documentation of this file.
1//===--- LangStandards.cpp - Language Standard Definitions ----------------===//
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
10#include "clang/Config/config.h"
11#include "llvm/ADT/StringSwitch.h"
12#include "llvm/Support/ErrorHandling.h"
13#include "llvm/TargetParser/Triple.h"
14using namespace clang;
15
17 switch (L) {
18 case Language::Unknown:
19 return "Unknown";
20 case Language::Asm:
21 return "Asm";
22 case Language::LLVM_IR:
23 return "LLVM IR";
24 case Language::CIR:
25 return "ClangIR";
26 case Language::C:
27 return "C";
28 case Language::CXX:
29 return "C++";
30 case Language::ObjC:
31 return "Objective-C";
32 case Language::ObjCXX:
33 return "Objective-C++";
34 case Language::OpenCL:
35 return "OpenCL";
36 case Language::OpenCLCXX:
37 return "OpenCLC++";
38 case Language::CUDA:
39 return "CUDA";
40 case Language::RenderScript:
41 return "RenderScript";
42 case Language::HIP:
43 return "HIP";
44 case Language::HLSL:
45 return "HLSL";
46 }
47
48 llvm_unreachable("unhandled language kind");
49}
50
51#define LANGSTANDARD(id, name, lang, desc, features) \
52 static const LangStandard Lang_##id = {name, desc, features, Language::lang};
53#include "clang/Basic/LangStandards.def"
54
56 switch (K) {
58 llvm::report_fatal_error("getLangStandardForKind() on unspecified kind");
59#define LANGSTANDARD(id, name, lang, desc, features) \
60 case lang_##id: return Lang_##id;
61#include "clang/Basic/LangStandards.def"
62 }
63 llvm_unreachable("Invalid language kind!");
64}
65
67 return llvm::StringSwitch<Kind>(Name)
68#define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id)
69#define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id)
70#include "clang/Basic/LangStandards.def"
71 .Default(lang_unspecified);
72}
73
75 return llvm::StringSwitch<LangStandard::Kind>(Name)
76 .Case("2016", LangStandard::lang_hlsl2016)
77 .Case("2017", LangStandard::lang_hlsl2017)
78 .Case("2018", LangStandard::lang_hlsl2018)
79 .Case("2021", LangStandard::lang_hlsl2021)
80 .Case("202x", LangStandard::lang_hlsl202x)
82}
83
85 Kind K = getLangKind(Name);
86 if (K == lang_unspecified)
87 return nullptr;
88
89 return &getLangStandardForKind(K);
90}
91
93 const llvm::Triple &T) {
94 switch (Lang) {
97 case Language::CIR:
98 llvm_unreachable("Invalid input kind!");
100 return LangStandard::lang_opencl12;
102 return LangStandard::lang_openclcpp10;
103 case Language::Asm:
104 case Language::C:
105 // The PS4 uses C99 as the default C standard.
106 if (T.isPS4())
107 return LangStandard::lang_gnu99;
108 return LangStandard::lang_gnu17;
109 case Language::ObjC:
110 return LangStandard::lang_gnu11;
111 case Language::CXX:
112 case Language::ObjCXX:
113 case Language::CUDA:
114 case Language::HIP:
115 return LangStandard::lang_gnucxx17;
117 return LangStandard::lang_c99;
118 case Language::HLSL:
119 return LangStandard::lang_hlsl2021;
120 }
121 llvm_unreachable("unhandled Language kind!");
122}
The JSON file list parser is used to communicate input to InstallAPI.
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
@ C
Languages that the frontend can parse and compile.
@ 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
LangStandard - Information about the properties of a particular language standard.
Definition: LangStandard.h:72
static const LangStandard * getLangStandardForName(StringRef Name)
static Kind getHLSLLangKind(StringRef Name)
static const LangStandard & getLangStandardForKind(Kind K)
static Kind getLangKind(StringRef Name)