OILS / _gen / core / optview.h View on Github | oils.pub

148 lines, 128 significant
1#ifndef OPTVIEW_H
2#define OPTVIEW_H
3
4#include "_gen/frontend/option.asdl.h"
5#include "mycpp/runtime.h"
6
7namespace optview {
8
9using option_asdl::option_i;
10
11class _View {
12 public:
13 _View(List<bool>* opt0_array, List<List<bool>*>* opt_stacks)
14 : opt0_array(opt0_array), opt_stacks(opt_stacks) {
15 }
16
17 bool _Get(int opt_num) {
18 List<bool>* overlay = opt_stacks->at(opt_num);
19 if ((overlay == nullptr) or len(overlay) == 0) {
20 return opt0_array->at(opt_num);
21 } else {
22 return overlay->at(-1);
23 }
24 }
25
26 static constexpr ObjHeader obj_header() {
27 return ObjHeader::ClassFixed(field_mask(), sizeof(_View));
28 }
29
30 List<bool>* opt0_array;
31 List<List<bool>*>* opt_stacks;
32
33 static constexpr uint32_t field_mask() {
34 return
35 maskbit(offsetof(_View, opt0_array))
36 | maskbit(offsetof(_View, opt_stacks));
37 }
38};
39
40class Parse : public _View {
41 public:
42 Parse(List<bool>* opt0_array, List<List<bool>*>* opt_stacks)
43 : _View(opt0_array, opt_stacks) {
44 }
45 bool strict_parse_equals() { return _Get(option_i::strict_parse_equals); }
46 bool strict_parse_slice() { return _Get(option_i::strict_parse_slice); }
47 bool parse_at() { return _Get(option_i::parse_at); }
48 bool parse_proc() { return _Get(option_i::parse_proc); }
49 bool parse_func() { return _Get(option_i::parse_func); }
50 bool parse_brace() { return _Get(option_i::parse_brace); }
51 bool parse_bracket() { return _Get(option_i::parse_bracket); }
52 bool parse_equals() { return _Get(option_i::parse_equals); }
53 bool parse_paren() { return _Get(option_i::parse_paren); }
54 bool parse_ysh_string() { return _Get(option_i::parse_ysh_string); }
55 bool parse_triple_quote() { return _Get(option_i::parse_triple_quote); }
56 bool parse_ysh_expr_sub() { return _Get(option_i::parse_ysh_expr_sub); }
57 bool parse_at_all() { return _Get(option_i::parse_at_all); }
58 bool no_parse_backslash() { return _Get(option_i::no_parse_backslash); }
59 bool no_parse_backticks() { return _Get(option_i::no_parse_backticks); }
60 bool no_parse_bare_word() { return _Get(option_i::no_parse_bare_word); }
61 bool no_parse_dbracket() { return _Get(option_i::no_parse_dbracket); }
62 bool no_parse_dollar() { return _Get(option_i::no_parse_dollar); }
63 bool no_parse_dparen() { return _Get(option_i::no_parse_dparen); }
64 bool no_parse_ignored() { return _Get(option_i::no_parse_ignored); }
65 bool no_parse_osh() { return _Get(option_i::no_parse_osh); }
66 bool no_parse_sh_arith() { return _Get(option_i::no_parse_sh_arith); }
67 bool no_parse_word_join() { return _Get(option_i::no_parse_word_join); }
68 bool expand_aliases() { return _Get(option_i::expand_aliases); }
69};
70
71class Exec : public _View {
72 public:
73 Exec(List<bool>* opt0_array, List<List<bool>*>* opt_stacks)
74 : _View(opt0_array, opt_stacks) {
75 }
76 bool errexit() { return _Get(option_i::errexit); }
77 bool nounset() { return _Get(option_i::nounset); }
78 bool pipefail() { return _Get(option_i::pipefail); }
79 bool inherit_errexit() { return _Get(option_i::inherit_errexit); }
80 bool nullglob() { return _Get(option_i::nullglob); }
81 bool verbose_errexit() { return _Get(option_i::verbose_errexit); }
82 bool verbose_warn() { return _Get(option_i::verbose_warn); }
83 bool allexport() { return _Get(option_i::allexport); }
84 bool noexec() { return _Get(option_i::noexec); }
85 bool xtrace() { return _Get(option_i::xtrace); }
86 bool verbose() { return _Get(option_i::verbose); }
87 bool noglob() { return _Get(option_i::noglob); }
88 bool noclobber() { return _Get(option_i::noclobber); }
89 bool errtrace() { return _Get(option_i::errtrace); }
90 bool posix() { return _Get(option_i::posix); }
91 bool vi() { return _Get(option_i::vi); }
92 bool emacs() { return _Get(option_i::emacs); }
93 bool interactive() { return _Get(option_i::interactive); }
94 bool hashall() { return _Get(option_i::hashall); }
95 bool lastpipe() { return _Get(option_i::lastpipe); }
96 bool failglob() { return _Get(option_i::failglob); }
97 bool extglob() { return _Get(option_i::extglob); }
98 bool nocasematch() { return _Get(option_i::nocasematch); }
99 bool dotglob() { return _Get(option_i::dotglob); }
100 bool extdebug() { return _Get(option_i::extdebug); }
101 bool eval_unsafe_arith() { return _Get(option_i::eval_unsafe_arith); }
102 bool ignore_flags_not_impl() { return _Get(option_i::ignore_flags_not_impl); }
103 bool ignore_shopt_not_impl() { return _Get(option_i::ignore_shopt_not_impl); }
104 bool rewrite_extern() { return _Get(option_i::rewrite_extern); }
105 bool _allow_command_sub() { return _Get(option_i::_allow_command_sub); }
106 bool _allow_process_sub() { return _Get(option_i::_allow_process_sub); }
107 bool dynamic_scope() { return _Get(option_i::dynamic_scope); }
108 bool redefine_const() { return _Get(option_i::redefine_const); }
109 bool redefine_source() { return _Get(option_i::redefine_source); }
110 bool _running_trap() { return _Get(option_i::_running_trap); }
111 bool _running_hay() { return _Get(option_i::_running_hay); }
112 bool _no_debug_trap() { return _Get(option_i::_no_debug_trap); }
113 bool _no_err_trap() { return _Get(option_i::_no_err_trap); }
114 bool strict_argv() { return _Get(option_i::strict_argv); }
115 bool strict_arith() { return _Get(option_i::strict_arith); }
116 bool strict_arg_parse() { return _Get(option_i::strict_arg_parse); }
117 bool strict_array() { return _Get(option_i::strict_array); }
118 bool strict_control_flow() { return _Get(option_i::strict_control_flow); }
119 bool strict_env_binding() { return _Get(option_i::strict_env_binding); }
120 bool strict_errexit() { return _Get(option_i::strict_errexit); }
121 bool strict_nameref() { return _Get(option_i::strict_nameref); }
122 bool strict_word_eval() { return _Get(option_i::strict_word_eval); }
123 bool strict_tilde() { return _Get(option_i::strict_tilde); }
124 bool strict_glob() { return _Get(option_i::strict_glob); }
125 bool simple_word_eval() { return _Get(option_i::simple_word_eval); }
126 bool no_dash_glob() { return _Get(option_i::no_dash_glob); }
127 bool command_sub_errexit() { return _Get(option_i::command_sub_errexit); }
128 bool process_sub_fail() { return _Get(option_i::process_sub_fail); }
129 bool xtrace_rich() { return _Get(option_i::xtrace_rich); }
130 bool no_xtrace_osh() { return _Get(option_i::no_xtrace_osh); }
131 bool sigpipe_status_ok() { return _Get(option_i::sigpipe_status_ok); }
132 bool env_obj() { return _Get(option_i::env_obj); }
133 bool init_ysh_globals() { return _Get(option_i::init_ysh_globals); }
134 bool for_loop_frames() { return _Get(option_i::for_loop_frames); }
135 bool no_exported() { return _Get(option_i::no_exported); }
136 bool no_init_globals() { return _Get(option_i::no_init_globals); }
137 bool no_osh_builtins() { return _Get(option_i::no_osh_builtins); }
138 bool simple_echo() { return _Get(option_i::simple_echo); }
139 bool simple_eval_builtin() { return _Get(option_i::simple_eval_builtin); }
140 bool simple_test_builtin() { return _Get(option_i::simple_test_builtin); }
141 bool simple_trap_builtin() { return _Get(option_i::simple_trap_builtin); }
142 bool progcomp() { return _Get(option_i::progcomp); }
143 bool hostcomplete() { return _Get(option_i::hostcomplete); }
144};
145
146} // namespace optview
147
148#endif // OPTVIEW_H