From 86f852cd76cf92a4b08b59b127cc954420f95744 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Mon, 31 Jul 2023 13:53:16 -0700 Subject: share more code between the C examples --- c/libdietc.l | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'c/libdietc.l') diff --git a/c/libdietc.l b/c/libdietc.l index 51c8e91..abdb914 100644 --- a/c/libdietc.l +++ b/c/libdietc.l @@ -280,3 +280,23 @@ struct type *libdietc_lhs_type(struct program program, struct instruction *instr name = libdietc_tokdup(libdietc_nth_token(instruction->line, 0)); return libdietc_object_type(program, name); } + +struct instruction *libdietc_insert_before(struct instruction *i, char *line) { + struct instruction *new = calloc(1, sizeof(*new)); + *(i->pprev) = new; + new->pprev = i->pprev; + new->line = line; + new->next = i; + i->pprev = &(new->next); + return new; +} + +struct instruction *libdietc_insert_after(struct instruction *i, char *line) { + struct instruction *new = calloc(1, sizeof(*new)); + new->line = line; + new->next = i->next; + i->next->pprev = &(new->next); + new->pprev = &(i->next); + i->next = new; + return new; +} -- cgit v1.2.3