1 //===--- LangStandard.h -----------------------------------------*- C++ -*-===// 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 #ifndef LLVM_CLANG_BASIC_LANGSTANDARD_H 10 #define LLVM_CLANG_BASIC_LANGSTANDARD_H 11 12 #include "clang/Basic/LLVM.h" 13 #include "llvm/ADT/StringRef.h" 14 15 namespace llvm { 16 class Triple; 17 } 18 19 namespace clang { 20 21 /// The language for the input, used to select and validate the language 22 /// standard and possible actions. 23 enum class Language : uint8_t { 24 Unknown, 25 26 /// Assembly: we accept this only so that we can preprocess it. 27 Asm, 28 29 /// LLVM IR & CIR: we accept these so that we can run the optimizer on them, 30 /// and compile them to assembly or object code (or LLVM for CIR). 31 CIR, 32 LLVM_IR, 33 34 ///@{ Languages that the frontend can parse and compile. 35 C, 36 CXX, 37 ObjC, 38 ObjCXX, 39 OpenCL, 40 OpenCLCXX, 41 CUDA, 42 RenderScript, 43 HIP, 44 HLSL, 45 ///@} 46 }; 47 StringRef languageToString(Language L); 48 49 enum LangFeatures { 50 LineComment = (1 << 0), 51 C99 = (1 << 1), 52 C11 = (1 << 2), 53 C17 = (1 << 3), 54 C23 = (1 << 4), 55 C2y = (1 << 5), 56 CPlusPlus = (1 << 6), 57 CPlusPlus11 = (1 << 7), 58 CPlusPlus14 = (1 << 8), 59 CPlusPlus17 = (1 << 9), 60 CPlusPlus20 = (1 << 10), 61 CPlusPlus23 = (1 << 11), 62 CPlusPlus26 = (1 << 12), 63 Digraphs = (1 << 13), 64 GNUMode = (1 << 14), 65 HexFloat = (1 << 15), 66 OpenCL = (1 << 16), 67 HLSL = (1 << 17) 68 }; 69 70 /// LangStandard - Information about the properties of a particular language 71 /// standard. 72 struct LangStandard { 73 enum Kind { 74 #define LANGSTANDARD(id, name, lang, desc, features) \ 75 lang_##id, 76 #include "clang/Basic/LangStandards.def" 77 lang_unspecified 78 }; 79 80 const char *ShortName; 81 const char *Description; 82 unsigned Flags; 83 clang::Language Language; 84 85 public: 86 /// getName - Get the name of this standard. getNameLangStandard87 const char *getName() const { return ShortName; } 88 89 /// getDescription - Get the description of this standard. getDescriptionLangStandard90 const char *getDescription() const { return Description; } 91 92 /// Get the language that this standard describes. getLanguageLangStandard93 clang::Language getLanguage() const { return Language; } 94 95 /// Language supports '//' comments. hasLineCommentsLangStandard96 bool hasLineComments() const { return Flags & LineComment; } 97 98 /// isC99 - Language is a superset of C99. isC99LangStandard99 bool isC99() const { return Flags & C99; } 100 101 /// isC11 - Language is a superset of C11. isC11LangStandard102 bool isC11() const { return Flags & C11; } 103 104 /// isC17 - Language is a superset of C17. isC17LangStandard105 bool isC17() const { return Flags & C17; } 106 107 /// isC23 - Language is a superset of C23. isC23LangStandard108 bool isC23() const { return Flags & C23; } 109 110 /// isC2y - Language is a superset of C2y. isC2yLangStandard111 bool isC2y() const { return Flags & C2y; } 112 113 /// isCPlusPlus - Language is a C++ variant. isCPlusPlusLangStandard114 bool isCPlusPlus() const { return Flags & CPlusPlus; } 115 116 /// isCPlusPlus11 - Language is a C++11 variant (or later). isCPlusPlus11LangStandard117 bool isCPlusPlus11() const { return Flags & CPlusPlus11; } 118 119 /// isCPlusPlus14 - Language is a C++14 variant (or later). isCPlusPlus14LangStandard120 bool isCPlusPlus14() const { return Flags & CPlusPlus14; } 121 122 /// isCPlusPlus17 - Language is a C++17 variant (or later). isCPlusPlus17LangStandard123 bool isCPlusPlus17() const { return Flags & CPlusPlus17; } 124 125 /// isCPlusPlus20 - Language is a C++20 variant (or later). isCPlusPlus20LangStandard126 bool isCPlusPlus20() const { return Flags & CPlusPlus20; } 127 128 /// isCPlusPlus23 - Language is a post-C++23 variant (or later). isCPlusPlus23LangStandard129 bool isCPlusPlus23() const { return Flags & CPlusPlus23; } 130 131 /// isCPlusPlus26 - Language is a post-C++26 variant (or later). isCPlusPlus26LangStandard132 bool isCPlusPlus26() const { return Flags & CPlusPlus26; } 133 134 /// hasDigraphs - Language supports digraphs. hasDigraphsLangStandard135 bool hasDigraphs() const { return Flags & Digraphs; } 136 137 /// hasRawStringLiterals - Language supports R"()" raw string literals. hasRawStringLiteralsLangStandard138 bool hasRawStringLiterals() const { 139 // GCC supports raw string literals in C99 and later, but not in C++ 140 // before C++11. 141 return isCPlusPlus11() || (!isCPlusPlus() && isC99() && isGNUMode()); 142 } 143 144 /// isGNUMode - Language includes GNU extensions. isGNUModeLangStandard145 bool isGNUMode() const { return Flags & GNUMode; } 146 147 /// hasHexFloats - Language supports hexadecimal float constants. hasHexFloatsLangStandard148 bool hasHexFloats() const { return Flags & HexFloat; } 149 150 /// isOpenCL - Language is a OpenCL variant. isOpenCLLangStandard151 bool isOpenCL() const { return Flags & OpenCL; } 152 153 static Kind getLangKind(StringRef Name); 154 static Kind getHLSLLangKind(StringRef Name); 155 static const LangStandard &getLangStandardForKind(Kind K); 156 static const LangStandard *getLangStandardForName(StringRef Name); 157 }; 158 159 LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang, 160 const llvm::Triple &T); 161 162 } // end namespace clang 163 164 #endif 165