Skip to content

Commit

Permalink
Add friend class declaration for compilation_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardodebenedictis committed Mar 25, 2024
1 parent 920dcec commit 4cd73a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/declaration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
namespace riddle
{
class class_declaration;
class compilation_unit;

class type_declaration
{
friend class class_declaration;
friend class compilation_unit;

public:
type_declaration() = default;
Expand Down Expand Up @@ -158,6 +160,7 @@ namespace riddle
class method_declaration
{
friend class class_declaration;
friend class compilation_unit;

public:
method_declaration(std::vector<id_token> &&rt, const id_token &&name, std::vector<std::pair<std::vector<id_token>, id_token>> &&params, std::vector<std::unique_ptr<statement>> &&stmts) : return_type(std::move(rt)), name(std::move(name)), parameters(std::move(params)), body(std::move(stmts)) {}
Expand Down Expand Up @@ -197,6 +200,7 @@ namespace riddle
class predicate_declaration
{
friend class class_declaration;
friend class compilation_unit;

public:
predicate_declaration(const id_token &&name, std::vector<std::pair<std::vector<id_token>, id_token>> &&params, std::vector<std::vector<id_token>> &&base_predicates, std::vector<std::unique_ptr<statement>> &&stmts) : name(std::move(name)), parameters(std::move(params)), base_predicates(std::move(base_predicates)), body(std::move(stmts)) {}
Expand Down
19 changes: 19 additions & 0 deletions src/compilation_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@ namespace riddle
{
void compilation_unit::declare(scope &scp) const
{
// we declare the types..
for (const auto &t : types)
t->declare(scp);
// we declare the predicates..
for (const auto &p : predicates)
p->declare(scp);
}

void compilation_unit::refine(scope &scp) const
{
// we refine the types..
for (const auto &t : types)
t->refine(scp);
// we refine the methods..
for (const auto &m : methods)
m->refine(scp);
// we refine the predicates..
for (const auto &p : predicates)
p->refine(scp);
}

void compilation_unit::refine_predicates(scope &scp) const
{
// we refine the types..
for (const auto &t : types)
t->refine_predicates(scp);
}

void compilation_unit::execute(scope &scp, std::shared_ptr<env> &ctx) const
{
// we execute the statements..
for (const auto &stmt : body)
stmt->execute(scp, ctx);
}
Expand Down

0 comments on commit 4cd73a9

Please sign in to comment.