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::HIP:
41 return "HIP";
42 case Language::HLSL:
43 return "HLSL";
44 }
45
46 llvm_unreachable("unhandled language kind");
47}
48
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"
52
54 switch (K) {
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"
60 }
61 llvm_unreachable("Invalid language kind!");
62}
63
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);
70}
71
73 return llvm::StringSwitch<LangStandard::Kind>(Name)
74 .Case("2016", LangStandard::lang_hlsl2016)
75 .Case("2017", LangStandard::lang_hlsl2017)
76 .Case("2018", LangStandard::lang_hlsl2018)
77 .Case("2021", LangStandard::lang_hlsl2021)
78 .Case("202x", LangStandard::lang_hlsl202x)
79 .Case("202y", LangStandard::lang_hlsl202y)
81}
82
84 Kind K = getLangKind(Name);
85 if (K == lang_unspecified)
86 return nullptr;
87
88 return &getLangStandardForKind(K);
89}
90
92 const llvm::Triple &T) {
93 switch (Lang) {
96 case Language::CIR:
97 llvm_unreachable("Invalid input kind!");
99 return LangStandard::lang_opencl12;
101 return LangStandard::lang_openclcpp10;
102 case Language::Asm:
103 case Language::C:
104 // The PS4 uses C99 as the default C standard.
105 if (T.isPS4())
106 return LangStandard::lang_gnu99;
107 return LangStandard::lang_gnu17;
108 case Language::ObjC:
109 return LangStandard::lang_gnu11;
110 case Language::CXX:
111 case Language::ObjCXX:
112 case Language::CUDA:
113 case Language::HIP:
114 return LangStandard::lang_gnucxx17;
115 case Language::HLSL:
116 return LangStandard::lang_hlsl202x;
117 }
118 llvm_unreachable("unhandled Language kind!");
119}
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:71
static const LangStandard * getLangStandardForName(StringRef Name)
static Kind getHLSLLangKind(StringRef Name)
static const LangStandard & getLangStandardForKind(Kind K)
static Kind getLangKind(StringRef Name)