summaryrefslogtreecommitdiff
path: root/mi
diff options
context:
space:
mode:
authorMura Li <mural@ctli.io>2022-03-24 03:59:04 +0000
committerOri Bernstein <ori@eigenstate.org>2022-03-24 03:59:04 +0000
commitfbd0a767de45e5c5d9dfe6dc4a86c95a328bd22b (patch)
treedf5a24252a19495aab214046bd4573984de77826 /mi
parent0f3f41fae775b2647cd0cdaf0a9ef395c19b9878 (diff)
downloadmc-fbd0a767de45e5c5d9dfe6dc4a86c95a328bd22b.tar.gz
Fix construction of pattern variable bindings
Previously, inserting the variable bindings would make the Oasn nodes appear before the decl nodes in a block. Signed-off-by: Mura Li <mural@ctli.io>
Diffstat (limited to 'mi')
-rw-r--r--mi/match.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/mi/match.c b/mi/match.c
index e3855e0..fd443d1 100644
--- a/mi/match.c
+++ b/mi/match.c
@@ -158,19 +158,22 @@ structmemb(Node *n, Node *name, Type *ty)
static Node *
addcapture(Node *n, Node **cap, size_t ncap)
{
- Node **blk;
- size_t nblk, i;
-
- nblk = 0;
- blk = NULL;
-
- for (i = 0; i < ncap; i++)
- lappend(&blk, &nblk, cap[i]);
- for (i = 0; i < n->block.nstmts; i++)
- lappend(&blk, &nblk, n->block.stmts[i]);
- lfree(&n->block.stmts, &n->block.nstmts);
- n->block.stmts = blk;
- n->block.nstmts = nblk;
+ size_t i, j;
+
+ for (i = 0; i < n->block.nstmts; i++) {
+ if (n->block.stmts[i]->type != Ndecl)
+ continue;
+ for (j = 0; j < ncap; j++) {
+ assert(cap[j]->expr.op == Oasn);
+ assert(cap[j]->expr.args[0]->expr.op == Ovar);
+ assert(cap[j]->expr.args[0]->expr.isconst == 0);
+ if (n->block.stmts[i]->decl.did != cap[j]->expr.args[0]->expr.did)
+ continue;
+ assert(n->block.stmts[i]->decl.init == NULL);
+ assert(cap[j]->expr.args[0]->expr.op == Ovar);
+ n->block.stmts[i]->decl.init = cap[j]->expr.args[1];
+ }
+ }
return n;
}