File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ void usage() {
18
18
std::cerr << " \n " ;
19
19
std::cerr << " options:\n " ;
20
20
std::cerr << " -o <output_format> select output_format (default '" << DEFAULT_OUTPUT_FORMAT << " '); available options are:\n " ;
21
- for (const auto & f : output_format::output_formats ) {
21
+ for (const auto & f : output_format::all () ) {
22
22
std::cerr << " " << f->name << std::endl;
23
23
std::cerr << " " << f->get_description () << std::endl;
24
24
}
@@ -79,11 +79,11 @@ int main(int argc, char *argv[]) {
79
79
}
80
80
std::shared_ptr<output_format> oformat;
81
81
if (!res) {
82
- const auto & e = std::find_if (output_format::output_formats .begin (), output_format::output_formats .end (),
82
+ const auto & e = std::find_if (output_format::all () .begin (), output_format::all () .end (),
83
83
[&](const std::shared_ptr<output_format> &f) {
84
84
return f->name == format;
85
85
});
86
- if (e == output_format::output_formats .end ()) {
86
+ if (e == output_format::all () .end ()) {
87
87
std::cerr << " error: unknown output format '" << format << " '" << std::endl;
88
88
res = 1 ;
89
89
} else {
Original file line number Diff line number Diff line change @@ -77,13 +77,12 @@ struct compiled_source {
77
77
};
78
78
79
79
struct output_format {
80
- static std::vector<std::shared_ptr<output_format>> output_formats;
81
80
static std::string default_name;
82
81
83
82
std::string name;
84
83
85
84
static void add (output_format *lang) {
86
- output_formats .push_back (std::shared_ptr<output_format>(lang));
85
+ all () .push_back (std::shared_ptr<output_format>(lang));
87
86
}
88
87
89
88
virtual int output (std::string destination, std::vector<std::string> output_options,
@@ -93,6 +92,11 @@ struct output_format {
93
92
94
93
FILE *open_single_output (std::string destination);
95
94
virtual ~output_format () = default ;
95
+
96
+ static std::vector<std::shared_ptr<output_format>>& all () {
97
+ static std::vector<std::shared_ptr<output_format>> output_formats;
98
+ return output_formats;
99
+ }
96
100
protected:
97
101
output_format (std::string name) : name(std::move(name)) {}
98
102
};
Original file line number Diff line number Diff line change 15
15
16
16
using syntax_error = yy::parser::syntax_error;
17
17
18
- std::vector<std::shared_ptr<output_format>> output_format::output_formats;
19
18
std::string output_format::default_name = " c-sdk" ;
20
19
21
20
pio_assembler::pio_assembler () {
@@ -324,7 +323,7 @@ std::vector<compiled_source::symbol> pio_assembler::public_symbols(program &prog
324
323
325
324
int pio_assembler::write_output () {
326
325
std::set<std::string> known_output_formats;
327
- std::transform (output_format::output_formats .begin (), output_format::output_formats .end (),
326
+ std::transform (output_format::all () .begin (), output_format::all () .end (),
328
327
std::inserter (known_output_formats, known_output_formats.begin ()),
329
328
[&](std::shared_ptr<output_format> &f) {
330
329
return f->name ;
You can’t perform that action at this time.
0 commit comments