clang API Documentation

LangOptions.h
Go to the documentation of this file.
00001 //===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Defines the clang::LangOptions interface.
00012 ///
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
00016 #define LLVM_CLANG_BASIC_LANGOPTIONS_H
00017 
00018 #include "clang/Basic/CommentOptions.h"
00019 #include "clang/Basic/LLVM.h"
00020 #include "clang/Basic/ObjCRuntime.h"
00021 #include "clang/Basic/Sanitizers.h"
00022 #include "clang/Basic/Visibility.h"
00023 #include <string>
00024 
00025 namespace clang {
00026 
00027 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
00028 /// this large collection of bitfields is a trivial class type.
00029 class LangOptionsBase {
00030 public:
00031   // Define simple language options (with no accessors).
00032 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
00033 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
00034 #include "clang/Basic/LangOptions.def"
00035 
00036 protected:
00037   // Define language options of enumeration type. These are private, and will
00038   // have accessors (below).
00039 #define LANGOPT(Name, Bits, Default, Description)
00040 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
00041   unsigned Name : Bits;
00042 #include "clang/Basic/LangOptions.def"
00043 };
00044 
00045 /// \brief Keeps track of the various options that can be
00046 /// enabled, which controls the dialect of C or C++ that is accepted.
00047 class LangOptions : public LangOptionsBase {
00048 public:
00049   typedef clang::Visibility Visibility;
00050   
00051   enum GCMode { NonGC, GCOnly, HybridGC };
00052   enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
00053   
00054   enum SignedOverflowBehaviorTy {
00055     SOB_Undefined,  // Default C standard behavior.
00056     SOB_Defined,    // -fwrapv
00057     SOB_Trapping    // -ftrapv
00058   };
00059 
00060   enum PragmaMSPointersToMembersKind {
00061     PPTMK_BestCase,
00062     PPTMK_FullGeneralitySingleInheritance,
00063     PPTMK_FullGeneralityMultipleInheritance,
00064     PPTMK_FullGeneralityVirtualInheritance
00065   };
00066 
00067   enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
00068 
00069 public:
00070   /// \brief Set of enabled sanitizers.
00071   SanitizerSet Sanitize;
00072 
00073   /// \brief Path to blacklist file specifying which objects
00074   /// (files, functions, variables) should not be instrumented.
00075   std::string SanitizerBlacklistFile;
00076 
00077   clang::ObjCRuntime ObjCRuntime;
00078 
00079   std::string ObjCConstantStringClass;
00080   
00081   /// \brief The name of the handler function to be called when -ftrapv is
00082   /// specified.
00083   ///
00084   /// If none is specified, abort (GCC-compatible behaviour).
00085   std::string OverflowHandler;
00086 
00087   /// \brief The name of the current module.
00088   std::string CurrentModule;
00089 
00090   /// \brief The name of the module that the translation unit is an
00091   /// implementation of. Prevents semantic imports, but does not otherwise
00092   /// treat this as the CurrentModule.
00093   std::string ImplementationOfModule;
00094 
00095   /// \brief Options for parsing comments.
00096   CommentOptions CommentOpts;
00097   
00098   LangOptions();
00099 
00100   // Define accessors/mutators for language options of enumeration type.
00101 #define LANGOPT(Name, Bits, Default, Description) 
00102 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
00103   Type get##Name() const { return static_cast<Type>(Name); } \
00104   void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }  
00105 #include "clang/Basic/LangOptions.def"
00106   
00107   bool isSignedOverflowDefined() const {
00108     return getSignedOverflowBehavior() == SOB_Defined;
00109   }
00110   
00111   bool isSubscriptPointerArithmetic() const {
00112     return ObjCRuntime.isSubscriptPointerArithmetic() &&
00113            !ObjCSubscriptingLegacyRuntime;
00114   }
00115 
00116   /// \brief Reset all of the options that are not considered when building a
00117   /// module.
00118   void resetNonModularOptions();
00119 };
00120 
00121 /// \brief Floating point control options
00122 class FPOptions {
00123 public:
00124   unsigned fp_contract : 1;
00125 
00126   FPOptions() : fp_contract(0) {}
00127 
00128   FPOptions(const LangOptions &LangOpts) :
00129     fp_contract(LangOpts.DefaultFPContract) {}
00130 };
00131 
00132 /// \brief OpenCL volatile options
00133 class OpenCLOptions {
00134 public:
00135 #define OPENCLEXT(nm)  unsigned nm : 1;
00136 #include "clang/Basic/OpenCLExtensions.def"
00137 
00138   OpenCLOptions() {
00139 #define OPENCLEXT(nm)   nm = 0;
00140 #include "clang/Basic/OpenCLExtensions.def"
00141   }
00142 };
00143 
00144 /// \brief Describes the kind of translation unit being processed.
00145 enum TranslationUnitKind {
00146   /// \brief The translation unit is a complete translation unit.
00147   TU_Complete,
00148   /// \brief The translation unit is a prefix to a translation unit, and is
00149   /// not complete.
00150   TU_Prefix,
00151   /// \brief The translation unit is a module.
00152   TU_Module
00153 };
00154   
00155 }  // end namespace clang
00156 
00157 #endif