in generated code, use pointer for all aggregate members

This commit is contained in:
Mark Pictor
2012-02-09 19:02:36 -05:00
parent 3aee5f353c
commit 809e1dd495
2 changed files with 43 additions and 58 deletions
+9 -5
View File
@@ -672,9 +672,9 @@ void AGGRprint_access_methods( CONST char * entnm, Variable a, FILE * file, Type
char * ctype, char * attrnm ) {
ATTRprint_access_methods_get_head( entnm, a, file );
fprintf( file, "{\n" );
fprintf( file, " return (%s) &_%s; \n}\n", ctype, attrnm );
fprintf( file, " return (%s) %s_%s;\n}\n", ctype,( ( a->type->u.type->body->base ) ? "" : "&"), attrnm );
ATTRprint_access_methods_put_head( entnm, a, file );
fprintf( file, " { _%s.ShallowCopy (*x); }\n", attrnm );
fprintf( file, "{\n _%s%sShallowCopy (*x);\n}\n", attrnm, ( ( a->type->u.type->body->base ) ? "->" : ".") );
return;
}
@@ -1081,6 +1081,8 @@ void DataMemberPrintAttr( Entity entity, Variable a, FILE * file ) {
}
if( TYPEis_entity( VARget_type( a ) ) ) {
fprintf( file, " SDAI_Application_instance_ptr _%s ;", attrnm );
} else if( TYPEis_aggregate( VARget_type( a ) ) ) {
fprintf( file, " %s_ptr _%s ;", ctype, attrnm );
} else {
fprintf( file, " %s _%s ;", ctype, attrnm );
}
@@ -1572,13 +1574,14 @@ void LIBstructor_print( Entity entity, FILE * file, Schema schema ) {
/* 1. create a new STEPattribute */
fprintf( file, " "
"%sa = new STEPattribute(*%s::%s%d%s%s, %s &_%s);\n",
( first ? "STEPattribute *" : "" ), // first time through, declare a
"%sa = new STEPattribute(*%s::%s%d%s%s, %s %s_%s);\n",
( first ? "STEPattribute *" : "" ), // first time through, declare 'a'
SCHEMAget_name( schema ),
ATTR_PREFIX, count,
( VARis_type_shifter( a ) ? "R" : "" ),
attrnm,
( TYPEis_entity( t ) ? "(SDAI_Application_instance_ptr *)" : "" ),
( TYPEis_aggregate( t ) ? "" : "&" ),
attrnm );
if( first ) {
first = 0 ;
@@ -1754,13 +1757,14 @@ void LIBstructor_print_w_args( Entity entity, FILE * file, Schema schema ) {
/* 1. create a new STEPattribute */
fprintf( file, " "
"%sa = new STEPattribute(*%s::%s%d%s%s, %s &_%s);\n",
"%sa = new STEPattribute(*%s::%s%d%s%s, %s %s_%s);\n",
( first ? "STEPattribute *" : "" ), // first time through, declare a
SCHEMAget_name( schema ),
ATTR_PREFIX, count,
( VARis_type_shifter( a ) ? "R" : "" ),
attrnm,
( TYPEis_entity( t ) ? "(SDAI_Application_instance_ptr *)" : "" ),
( TYPEis_aggregate( t ) ? "" : "&" ),
attrnm );
if( first ) {
+34 -53
View File
@@ -571,12 +571,10 @@ SEL_TYPEgetnew_attribute_list( const Type type ) {
return newlist;
}
/*******************
TYPEselect_inc_print_vars prints the class 'definition', that is, the objects
and the constructor(s)/destructor for a select class.
********************/
void
TYPEselect_inc_print_vars( const Type type, FILE * f, Linked_List dups ) {
/** prints the class 'definition', that is, the objects
* and the constructor(s)/destructor for a select class.
*/
void TYPEselect_inc_print_vars( const Type type, FILE * f, Linked_List dups ) {
int size, j;
Linked_List data_members = SELgetnew_dmlist( type );
char dmname [BUFSIZ],
@@ -848,7 +846,8 @@ TYPEselect_lib_print_part_one( const Type type, FILE * f, Schema schema,
fprintf( f, " }\n#endif\n" );
if( isAggregateType( t ) ) {
fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " _%s%sShallowCopy (*o);\n", SEL_ITEMget_dmname( t ),
( ( t->u.type->body->base ) ? "->" : "." ) );
} else {
fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) );
}
@@ -881,7 +880,7 @@ TYPEselect_lib_print_part_one( const Type type, FILE * f, Schema schema,
" *logStream << \"DAVE ERR entering %s constructor.\""
" << std::endl;\n", n );
fprintf( f, " }\n#endif\n" );
fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " _%s%sShallowCopy (*o);\n", SEL_ITEMget_dmname( t ), ( ( t->u.type->body->base ) ? "->" : "." ) );
} else {
fprintf( f, "%s::%s( const %s& o,\n", n, n, TYPEget_utype( t ) );
for( j = 0; j < size; j++ ) {
@@ -1216,7 +1215,8 @@ TYPEselect_lib_print_part_four( const Type type, FILE * f, Schema schema,
n, n, AccessType( t ) );
if( isAggregateType( t ) ) {
fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " _%s%sShallowCopy (*o);\n", SEL_ITEMget_dmname( t ),
( ( t->u.type->body->base ) ? "->" : "." ) );
} else {
fprintf( f, " _%s = o;\n", SEL_ITEMget_dmname( t ) );
}
@@ -1230,7 +1230,7 @@ TYPEselect_lib_print_part_four( const Type type, FILE * f, Schema schema,
if( isAggregateType( t ) ) {
fprintf( f, "%s& %s::operator =( const %s& o )\n{\n",
n, n, AccessType( t ) );
fprintf( f, " _%s.ShallowCopy (*o);\n", SEL_ITEMget_dmname( t ) );
fprintf( f, " _%s%sShallowCopy (*o);\n", SEL_ITEMget_dmname( t ), ( ( t->u.type->body->base ) ? "->" : "." ) );
} else {
fprintf( f, "%s& %s::operator =( const %s& o )\n{\n",
n, n, TYPEget_utype( t ) );
@@ -1405,18 +1405,11 @@ TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) {
case string_:
case enumeration_:
case aggregate_:
case array_:
case bag_:
case set_:
case list_:
case logical_:
case boolean_:
case binary_:
/* for string\'s, enum\'s, select\'s, binary\'s, and aggregate\'s
it\'ll be embedded;
*/
fprintf( f, "\t_%s.STEPwrite (out);\n else ", dm );
/* for string's, enum's, select's, and binary's it'll be embedded */
fprintf( f, " _%s.STEPwrite (out);\n else ", dm );
break;
case select_:
@@ -1427,6 +1420,12 @@ TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) {
// schema which USEs "DATA" and renames it to "VAL"), we pass currSch. */
break;
// aggregate, array, bag, set, and list were above with string, binary, etc. moved them because they will be pointers
case aggregate_:
case array_:
case bag_:
case set_:
case list_:
default:
/* otherwise it's a pointer */
fprintf( f, " _%s -> STEPwrite (out);\n else ", dm );
@@ -1518,7 +1517,8 @@ TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) {
case list_:
/* Aggregates need currSch passed since they may be aggrs of sels. */
fprintf( f, " {\n out << tmp << \"(\";\n" );
fprintf( f, " _%s.STEPwrite (out, currSch);\n", dm );
fprintf( f, " _%s%sSTEPwrite (out, currSch);\n", dm,
( ( t->u.type->body->base ) ? "->" : "." ) );
fprintf( f, " out << \")\";\n }\n else " );
break;
case select_:
@@ -1608,12 +1608,11 @@ TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) {
case bag_:
case set_:
case list_:
fprintf( f,
" {\n\t_%s.STEPread (in, &_error,\n"
"\t\t\t %s -> AggrElemTypeDescriptor (),\n"
"\t\t\t instances, addFileId, currSch);\n"
"\treturn severity ();\n }\n",
dm, TYPEtd_name( t ) );
fprintf( f, " {\n _%s%sSTEPread (in, &_error, %s -> AggrElemTypeDescriptor (),\n"
" instances, addFileId, currSch);\n", dm,
( ( t->u.type->body->base ) ? "->" : "." ),
TYPEtd_name( t ) );
fprintf( f, " return severity ();\n }\n" );
break;
default:
@@ -1627,17 +1626,9 @@ TYPEselect_lib_part21( const Type type, FILE * f, Schema schema ) {
LISTod;
PRINT_SELECTBUG_WARNING( f ) ;
fprintf( f, "#ifdef __SUNCPLUSPLUS__\n"
"std::cerr << instances << \" \" << addFileId << std::endl;\n"
"#endif\n" );
LISTfree( data_members );
fprintf( f,
/* "#ifdef __GNUG__\n"*/
/* "\n return SEVERITY_NULL;\n"*/
/* "#endif"*/
"\n return severity ();"
"\n}\n" );
fprintf( f, "\n return severity ();\n}\n" );
}
@@ -1704,8 +1695,7 @@ TYPEselect_lib_StrToVal( const Type type, FILE * f, Schema schema ) {
case list_:
fprintf( f, " case %s : \n", FundamentalType( t, 0 ) );
fprintf( f, " return _%s%sStrToVal (str, &_error, %s -> AggrElemTypeDescriptor ());\n", SEL_ITEMget_dmname( t ),
( ( ( t->u.type->body->base )
&& (t->u.type->body->base->u.type->body->type == select_ ) ) ? "->" : "." ),
( ( t->u.type->body->base ) ? "->" : "." ),
TYPEtd_name( t ) );
break;
@@ -1825,26 +1815,18 @@ TYPEselect_lib_print( const Type type, FILE * f, Schema schema ) {
LISTdo( SEL_TYPEget_items( type ), t, Type )
if( TYPEis_entity( t ) ) {
/* if an entity */
fprintf( f, "%s::operator %s_ptr()\n{\n", n,
ClassName( TYPEget_name( t ) ) );
fprintf( f, " if( CurrentUnderlyingType () == %s )\n",
TYPEtd_name( t ) );
fprintf( f, " return ((%s_ptr) _%s);\n",
ClassName( TYPEget_name( t ) ),
SEL_ITEMget_dmname( t ) );
fprintf( f, "%s::operator %s_ptr()\n{\n", n, ClassName( TYPEget_name( t ) ) );
fprintf( f, " if( CurrentUnderlyingType () == %s )\n", TYPEtd_name( t ) );
fprintf( f, " return ((%s_ptr) _%s);\n", ClassName( TYPEget_name( t ) ), SEL_ITEMget_dmname( t ) );
PRINT_SELECTBUG_WARNING( f );
fprintf( f, " return NULL;\n}\n\n" );
} else if( !utype_member( dups, t, 1 ) ) {
/** if not in the dup list **/
fprintf( f, "%s::operator %s()\n{\n", n, AccessType( t ) );
fprintf( f, " if( CurrentUnderlyingType () == %s )\n",
TYPEtd_name( t ) );
fprintf( f, " return %s _%s;\n",
( ( TYPEis_aggregate( t ) || TYPEis_select( t ) ) ? "&" : "" ),
SEL_ITEMget_dmname( t ) );
fprintf( f, " if( CurrentUnderlyingType () == %s )\n", TYPEtd_name( t ) );
fprintf( f, " return %s _%s;\n", ( ( TYPEis_select( t ) ) ? "&" : "" ), SEL_ITEMget_dmname( t ) );
fprintf( f, "\n severity( SEVERITY_WARNING );\n" );
fprintf( f, " Error( \"Underlying type is not %s\" );\n",
AccessType( t ) );
fprintf( f, " Error( \"Underlying type is not %s\" );\n", AccessType( t ) );
PRINT_SELECTBUG_WARNING( f ) ;
if( TYPEis_boolean( t ) || TYPEis_logical( t ) ) {
fprintf( f, " return (%s)0;\n}\n\n", TYPEget_utype( t ) );
@@ -1870,8 +1852,7 @@ TYPEselect_lib_print( const Type type, FILE * f, Schema schema ) {
fprintf( f, " if( CurrentUnderlyingType () == %s )\n",
TYPEtd_name( x ) );
fprintf( f, " return %s _%s;\n",
( ( TYPEis_aggregate( x ) || TYPEis_select( x ) ) ?
"&" : "" ),
( ( TYPEis_select( x ) ) ? "&" : "" ),
SEL_ITEMget_dmname( x ) );
}
LISTod;