Home | History | Annotate | Line # | Download | only in Basic
      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   OpenCLCXX,
     36   CUDA,
     37   RenderScript,
     38   HIP,
     39   ///@}
     40 };
     41 
     42 enum LangFeatures {
     43   LineComment = (1 << 0),
     44   C99 = (1 << 1),
     45   C11 = (1 << 2),
     46   C17 = (1 << 3),
     47   C2x = (1 << 4),
     48   CPlusPlus = (1 << 5),
     49   CPlusPlus11 = (1 << 6),
     50   CPlusPlus14 = (1 << 7),
     51   CPlusPlus17 = (1 << 8),
     52   CPlusPlus20 = (1 << 9),
     53   CPlusPlus2b = (1 << 10),
     54   Digraphs = (1 << 11),
     55   GNUMode = (1 << 12),
     56   HexFloat = (1 << 13),
     57   ImplicitInt = (1 << 14),
     58   OpenCL = (1 << 15)
     59 };
     60 
     61 /// LangStandard - Information about the properties of a particular language
     62 /// standard.
     63 struct LangStandard {
     64   enum Kind {
     65 #define LANGSTANDARD(id, name, lang, desc, features) \
     66     lang_##id,
     67 #include "clang/Basic/LangStandards.def"
     68     lang_unspecified
     69   };
     70 
     71   const char *ShortName;
     72   const char *Description;
     73   unsigned Flags;
     74   clang::Language Language;
     75 
     76 public:
     77   /// getName - Get the name of this standard.
     78   const char *getName() const { return ShortName; }
     79 
     80   /// getDescription - Get the description of this standard.
     81   const char *getDescription() const { return Description; }
     82 
     83   /// Get the language that this standard describes.
     84   clang::Language getLanguage() const { return Language; }
     85 
     86   /// Language supports '//' comments.
     87   bool hasLineComments() const { return Flags & LineComment; }
     88 
     89   /// isC99 - Language is a superset of C99.
     90   bool isC99() const { return Flags & C99; }
     91 
     92   /// isC11 - Language is a superset of C11.
     93   bool isC11() const { return Flags & C11; }
     94 
     95   /// isC17 - Language is a superset of C17.
     96   bool isC17() const { return Flags & C17; }
     97 
     98   /// isC2x - Language is a superset of C2x.
     99   bool isC2x() const { return Flags & C2x; }
    100 
    101   /// isCPlusPlus - Language is a C++ variant.
    102   bool isCPlusPlus() const { return Flags & CPlusPlus; }
    103 
    104   /// isCPlusPlus11 - Language is a C++11 variant (or later).
    105   bool isCPlusPlus11() const { return Flags & CPlusPlus11; }
    106 
    107   /// isCPlusPlus14 - Language is a C++14 variant (or later).
    108   bool isCPlusPlus14() const { return Flags & CPlusPlus14; }
    109 
    110   /// isCPlusPlus17 - Language is a C++17 variant (or later).
    111   bool isCPlusPlus17() const { return Flags & CPlusPlus17; }
    112 
    113   /// isCPlusPlus20 - Language is a C++20 variant (or later).
    114   bool isCPlusPlus20() const { return Flags & CPlusPlus20; }
    115 
    116   /// isCPlusPlus2b - Language is a post-C++20 variant (or later).
    117   bool isCPlusPlus2b() const { return Flags & CPlusPlus2b; }
    118 
    119   /// hasDigraphs - Language supports digraphs.
    120   bool hasDigraphs() const { return Flags & Digraphs; }
    121 
    122   /// isGNUMode - Language includes GNU extensions.
    123   bool isGNUMode() const { return Flags & GNUMode; }
    124 
    125   /// hasHexFloats - Language supports hexadecimal float constants.
    126   bool hasHexFloats() const { return Flags & HexFloat; }
    127 
    128   /// hasImplicitInt - Language allows variables to be typed as int implicitly.
    129   bool hasImplicitInt() const { return Flags & ImplicitInt; }
    130 
    131   /// isOpenCL - Language is a OpenCL variant.
    132   bool isOpenCL() const { return Flags & OpenCL; }
    133 
    134   static Kind getLangKind(StringRef Name);
    135   static const LangStandard &getLangStandardForKind(Kind K);
    136   static const LangStandard *getLangStandardForName(StringRef Name);
    137 };
    138 
    139 }  // end namespace clang
    140 
    141 #endif
    142