Skip to content

Commit 7d1701b

Browse files
Merge pull request #91 from AjayBrahmakshatriya/master
Add support for nd_vars and Merge pattern matchers
2 parents 7d6a15c + 779266f commit 7d1701b

File tree

20 files changed

+1568
-17
lines changed

20 files changed

+1568
-17
lines changed

include/blocks/block_replacer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ class block_replacer : public block_visitor {
88
public:
99
using block_visitor::visit;
1010
std::shared_ptr<block> node;
11+
12+
// optional generic exact replacing mechanism
13+
std::shared_ptr<block> to_replace;
14+
std::shared_ptr<block> replace_with;
15+
1116
template <typename T = expr>
1217
typename T::Ptr rewrite(typename T::Ptr ptr) {
1318
auto tmp = node;
1419
node = nullptr;
1520
ptr->accept(this);
1621
auto ret = to<T>(node);
1722
node = tmp;
23+
if (to_replace != nullptr && ret == to_replace)
24+
return to<T>(replace_with);
1825
return ret;
1926
}
2027
void unary_helper(std::shared_ptr<unary_expr> a);

include/blocks/expr.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,8 @@ class member_access_expr : public expr {
729729
}
730730
};
731731

732-
class addr_of_expr : public expr {
733-
public:
734-
expr::Ptr expr1;
735-
732+
class addr_of_expr: public unary_expr {
733+
public:
736734
typedef std::shared_ptr<addr_of_expr> Ptr;
737735
virtual void dump(std::ostream &oss, int) override;
738736
virtual void accept(block_visitor *a) override {

include/blocks/matchers/matchers.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef BLOCKS_MATCHERS_H
2+
#define BLOCKS_MATCHERS_H
3+
#include "blocks/matchers/patterns.h"
4+
#include "blocks/block.h"
5+
#include <map>
6+
7+
namespace block {
8+
namespace matcher {
9+
10+
struct match {
11+
block::Ptr node;
12+
std::map<std::string, block::Ptr> captures;
13+
};
14+
15+
std::vector<match> find_all_matches(std::shared_ptr<pattern> p, block::Ptr node);
16+
bool check_match(std::shared_ptr<pattern> p, block::Ptr node, std::map<std::string, block::Ptr>& captures);
17+
18+
}
19+
}
20+
21+
22+
#endif

0 commit comments

Comments
 (0)