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  std::string cxx_namespace_intern = "__hlt";
47  std::vector<hilti::rt::filesystem::path>
49  bool keep_tmps = false;
50  std::vector<std::string> cxx_link;
52  false;
53  bool global_optimizations = true;
67  template<typename T>
68  T getAuxOption(const std::string& key, T default_) const {
69  auto i = _aux_options.find(key);
70  if ( i != _aux_options.end() )
71  return hilti::rt::any_cast<T>(i->second);
72  else
73  return default_;
74  }
75 
84  template<typename T>
85  void setAuxOption(const std::string& key, T value) {
86  _aux_options[key] = value;
87  }
88 
96  Result<Nothing> parseDebugAddl(const std::string& flags);
97 
99  void print(std::ostream& out) const;
100 
101 private:
102  std::map<std::string, hilti::rt::any> _aux_options;
103 };
104 
105 namespace context {} // namespace context
106 
108 class Context {
109 public:
113  explicit Context(Options options);
114 
116  ~Context();
117 
119  const Options& options() const { return _options; }
120 
122  auto* astContext() const { return _ast_context.get(); }
123 
124 private:
125  Options _options;
126  std::unique_ptr<ASTContext> _ast_context;
127 };
128 
129 } // namespace hilti
Definition: context.h:108
~Context()
Definition: context.cc:65
auto * astContext() const
Definition: context.h:122
const Options & options() const
Definition: context.h:119
Context(Options options)
Definition: context.cc:62
Definition: result.h:71
Definition: context.h:33
bool import_standard_modules
Definition: context.h:54
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:53
std::vector< std::string > cxx_link
Definition: context.h:50
bool debug_flow
Definition: context.h:37
void setAuxOption(const std::string &key, T value)
Definition: context.h:85
bool debug
Definition: context.h:34
std::vector< hilti::rt::filesystem::path > cxx_include_paths
Definition: context.h:48
bool enable_profiling
Definition: context.h:42
std::string cxx_namespace_intern
Definition: context.h:46
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:68
bool cxx_enable_dynamic_globals
Definition: context.h:51
bool keep_tmps
Definition: context.h:49