Skip to content

Commit 663414f

Browse files
committed
split resolve.c, add a linker seam to facilitate tests
1 parent b58e30c commit 663414f

4 files changed

Lines changed: 131 additions & 120 deletions

File tree

include/express/resolve.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ extern SC_EXPRESS_EXPORT void EXP_resolve( Expression, Scope, Type );
8383
extern SC_EXPRESS_EXPORT void ALGresolve( Scope );
8484
extern SC_EXPRESS_EXPORT void SCHEMAresolve( Scope );
8585

86+
/*
87+
* for unit tests, no extern / export
88+
*/
89+
void ENTITYresolve_subtypes( Schema );
90+
void ENTITYresolve_supertypes( Entity );
91+
void ENTITYresolve_expressions( Entity e );
92+
void ALGresolve_expressions_statements( Scope, Linked_List );
93+
int WHEREresolve( Linked_List, Scope, int );
94+
void TYPEresolve_expressions( Type, Scope );
95+
void STMTlist_resolve( Linked_List, Scope );
96+
8697
#endif /*RESOLVE_H*/

src/express/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ set(EXPRESS_SOURCES
7272
scope.c
7373
schema.c
7474
resolve.c
75+
resolve2.c
7576
lexact.c
7677
linklist.c
7778
error.c

src/express/resolve.c

Lines changed: 4 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ Error ERROR_ambiguous_group = ERROR_none;
7777
Error WARNING_fn_skip_branch = ERROR_none;
7878
Error WARNING_case_skip_label = ERROR_none;
7979

80-
81-
static void ENTITYresolve_subtypes( Schema );
82-
static void ENTITYresolve_supertypes( Entity );
83-
static void TYPEresolve_expressions( Type, Scope );
84-
8580
static Error ERROR_wrong_arg_count;
8681
static Error ERROR_supertype_resolve;
8782
static Error ERROR_subtype_resolve;
@@ -115,7 +110,6 @@ static bool found_self; /**< remember whether we've seen a SELF in a WHERE clau
115110
/* function prototypes */
116111
/***********************/
117112

118-
static int WHEREresolve( Linked_List, Scope, int );
119113
extern void VAR_resolve_expressions( Variable, Entity );
120114
extern void VAR_resolve_types( Variable v );
121115

@@ -940,21 +934,6 @@ void STMTresolve( Statement statement, Scope scope ) {
940934
}
941935
}
942936

943-
void ALGresolve_expressions_statements( Scope s, Linked_List statements ) {
944-
int status = 0;
945-
946-
if( print_objects_while_running & OBJ_ALGORITHM_BITS &
947-
OBJget_bits( s->type ) ) {
948-
fprintf( stderr, "pass %d: %s (%s)\n", EXPRESSpass,
949-
s->symbol.name, OBJget_type( s->type ) );
950-
}
951-
952-
SCOPEresolve_expressions_statements( s );
953-
STMTlist_resolve( statements, s );
954-
955-
s->symbol.resolved = status;
956-
}
957-
958937
static Variable ENTITY_get_local_attribute( Entity e, char * name ) {
959938
LISTdo( e->u.entity->attributes, a, Variable )
960939
if( !strcmp( VARget_simple_name( a ), name ) ) {
@@ -1194,52 +1173,8 @@ void SCOPEresolve_types( Scope s ) {
11941173
}
11951174
}
11961175

1197-
1198-
1199-
/********************************new****************************************/
1200-
1201-
void SCOPEresolve_subsupers( Scope scope ) {
1202-
DictionaryEntry de;
1203-
void *x;
1204-
char type;
1205-
Symbol * sym;
1206-
Type t;
1207-
1208-
if( print_objects_while_running & OBJ_SCOPE_BITS &
1209-
OBJget_bits( scope->type ) ) {
1210-
fprintf( stderr, "pass %d: %s (%s)\n", EXPRESSpass,
1211-
scope->symbol.name, OBJget_type( scope->type ) );
1212-
}
1213-
1214-
DICTdo_init( scope->symbol_table, &de );
1215-
while( 0 != ( x = DICTdo( &de ) ) ) {
1216-
switch( type = DICT_type ) {
1217-
case OBJ_ENTITY:
1218-
ENTITYresolve_supertypes( ( Entity )x );
1219-
ENTITYresolve_subtypes( ( Entity )x );
1220-
break;
1221-
case OBJ_FUNCTION:
1222-
case OBJ_PROCEDURE:
1223-
case OBJ_RULE:
1224-
SCOPEresolve_subsupers( ( Scope )x );
1225-
break;
1226-
case OBJ_TYPE:
1227-
t = ( Type )x;
1228-
TYPEresolve( &t );
1229-
break;
1230-
default:
1231-
/* ignored everything else */
1232-
break;
1233-
}
1234-
sym = OBJget_symbol( x, type );
1235-
if( is_resolve_failed_raw( sym ) ) {
1236-
resolve_failed( scope );
1237-
}
1238-
}
1239-
}
1240-
12411176
/** for each supertype, find the entity it refs to */
1242-
static void ENTITYresolve_supertypes( Entity e ) {
1177+
void ENTITYresolve_supertypes( Entity e ) {
12431178
Entity ref_entity;
12441179

12451180
if( print_objects_while_running & OBJ_ENTITY_BITS ) {
@@ -1296,7 +1231,7 @@ static void ENTITYresolve_supertypes( Entity e ) {
12961231
} LISTod;
12971232
}
12981233

1299-
static void ENTITYresolve_subtypes( Entity e ) {
1234+
void ENTITYresolve_subtypes( Entity e ) {
13001235
int i;
13011236

13021237
if( print_objects_while_running & OBJ_ENTITY_BITS ) {
@@ -1389,7 +1324,7 @@ void ENTITYresolve_types( Entity e ) {
13891324
}
13901325

13911326
/** resolve all expressions in type definitions */
1392-
static void TYPEresolve_expressions( Type t, Scope s ) {
1327+
void TYPEresolve_expressions( Type t, Scope s ) {
13931328
TypeBody body;
13941329

13951330
/* meaning of self in a type declaration refers to the type itself, so */
@@ -1427,58 +1362,7 @@ static void TYPEresolve_expressions( Type t, Scope s ) {
14271362
self = self_old;
14281363
}
14291364

1430-
void SCOPEresolve_expressions_statements( Scope s ) {
1431-
DictionaryEntry de;
1432-
void *x;
1433-
Variable v;
1434-
1435-
if( print_objects_while_running & OBJ_SCOPE_BITS &
1436-
OBJget_bits( s->type ) ) {
1437-
fprintf( stderr, "pass %d: %s (%s)\n", EXPRESSpass,
1438-
s->symbol.name, OBJget_type( s->type ) );
1439-
}
1440-
1441-
DICTdo_init( s->symbol_table, &de );
1442-
while( 0 != ( x = DICTdo( &de ) ) ) {
1443-
switch( DICT_type ) {
1444-
case OBJ_SCHEMA:
1445-
if( is_not_resolvable( ( Schema )x ) ) {
1446-
break;
1447-
}
1448-
SCOPEresolve_expressions_statements( ( Scope )x );
1449-
break;
1450-
case OBJ_ENTITY:
1451-
ENTITYresolve_expressions( ( Entity )x );
1452-
break;
1453-
case OBJ_FUNCTION:
1454-
ALGresolve_expressions_statements( ( Scope )x, ( ( Scope )x )->u.func->body );
1455-
break;
1456-
case OBJ_PROCEDURE:
1457-
ALGresolve_expressions_statements( ( Scope )x, ( ( Scope )x )->u.proc->body );
1458-
break;
1459-
case OBJ_RULE:
1460-
ALGresolve_expressions_statements( ( Scope )x, ( ( Scope )x )->u.rule->body );
1461-
1462-
WHEREresolve( RULEget_where( ( Scope )x ), ( Scope )x, 0 );
1463-
break;
1464-
case OBJ_VARIABLE:
1465-
v = ( Variable )x;
1466-
TYPEresolve_expressions( v->type, s );
1467-
if( v->initializer ) {
1468-
EXPresolve( v->initializer, s, v->type );
1469-
}
1470-
break;
1471-
case OBJ_TYPE:
1472-
TYPEresolve_expressions( ( Type )x, s );
1473-
break;
1474-
default:
1475-
/* ignored everything else */
1476-
break;
1477-
}
1478-
}
1479-
}
1480-
1481-
static int WHEREresolve( Linked_List list, Scope scope, int need_self ) {
1365+
int WHEREresolve( Linked_List list, Scope scope, int need_self ) {
14821366
int status = 0;
14831367

14841368
LISTdo( list, w, Where )

src/express/resolve2.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* This software was developed by U.S. Government employees as part of
3+
* their official duties and is not subject to copyright.
4+
*/
5+
6+
#include "express/express.h"
7+
#include "express/schema.h"
8+
#include "express/resolve.h"
9+
10+
void SCOPEresolve_subsupers( Scope scope ) {
11+
DictionaryEntry de;
12+
void *x;
13+
char type;
14+
Symbol * sym;
15+
Type t;
16+
17+
if( print_objects_while_running & OBJ_SCOPE_BITS &
18+
OBJget_bits( scope->type ) ) {
19+
fprintf( stderr, "pass %d: %s (%s)\n", EXPRESSpass,
20+
scope->symbol.name, OBJget_type( scope->type ) );
21+
}
22+
23+
DICTdo_init( scope->symbol_table, &de );
24+
while( 0 != ( x = DICTdo( &de ) ) ) {
25+
switch( type = DICT_type ) {
26+
case OBJ_ENTITY:
27+
ENTITYresolve_supertypes( ( Entity )x );
28+
ENTITYresolve_subtypes( ( Entity )x );
29+
break;
30+
case OBJ_FUNCTION:
31+
case OBJ_PROCEDURE:
32+
case OBJ_RULE:
33+
SCOPEresolve_subsupers( ( Scope )x );
34+
break;
35+
case OBJ_TYPE:
36+
t = ( Type )x;
37+
TYPEresolve( &t );
38+
break;
39+
default:
40+
/* ignored everything else */
41+
break;
42+
}
43+
sym = OBJget_symbol( x, type );
44+
if( is_resolve_failed_raw( sym ) ) {
45+
resolve_failed( scope );
46+
}
47+
}
48+
}
49+
50+
void SCOPEresolve_expressions_statements( Scope s ) {
51+
DictionaryEntry de;
52+
void *x;
53+
Variable v;
54+
55+
if( print_objects_while_running & OBJ_SCOPE_BITS &
56+
OBJget_bits( s->type ) ) {
57+
fprintf( stderr, "pass %d: %s (%s)\n", EXPRESSpass,
58+
s->symbol.name, OBJget_type( s->type ) );
59+
}
60+
61+
DICTdo_init( s->symbol_table, &de );
62+
while( 0 != ( x = DICTdo( &de ) ) ) {
63+
switch( DICT_type ) {
64+
case OBJ_SCHEMA:
65+
if( is_not_resolvable( ( Schema )x ) ) {
66+
break;
67+
}
68+
SCOPEresolve_expressions_statements( ( Scope )x );
69+
break;
70+
case OBJ_ENTITY:
71+
ENTITYresolve_expressions( ( Entity )x );
72+
break;
73+
case OBJ_FUNCTION:
74+
ALGresolve_expressions_statements( ( Scope )x, ( ( Scope )x )->u.func->body );
75+
break;
76+
case OBJ_PROCEDURE:
77+
ALGresolve_expressions_statements( ( Scope )x, ( ( Scope )x )->u.proc->body );
78+
break;
79+
case OBJ_RULE:
80+
ALGresolve_expressions_statements( ( Scope )x, ( ( Scope )x )->u.rule->body );
81+
82+
WHEREresolve( RULEget_where( ( Scope )x ), ( Scope )x, 0 );
83+
break;
84+
case OBJ_VARIABLE:
85+
v = ( Variable )x;
86+
TYPEresolve_expressions( v->type, s );
87+
if( v->initializer ) {
88+
EXPresolve( v->initializer, s, v->type );
89+
}
90+
break;
91+
case OBJ_TYPE:
92+
TYPEresolve_expressions( ( Type )x, s );
93+
break;
94+
default:
95+
/* ignored everything else */
96+
break;
97+
}
98+
}
99+
}
100+
101+
void ALGresolve_expressions_statements( Scope s, Linked_List statements ) {
102+
int status = 0;
103+
104+
if( print_objects_while_running & OBJ_ALGORITHM_BITS &
105+
OBJget_bits( s->type ) ) {
106+
fprintf( stderr, "pass %d: %s (%s)\n", EXPRESSpass,
107+
s->symbol.name, OBJget_type( s->type ) );
108+
}
109+
110+
SCOPEresolve_expressions_statements( s );
111+
STMTlist_resolve( statements, s );
112+
113+
s->symbol.resolved = status;
114+
}
115+

0 commit comments

Comments
 (0)