Skip to content

Commit

Permalink
remove static order dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
kilograham committed Feb 1, 2021
1 parent 8a4e21b commit 2d5789e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions tools/pioasm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void usage() {
std::cerr << "\n";
std::cerr << "options:\n";
std::cerr << " -o <output_format> select output_format (default '" << DEFAULT_OUTPUT_FORMAT << "'); available options are:\n";
for(const auto& f : output_format::output_formats) {
for(const auto& f : output_format::all()) {
std::cerr << " " << f->name << std::endl;
std::cerr << " " << f->get_description() << std::endl;
}
Expand Down Expand Up @@ -79,11 +79,11 @@ int main(int argc, char *argv[]) {
}
std::shared_ptr<output_format> oformat;
if (!res) {
const auto& e = std::find_if(output_format::output_formats.begin(), output_format::output_formats.end(),
const auto& e = std::find_if(output_format::all().begin(), output_format::all().end(),
[&](const std::shared_ptr<output_format> &f) {
return f->name == format;
});
if (e == output_format::output_formats.end()) {
if (e == output_format::all().end()) {
std::cerr << "error: unknown output format '" << format << "'" << std::endl;
res = 1;
} else {
Expand Down
8 changes: 6 additions & 2 deletions tools/pioasm/output_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ struct compiled_source {
};

struct output_format {
static std::vector<std::shared_ptr<output_format>> output_formats;
static std::string default_name;

std::string name;

static void add(output_format *lang) {
output_formats.push_back(std::shared_ptr<output_format>(lang));
all().push_back(std::shared_ptr<output_format>(lang));
}

virtual int output(std::string destination, std::vector<std::string> output_options,
Expand All @@ -93,6 +92,11 @@ struct output_format {

FILE *open_single_output(std::string destination);
virtual ~output_format() = default;

static std::vector<std::shared_ptr<output_format>>& all() {
static std::vector<std::shared_ptr<output_format>> output_formats;
return output_formats;
}
protected:
output_format(std::string name) : name(std::move(name)) {}
};
Expand Down
3 changes: 1 addition & 2 deletions tools/pioasm/pio_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

using syntax_error = yy::parser::syntax_error;

std::vector<std::shared_ptr<output_format>> output_format::output_formats;
std::string output_format::default_name = "c-sdk";

pio_assembler::pio_assembler() {
Expand Down Expand Up @@ -324,7 +323,7 @@ std::vector<compiled_source::symbol> pio_assembler::public_symbols(program &prog

int pio_assembler::write_output() {
std::set<std::string> known_output_formats;
std::transform(output_format::output_formats.begin(), output_format::output_formats.end(),
std::transform(output_format::all().begin(), output_format::all().end(),
std::inserter(known_output_formats, known_output_formats.begin()),
[&](std::shared_ptr<output_format> &f) {
return f->name;
Expand Down

0 comments on commit 2d5789e

Please sign in to comment.