Skip to content

Commit db4f1a6

Browse files
committed
simplify OBJ lookup, compile time initialisation
1 parent e76d92d commit db4f1a6

File tree

11 files changed

+67
-79
lines changed

11 files changed

+67
-79
lines changed

include/express/object.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct Object {
8181
/* global variables */
8282
/********************/
8383

84-
extern SC_EXPRESS_EXPORT struct Object * OBJ;
84+
extern SC_EXPRESS_EXPORT struct Object OBJ[];
8585

8686
/******************************/
8787
/* macro function definitions */
@@ -97,9 +97,4 @@ extern SC_EXPRESS_EXPORT struct Object * OBJ;
9797
/* function prototypes */
9898
/***********************/
9999

100-
extern SC_EXPRESS_EXPORT void OBJinitialize( void );
101-
extern SC_EXPRESS_EXPORT void OBJcleanup( void );
102-
extern SC_EXPRESS_EXPORT void OBJcreate( char, struct Symbol_ * (*) (void *), char *, int);
103-
extern SC_EXPRESS_EXPORT Symbol * UNK_get_symbol( void *x );
104-
105100
#endif /*OBJECT_H*/

src/express/alg.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,12 @@ Scope ALGcreate( char type ) {
7373
** Description: Initialize the Algorithm module.
7474
*/
7575

76-
Symbol * WHERE_get_symbol( void *w ) {
77-
return( ( ( Where )w )->label );
78-
}
79-
8076
/** Initialize the Algorithm module. */
8177
void ALGinitialize( void ) {
8278
ALLOCinitialize( &FUNC_fl, sizeof( struct Function_ ), 100, 50 );
8379
ALLOCinitialize( &RULE_fl, sizeof( struct Rule_ ), 100, 50 );
8480
ALLOCinitialize( &PROC_fl, sizeof( struct Procedure_ ), 100, 50 );
8581
ALLOCinitialize( &WHERE_fl, sizeof( struct Where_ ), 100, 50 );
86-
OBJcreate( OBJ_RULE, SCOPE_get_symbol, "rule", OBJ_UNUSED_BITS );
87-
OBJcreate( OBJ_PROCEDURE, SCOPE_get_symbol, "procedure", OBJ_PROCEDURE_BITS );
88-
OBJcreate( OBJ_FUNCTION, SCOPE_get_symbol, "function", OBJ_FUNCTION_BITS );
89-
OBJcreate( OBJ_WHERE, WHERE_get_symbol, "where", OBJ_WHERE_BITS );
9082
}
9183

9284
void ALGput_full_text( Scope s, int start, int end ) {

src/express/entity.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ Entity ENTITYcopy( Entity e ) {
299299
/** Initialize the Entity module. */
300300
void ENTITYinitialize() {
301301
ALLOCinitialize( &ENTITY_fl, sizeof( struct Entity_ ), 500, 100 );
302-
OBJcreate( OBJ_ENTITY, SCOPE_get_symbol, "entity",
303-
OBJ_ENTITY_BITS );
304302
}
305303

306304
/**

src/express/expr.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,12 @@ Expression EXPcreate_from_symbol( Type type, Symbol * symbol ) {
141141
return e;
142142
}
143143

144-
Symbol * EXP_get_symbol( void *e ) {
145-
return( &( ( Expression )e )->symbol );
146-
}
147-
148144
/** Description: Initialize the Expression module. */
149145
void EXPinitialize( void ) {
150146
ALLOCinitialize( &EXP_fl, sizeof( struct Expression_ ), 500, 200 );
151147
ALLOCinitialize( &OP_fl, sizeof( struct Op_Subexpression ), 500, 100 );
152148
ALLOCinitialize( &QUERY_fl, sizeof( struct Query_ ), 50, 10 );
153149
ALLOCinitialize( &QUAL_ATTR_fl, sizeof( struct Query_ ), 20, 10 );
154-
OBJcreate( OBJ_EXPRESSION, EXP_get_symbol, "expression", OBJ_EXPRESSION_BITS );
155-
OBJcreate( OBJ_AMBIG_ENUM, EXP_get_symbol, "ambiguous enumeration", OBJ_UNUSED_BITS );
156150

157151
#ifdef does_not_appear_to_be_necessary_or_even_make_sense
158152
LITERAL_EMPTY_SET = EXPcreate_simple( Type_Set );

src/express/express.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ int EXPRESS_succeed( Express model ) {
152152
return 0;
153153
}
154154

155-
Symbol * EXPRESS_get_symbol( void *e ) {
156-
return( &( ( Express )e )->symbol );
157-
}
158-
159155
Express EXPRESScreate() {
160156
Express model = SCOPEcreate( OBJ_EXPRESS );
161157
model->u.express = ( struct Express_ * )sc_calloc( 1, sizeof( struct Express_ ) );
@@ -259,14 +255,12 @@ static void EXPRESS_PATHfree( void ) {
259255

260256
/** inform object system about bit representation for handling pass diagnostics */
261257
void PASSinitialize() {
262-
OBJcreate( OBJ_PASS, UNK_get_symbol, "pass", OBJ_PASS_BITS );
263258
}
264259

265260
/** Initialize the Express package. */
266261
void EXPRESSinitialize( void ) {
267262
_ALLOCinitialize();
268263
ERRORinitialize();
269-
OBJinitialize();
270264

271265
HASHinitialize(); /* comes first - used by just about everything else! */
272266
DICTinitialize();
@@ -312,8 +306,6 @@ void EXPRESSinitialize( void ) {
312306
ERROR_warn_small_real = ERRORcreate( "REALs with extremely small magnitude may be interpreted as zero by other EXPRESS parsers "
313307
"(IEEE 754 float denormals are sometimes rounded to zero) - fabs(%f) <= FLT_MIN.", SEVERITY_WARNING );
314308

315-
OBJcreate( OBJ_EXPRESS, EXPRESS_get_symbol, "express file", OBJ_UNUSED_BITS );
316-
317309
/* I don't think this should be a mere warning; exppp crashes if this warning is suppressed.
318310
* ERRORcreate_warning( "unknown_subtype", ERROR_unknown_subtype );
319311
*/
@@ -339,7 +331,6 @@ void EXPRESScleanup( void ) {
339331
ERRORdestroy( ERROR_warn_small_real );
340332

341333
DICTcleanup();
342-
OBJcleanup();
343334
ERRORcleanup();
344335
RESOLVEcleanup();
345336
TYPEcleanup();

src/express/object.c

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,53 @@
2121
* prettied up interface to print_objects_when_running
2222
*/
2323

24-
#include <sc_memmgr.h>
25-
#include <stdlib.h>
2624
#include "express/object.h"
2725

28-
struct Object * OBJ;
26+
#include "express/scope.h"
27+
#include "express/variable.h"
28+
#include "express/alg.h"
29+
#include "express/schema.h"
30+
#include "express/type.h"
31+
#include "express/expr.h"
32+
33+
Symbol * SCOPE_get_symbol( void *s );
34+
Symbol * EXPRESS_get_symbol( void *e );
35+
Symbol * RENAME_get_symbol( void *r );
36+
Symbol * TYPE_get_symbol( void *t );
37+
Symbol * EXP_get_symbol( void *e );
38+
Symbol * WHERE_get_symbol( void *w );
39+
Symbol * VAR_get_symbol( void *v );
40+
Symbol * UNK_get_symbol( void *x );
41+
42+
/* global Object type array */
43+
struct Object OBJ[] = {
44+
[0] = {UNK_get_symbol, "of unknown type", 0},
45+
46+
[OBJ_VARIABLE] = {VAR_get_symbol, "variable", OBJ_VARIABLE_BITS},
47+
[OBJ_ENTITY] = {SCOPE_get_symbol, "entity", OBJ_ENTITY_BITS},
48+
49+
[OBJ_EXPRESSION] = {EXP_get_symbol, "expression", OBJ_EXPRESSION_BITS},
50+
[OBJ_AMBIG_ENUM] = {EXP_get_symbol, "ambiguous enumeration", OBJ_UNUSED_BITS},
51+
52+
[OBJ_RULE] = {SCOPE_get_symbol, "rule", OBJ_UNUSED_BITS},
53+
[OBJ_PROCEDURE] = {SCOPE_get_symbol, "procedure", OBJ_PROCEDURE_BITS},
54+
[OBJ_FUNCTION] = {SCOPE_get_symbol, "function", OBJ_FUNCTION_BITS},
55+
[OBJ_WHERE] = {WHERE_get_symbol, "where", OBJ_WHERE_BITS},
56+
57+
[OBJ_SCHEMA] = {SCOPE_get_symbol, "schema", OBJ_SCHEMA_BITS},
58+
/* TODO: PASS should also have a symbol */
59+
[OBJ_PASS] = {UNK_get_symbol, "pass", OBJ_PASS_BITS},
60+
[OBJ_EXPRESS] = {EXPRESS_get_symbol, "express file", OBJ_UNUSED_BITS},
61+
[OBJ_RENAME] = {RENAME_get_symbol, "rename clause", OBJ_UNUSED_BITS},
62+
63+
[OBJ_TYPE] = {TYPE_get_symbol, "type", OBJ_TYPE_BITS},
64+
[OBJ_TAG] = {TYPE_get_symbol, "tag", OBJ_TYPE_BITS},
65+
66+
[OBJ_ALIAS] = {SCOPE_get_symbol, "alias scope", OBJ_UNUSED_BITS },
67+
[OBJ_INCREMENT] = {SCOPE_get_symbol, "increment scope", OBJ_UNUSED_BITS },
68+
69+
{0}
70+
};
2971

3072
Symbol * UNK_get_symbol( void *x ) {
3173
(void) x; /* quell unused param warning; it appears that the prototype must match other functions */
@@ -34,26 +76,30 @@ Symbol * UNK_get_symbol( void *x ) {
3476
return 0;
3577
}
3678

37-
/** Initialize the Object module */
38-
void OBJinitialize() {
39-
int i;
79+
Symbol * VAR_get_symbol( void *v ) {
80+
return &( ( Variable )v )->name->symbol;
81+
}
82+
83+
Symbol * SCOPE_get_symbol( void *s ) {
84+
return &( ( Scope )s )->symbol;
85+
}
86+
87+
Symbol * EXP_get_symbol( void *e ) {
88+
return &( ( Expression )e )->symbol;
89+
}
90+
91+
Symbol * WHERE_get_symbol( void *w ) {
92+
return ( ( Where )w )->label;
93+
}
4094

41-
OBJ = ( struct Object * )sc_malloc( MAX_OBJECT_TYPES * sizeof( struct Object ) );
42-
for( i = 0; i < MAX_OBJECT_TYPES; i++ ) {
43-
OBJ[i].get_symbol = UNK_get_symbol;
44-
OBJ[i].type = "of unknown_type";
45-
OBJ[i].bits = 0;
46-
}
95+
Symbol * EXPRESS_get_symbol( void *e ) {
96+
return &( ( Express )e )->symbol;
4797
}
4898

49-
/** Clean up the Object module */
50-
void OBJcleanup() {
51-
sc_free( OBJ );
99+
Symbol * RENAME_get_symbol( void *r ) {
100+
return ( ( Rename * )r )->old;
52101
}
53102

54-
void OBJcreate( char type, struct Symbol_ * ( *get_symbol ) ( void * ), char * printable_type, int bits ) {
55-
int index = ( int )type;
56-
OBJ[index].get_symbol = get_symbol;
57-
OBJ[index].type = printable_type;
58-
OBJ[index].bits = bits;
103+
Symbol * TYPE_get_symbol( void *t ) {
104+
return &( ( Type )t )->symbol;
59105
}

src/express/schema.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,8 @@ struct freelist_head REN_fl;
5555

5656
int __SCOPE_search_id = 0;
5757

58-
Symbol * RENAME_get_symbol( void *r ) {
59-
return ( ( Rename * )r )->old;
60-
}
61-
6258
/** Initialize the Schema module. */
6359
void SCHEMAinitialize( void ) {
64-
OBJcreate( OBJ_RENAME, RENAME_get_symbol, "rename clause", OBJ_UNUSED_BITS );
6560
ALLOCinitialize( &REN_fl, sizeof( struct Rename ), 30, 30 );
6661
ALLOCinitialize( &SCHEMA_fl, sizeof( struct Schema_ ), 40, 20 );
6762
}

src/express/scope.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@
4444
#include "express/scope.h"
4545
#include "express/resolve.h"
4646

47-
Symbol * SCOPE_get_symbol( void *s ) {
48-
return( &( ( Scope )s )->symbol );
49-
}
50-
5147
void SCOPEinitialize( void ) {
52-
OBJcreate( OBJ_SCHEMA, SCOPE_get_symbol, "schema", OBJ_SCHEMA_BITS );
5348
ALLOCinitialize( &SCOPE_fl, sizeof( struct Scope_ ), 100, 50 );
5449
}
5550

src/express/stmt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ void STMTinitialize( void ) {
8080
ALLOCinitialize( &RET_fl, sizeof( struct Return_Statement_ ), 100, 30 );
8181
ALLOCinitialize( &INCR_fl, sizeof( struct Increment_ ), 100, 30 );
8282

83-
OBJcreate( OBJ_ALIAS, SCOPE_get_symbol, "alias scope", OBJ_UNUSED_BITS );
84-
OBJcreate( OBJ_INCREMENT, SCOPE_get_symbol, "increment scope", OBJ_UNUSED_BITS );
85-
8683
STATEMENT_SKIP = STMTcreate( STMT_SKIP );
8784
STATEMENT_ESCAPE = STMTcreate( STMT_ESCAPE );
8885
}

src/express/type.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,10 @@ return( false );
256256
}
257257
#endif
258258

259-
Symbol * TYPE_get_symbol( void *t ) {
260-
return &( ( Type )t )->symbol;
261-
}
262-
263-
264259
/** Initialize the Type module */
265260
void TYPEinitialize() {
266261
ALLOCinitialize( &TYPEHEAD_fl, sizeof( struct TypeHead_ ), 500, 100 );
267262
ALLOCinitialize( &TYPEBODY_fl, sizeof( struct TypeBody_ ), 200, 100 );
268-
OBJcreate( OBJ_TYPE, TYPE_get_symbol, "type", OBJ_TYPE_BITS );
269-
/* OBJcreate(OBJ_TYPE,TYPE_get_symbol,"(headless) type", OBJ_UNFINDABLE_BITS);*/
270-
OBJcreate( OBJ_TAG, TYPE_get_symbol, "tag", OBJ_TYPE_BITS );
271-
272263
/* Very commonly-used read-only types */
273264
Type_Unknown = TYPEcreate( unknown_ );
274265
Type_Dont_Care = TYPEcreate( special_ );

0 commit comments

Comments
 (0)