block.c
1.16 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
83
84
85
86
87
88
#include <malloc.h>
#include <identList.h>
#include <stmtQueue.h>
struct block /* a stack of used blocks. */
{
s_stmtQueue * stmts;
s_identList * idl;
s_block * prev;
};
s_identList *
blockGetIdl (s_block * block)
{
return block->idl;
}
s_block *
blockNew (s_stmtQueue * stmts)
{
s_block * new = (s_block *) malloc (sizeof (s_block));
new->stmts = stmts;
new->prev = NULL;
new->idl = identListNew (); /* !!!FIXME: i guess idl should know about
its block! (Give the block as arg) */
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;
}