41
41
stree_ident_t *name);
42
42
static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog,
43
43
stree_ident_t *name, stree_csi_t *csi);
44
static stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr);
44
45
static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol);
46
47
/** Lookup symbol in CSI using a type expression.
88
89
/** Lookup symbol reference in CSI.
91
* XXX These functions should take just an sid, not a full identifier.
92
* Sometimes we search for a name which has no associated cspan.
90
94
* @param prog Program to look in
91
95
* @param scope CSI in @a prog which is the base for references
92
96
* @param name Identifier of the symbol
127
131
stree_symbol_t *symbol_search_csi(stree_program_t *prog,
128
132
stree_csi_t *scope, stree_ident_t *name)
131
stree_csimbr_t *csimbr;
132
stree_symbol_t *symbol;
133
stree_ident_t *mbr_name;
134
134
stree_symbol_t *base_csi_sym;
135
135
stree_csi_t *base_csi;
136
stree_symbol_t *symbol;
139
138
/* Look in new members in this class. */
141
node = list_first(&scope->members);
142
while (node != NULL) {
143
csimbr = list_node_data(node, stree_csimbr_t *);
145
/* Keep compiler happy. */
148
switch (csimbr->cc) {
149
case csimbr_csi: mbr_name = csimbr->u.csi->name; break;
150
case csimbr_deleg: mbr_name = csimbr->u.deleg->name; break;
151
case csimbr_fun: mbr_name = csimbr->u.fun->name; break;
152
case csimbr_var: mbr_name = csimbr->u.var->name; break;
153
case csimbr_prop: mbr_name = csimbr->u.prop->name; break;
156
if (name->sid == mbr_name->sid) {
158
switch (csimbr->cc) {
160
symbol = csi_to_symbol(csimbr->u.csi);
163
symbol = deleg_to_symbol(csimbr->u.deleg);
166
symbol = fun_to_symbol(csimbr->u.fun);
169
symbol = var_to_symbol(csimbr->u.var);
172
symbol = prop_to_symbol(csimbr->u.prop);
179
node = list_next(&scope->members, node);
139
symbol = symbol_search_csi_no_base(prog, scope, name);
182
143
/* Try inherited members. */
183
144
if (scope->base_csi_ref != NULL) {
157
/** Look for symbol strictly in CSI.
159
* Look for symbol in definition of a CSI and its ancestors. (But not
160
* in lexically enclosing CSI or in base CSI.)
162
* @param prog Program to look in
163
* @param scope CSI in which to look
164
* @param name Identifier of the symbol
166
* @return Symbol or @c NULL if symbol not found.
168
stree_symbol_t *symbol_search_csi_no_base(stree_program_t *prog,
169
stree_csi_t *scope, stree_ident_t *name)
172
stree_csimbr_t *csimbr;
173
stree_ident_t *mbr_name;
177
/* Look in new members in this class. */
179
node = list_first(&scope->members);
180
while (node != NULL) {
181
csimbr = list_node_data(node, stree_csimbr_t *);
182
mbr_name = stree_csimbr_get_name(csimbr);
184
if (name->sid == mbr_name->sid) {
186
return csimbr_to_symbol(csimbr);
189
node = list_next(&scope->members, node);
196
195
/** Look for symbol in global scope.
198
197
* @param prog Program to look in
206
205
list_node_t *node;
207
206
stree_modm_t *modm;
208
207
stree_symbol_t *symbol;
208
stree_ident_t *mbr_name;
210
210
node = list_first(&prog->module->members);
211
211
while (node != NULL) {
212
212
modm = list_node_data(node, stree_modm_t *);
213
if (name->sid == modm->u.csi->name->sid) {
215
case mc_csi: mbr_name = modm->u.csi->name; break;
216
case mc_enum: mbr_name = modm->u.enum_d->name; break;
219
if (name->sid == mbr_name->sid) {
215
221
switch (modm->mc) {
217
223
symbol = csi_to_symbol(modm->u.csi);
226
symbol = enum_to_symbol(modm->u.enum_d);
345
352
return deleg->symbol;
355
/** Convert symbol to enum (base to derived).
357
* @param symbol Symbol
358
* @return Enum or @c NULL if symbol is not a enum
360
stree_enum_t *symbol_to_enum(stree_symbol_t *symbol)
362
if (symbol->sc != sc_enum)
365
return symbol->u.enum_d;
368
/** Convert enum to symbol (derived to base).
373
stree_symbol_t *enum_to_symbol(stree_enum_t *enum_d)
375
assert(enum_d->symbol);
376
return enum_d->symbol;
348
379
/** Convert symbol to CSI (base to derived).
350
381
* @param symbol Symbol
369
400
return csi->symbol;
403
/** Convert symbol to constructor (base to derived).
405
* @param symbol Symbol
406
* @return Constructor or @c NULL if symbol is not a constructor
408
stree_ctor_t *symbol_to_ctor(stree_symbol_t *symbol)
410
if (symbol->sc != sc_ctor)
413
return symbol->u.ctor;
416
/** Convert constructor to symbol (derived to base).
418
* @param ctor Constructor
421
stree_symbol_t *ctor_to_symbol(stree_ctor_t *ctor)
423
assert(ctor->symbol);
372
428
/** Convert symbol to function (base to derived).
374
430
* @param symbol Symbol
430
486
return symbol->u.prop;
489
/** Get symbol from CSI member.
491
* A symbol corresponds to any CSI member. Return it.
493
* @param csimbr CSI member
496
static stree_symbol_t *csimbr_to_symbol(stree_csimbr_t *csimbr)
498
stree_symbol_t *symbol;
500
/* Keep compiler happy. */
504
switch (csimbr->cc) {
506
symbol = csi_to_symbol(csimbr->u.csi);
509
symbol = ctor_to_symbol(csimbr->u.ctor);
512
symbol = deleg_to_symbol(csimbr->u.deleg);
515
symbol = enum_to_symbol(csimbr->u.enum_d);
518
symbol = fun_to_symbol(csimbr->u.fun);
521
symbol = var_to_symbol(csimbr->u.var);
524
symbol = prop_to_symbol(csimbr->u.prop);
433
532
/** Convert property to symbol (derived to base).
435
534
* @param fun Property
472
571
switch (symbol->sc) {
473
572
case sc_csi: ident = symbol->u.csi->name; break;
573
case sc_ctor: ident = symbol->u.ctor->name; break;
474
574
case sc_deleg: ident = symbol->u.deleg->name; break;
575
case sc_enum: ident = symbol->u.enum_d->name; break;
475
576
case sc_fun: ident = symbol->u.fun->name; break;
476
577
case sc_var: ident = symbol->u.var->name; break;
477
578
case sc_prop: ident = symbol->u.prop->name; break;