Skip to content

Commit

Permalink
Update json submodule and add COMPUTE_NAMES feature with recompute_na…
Browse files Browse the repository at this point in the history
…mes method
  • Loading branch information
riccardodebenedictis committed Jan 15, 2025
1 parent 92617c0 commit 2376cba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extern/json
Submodule json updated 3 files
+1 −1 extern/utils
+12 −41 include/json.hpp
+7 −0 src/json.cpp
3 changes: 3 additions & 0 deletions include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace riddle
friend class method_declaration;
friend class class_declaration;
friend class predicate_declaration;
#ifdef COMPUTE_NAMES
friend class component;
#endif

public:
core(std::string_view name = "RiDDLe") noexcept;
Expand Down
3 changes: 3 additions & 0 deletions include/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ namespace riddle
friend class return_statement;
friend class formula_statement;
friend class disjunction_statement;
#ifdef COMPUTE_NAMES
friend class core;
#endif

public:
env(core &c, env &parent, std::map<std::string, std::shared_ptr<item>, std::less<>> &&items = {}) noexcept;
Expand Down
26 changes: 26 additions & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,30 @@ namespace riddle
if (!types.emplace(name, std::move(t)).second)
throw std::invalid_argument("type `" + name + "` already exists");
}

#ifdef COMPUTE_NAMES
void core::recompute_names() noexcept
{
expr_names.clear();

std::queue<std::pair<std::string, std::shared_ptr<item>>> q;
for (const auto &xpr : items)
{
expr_names.emplace(xpr.second.get(), xpr.first);
if (!xpr.second->get_type().is_primitive())
q.push(xpr);
}

while (!q.empty())
{
const auto &c_xpr = q.front();
if (const auto *c_env = dynamic_cast<env *>(c_xpr.second.get()))
for (const auto &xpr : c_env->items)
if (expr_names.emplace(xpr.second.get(), expr_names.at(c_xpr.second.get()) + '.' + xpr.first).second)
if (!xpr.second->get_type().is_primitive())
q.push(xpr);
q.pop();
}
}
#endif
} // namespace riddle

0 comments on commit 2376cba

Please sign in to comment.