Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:50

0001 //===--- LangStandard.h -----------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_BASIC_LANGSTANDARD_H
0010 #define LLVM_CLANG_BASIC_LANGSTANDARD_H
0011 
0012 #include "clang/Basic/LLVM.h"
0013 #include "llvm/ADT/StringRef.h"
0014 
0015 namespace llvm {
0016 class Triple;
0017 }
0018 
0019 namespace clang {
0020 
0021 /// The language for the input, used to select and validate the language
0022 /// standard and possible actions.
0023 enum class Language : uint8_t {
0024   Unknown,
0025 
0026   /// Assembly: we accept this only so that we can preprocess it.
0027   Asm,
0028 
0029   /// LLVM IR & CIR: we accept these so that we can run the optimizer on them,
0030   /// and compile them to assembly or object code (or LLVM for CIR).
0031   CIR,
0032   LLVM_IR,
0033 
0034   ///@{ Languages that the frontend can parse and compile.
0035   C,
0036   CXX,
0037   ObjC,
0038   ObjCXX,
0039   OpenCL,
0040   OpenCLCXX,
0041   CUDA,
0042   HIP,
0043   HLSL,
0044   ///@}
0045 };
0046 StringRef languageToString(Language L);
0047 
0048 enum LangFeatures {
0049   LineComment = (1 << 0),
0050   C99 = (1 << 1),
0051   C11 = (1 << 2),
0052   C17 = (1 << 3),
0053   C23 = (1 << 4),
0054   C2y = (1 << 5),
0055   CPlusPlus = (1 << 6),
0056   CPlusPlus11 = (1 << 7),
0057   CPlusPlus14 = (1 << 8),
0058   CPlusPlus17 = (1 << 9),
0059   CPlusPlus20 = (1 << 10),
0060   CPlusPlus23 = (1 << 11),
0061   CPlusPlus26 = (1 << 12),
0062   Digraphs = (1 << 13),
0063   GNUMode = (1 << 14),
0064   HexFloat = (1 << 15),
0065   OpenCL = (1 << 16),
0066   HLSL = (1 << 17)
0067 };
0068 
0069 /// LangStandard - Information about the properties of a particular language
0070 /// standard.
0071 struct LangStandard {
0072   enum Kind {
0073 #define LANGSTANDARD(id, name, lang, desc, features) \
0074     lang_##id,
0075 #include "clang/Basic/LangStandards.def"
0076     lang_unspecified
0077   };
0078 
0079   const char *ShortName;
0080   const char *Description;
0081   unsigned Flags;
0082   clang::Language Language;
0083 
0084 public:
0085   /// getName - Get the name of this standard.
0086   const char *getName() const { return ShortName; }
0087 
0088   /// getDescription - Get the description of this standard.
0089   const char *getDescription() const { return Description; }
0090 
0091   /// Get the language that this standard describes.
0092   clang::Language getLanguage() const { return Language; }
0093 
0094   /// Language supports '//' comments.
0095   bool hasLineComments() const { return Flags & LineComment; }
0096 
0097   /// isC99 - Language is a superset of C99.
0098   bool isC99() const { return Flags & C99; }
0099 
0100   /// isC11 - Language is a superset of C11.
0101   bool isC11() const { return Flags & C11; }
0102 
0103   /// isC17 - Language is a superset of C17.
0104   bool isC17() const { return Flags & C17; }
0105 
0106   /// isC23 - Language is a superset of C23.
0107   bool isC23() const { return Flags & C23; }
0108 
0109   /// isC2y - Language is a superset of C2y.
0110   bool isC2y() const { return Flags & C2y; }
0111 
0112   /// isCPlusPlus - Language is a C++ variant.
0113   bool isCPlusPlus() const { return Flags & CPlusPlus; }
0114 
0115   /// isCPlusPlus11 - Language is a C++11 variant (or later).
0116   bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
0117 
0118   /// isCPlusPlus14 - Language is a C++14 variant (or later).
0119   bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
0120 
0121   /// isCPlusPlus17 - Language is a C++17 variant (or later).
0122   bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
0123 
0124   /// isCPlusPlus20 - Language is a C++20 variant (or later).
0125   bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
0126 
0127   /// isCPlusPlus23 - Language is a post-C++23 variant (or later).
0128   bool isCPlusPlus23() const { return Flags & CPlusPlus23; }
0129 
0130   /// isCPlusPlus26 - Language is a post-C++26 variant (or later).
0131   bool isCPlusPlus26() const { return Flags & CPlusPlus26; }
0132 
0133   /// hasDigraphs - Language supports digraphs.
0134   bool hasDigraphs() const { return Flags & Digraphs; }
0135 
0136   /// hasRawStringLiterals - Language supports R"()" raw string literals.
0137   bool hasRawStringLiterals() const {
0138     // GCC supports raw string literals in C99 and later, but not in C++
0139     // before C++11.
0140     return isCPlusPlus11() || (!isCPlusPlus() && isC99() && isGNUMode());
0141   }
0142 
0143   /// isGNUMode - Language includes GNU extensions.
0144   bool isGNUMode() const { return Flags & GNUMode; }
0145 
0146   /// hasHexFloats - Language supports hexadecimal float constants.
0147   bool hasHexFloats() const { return Flags & HexFloat; }
0148 
0149   /// isOpenCL - Language is a OpenCL variant.
0150   bool isOpenCL() const { return Flags & OpenCL; }
0151 
0152   static Kind getLangKind(StringRef Name);
0153   static Kind getHLSLLangKind(StringRef Name);
0154   static const LangStandard &getLangStandardForKind(Kind K);
0155   static const LangStandard *getLangStandardForName(StringRef Name);
0156 };
0157 
0158 LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang,
0159                                               const llvm::Triple &T);
0160 
0161 }  // end namespace clang
0162 
0163 #endif