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 9 #include "clang/Basic/LangStandard.h" 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 20 const LangStandard &LangStandard::getLangStandardForKind(Kind K) { 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 31 LangStandard::Kind LangStandard::getLangKind(StringRef Name) { 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 39 const LangStandard *LangStandard::getLangStandardForName(StringRef Name) { 40 Kind K = getLangKind(Name); 41 if (K == lang_unspecified) 42 return nullptr; 43 44 return &getLangStandardForKind(K); 45 } 46 47 LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang, 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; 55 case Language::OpenCLCXX: 56 return LangStandard::lang_openclcpp10; 57 case Language::CUDA: 58 return LangStandard::lang_cuda; 59 case Language::Asm: 60 case Language::C: 61 if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified) 62 return CLANG_DEFAULT_STD_C; 63 64 // The PS4 uses C99 as the default C standard. 65 if (T.isPS4()) 66 return LangStandard::lang_gnu99; 67 return LangStandard::lang_gnu17; 68 case Language::ObjC: 69 if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified) 70 return CLANG_DEFAULT_STD_C; 71 72 return LangStandard::lang_gnu11; 73 case Language::CXX: 74 case Language::ObjCXX: 75 if (CLANG_DEFAULT_STD_CXX != LangStandard::lang_unspecified) 76 return CLANG_DEFAULT_STD_CXX; 77 78 if (T.isDriverKit()) 79 return LangStandard::lang_gnucxx17; 80 else 81 return LangStandard::lang_gnucxx14; 82 case Language::RenderScript: 83 return LangStandard::lang_c99; 84 case Language::HIP: 85 return LangStandard::lang_hip; 86 case Language::HLSL: 87 return LangStandard::lang_hlsl2021; 88 } 89 llvm_unreachable("unhandled Language kind!"); 90 } 91