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_BASIC_LANGOPTIONS_H 16#define LLVM_CLANG_BASIC_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/Sanitizers.h" 22#include "clang/Basic/Visibility.h" 23#include <string> 24#include <vector> 25 26namespace clang { 27 28/// Bitfields of LangOptions, split out from LangOptions in order to ensure that 29/// this large collection of bitfields is a trivial class type. 30class LangOptionsBase { 31public: 32 // Define simple language options (with no accessors). 33#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits; 34#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) 35#include "clang/Basic/LangOptions.def" 36 37protected: 38 // Define language options of enumeration type. These are private, and will 39 // have accessors (below). 40#define LANGOPT(Name, Bits, Default, Description) 41#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ 42 unsigned Name : Bits; 43#include "clang/Basic/LangOptions.def" 44}; 45 46/// \brief Keeps track of the various options that can be 47/// enabled, which controls the dialect of C or C++ that is accepted. 48class LangOptions : public LangOptionsBase { 49public: 50 typedef clang::Visibility Visibility; 51 52 enum GCMode { NonGC, GCOnly, HybridGC }; 53 enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq }; 54 55 enum SignedOverflowBehaviorTy { 56 SOB_Undefined, // Default C standard behavior. 57 SOB_Defined, // -fwrapv 58 SOB_Trapping // -ftrapv 59 }; 60 61 enum PragmaMSPointersToMembersKind { 62 PPTMK_BestCase, 63 PPTMK_FullGeneralitySingleInheritance, 64 PPTMK_FullGeneralityMultipleInheritance, 65 PPTMK_FullGeneralityVirtualInheritance 66 }; 67 68 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off }; 69 70public: 71 /// \brief Set of enabled sanitizers. 72 SanitizerSet Sanitize; 73 74 /// \brief Paths to blacklist files specifying which objects 75 /// (files, functions, variables) should not be instrumented. 76 std::vector<std::string> SanitizerBlacklistFiles; 77 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 The name of the module that the translation unit is an 92 /// implementation of. Prevents semantic imports, but does not otherwise 93 /// treat this as the CurrentModule. 94 std::string ImplementationOfModule; 95 96 /// \brief The names of any features to enable in module 'requires' decls 97 /// in addition to the hard-coded list in Module.cpp and the target features. 98 std::vector<std::string> ModuleFeatures; 99 100 /// \brief Options for parsing comments. 101 CommentOptions CommentOpts; 102 103 LangOptions(); 104 105 // Define accessors/mutators for language options of enumeration type. 106#define LANGOPT(Name, Bits, Default, Description) 107#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ 108 Type get##Name() const { return static_cast<Type>(Name); } \ 109 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } 110#include "clang/Basic/LangOptions.def" 111 112 bool isSignedOverflowDefined() const { 113 return getSignedOverflowBehavior() == SOB_Defined; 114 } 115 116 bool isSubscriptPointerArithmetic() const { 117 return ObjCRuntime.isSubscriptPointerArithmetic() && 118 !ObjCSubscriptingLegacyRuntime; 119 } 120 121 bool isCompatibleWithMSVC(unsigned MajorVersion) const { 122 return MSCompatibilityVersion >= MajorVersion * 10000000U; 123 } 124 125 /// \brief Reset all of the options that are not considered when building a 126 /// module. 127 void resetNonModularOptions(); 128}; 129 130/// \brief Floating point control options 131class FPOptions { 132public: 133 unsigned fp_contract : 1; 134 135 FPOptions() : fp_contract(0) {} 136 137 FPOptions(const LangOptions &LangOpts) : 138 fp_contract(LangOpts.DefaultFPContract) {} 139}; 140 141/// \brief OpenCL volatile options 142class OpenCLOptions { 143public: 144#define OPENCLEXT(nm) unsigned nm : 1; 145#include "clang/Basic/OpenCLExtensions.def" 146 147 OpenCLOptions() { 148#define OPENCLEXT(nm) nm = 0; 149#include "clang/Basic/OpenCLExtensions.def" 150 } 151}; 152 153/// \brief Describes the kind of translation unit being processed. 154enum TranslationUnitKind { 155 /// \brief The translation unit is a complete translation unit. 156 TU_Complete, 157 /// \brief The translation unit is a prefix to a translation unit, and is 158 /// not complete. 159 TU_Prefix, 160 /// \brief The translation unit is a module. 161 TU_Module 162}; 163 164} // end namespace clang 165 166#endif 167