clang  16.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/ADT/Triple.h"
13 #include "llvm/Support/ErrorHandling.h"
14 using namespace clang;
15 
16 #define LANGSTANDARD(id, name, lang, desc, features) \
17  static const LangStandard Lang_##id = {name, desc, features, Language::lang};
18 #include "clang/Basic/LangStandards.def"
19 
21  switch (K) {
22  case lang_unspecified:
23  llvm::report_fatal_error("getLangStandardForKind() on unspecified kind");
24 #define LANGSTANDARD(id, name, lang, desc, features) \
25  case lang_##id: return Lang_##id;
26 #include "clang/Basic/LangStandards.def"
27  }
28  llvm_unreachable("Invalid language kind!");
29 }
30 
32  return llvm::StringSwitch<Kind>(Name)
33 #define LANGSTANDARD(id, name, lang, desc, features) .Case(name, lang_##id)
34 #define LANGSTANDARD_ALIAS(id, alias) .Case(alias, lang_##id)
35 #include "clang/Basic/LangStandards.def"
36  .Default(lang_unspecified);
37 }
38 
40  Kind K = getLangKind(Name);
41  if (K == lang_unspecified)
42  return nullptr;
43 
44  return &getLangStandardForKind(K);
45 }
46 
48  const llvm::Triple &T) {
49  switch (Lang) {
50  case Language::Unknown:
51  case Language::LLVM_IR:
52  llvm_unreachable("Invalid input kind!");
53  case Language::OpenCL:
54  return LangStandard::lang_opencl12;
56  return LangStandard::lang_openclcpp10;
57  case Language::CUDA:
58  return LangStandard::lang_cuda;
59  case Language::Asm:
60  case Language::C:
61  // The PS4 uses C99 as the default C standard.
62  if (T.isPS4())
63  return LangStandard::lang_gnu99;
64  return LangStandard::lang_gnu17;
65  case Language::ObjC:
66  return LangStandard::lang_gnu11;
67  case Language::CXX:
68  case Language::ObjCXX:
69  if (T.isPS())
70  return LangStandard::lang_gnucxx14;
71  return LangStandard::lang_gnucxx17;
73  return LangStandard::lang_c99;
74  case Language::HIP:
75  return LangStandard::lang_hip;
76  case Language::HLSL:
77  return LangStandard::lang_hlsl2021;
78  }
79  llvm_unreachable("unhandled Language kind!");
80 }
clang::Language::CUDA
@ CUDA
clang::Language::OpenCLCXX
@ OpenCLCXX
clang::Language::Asm
@ Asm
Assembly: we accept this only so that we can preprocess it.
clang::LangStandard::Kind
Kind
Definition: LangStandard.h:69
clang::LangStandard::getLangKind
static Kind getLangKind(StringRef Name)
Definition: LangStandards.cpp:31
clang::Language::RenderScript
@ RenderScript
clang::Language::C
@ C
Languages that the frontend can parse and compile.
clang::Language
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
LangStandard.h
clang::Language::CXX
@ CXX
clang::Language::ObjCXX
@ ObjCXX
clang::Language::LLVM_IR
@ LLVM_IR
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
clang::LangStandard::getLangStandardForName
static const LangStandard * getLangStandardForName(StringRef Name)
Definition: LangStandards.cpp:39
clang::Language::ObjC
@ ObjC
clang::LangStandard::lang_unspecified
@ lang_unspecified
Definition: LangStandard.h:73
clang::LangStandard
LangStandard - Information about the properties of a particular language standard.
Definition: LangStandard.h:68
clang
Definition: CalledOnceCheck.h:17
clang::getDefaultLanguageStandard
LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang, const llvm::Triple &T)
Definition: LangStandards.cpp:47
clang::Language::Unknown
@ Unknown
clang::Language::HIP
@ HIP
clang::HLSL
@ HLSL
Definition: LangStandard.h:63
clang::LangStandard::getLangStandardForKind
static const LangStandard & getLangStandardForKind(Kind K)
Definition: LangStandards.cpp:20
clang::OpenCL
@ OpenCL