blob: 9bffc7cb18cf49e8179bff064c75c1d2aa34cbfa [file] [log] [blame]
//===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
// The LLVM Compiler Infrastructure
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
/// \file
/// \brief Defines the clang::LangOptions interface.
#include "clang/Basic/CommentOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Visibility.h"
#include <string>
namespace clang {
struct SanitizerOptions {
#define SANITIZER(NAME, ID) unsigned ID : 1;
#include "clang/Basic/Sanitizers.def"
/// \brief Cached set of sanitizer options with all sanitizers disabled.
static const SanitizerOptions Disabled;
/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
/// this large collection of bitfields is a trivial class type.
class LangOptionsBase {
// Define simple language options (with no accessors).
#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
#include "clang/Basic/LangOptions.def"
SanitizerOptions Sanitize;
// Define language options of enumeration type. These are private, and will
// have accessors (below).
#define LANGOPT(Name, Bits, Default, Description)
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
unsigned Name : Bits;
#include "clang/Basic/LangOptions.def"
/// \brief Keeps track of the various options that can be
/// enabled, which controls the dialect of C or C++ that is accepted.
class LangOptions : public LangOptionsBase {
typedef clang::Visibility Visibility;
enum GCMode { NonGC, GCOnly, HybridGC };
enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
enum SignedOverflowBehaviorTy {
SOB_Undefined, // Default C standard behavior.
SOB_Defined, // -fwrapv
SOB_Trapping // -ftrapv
enum PragmaMSPointersToMembersKind {
enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
clang::ObjCRuntime ObjCRuntime;
std::string ObjCConstantStringClass;
/// \brief The name of the handler function to be called when -ftrapv is
/// specified.
/// If none is specified, abort (GCC-compatible behaviour).
std::string OverflowHandler;
/// \brief The name of the current module.
std::string CurrentModule;
/// \brief Options for parsing comments.
CommentOptions CommentOpts;
// Define accessors/mutators for language options of enumeration type.
#define LANGOPT(Name, Bits, Default, Description)
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
Type get##Name() const { return static_cast<Type>(Name); } \
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
#include "clang/Basic/LangOptions.def"
bool isSignedOverflowDefined() const {
return getSignedOverflowBehavior() == SOB_Defined;
bool isSubscriptPointerArithmetic() const {
return ObjCRuntime.isSubscriptPointerArithmetic() &&
/// \brief Reset all of the options that are not considered when building a
/// module.
void resetNonModularOptions();
/// \brief Floating point control options
class FPOptions {
unsigned fp_contract : 1;
FPOptions() : fp_contract(0) {}
FPOptions(const LangOptions &LangOpts) :
fp_contract(LangOpts.DefaultFPContract) {}
/// \brief OpenCL volatile options
class OpenCLOptions {
#define OPENCLEXT(nm) unsigned nm : 1;
#include "clang/Basic/OpenCLExtensions.def"
OpenCLOptions() {
#define OPENCLEXT(nm) nm = 0;
#include "clang/Basic/OpenCLExtensions.def"
/// \brief Describes the kind of translation unit being processed.
enum TranslationUnitKind {
/// \brief The translation unit is a complete translation unit.
/// \brief The translation unit is a prefix to a translation unit, and is
/// not complete.
/// \brief The translation unit is a module.
} // end namespace clang