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 clang { 16 17 /// The language for the input, used to select and validate the language 18 /// standard and possible actions. 19 enum class Language : uint8_t { 20 Unknown, 21 22 /// Assembly: we accept this only so that we can preprocess it. 23 Asm, 24 25 /// LLVM IR: we accept this so that we can run the optimizer on it, 26 /// and compile it to assembly or object code. 27 LLVM_IR, 28 29 ///@{ Languages that the frontend can parse and compile. 30 C, 31 CXX, 32 ObjC, 33 ObjCXX, 34 OpenCL, 35 CUDA, 36 RenderScript, 37 HIP, 38 ///@} 39 }; 40 41 enum LangFeatures { 42 LineComment = (1 << 0), 43 C99 = (1 << 1), 44 C11 = (1 << 2), 45 C17 = (1 << 3), 46 C2x = (1 << 4), 47 CPlusPlus = (1 << 5), 48 CPlusPlus11 = (1 << 6), 49 CPlusPlus14 = (1 << 7), 50 CPlusPlus17 = (1 << 8), 51 CPlusPlus20 = (1 << 9), 52 CPlusPlus2b = (1 << 10), 53 Digraphs = (1 << 11), 54 GNUMode = (1 << 12), 55 HexFloat = (1 << 13), 56 ImplicitInt = (1 << 14), 57 OpenCL = (1 << 15) 58 }; 59 60 /// LangStandard - Information about the properties of a particular language 61 /// standard. 62 struct LangStandard { 63 enum Kind { 64 #define LANGSTANDARD(id, name, lang, desc, features) \ 65 lang_##id, 66 #include "clang/Basic/LangStandards.def" 67 lang_unspecified 68 }; 69 70 const char *ShortName; 71 const char *Description; 72 unsigned Flags; 73 clang::Language Language; 74 75 public: 76 /// getName - Get the name of this standard. getNameLangStandard77 const char *getName() const { return ShortName; } 78 79 /// getDescription - Get the description of this standard. getDescriptionLangStandard80 const char *getDescription() const { return Description; } 81 82 /// Get the language that this standard describes. getLanguageLangStandard83 clang::Language getLanguage() const { return Language; } 84 85 /// Language supports '//' comments. hasLineCommentsLangStandard86 bool hasLineComments() const { return Flags & LineComment; } 87 88 /// isC99 - Language is a superset of C99. isC99LangStandard89 bool isC99() const { return Flags & C99; } 90 91 /// isC11 - Language is a superset of C11. isC11LangStandard92 bool isC11() const { return Flags & C11; } 93 94 /// isC17 - Language is a superset of C17. isC17LangStandard95 bool isC17() const { return Flags & C17; } 96 97 /// isC2x - Language is a superset of C2x. isC2xLangStandard98 bool isC2x() const { return Flags & C2x; } 99 100 /// isCPlusPlus - Language is a C++ variant. isCPlusPlusLangStandard101 bool isCPlusPlus() const { return Flags & CPlusPlus; } 102 103 /// isCPlusPlus11 - Language is a C++11 variant (or later). isCPlusPlus11LangStandard104 bool isCPlusPlus11() const { return Flags & CPlusPlus11; } 105 106 /// isCPlusPlus14 - Language is a C++14 variant (or later). isCPlusPlus14LangStandard107 bool isCPlusPlus14() const { return Flags & CPlusPlus14; } 108 109 /// isCPlusPlus17 - Language is a C++17 variant (or later). isCPlusPlus17LangStandard110 bool isCPlusPlus17() const { return Flags & CPlusPlus17; } 111 112 /// isCPlusPlus20 - Language is a C++20 variant (or later). isCPlusPlus20LangStandard113 bool isCPlusPlus20() const { return Flags & CPlusPlus20; } 114 115 /// isCPlusPlus2b - Language is a post-C++20 variant (or later). isCPlusPlus2bLangStandard116 bool isCPlusPlus2b() const { return Flags & CPlusPlus2b; } 117 118 /// hasDigraphs - Language supports digraphs. hasDigraphsLangStandard119 bool hasDigraphs() const { return Flags & Digraphs; } 120 121 /// isGNUMode - Language includes GNU extensions. isGNUModeLangStandard122 bool isGNUMode() const { return Flags & GNUMode; } 123 124 /// hasHexFloats - Language supports hexadecimal float constants. hasHexFloatsLangStandard125 bool hasHexFloats() const { return Flags & HexFloat; } 126 127 /// hasImplicitInt - Language allows variables to be typed as int implicitly. hasImplicitIntLangStandard128 bool hasImplicitInt() const { return Flags & ImplicitInt; } 129 130 /// isOpenCL - Language is a OpenCL variant. isOpenCLLangStandard131 bool isOpenCL() const { return Flags & OpenCL; } 132 133 static Kind getLangKind(StringRef Name); 134 static const LangStandard &getLangStandardForKind(Kind K); 135 static const LangStandard *getLangStandardForName(StringRef Name); 136 }; 137 138 } // end namespace clang 139 140 #endif 141