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: we accept this so that we can run the optimizer on it, 30 /// and compile it to assembly or object code. 31 LLVM_IR, 32 33 ///@{ Languages that the frontend can parse and compile. 34 C, 35 CXX, 36 ObjC, 37 ObjCXX, 38 OpenCL, 39 OpenCLCXX, 40 CUDA, 41 RenderScript, 42 HIP, 43 HLSL, 44 ///@} 45 }; 46 47 enum LangFeatures { 48 LineComment = (1 << 0), 49 C99 = (1 << 1), 50 C11 = (1 << 2), 51 C17 = (1 << 3), 52 C2x = (1 << 4), 53 CPlusPlus = (1 << 5), 54 CPlusPlus11 = (1 << 6), 55 CPlusPlus14 = (1 << 7), 56 CPlusPlus17 = (1 << 8), 57 CPlusPlus20 = (1 << 9), 58 CPlusPlus23 = (1 << 10), 59 CPlusPlus26 = (1 << 11), 60 Digraphs = (1 << 12), 61 GNUMode = (1 << 13), 62 HexFloat = (1 << 14), 63 OpenCL = (1 << 15), 64 HLSL = (1 << 16) 65 }; 66 67 /// LangStandard - Information about the properties of a particular language 68 /// standard. 69 struct LangStandard { 70 enum Kind { 71 #define LANGSTANDARD(id, name, lang, desc, features) \ 72 lang_##id, 73 #include "clang/Basic/LangStandards.def" 74 lang_unspecified 75 }; 76 77 const char *ShortName; 78 const char *Description; 79 unsigned Flags; 80 clang::Language Language; 81 82 public: 83 /// getName - Get the name of this standard. 84 const char *getName() const { return ShortName; } 85 86 /// getDescription - Get the description of this standard. 87 const char *getDescription() const { return Description; } 88 89 /// Get the language that this standard describes. 90 clang::Language getLanguage() const { return Language; } 91 92 /// Language supports '//' comments. 93 bool hasLineComments() const { return Flags & LineComment; } 94 95 /// isC99 - Language is a superset of C99. 96 bool isC99() const { return Flags & C99; } 97 98 /// isC11 - Language is a superset of C11. 99 bool isC11() const { return Flags & C11; } 100 101 /// isC17 - Language is a superset of C17. 102 bool isC17() const { return Flags & C17; } 103 104 /// isC2x - Language is a superset of C2x. 105 bool isC2x() const { return Flags & C2x; } 106 107 /// isCPlusPlus - Language is a C++ variant. 108 bool isCPlusPlus() const { return Flags & CPlusPlus; } 109 110 /// isCPlusPlus11 - Language is a C++11 variant (or later). 111 bool isCPlusPlus11() const { return Flags & CPlusPlus11; } 112 113 /// isCPlusPlus14 - Language is a C++14 variant (or later). 114 bool isCPlusPlus14() const { return Flags & CPlusPlus14; } 115 116 /// isCPlusPlus17 - Language is a C++17 variant (or later). 117 bool isCPlusPlus17() const { return Flags & CPlusPlus17; } 118 119 /// isCPlusPlus20 - Language is a C++20 variant (or later). 120 bool isCPlusPlus20() const { return Flags & CPlusPlus20; } 121 122 /// isCPlusPlus23 - Language is a post-C++23 variant (or later). 123 bool isCPlusPlus23() const { return Flags & CPlusPlus23; } 124 125 /// isCPlusPlus26 - Language is a post-C++26 variant (or later). 126 bool isCPlusPlus26() const { return Flags & CPlusPlus26; } 127 128 /// hasDigraphs - Language supports digraphs. 129 bool hasDigraphs() const { return Flags & Digraphs; } 130 131 /// isGNUMode - Language includes GNU extensions. 132 bool isGNUMode() const { return Flags & GNUMode; } 133 134 /// hasHexFloats - Language supports hexadecimal float constants. 135 bool hasHexFloats() const { return Flags & HexFloat; } 136 137 /// isOpenCL - Language is a OpenCL variant. 138 bool isOpenCL() const { return Flags & OpenCL; } 139 140 static Kind getLangKind(StringRef Name); 141 static const LangStandard &getLangStandardForKind(Kind K); 142 static const LangStandard *getLangStandardForName(StringRef Name); 143 }; 144 145 LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang, 146 const llvm::Triple &T); 147 148 } // end namespace clang 149 150 #endif 151