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