block.c
1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <identList.h>
#include <stmtQueue.h>
typedef struct block s_block;
struct block /* a stack of used blocks. */
{
s_stmtQueue * stmts;
s_identList * idl;
s_block * prev;
};
s_block *
blockNew (s_stmtQueue * stmts)
{
s_block * new = (s_block *) malloc (sizeof (s_block));
new->stmts = stmts;
new->prev = NULL;
new->idl = identListNew (new);
return new;
}
void
blockFree (s_block * bs)
{
if (bs->prev != NULL)
blockFree (bs->prev);
if (bs->stmts != NULL)
stmtQueueFree (bs->stmts);
identListFree (bs->idl);
free (bs);
}
void
blockSetNonLocalId (s_block * bs, s_ident * id)
{
s_identListPutVal (bs->idl, id);
}
s_block *
blockPush (s_block ** bs, s_block * new)
{
new->prev = *bs;
*bs = new;
return *bs;
}
s_block *
blockPop (s_block ** bs)
{
s_block * ret = *bs;
*bs = (*bs)->prev;
return ret;
}
s_block *
blockPrev (s_block * bs)
{
return bs->prev;
}
s_stmtQueue *
blockStmts (s_block * bs)
{
return bs->stmts;
}
s_identList *
blockIdl (s_block * bs)
{
return bs->idl;
}