Skip to content

Commit

Permalink
Merge pull request #91 from AjayBrahmakshatriya/master
Browse files Browse the repository at this point in the history
Add support for nd_vars and Merge pattern matchers
  • Loading branch information
AjayBrahmakshatriya authored Mar 2, 2025
2 parents 7d6a15c + 779266f commit 7d1701b
Show file tree
Hide file tree
Showing 20 changed files with 1,568 additions and 17 deletions.
7 changes: 7 additions & 0 deletions include/blocks/block_replacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ class block_replacer : public block_visitor {
public:
using block_visitor::visit;
std::shared_ptr<block> node;

// optional generic exact replacing mechanism
std::shared_ptr<block> to_replace;
std::shared_ptr<block> replace_with;

template <typename T = expr>
typename T::Ptr rewrite(typename T::Ptr ptr) {
auto tmp = node;
node = nullptr;
ptr->accept(this);
auto ret = to<T>(node);
node = tmp;
if (to_replace != nullptr && ret == to_replace)
return to<T>(replace_with);
return ret;
}
void unary_helper(std::shared_ptr<unary_expr> a);
Expand Down
6 changes: 2 additions & 4 deletions include/blocks/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,8 @@ class member_access_expr : public expr {
}
};

class addr_of_expr : public expr {
public:
expr::Ptr expr1;

class addr_of_expr: public unary_expr {
public:
typedef std::shared_ptr<addr_of_expr> Ptr;
virtual void dump(std::ostream &oss, int) override;
virtual void accept(block_visitor *a) override {
Expand Down
22 changes: 22 additions & 0 deletions include/blocks/matchers/matchers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BLOCKS_MATCHERS_H
#define BLOCKS_MATCHERS_H
#include "blocks/matchers/patterns.h"
#include "blocks/block.h"
#include <map>

namespace block {
namespace matcher {

struct match {
block::Ptr node;
std::map<std::string, block::Ptr> captures;
};

std::vector<match> find_all_matches(std::shared_ptr<pattern> p, block::Ptr node);
bool check_match(std::shared_ptr<pattern> p, block::Ptr node, std::map<std::string, block::Ptr>& captures);

}
}


#endif
Loading

0 comments on commit 7d1701b

Please sign in to comment.