Home | History | Annotate | Download | only in Basic
      1 //===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 ///
     10 /// \file
     11 /// \brief Defines the clang::LangOptions interface.
     12 ///
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CLANG_LANGOPTIONS_H
     16 #define LLVM_CLANG_LANGOPTIONS_H
     17 
     18 #include "clang/Basic/CommentOptions.h"
     19 #include "clang/Basic/LLVM.h"
     20 #include "clang/Basic/ObjCRuntime.h"
     21 #include "clang/Basic/Visibility.h"
     22 #include <string>
     23 
     24 namespace clang {
     25 
     26 struct SanitizerOptions {
     27 #define SANITIZER(NAME, ID) unsigned ID : 1;
     28 #include "clang/Basic/Sanitizers.def"
     29 
     30   /// \brief Cached set of sanitizer options with all sanitizers disabled.
     31   static const SanitizerOptions Disabled;
     32 };
     33 
     34 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
     35 /// this large collection of bitfields is a trivial class type.
     36 class LangOptionsBase {
     37 public:
     38   // Define simple language options (with no accessors).
     39 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
     40 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
     41 #include "clang/Basic/LangOptions.def"
     42 
     43   SanitizerOptions Sanitize;
     44 protected:
     45   // Define language options of enumeration type. These are private, and will
     46   // have accessors (below).
     47 #define LANGOPT(Name, Bits, Default, Description)
     48 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
     49   unsigned Name : Bits;
     50 #include "clang/Basic/LangOptions.def"
     51 };
     52 
     53 /// \brief Keeps track of the various options that can be
     54 /// enabled, which controls the dialect of C or C++ that is accepted.
     55 class LangOptions : public LangOptionsBase {
     56 public:
     57   typedef clang::Visibility Visibility;
     58 
     59   enum GCMode { NonGC, GCOnly, HybridGC };
     60   enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
     61 
     62   enum SignedOverflowBehaviorTy {
     63     SOB_Undefined,  // Default C standard behavior.
     64     SOB_Defined,    // -fwrapv
     65     SOB_Trapping    // -ftrapv
     66   };
     67 
     68   enum PragmaMSPointersToMembersKind {
     69     PPTMK_BestCase,
     70     PPTMK_FullGeneralitySingleInheritance,
     71     PPTMK_FullGeneralityMultipleInheritance,
     72     PPTMK_FullGeneralityVirtualInheritance
     73   };
     74 
     75   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
     76 
     77 public:
     78   clang::ObjCRuntime ObjCRuntime;
     79 
     80   std::string ObjCConstantStringClass;
     81 
     82   /// \brief The name of the handler function to be called when -ftrapv is
     83   /// specified.
     84   ///
     85   /// If none is specified, abort (GCC-compatible behaviour).
     86   std::string OverflowHandler;
     87 
     88   /// \brief The name of the current module.
     89   std::string CurrentModule;
     90 
     91   /// \brief Options for parsing comments.
     92   CommentOptions CommentOpts;
     93 
     94   LangOptions();
     95 
     96   // Define accessors/mutators for language options of enumeration type.
     97 #define LANGOPT(Name, Bits, Default, Description)
     98 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
     99   Type get##Name() const { return static_cast<Type>(Name); } \
    100   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
    101 #include "clang/Basic/LangOptions.def"
    102 
    103   bool isSignedOverflowDefined() const {
    104     return getSignedOverflowBehavior() == SOB_Defined;
    105   }
    106 
    107   bool isSubscriptPointerArithmetic() const {
    108     return ObjCRuntime.isSubscriptPointerArithmetic() &&
    109            !ObjCSubscriptingLegacyRuntime;
    110   }
    111 
    112   /// \brief Reset all of the options that are not considered when building a
    113   /// module.
    114   void resetNonModularOptions();
    115 };
    116 
    117 /// \brief Floating point control options
    118 class FPOptions {
    119 public:
    120   unsigned fp_contract : 1;
    121 
    122   FPOptions() : fp_contract(0) {}
    123 
    124   FPOptions(const LangOptions &LangOpts) :
    125     fp_contract(LangOpts.DefaultFPContract) {}
    126 };
    127 
    128 /// \brief OpenCL volatile options
    129 class OpenCLOptions {
    130 public:
    131 #define OPENCLEXT(nm)  unsigned nm : 1;
    132 #include "clang/Basic/OpenCLExtensions.def"
    133 
    134   OpenCLOptions() {
    135 #define OPENCLEXT(nm)   nm = 0;
    136 #include "clang/Basic/OpenCLExtensions.def"
    137   }
    138 };
    139 
    140 /// \brief Describes the kind of translation unit being processed.
    141 enum TranslationUnitKind {
    142   /// \brief The translation unit is a complete translation unit.
    143   TU_Complete,
    144   /// \brief The translation unit is a prefix to a translation unit, and is
    145   /// not complete.
    146   TU_Prefix,
    147   /// \brief The translation unit is a module.
    148   TU_Module
    149 };
    150 
    151 }  // end namespace clang
    152 
    153 #endif
    154