Skip to content

Commit c415e49

Browse files
committed
put enums in separate table
1 parent 064a2b4 commit c415e49

File tree

4 files changed

+71
-44
lines changed

4 files changed

+71
-44
lines changed

include/express/scope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct Scope_ {
9090
char type; /* see above */
9191
ClientData clientData; /* user may use this for any purpose */
9292
int search_id; /* key to avoid searching this scope twice */
93-
Dictionary symbol_table;
93+
Dictionary symbol_table,enum_table;
9494
struct Scope_ * superscope;
9595
union {
9696
/* struct Constant *constant;*/

src/express/expparse.y

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -776,22 +776,24 @@ enumeration_type : TOK_ENUMERATION TOK_OF nested_id_list
776776
CURRENT_SCOPE->u.type->body = tb;
777777
tb->list = $3;
778778
if (!CURRENT_SCOPE->symbol_table) {
779-
CURRENT_SCOPE->symbol_table = DICTcreate(25);
779+
CURRENT_SCOPE->symbol_table = DICTcreate(25);
780+
}
781+
if (!PREVIOUS_SCOPE->enum_table) {
782+
PREVIOUS_SCOPE->enum_table = DICTcreate(25);
780783
}
781-
LISTdo_links($3, id)
782-
tmp = (Symbol *)id->data;
783-
id->data = (Generic)(x = EXPcreate(CURRENT_SCOPE));
784-
x->symbol = *(tmp);
785-
x->u.integer = ++value;
786-
/* define both in enum scope and scope of */
787-
/* 1st visibility */
788-
DICT_define(CURRENT_SCOPE->symbol_table,
789-
x->symbol.name,
790-
(Generic)x,&x->symbol,OBJ_EXPRESSION);
791-
DICTdefine(PREVIOUS_SCOPE->symbol_table,x->symbol.name,
792-
(Generic)x,&x->symbol,OBJ_EXPRESSION);
784+
LISTdo_links($3, id) {
785+
tmp = (Symbol *)id->data;
786+
id->data = (Generic)(x = EXPcreate(CURRENT_SCOPE));
787+
x->symbol = *(tmp);
788+
x->u.integer = ++value;
789+
/* define both in enum scope and scope of */
790+
/* 1st visibility */
791+
DICT_define(CURRENT_SCOPE->symbol_table, x->symbol.name,
792+
(Generic)x,&x->symbol,OBJ_EXPRESSION);
793+
DICTdefine(PREVIOUS_SCOPE->enum_table,x->symbol.name,
794+
(Generic)x,&x->symbol,OBJ_EXPRESSION);
793795
SYMBOL_destroy(tmp);
794-
LISTod;
796+
} LISTod;
795797
}
796798
;
797799

src/express/resolve.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,35 @@ EXP_resolve( Expression expr, Scope scope, Type typecheck ) {
403403
break;
404404
case identifier_:
405405

406-
/* if this must match an enumeration, try first looking */
407-
/* in the enumeration tag scope */
408406
x = 0;
409-
#ifdef permissive_checks
410-
if( typecheck->u.type->body->type == enumeration_ ) {
411-
x = DICTlookup( TYPEget_enum_tags( typecheck ), expr->symbol.name );
412-
}
413-
#endif
414-
/* if not an enumeration tag, assume it's a variable/attribute */
407+
408+
/* assume it's a variable/attribute */
415409
if( !x ) {
416410
x = ( Generic )VARfind( scope, expr->symbol.name, 0 );
417411
}
418412
/* if not found as a variable, try as function, etc ... */
419-
if( !x ) x = SCOPEfind( scope, expr->symbol.name,
420-
SCOPE_FIND_ANYTHING );
413+
if( !x ) {
414+
x = SCOPEfind( scope, expr->symbol.name,
415+
SCOPE_FIND_ANYTHING );
416+
}
417+
/* Not all enums have `typecheck->u.type->body->type` == `enumeration_` - ?! */
418+
if( !x ) {
419+
Scope enumscope = scope;
420+
while( 1 ) {
421+
// look up locally, then go through the superscopes
422+
x = DICTlookup( enumscope->enum_table, expr->symbol.name );
423+
if( x ) {
424+
break;
425+
}
426+
if( enumscope->type == OBJ_SCHEMA ) {
427+
//if we get here, this means that we've looked through all scopes
428+
x = 0;
429+
break;
430+
}
431+
enumscope = enumscope->superscope;
432+
}
433+
}
434+
421435
if( !x ) {
422436
if( typecheck == Type_Unknown ) {
423437
return;

src/fedex_plus/classes_wrapper.cc

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,29 @@ void SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model,
201201
/* and print the enumerations */
202202
fprintf( files -> inc, "\n/* ************** TYPES */\n" );
203203
fprintf( files -> lib, "\n/* ************** TYPES */\n" );
204-
SCOPEdo_types( scope, t, de )
205-
// First check for one exception: Say enumeration type B is defined
206-
// to be a rename of enum A. If A is in this schema but has not been
207-
// processed yet, we must wait till it's processed first. The reason
208-
// is because B will basically be defined with a couple of typedefs to
209-
// the classes which represent A. (To simplify, we wait even if A is
210-
// in another schema, so long as it's been processed.)
211-
if( ( t->search_id == CANPROCESS )
212-
&& ( TYPEis_enumeration( t ) )
213-
&& ( ( i = TYPEget_ancestor( t ) ) != NULL )
214-
&& ( i->search_id >= CANPROCESS ) ) {
215-
redefs = 1;
204+
/* The following was `SCOPEdo_types( scope, t, de ) ... SCOPEod;`
205+
* Modified Jan 2012 by MAP - moving enums to own dictionary */
206+
HASHlistinit_by_type(scope->enum_table,&de,OBJ_TYPE);{
207+
Type t;
208+
while ( 0 != ( t = (Type) DICTdo( &de ) ) ) {
209+
// First check for one exception: Say enumeration type B is defined
210+
// to be a rename of enum A. If A is in this schema but has not been
211+
// processed yet, we must wait till it's processed first. The reason
212+
// is because B will basically be defined with a couple of typedefs to
213+
// the classes which represent A. (To simplify, we wait even if A is
214+
// in another schema, so long as it's been processed.)
215+
if( ( t->search_id == CANPROCESS )
216+
&& ( TYPEis_enumeration( t ) )
217+
&& ( ( i = TYPEget_ancestor( t ) ) != NULL )
218+
&& ( i->search_id >= CANPROCESS ) ) {
219+
redefs = 1;
220+
}
221+
}
216222
}
217-
SCOPEod
218223

219224
SCOPEdo_types( scope, t, de )
220-
// Do the non-redefined enumerations:
225+
/* NOTE the following comment seems to contradict the logic below it (... && !( TYPEis_enumeration( t ) && ...)
226+
// Do the non-redefined enumerations:*/
221227
if( ( t->search_id == CANPROCESS )
222228
&& !( TYPEis_enumeration( t ) && TYPEget_head( t ) ) ) {
223229
TYPEprint_descriptions( t, files, schema );
@@ -231,12 +237,17 @@ void SCOPEPrint( Scope scope, FILES * files, Schema schema, Express model,
231237
if( redefs ) {
232238
// Here we process redefined enumerations. See note, 2 loops ago.
233239
fprintf( files->inc, "// ***** Redefined Enumerations:\n" );
234-
SCOPEdo_types( scope, t, de )
235-
if( t->search_id == CANPROCESS && TYPEis_enumeration( t ) ) {
236-
TYPEprint_descriptions( t, files, schema );
237-
t->search_id = PROCESSED;
240+
/* The following was `SCOPEdo_types( scope, t, de ) ... SCOPEod;`
241+
* Modified Jan 2012 by MAP - moving enums to own dictionary */
242+
HASHlistinit_by_type(scope->enum_table,&de,OBJ_TYPE);{
243+
Type t;
244+
while ( 0 != ( t = (Type) DICTdo( &de ) ) ) {
245+
if( t->search_id == CANPROCESS && TYPEis_enumeration( t ) ) {
246+
TYPEprint_descriptions( t, files, schema );
247+
t->search_id = PROCESSED;
248+
}
249+
}
238250
}
239-
SCOPEod;
240251
}
241252

242253
/* do the select definitions next, since they depend on the others */

0 commit comments

Comments
 (0)