Spicy
context.h
1 // Copyright (c) 2020-now by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <map>
6 #include <memory>
7 #include <string>
8 #include <tuple>
9 #include <unordered_map>
10 #include <utility>
11 #include <vector>
12 
13 #include <hilti/rt/any.h>
14 #include <hilti/rt/filesystem.h>
15 
16 #include <hilti/ast/id.h>
17 #include <hilti/autogen/config.h>
18 #include <hilti/base/logger.h>
19 #include <hilti/base/result.h>
20 #include <hilti/base/util.h>
21 
22 namespace hilti {
23 
24 class PluginRegistry;
25 class Unit;
26 
33 struct Options {
34  bool debug = false;
35  bool debug_trace =
36  false;
37  bool debug_flow = false;
39  bool track_location = true;
40  bool skip_validation = false;
42  bool enable_profiling = false;
43  std::vector<hilti::rt::filesystem::path> library_paths;
44  std::string cxx_namespace_extern =
45  "hlt";
46  // NOTE: This should be consistent with identifiers generated with `HILTI_INTERNAL_GLOBAL_ID`.
47  std::string cxx_namespace_intern = HILTI_INTERNAL_NS_ID;
48  std::vector<hilti::rt::filesystem::path>
50  bool keep_tmps = false;
51  std::vector<std::string> cxx_link;
53  false;
54  bool global_optimizations = true;
59  enum class PublicAPIMode {
60  Strict,
61  NonStrict,
63  Default,
65  };
66 
67  PublicAPIMode public_api_mode = PublicAPIMode::Default;
68 
79  template<typename T>
80  T getAuxOption(const std::string& key, T default_) const {
81  auto i = _aux_options.find(key);
82  if ( i != _aux_options.end() )
83  return hilti::rt::any_cast<T>(i->second);
84  else
85  return default_;
86  }
87 
96  template<typename T>
97  void setAuxOption(const std::string& key, T value) {
98  _aux_options[key] = value;
99  }
100 
108  Result<Nothing> parseDebugAddl(const std::string& flags);
109 
111  void print(std::ostream& out) const;
112 
113 private:
114  std::map<std::string, hilti::rt::any> _aux_options;
115 };
116 
117 namespace context {} // namespace context
118 
120 class Context {
121 public:
125  explicit Context(Options options);
126 
128  ~Context();
129 
131  const Options& options() const { return _options; }
132 
134  auto* astContext() const { return _ast_context.get(); }
135 
136 private:
137  Options _options;
138  std::unique_ptr<ASTContext> _ast_context;
139 };
140 
141 } // namespace hilti
Definition: context.h:120
~Context()
Definition: context.cc:65
auto * astContext() const
Definition: context.h:134
const Options & options() const
Definition: context.h:131
Context(Options options)
Definition: context.cc:62
Definition: result.h:73
Definition: context.h:33
bool import_standard_modules
Definition: context.h:55
bool skip_validation
Definition: context.h:40
std::string cxx_namespace_extern
Definition: context.h:44
bool track_location
Definition: context.h:39
bool debug_trace
Definition: context.h:35
bool global_optimizations
Definition: context.h:54
std::vector< std::string > cxx_link
Definition: context.h:51
bool debug_flow
Definition: context.h:37
void setAuxOption(const std::string &key, T value)
Definition: context.h:97
bool debug
Definition: context.h:34
std::vector< hilti::rt::filesystem::path > cxx_include_paths
Definition: context.h:49
bool enable_profiling
Definition: context.h:42
std::string cxx_namespace_intern
Definition: context.h:47
PublicAPIMode
Definition: context.h:59
Result< Nothing > parseDebugAddl(const std::string &flags)
Definition: context.cc:16
void print(std::ostream &out) const
Definition: context.cc:34
std::vector< hilti::rt::filesystem::path > library_paths
Definition: context.h:43
T getAuxOption(const std::string &key, T default_) const
Definition: context.h:80
bool cxx_enable_dynamic_globals
Definition: context.h:52
bool keep_tmps
Definition: context.h:50