Skip to content

Commit

Permalink
Merge pull request #81 from AjayBrahmakshatriya/master
Browse files Browse the repository at this point in the history
Blocks AST cloning
  • Loading branch information
AjayBrahmakshatriya authored Sep 25, 2024
2 parents 7347252 + 65a68b8 commit ea71cf5
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 1 deletion.
21 changes: 21 additions & 0 deletions include/blocks/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ std::shared_ptr<T> to(std::shared_ptr<block> p) {
return ret;
}

template <typename T>
std::shared_ptr<T> clone(std::shared_ptr<T> p) {
if (!p) return nullptr;
return to<T>(p->clone_impl());
}

template <typename T>
std::shared_ptr<T> clone_obj(T* t) {
auto np = std::make_shared<T>();
np->static_offset = t->static_offset;
np->metadata_map = t->metadata_map;
return np;
}

template <typename T>
class block_metadata_impl;

Expand Down Expand Up @@ -62,6 +76,8 @@ class block_metadata_impl : public block_metadata {
block_metadata_impl(T _val) : val(_val) {}
};



class block : public std::enable_shared_from_this<block> {
public:
virtual ~block() = default;
Expand Down Expand Up @@ -113,6 +129,11 @@ class block : public std::enable_shared_from_this<block> {
return false;
return true;
}

virtual block::Ptr clone_impl(void) {
// abstract class always returns nullptr
return nullptr;
}
};
} // namespace block
#endif
Loading

0 comments on commit ea71cf5

Please sign in to comment.