Revision: 50630
http://brlcad.svn.sourceforge.net/brlcad/?rev=50630&view=rev
Author: n_reed
Date: 2012-05-22 17:58:52 +0000 (Tue, 22 May 2012)
Log Message:
-----------
apply more changes from SCL git 290850a: cleanup some multiple inheritance code
- passing around attribute list to print routines instead of rebuilding it
Modified Paths:
--------------
brlcad/trunk/src/other/step/src/fedex_plus/classes.c
brlcad/trunk/src/other/step/src/fedex_plus/classes.h
brlcad/trunk/src/other/step/src/fedex_plus/selects.c
Modified: brlcad/trunk/src/other/step/src/fedex_plus/classes.c
===================================================================
--- brlcad/trunk/src/other/step/src/fedex_plus/classes.c 2012-05-22
15:36:42 UTC (rev 50629)
+++ brlcad/trunk/src/other/step/src/fedex_plus/classes.c 2012-05-22
17:58:52 UTC (rev 50630)
@@ -1069,57 +1069,75 @@
}
/**************************************************************//**
- ** Procedure: DataMemberPrint
- ** Parameters: const Entity entity -- entity being processed
- ** FILE* file -- file being written to
+ ** Procedure: DataMemberPrintAttr
+ ** Parameters: Entity entity -- entity being processed
+ ** Variable a -- attribute being processed
+ ** FILE* file -- file being written to
** Returns:
- ** Description: prints out the data members for an entity's c++ class
+ ** Description: prints out the current attribute for an entity's c++ class
** definition
- ** Side Effects: generates c++ code
- ** Status: ok 1/15/91
******************************************************************/
-void DataMemberPrint( Entity entity, FILE * file, Schema schema ) {
- Linked_List attr_list;
- char entnm [BUFSIZ];
+void DataMemberPrintAttr( Entity entity, Variable a, FILE * file ) {
char attrnm [BUFSIZ];
-
const char * ctype, * etype;
-
- strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm
*/
-
- /* print list of attributes in the protected access area */
-
- fprintf( file, " protected:\n" );
-
- attr_list = ENTITYget_attributes( entity );
- LISTdo( attr_list, a, Variable )
if( VARget_initializer( a ) == EXPRESSION_NULL ) {
ctype = TYPEget_ctype( VARget_type( a ) );
generate_attribute_name( a, attrnm );
if( !strcmp( ctype, "SCLundefined" ) ) {
printf( "WARNING: in entity %s:\n", ENTITYget_name( entity ) );
- printf( "\tthe type for attribute %s is not fully implemented\n",
attrnm );
+ printf( " the type for attribute %s is not fully
implemented\n", attrnm );
}
if( TYPEis_entity( VARget_type( a ) ) ) {
- fprintf( file, "\tSDAI_Application_instance_ptr _%s ;", attrnm );
+ fprintf( file, " SDAI_Application_instance_ptr _%s ;",
attrnm );
} else {
- fprintf( file, "\t%s _%s ;", ctype, attrnm );
+ fprintf( file, " %s _%s ;", ctype, attrnm );
}
if( VARget_optional( a ) ) {
fprintf( file, " // OPTIONAL" );
}
if( isAggregate( a ) ) {
/* if it's a named type, comment the type */
- etype = TYPEget_name ( TYPEget_nonaggregate_base_type(
VARget_type( a ) ) );
- if( etype ) {
- fprintf( file, "\t // of %s\n", etype );
+ if( ( etype = TYPEget_name
+ ( TYPEget_nonaggregate_base_type( VARget_type( a ) )
) ) ) {
+ fprintf( file, " // of %s\n", etype );
}
}
fprintf( file, "\n" );
}
+}
+/**************************************************************//**
+ ** Procedure: DataMemberPrint
+ ** Parameters: const Entity entity -- entity being processed
+ ** FILE* file -- file being written to
+ ** Returns:
+ ** Description: prints out the data members for an entity's c++ class
+ ** definition
+ ** Side Effects: generates c++ code
+ ** Status: ok 1/15/91
+ ******************************************************************/
+void DataMemberPrint( Entity entity, Linked_List neededAttr, FILE * file,
Schema schema ) {
+ Linked_List attr_list;
+ char entnm [BUFSIZ];
+ strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm
*/
+
+ /* print list of attributes in the protected access area */
+ fprintf( file, " protected:\n" );
+
+ attr_list = ENTITYget_attributes( entity );
+ LISTdo( attr_list, attr, Variable ) {
+ DataMemberPrintAttr( entity, attr, file );
+ }
LISTod;
+
+ // add attributes for parent attributes not inherited through C++
inheritance.
+ if( multiple_inheritance ) {
+ LISTdo( neededAttr, attr, Variable ) {
+ DataMemberPrintAttr( entity, attr, file );
+ }
+ LISTod;
+ }
}
/**************************************************************//**
@@ -1134,30 +1152,32 @@
******************************************************************/
enum CollectType { ALL, ALL_BUT_FIRST, FIRST_ONLY };
-void collectAttributes( Linked_List curList, Entity curEntity, enum
CollectType collect ) {
+static void collectAttributes( Linked_List curList, const Entity curEntity,
enum CollectType collect ) {
Linked_List parent_list = ENTITYget_supertypes( curEntity );
if( ! LISTempty( parent_list ) ) {
- Link first = LINKnext( parent_list -> mark );
-
- if ( collect == FIRST_ONLY ) {
- collectAttributes( curList, first , ALL );
+ if( collect != FIRST_ONLY ) {
+ // collect attributes from parents and their supertypes
+ LISTdo( parent_list, e, Entity ) {
+ if ( collect == ALL_BUT_FIRST ) {
+ // skip first and collect from the rest
+ collect = ALL;
+ } else {
+ // collect attributes of this parent and its supertypes
+ collectAttributes( curList, e, ALL );
+ }
+ }
+ LISTod;
} else {
- if ( collect == ALL_BUT_FIRST ) {
- // remove first parent before proceeding
- parent_list -> mark -> next = LINKnext( first );
- LINK_destroy( first );
- }
- // collect attributes for all parents
- LISTdo( parent_list, e, Entity )
- collectAttributes( curList, e, ALL );
- LISTod
+ // collect attributes of only first parent and its supertypes
+ collectAttributes( curList, ( Entity ) LISTpeek_first( parent_list
), ALL );
}
}
- // parse the attributes of the parent and add to the current list
- LISTdo( ENTITYget_attributes( curEntity ), a, Variable )
- LISTadd_first( curList, ( Generic ) a );
- LISTod
+ // prepend this entity's attributes to the result list
+ LISTdo( ENTITYget_attributes( curEntity ), attr, Variable ) {
+ LISTadd_first( curList, ( Generic ) attr );
+ }
+ LISTod;
}
/**************************************************************//**
@@ -1174,88 +1194,58 @@
** updated 17-Feb-1992 to print only the signature
and not the function definitions
******************************************************************/
-void MemberFunctionSign( Entity entity, FILE * file ) {
+void MemberFunctionSign( Entity entity, Linked_List neededAttr, FILE * file ) {
Linked_List attr_list;
static int entcode = 0;
char entnm [BUFSIZ];
- /* added for calling multiple_inheritance */
- Linked_List parent_attr_list;
- Linked_List parent_list;
- Entity super = 0;
- int super_cnt = 0;
-
strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm
*/
fprintf( file, " public: \n" );
/* put in member functions which belong to all entities */
/* constructor: */
- fprintf( file, "\n %s ( ); \n", entnm );
+ fprintf( file, "\n %s ( ); \n", entnm );
- fprintf( file, "\t%s (SDAI_Application_instance *se, int *addAttrs = 0);
\n", entnm );
+ fprintf( file, " %s (SDAI_Application_instance *se, int *addAttrs =
0); \n", entnm );
/* copy constructor*/
- fprintf( file, " %s (%s& e ); \n", entnm, entnm );
+ fprintf( file, " %s (%s& e ); \n", entnm, entnm );
/* destructor: */
- fprintf( file, " ~%s ();\n", entnm );
+ fprintf( file, " ~%s ();\n", entnm );
- fprintf( file, " int opcode () { return %d ; } \n",
+ fprintf( file, " int opcode () { return %d ; } \n",
entcode++ );
/* print signature of access functions for attributes */
attr_list = ENTITYget_attributes( entity );
- LISTdo( attr_list, a, Variable )
- if( VARget_initializer( a ) == EXPRESSION_NULL ) {
+ LISTdo( attr_list, a, Variable ) {
+ if( VARget_initializer( a ) == EXPRESSION_NULL ) {
- /* retrieval and assignment */
- ATTRsign_access_methods( a, file );
+ /* retrieval and assignment */
+ ATTRsign_access_methods( a, file );
+ }
}
-
LISTod;
+ /* //////////////// */
if( multiple_inheritance ) {
- /* could print out access functions for parent attributes not
- inherited through C++ inheritance. */
- parent_list = ENTITYget_supertypes( entity );
- if( ! LISTempty( parent_list ) ) {
-
- LISTdo( parent_list, e, Entity )
- /* if there\'s no super class yet,
- or the super class doesn\'t have any attributes
- */
-
- super = e;
- super_cnt++;
- if( super_cnt == 1 ) {
- /* ignore the 1st parent */
- fprintf( file,
- "\t/* The first parent's access functions are
*/\n%s\n",
- "\t/* above or covered by inherited functions. */" );
- } else {
- fprintf( file, "\n#if 0\n" );
-
- parent_attr_list = ENTITYget_attributes( e );
- LISTdo( parent_attr_list, a2, Variable )
- /* do for EXPLICIT, REDEFINED, and INVERSE attributes - but
not DERIVED */
- if( ! VARis_derived( a2 ) ) {
-
- /* retrieval and assignment */
- ATTRsign_access_methods( a2, file );
- }
- LISTod;
- fprintf( file, "\n#endif\n" );
+ // add the EXPRESS inherited attributes which are non
+ // inherited in C++
+ LISTdo( neededAttr, attr, Variable ) {
+ if( ! VARis_derived( attr ) && ! VARis_overrider( entity, attr ) )
{
+ ATTRsign_access_methods( attr, file );
}
- LISTod;
}
+ LISTod;
+
}
-
+ /* //////////////// */
fprintf( file, "};\n" );
/* print creation function for class */
fprintf( file, "inline %s *\ncreate_%s () { return new %s ; }\n",
entnm, entnm, entnm );
-
}
/**************************************************************//**
@@ -1302,19 +1292,17 @@
** Side Effects: prints c++ code to a file
** Status: ok 17-Feb-1992
******************************************************************/
-void LIBmemberFunctionPrint( Entity entity, FILE * file ) {
+void LIBmemberFunctionPrint( Entity entity, Linked_List neededAttr, FILE *
file ) {
Linked_List attr_list;
char entnm [BUFSIZ];
- /* added for calling multiple_inheritance */
- Linked_List parent_attr_list;
- Linked_List parent_list;
- int super_cnt = 0;
-
strncpy( entnm, ENTITYget_classname( entity ), BUFSIZ ); /* assign entnm
*/
- /* print access functions for attributes */
+ /* 1. put in member functions which belong to all entities */
+ /* the common function are still in the class definition 17-Feb-1992 */
+
+ /* 2. print access functions for attributes */
attr_list = ENTITYget_attributes( entity );
LISTdo( attr_list, a, Variable )
/* do for EXPLICIT, REDEFINED, and INVERSE attributes - but not DERIVED */
@@ -1324,41 +1312,17 @@
ATTRprint_access_methods( entnm, a, file );
}
LISTod;
-
+ /* //////////////// */
if( multiple_inheritance ) {
- /* could print out access functions for parent attributes not
- inherited through C++ inheritance. */
- parent_list = ENTITYget_supertypes( entity );
- if( ! LISTempty( parent_list ) ) {
-
- LISTdo( parent_list, e, Entity )
- /* if there\'s no super class yet,
- or the super class doesn\'t have any attributes
- */
-
- super_cnt++;
- if( super_cnt == 1 ) {
- /* ignore the 1st parent */
- fprintf( file,
- "\t/* The first parent's access functions are
*/\n%s\n",
- "\t/* above or covered by inherited functions. */" );
- } else {
- fprintf( file, "\n#if 0\n" );
-
- parent_attr_list = ENTITYget_attributes( e );
- LISTdo( parent_attr_list, a2, Variable )
- /* do for EXPLICIT, REDEFINED, and INVERSE attributes - but
not DERIVED */
- if( ! VARis_derived( a2 ) ) {
-
- /* retrieval and assignment */
- ATTRprint_access_methods( entnm, a2, file );
- }
- LISTod;
- fprintf( file, "\n#endif\n" );
+ LISTdo( neededAttr, attr, Variable ) {
+ if( ! VARis_derived( attr ) && ! VARis_overrider( entity, attr ) )
{
+ ATTRprint_access_methods( entnm, attr, file );
}
- LISTod;
}
+ LISTod;
}
+ /* //////////////// */
+
}
/**************************************************************//**
@@ -1370,10 +1334,10 @@
** Side Effects: prints segment of the c++ .h file
** Status: ok 1/15/91
******************************************************************/
-void ENTITYinc_print( Entity entity, FILE * file, Schema schema ) {
+void ENTITYinc_print( Entity entity, Linked_List neededAttr, FILE * file,
Schema schema ) {
ENTITYhead_print( entity, file, schema );
- DataMemberPrint( entity, file, schema );
- MemberFunctionSign( entity, file );
+ DataMemberPrint( entity, neededAttr, file, schema );
+ MemberFunctionSign( entity, neededAttr, file );
}
/**************************************************************//**
@@ -1863,13 +1827,13 @@
** Side Effects: generates code segment for c++ library file
** Status: ok 1/15/91
******************************************************************/
-void ENTITYlib_print( Entity entity, FILE * file, Schema schema ) {
+void ENTITYlib_print( Entity entity, Linked_List neededAttr, FILE * file,
Schema schema ) {
LIBdescribe_entity( entity, file, schema );
LIBstructor_print( entity, file, schema );
if( multiple_inheritance ) {
LIBstructor_print_w_args( entity, file, schema );
}
- LIBmemberFunctionPrint( entity, file );
+ LIBmemberFunctionPrint( entity, neededAttr, file );
}
/** return 1 if types are predefined by us */
@@ -2251,6 +2215,17 @@
#undef schema_name
}
+static bool listContainsVar( Linked_List l, Variable v ) {
+ const char *vName = VARget_simple_name( v );
+ LISTdo( l, curr, Variable ) {
+ if ( streq( vName, VARget_simple_name( curr ) ) ) {
+ return true;
+ }
+ }
+ LISTod;
+ return false;
+}
+
/**************************************************************//**
** Procedure: ENTITYPrint
** Parameters: Entity *entity -- entity being processed
@@ -2262,16 +2237,41 @@
** Status: complete 1/15/91
******************************************************************/
void ENTITYPrint( Entity entity, FILES * files, Schema schema ) {
+ char * n = ENTITYget_name( entity );
+ Linked_List remaining = LISTcreate();
- char * n = ENTITYget_name( entity );
DEBUG( "Entering ENTITYPrint for %s\n", n );
+ if( multiple_inheritance ) {
+ Linked_List existing = LISTcreate();
+ Linked_List required = LISTcreate();
+
+ // create list of attr inherited from the parents in C++
+ collectAttributes( existing, entity, FIRST_ONLY );
+
+ // create list of attr that have to be inherited in EXPRESS
+ collectAttributes( required, entity, ALL_BUT_FIRST );
+
+ // build list of unique attr that are required but havn't been
+ // inherited
+ LISTdo( required, attr, Variable ) {
+ if( !listContainsVar( existing, attr ) &&
+ !listContainsVar( remaining, attr ) )
+ {
+ LISTadd_first( remaining, ( Generic ) attr );
+ }
+ }
+ LISTod;
+ LIST_destroy( existing );
+ LIST_destroy( required );
+ }
+
fprintf( files->inc, "\n/////////\t ENTITY %s\n\n", n );
- ENTITYinc_print( entity, files -> inc, schema );
+ ENTITYinc_print( entity, remaining, files -> inc, schema );
fprintf( files->inc, "\n/////////\t END_ENTITY %s\n\n", n );
fprintf( files->lib, "\n/////////\t ENTITY %s\n\n", n );
- ENTITYlib_print( entity, files -> lib, schema );
+ ENTITYlib_print( entity, remaining, files -> lib, schema );
fprintf( files->lib, "\n/////////\t END_ENTITY %s\n\n", n );
fprintf( files->init, "\n/////////\t ENTITY %s\n\n", n );
@@ -2279,6 +2279,7 @@
fprintf( files->init, "/////////\t END_ENTITY %s\n", n );
DEBUG( "DONE ENTITYPrint\n" ) ;
+ LIST_destroy( remaining );
}
void MODELPrintConstructorBody( Entity entity, FILES * files, Schema schema ) {
Modified: brlcad/trunk/src/other/step/src/fedex_plus/classes.h
===================================================================
--- brlcad/trunk/src/other/step/src/fedex_plus/classes.h 2012-05-22
15:36:42 UTC (rev 50629)
+++ brlcad/trunk/src/other/step/src/fedex_plus/classes.h 2012-05-22
17:58:52 UTC (rev 50630)
@@ -139,6 +139,8 @@
/*Variable*/
#define VARis_simple_derived(a) (!VARis_overrider(a))
+Variable VARis_overrider( Entity e, Variable a );
+
/* Added for multiple schema support: */
void print_schemas_separate( Express, void *, FILES * );
void getMCPrint( Express, FILE *, FILE * );
Modified: brlcad/trunk/src/other/step/src/fedex_plus/selects.c
===================================================================
--- brlcad/trunk/src/other/step/src/fedex_plus/selects.c 2012-05-22
15:36:42 UTC (rev 50629)
+++ brlcad/trunk/src/other/step/src/fedex_plus/selects.c 2012-05-22
17:58:52 UTC (rev 50630)
@@ -1053,20 +1053,18 @@
{
/* for the select items which have the current attribute */
-
- /* if ( !multiple_inheritance ) { */
- if( !memberOfEntPrimary( ent, uattr ) ) {
- /* If multiple inheritance is not supported, we must addi-
- tionally check that uattr is a member of the entity's
- primary inheritance path (i.e., the entity, its first
- supertype, the super's first super, etc). The above
- `if' is commented out, because currently mult inher is
- not supported to the extent of handling accessor func-
- tions for non-primary supertypes. */
- continue;
+ if( !multiple_inheritance ) {
+ if( !memberOfEntPrimary( ent, uattr ) ) {
+ /* If multiple inheritance is not supported, we must addi-
+ tionally check that uattr is a member of the entity's
+ primary inheritance path (i.e., the entity, its first
+ supertype, the super's first super, etc). The above
+ `if' is commented out, because currently mult inher is
+ not supported to the extent of handling accessor func-
+ tions for non-primary supertypes. */
+ continue;
+ }
}
- /* } */
-
if( ! VARis_derived( uattr ) ) {
if( !strcmp( utype, TYPEget_ctype( VARget_type( uattr ) ) ) )
{
@@ -1078,6 +1076,13 @@
/* if the underlying type is that item\'s type
call the underlying_item\'s member function */
+ // if it is the same attribute
+ if( VARis_overrider( ENT_TYPEget_entity( t ), uattr ) ) {
+ // update attribute_func_name because is has been
overrid
+ generate_attribute_func_name( uattr, funcnm );
+ } else {
+ generate_attribute_func_name( a, funcnm );
+ }
fprintf( f,
" if( CurrentUnderlyingType () == %s ) \n\t//
%s\n",
TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) )
);
@@ -1150,12 +1155,12 @@
{
/* for the select items which have the current attribute */
- /* if ( !multiple_inheritance ) { */
- if( !memberOfEntPrimary( ent, uattr ) ) {
- /* See note for similar code segment in 1st part of fn. */
- continue;
+ if( !multiple_inheritance ) {
+ if( !memberOfEntPrimary( ent, uattr ) ) {
+ /* See note for similar code segment in 1st part of fn. */
+ continue;
+ }
}
- /* } */
if( ! VARis_derived( uattr ) ) {
@@ -1166,19 +1171,31 @@
/* if the underlying type is that item\'s type
call the underlying_item\'s member function */
+ // if it is the same attribute
+ if( VARis_overrider( ENT_TYPEget_entity( t ), uattr ) ) {
+ // update attribute_func_name because is has been
overrid
+ generate_attribute_func_name( uattr, funcnm );
+ } else {
+ generate_attribute_func_name( a, funcnm );
+ }
+
strncpy( uent, TYPEget_ctype( t ), BUFSIZ );
fprintf( f,
" if( CurrentUnderlyingType () == %s ) \n\t//
%s\n",
TYPEtd_name( t ), StrToUpper( TYPEget_name( t ) )
);
fprintf( f, "\t{ ((%s) _%s) ->%s( x );\n\t
return;\n\t}\n",
uent, SEL_ITEMget_dmname( t ), funcnm );
- } else /* warning printed above */
+ } else {
+ /* warning printed above */
fprintf( f, " // for %s attribute access function"
" has a different argument type\n",
SEL_ITEMget_enumtype( t ) );
- } else /* derived attributes */
+ }
+ } else {
+ /* derived attributes */
fprintf( f, " // for %s attribute is derived\n",
SEL_ITEMget_enumtype( t ) );
+ }
}
LISTod;
PRINT_SELECTBUG_WARNING( f );
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits