Skip to content

Commit

Permalink
feat: add as_string function
Browse files Browse the repository at this point in the history
  • Loading branch information
sillydan1 committed Dec 4, 2022
1 parent feba171 commit b1bf12a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/symbol_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace expr {
auto operator<<(std::ostream &os, const symbol_value_t &v) -> std::ostream&;
auto operator<<(std::ostream &os, const symbol_table_t &m) -> std::ostream&;
auto operator<<(std::ostream &os, const symbol_table_tree_t &t) -> std::ostream&;
auto as_string(const symbol_value_t& v) -> std::string;

enum class operator_type_t {
minus, plus, star, slash, percent, hat,
Expand Down
8 changes: 8 additions & 0 deletions src/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ namespace expr {
t.apply_dfs(printer_func);
return o;
}

auto as_string(const symbol_value_t& v) -> std::string {
return std::visit(ya::overload{
[](const std::string &s) -> std::string { return s; },
[](const expr::clock_t &s) -> std::string { return std::to_string(s.time_units); },
[](auto &&v) -> std::string { return std::to_string(v); }
}, static_cast<const underlying_symbol_value_t &>(v));
}
}

auto std::hash<expr::symbol_value_t>::operator()(const expr::symbol_value_t& v) const -> size_t {
Expand Down

0 comments on commit b1bf12a

Please sign in to comment.