-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontext.c
More file actions
154 lines (137 loc) · 3.21 KB
/
context.c
File metadata and controls
154 lines (137 loc) · 3.21 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "misc.h"
#include "defs.h"
#include "cvt.h"
#include "struct.h"
/*
* Pointer to the current context
*/
CONTEXT *context_head;
/*
* Pointer to all popped contexts
*/
CONTEXT *old_context;
/*
* Search DECL_MEMBER list for symbol and if found, return TRUE
* and pointer to DECL_ID for that symbol.
*/
find_member_symbol(symbol, decl_ptr, decl_id)
TOKEN *symbol;
DECL_MEMBER *decl_ptr;
DECL_ID **decl_id;
{
DECL_ID *var_ptr;
for (var_ptr = decl_ptr->name_list; var_ptr;
var_ptr = var_ptr->next_var) {
if (!strcmp(var_ptr->name->token_name, symbol->token_name)) {
*decl_id = var_ptr;
return TRUE;
}
}
*decl_id = NULL;
return FALSE;
}
/*
* Search DECL_MEMBER list for symbol.
* If found, return pointer to DECL_MEMBER containing that symbol
* in decl_found, and return TRUE.
* If not found, return null pointer in decl_found, and return FALSE.
*/
find_list_symbol(symbol, decl_ptr, decl_found, decl_id)
TOKEN *symbol;
DECL_MEMBER *decl_ptr, **decl_found;
DECL_ID **decl_id;
{
for (*decl_found = decl_ptr; *decl_found;
*decl_found = (*decl_found)->next_member) {
if (find_member_symbol(symbol, *decl_found, decl_id))
return TRUE;
}
return FALSE;
}
/*
* Search context for symbol.
* If found, return pointer to DECL_MEMBER containing that symbol
* in decl_found, return DECL_ID for that symbol in decl_id, and
* return TRUE.
* If not found, return null pointers in decl_found and decl_id,
* and return FALSE.
*/
find_symbol(symbol, decl_found, decl_id)
TOKEN *symbol;
DECL_MEMBER **decl_found;
DECL_ID **decl_id;
{
CONTEXT *context_ptr;
for (context_ptr = context_head; context_ptr;
context_ptr = context_ptr->next_context) {
if (find_list_symbol(symbol, context_ptr->decl_head,
decl_found, decl_id))
return TRUE;
}
return FALSE;
}
/*
* Add a declaration to current context
*/
add_to_context(decl)
DECL_MEMBER *decl;
{
DECL_MEMBER *decl_ptr;
/* Find end of declaration list */
for (decl_ptr = decl; decl_ptr->next_member; )
decl_ptr = decl_ptr->next_member;
/* Add current declarations to tail of new list */
decl_ptr->next_member = context_head->decl_head;
context_head->decl_head = decl;
}
/*
* Add a DECL list to context and NULL the list pointer
*/
add_decl_to_context(decl)
DECL *decl;
{
DECL *decl_ptr;
/* Find end of declaration list */
for (decl_ptr = decl; decl_ptr; decl_ptr = decl_ptr->next_decl) {
if (decl_ptr->decl_list)
add_to_context(decl_ptr->decl_list);
decl_ptr->decl_list = NULL;
}
}
/*
* Push a new context of specified type and name
*/
new_context(type, name)
int type;
TOKEN *name;
{
CONTEXT *new_context;
get_context_ptr(&new_context);
new_context->context_type = type;
if (name) {
get_token_ptr(&new_context->context_name);
token_copy(name, new_context->context_name);
} else
new_context->context_name = NULL;
new_context->next_context = context_head;
context_head = new_context;
}
/*
* Pop current context and place on old context
*/
pop_context()
{
CONTEXT *popped_context;
popped_context = context_head;
context_head = popped_context->next_context;
popped_context->next_context = old_context;
old_context = popped_context;
}
/*
* Initializes context pointers
*/
init_context()
{
context_head = NULL;
old_context = NULL;
}