Skip to content

Commit 14689c6

Browse files
committed
split ENTITYprint_new() into two, print into different files
* split into ENTITYprint_descriptors(), ENTITYprint_classes() * the former is now called from ENTITYprint_cc() * make some changes to the args (don't pass ComplexCollect, just a bool)
1 parent 01db378 commit 14689c6

File tree

4 files changed

+41
-44
lines changed

4 files changed

+41
-44
lines changed

src/exp2cxx/classes_entity.c

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
1616

1717
#include <sc_memmgr.h>
1818
#include <stdlib.h>
19+
#include <stdbool.h>
1920
#include <assert.h>
2021
#include <sc_mkdir.h>
2122
#include "classes.h"
@@ -1015,7 +1016,7 @@ void ENTITYPrint_h( const Entity entity, FILE * header, Linked_List neededAttr,
10151016
DEBUG( "DONE ENTITYPrint_h\n" );
10161017
}
10171018

1018-
void ENTITYPrint_cc( const Entity entity, FILE * header, FILE * impl, Linked_List neededAttr, Schema schema ) {
1019+
void ENTITYPrint_cc( const Entity entity, FILE * header, FILE * impl, Linked_List neededAttr, Schema schema, bool externMap ) {
10191020
const char * name = ENTITYget_classname( entity );
10201021

10211022
DEBUG( "Entering ENTITYPrint_cc for %s\n", name );
@@ -1033,6 +1034,7 @@ void ENTITYPrint_cc( const Entity entity, FILE * header, FILE * impl, Linked_Lis
10331034

10341035
fprintf( impl, "void init_%s( Registry& reg ) {\n", name );
10351036
fprintf( impl, " std::string str;\n\n" );
1037+
ENTITYprint_descriptors( entity, impl, schema, externMap );
10361038
ENTITYincode_print( entity, header, impl, schema );
10371039
fprintf( impl, "}\n\n" );
10381040

@@ -1153,7 +1155,7 @@ void ENTITYPrint( Entity entity, FILES * files, Schema schema, bool externMap )
11531155
fprintf( files->unity.entity.impl, "#include \"%s\"\n", names.impl );
11541156

11551157
ENTITYPrint_h( entity, hdr, remaining, schema );
1156-
ENTITYPrint_cc( entity, hdr, impl, remaining, schema );
1158+
ENTITYPrint_cc( entity, hdr, impl, remaining, schema, externMap );
11571159
FILEclose( hdr );
11581160
FILEclose( impl );
11591161

@@ -1191,32 +1193,30 @@ void ENTITYPrint( Entity entity, FILES * files, Schema schema, bool externMap )
11911193
* \p schema the current schema
11921194
* \p externMap true if entity must be instantiated with external mapping (see Part 21, sect 11.2.5.1).
11931195
*/
1194-
void ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap ) {
1195-
const char * n;
1196+
void ENTITYprint_descriptors( Entity entity, FILE * create, Schema schema, bool externMap ) {
11961197
Linked_List wheres;
11971198
char * whereRule, *whereRule_formatted = NULL;
11981199
size_t whereRule_formatted_size = 0;
11991200
char * ptr, *ptr2;
12001201
char * uniqRule, *uniqRule_formatted;
12011202
Linked_List uniqs;
12021203

1203-
fprintf( files->create, " %s::%s%s = new EntityDescriptor(\n ",
1204+
fprintf( create, " %s::%s%s = new EntityDescriptor(\n ",
12041205
SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
1205-
fprintf( files->create, " \"%s\", %s::schema, %s, ",
1206+
fprintf( create, " \"%s\", %s::schema, %s, ",
12061207
PrettyTmpName( ENTITYget_name( entity ) ),
12071208
SCHEMAget_name( schema ), ( ENTITYget_abstract( entity ) ? "LTrue" : "LFalse" ) );
1208-
fprintf( files->create, "%s,\n ", externMap ? "LTrue" :
1209-
"LFalse" );
1209+
fprintf( create, "%s,\n ", externMap ? "LTrue" : "LFalse" );
12101210

1211-
fprintf( files->create, " (Creator) create_%s );\n",
1211+
fprintf( create, " (Creator) create_%s );\n",
12121212
ENTITYget_classname( entity ) );
12131213
/* add the entity to the Schema dictionary entry */
1214-
fprintf( files->create, " %s::schema->AddEntity(%s::%s%s);\n", SCHEMAget_name( schema ), SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
1214+
fprintf( create, " %s::schema->AddEntity(%s::%s%s);\n", SCHEMAget_name( schema ), SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
12151215

12161216
wheres = TYPEget_where( entity );
12171217

12181218
if( wheres ) {
1219-
fprintf( files->create,
1219+
fprintf( create,
12201220
" %s::%s%s->_where_rules = new Where_rule__list;\n",
12211221
SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
12221222

@@ -1300,8 +1300,8 @@ void ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap
13001300
*ptr = '\0';
13011301
strcat( ptr, ");\\n" );
13021302
}
1303-
fprintf( files->create, " wr = new Where_rule(\"%s\");\n", whereRule_formatted );
1304-
fprintf( files->create, " %s::%s%s->_where_rules->Append(wr);\n",
1303+
fprintf( create, " wr = new Where_rule(\"%s\");\n", whereRule_formatted );
1304+
fprintf( create, " %s::%s%s->_where_rules->Append(wr);\n",
13051305
SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
13061306

13071307
sc_free( whereRule );
@@ -1312,7 +1312,7 @@ void ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap
13121312
uniqs = entity->u.entity->unique;
13131313

13141314
if( uniqs ) {
1315-
fprintf( files->create,
1315+
fprintf( create,
13161316
" %s::%s%s->_uniqueness_rules = new Uniqueness_rule__set;\n",
13171317
SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
13181318

@@ -1325,38 +1325,43 @@ void ENTITYprint_new( Entity entity, FILES * files, Schema schema, int externMap
13251325

13261326
LISTdo( uniqs, list, Linked_List ) {
13271327
int i = 0;
1328-
fprintf( files->create, " ur = new Uniqueness_rule(\"" );
1328+
fprintf( create, " ur = new Uniqueness_rule(\"" );
13291329
LISTdo_n( list, e, Expression, b ) {
13301330
i++;
13311331
if( i == 1 ) {
13321332
/* print label if present */
13331333
if( e ) {
1334-
fprintf( files->create, "%s : ", StrToUpper( ( ( Symbol * )e )->name ) );
1334+
fprintf( create, "%s : ", StrToUpper( ( ( Symbol * )e )->name ) );
13351335
}
13361336
} else {
13371337
if( i > 2 ) {
1338-
fprintf( files->create, ", " );
1338+
fprintf( create, ", " );
13391339
}
13401340
uniqRule = EXPRto_string( e );
1341-
fprintf( files->create, "%s", uniqRule );
1341+
fprintf( create, "%s", uniqRule );
13421342
sc_free( uniqRule );
13431343
}
13441344
} LISTod
1345-
fprintf( files->create, ";\\n\");\n" );
1346-
fprintf( files->create, " %s::%s%s->_uniqueness_rules->Append(ur);\n",
1345+
fprintf( create, ";\\n\");\n" );
1346+
fprintf( create, " %s::%s%s->_uniqueness_rules->Append(ur);\n",
13471347
SCHEMAget_name( schema ), ENT_PREFIX, ENTITYget_name( entity ) );
13481348
} LISTod
13491349
}
13501350

13511351
if( whereRule_formatted_size > 0 ) {
13521352
sc_free( whereRule_formatted );
13531353
}
1354+
}
13541355

1355-
n = ENTITYget_classname( entity );
1356-
fprintf( files->classes, "\nclass %s;\n", n );
1357-
fprintf( files->classes, "typedef %s * %sH;\n", n, n );
1358-
fprintf( files->classes, "typedef %s * %s_ptr;\n", n, n );
1359-
fprintf( files->classes, "typedef %s_ptr %s_var;\n", n, n );
1360-
fprintf( files->classes, "#define %s__set SDAI_DAObject__set\n", n );
1361-
fprintf( files->classes, "#define %s__set_var SDAI_DAObject__set_var\n", n );
1356+
/** print in classes file: class forward prototype, class typedefs
1357+
* split out of ENTITYprint_new, which is now ENTITYprint_descriptors
1358+
*/
1359+
void ENTITYprint_classes( Entity entity, FILE * classes ) {
1360+
const char * n = ENTITYget_classname( entity );
1361+
fprintf( classes, "\nclass %s;\n", n );
1362+
fprintf( classes, "typedef %s * %sH;\n", n, n );
1363+
fprintf( classes, "typedef %s * %s_ptr;\n", n, n );
1364+
fprintf( classes, "typedef %s_ptr %s_var;\n", n, n );
1365+
fprintf( classes, "#define %s__set SDAI_DAObject__set\n", n );
1366+
fprintf( classes, "#define %s__set_var SDAI_DAObject__set_var\n", n );
13621367
}

src/exp2cxx/classes_entity.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ Entity ENTITYget_superclass( Entity entity );
66
Entity ENTITYput_superclass( Entity entity );
77
int ENTITYhas_explicit_attributes( Entity e );
88
void ENTITYget_first_attribs( Entity entity, Linked_List result );
9-
10-
void ENTITYPrint( Entity, FILES *, Schema );
11-
void ENTITYprint_new( Entity, FILES *, Schema, int );
12-
9+
void ENTITYPrint( Entity entity, FILES * files, Schema schema, bool externMap );
10+
void ENTITYprint_descriptors( Entity entity, FILE* create, Schema schema, bool externMap );
11+
void ENTITYprint_classes( Entity entity, FILE * classes );
1312
#endif

src/exp2cxx/classes_wrapper.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,10 @@ void SCOPEPrint( Scope scope, FILES * files, Schema schema, ComplexCollect * col
182182

183183
SCOPEod;
184184

185-
/* do \'new\'s for entity descriptors */
186-
fprintf( files->create, "\n // ***** Initialize the Entities\n" );
187-
fprintf( files->classes, "\n// Entities:" );
188-
LISTdo( list, e, Entity );
189-
/* Print in include file: class forward prototype, class typedefs,
190-
and extern EntityDescriptor. (ENTITYprint_new() combines the
191-
functionality of TYPEprint_new() & print_typedefs() above.) */
192-
ENTITYprint_new( e, files, schema,
193-
col->externMapping( ENTITYget_name( e ) ) );
194-
LISTod;
195-
fprintf( files->create, "\n" );
185+
fprintf( files->classes, "\n// Entity class typedefs:" );
186+
LISTdo( list, e, Entity ) {
187+
ENTITYprint_classes( e, files->classes );
188+
} LISTod
196189
}
197190

198191
/* fill in the values for the type descriptors */
@@ -276,7 +269,7 @@ void SCOPEPrint( Scope scope, FILES * files, Schema schema, ComplexCollect * col
276269
fprintf( files->inc, "\n// ***** Print Entity Classes \n" );
277270
LISTdo( list, e, Entity );
278271
if( e->search_id == CANPROCESS ) {
279-
ENTITYPrint( e, files, schema );
272+
ENTITYPrint( e, files, schema, col->externMapping( ENTITYget_name( e ) ) );
280273
e->search_id = PROCESSED;
281274
}
282275
LISTod;

src/exp2cxx/complexSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class ComplexCollect {
412412
// it's used elsewhere.
413413
ComplexList * find( char * );
414414
int supports( EntNode * );
415-
int externMapping( const char * ent ) {
415+
bool externMapping( const char * ent ) {
416416
return ( clists ? clists->isDependent( ent ) : 0 );
417417
}
418418
// One of our clists shows that ent will have to be instantiated

0 commit comments

Comments
 (0)