break up huge strings in generated code
This commit is contained in:
@@ -93,6 +93,37 @@ char * format_for_stringout( char * orig_buf, char * return_buf ) {
|
||||
return return_buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like format_for_stringout, but splits the static string up
|
||||
* into numerous small ones that are appended to a std::string named
|
||||
* 'str'. It is assumed that this string already exists and is empty.
|
||||
*/
|
||||
char * format_for_std_stringout( char * orig_buf, char * return_buf ) {
|
||||
char * optr = orig_buf;
|
||||
char * rptr = return_buf;
|
||||
char * s_end = "\\n\" );\n";
|
||||
char * s_begin = " str.append( \"";
|
||||
strcpy( rptr, s_begin );
|
||||
rptr += strlen( rptr );
|
||||
while( *optr ) {
|
||||
if( *optr == '\n' ) {
|
||||
strcpy( rptr, s_end );
|
||||
strcat( rptr, s_begin );
|
||||
rptr += strlen( rptr ) - 1;
|
||||
} else if( *optr == '\\' ) {
|
||||
*rptr = '\\';
|
||||
rptr++;
|
||||
*rptr = '\\';
|
||||
} else {
|
||||
*rptr = *optr;
|
||||
}
|
||||
rptr++;
|
||||
optr++;
|
||||
}
|
||||
strcpy( rptr, s_end );
|
||||
return return_buf;
|
||||
}
|
||||
|
||||
void USEREFout( Schema schema, Dictionary refdict, Linked_List reflist, char * type, FILE * file ) {
|
||||
Dictionary dict;
|
||||
DictionaryEntry de;
|
||||
@@ -1981,28 +2012,30 @@ void ENTITYincode_print( Entity entity, FILE * file, Schema schema ) {
|
||||
#endif
|
||||
|
||||
if( ENTITYget_abstract( entity ) ) {
|
||||
fprintf( file, " %s::%s%s->AddSupertype_Stmt(\"",
|
||||
schema_name, ENT_PREFIX, entity_name );
|
||||
if( entity->u.entity->subtype_expression ) {
|
||||
fprintf( file, "ABSTRACT SUPERTYPE OF (" );
|
||||
|
||||
fprintf( file, " str.clear();\n str.append( \"ABSTRACT SUPERTYPE OF ( \" );\n" );
|
||||
|
||||
tmp = SUBTYPEto_string( entity->u.entity->subtype_expression );
|
||||
tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) );
|
||||
fprintf( file, "%s)\");\n", format_for_stringout( tmp, tmp2 ) );
|
||||
fprintf( file, "%s\n str.append( \")\" );\n", format_for_std_stringout( tmp, tmp2 ) );
|
||||
fprintf( file, " %s::%s%s->AddSupertype_Stmt( str.c_str() );", schema_name, ENT_PREFIX, entity_name );
|
||||
free( tmp );
|
||||
free( tmp2 );
|
||||
} else {
|
||||
fprintf( file, "ABSTRACT SUPERTYPE\");\n" );
|
||||
fprintf( file, " %s::%s%s->AddSupertype_Stmt( \"ABSTRACT SUPERTYPE\" );\n",
|
||||
schema_name, ENT_PREFIX, entity_name );
|
||||
}
|
||||
} else {
|
||||
if( entity->u.entity->subtype_expression ) {
|
||||
fprintf( file, " %s::%s%s->AddSupertype_Stmt(\"",
|
||||
schema_name, ENT_PREFIX, entity_name );
|
||||
fprintf( file, "SUPERTYPE OF (" );
|
||||
fprintf( file, " str.clear();\n str.append( \"SUPERTYPE OF ( \" );\n" );
|
||||
tmp = SUBTYPEto_string( entity->u.entity->subtype_expression );
|
||||
tmp2 = ( char * )malloc( sizeof( char ) * ( strlen( tmp ) + BUFSIZ ) );
|
||||
fprintf( file, "%s)\");\n", format_for_stringout( tmp, tmp2 ) );
|
||||
fprintf( file, "%s\n str.append( \")\" );\n", format_for_std_stringout( tmp, tmp2 ) );
|
||||
free( tmp );
|
||||
free( tmp2 );
|
||||
fprintf( file, " %s::%s%s->AddSupertype_Stmt( str.c_str() );", schema_name, ENT_PREFIX, entity_name );
|
||||
|
||||
}
|
||||
}
|
||||
LISTdo( ENTITYget_supertypes( entity ), sup, Entity )
|
||||
|
||||
@@ -90,7 +90,8 @@ struct SelectTag_ {
|
||||
};
|
||||
|
||||
const char * GetTypeDescriptorName( Type t );
|
||||
char * format_for_stringout( char * orig_buf, char * return_buf );
|
||||
char * format_for_stringout( char * orig_buf, char * return_buf );
|
||||
char * format_for_std_stringout( char * orig_buf, char * return_buf );
|
||||
const char * CheckWord( const char * );
|
||||
const char * StrToLower( const char * );
|
||||
const char * StrToUpper( const char * );
|
||||
|
||||
@@ -444,9 +444,9 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
|
||||
"#include \"schema.h\"\n"
|
||||
"#endif\n" );
|
||||
#endif
|
||||
fprintf( initfile, "#include <Registry.h>\n" );
|
||||
fprintf( initfile, "#include <Registry.h>\n#include <string>\n" );
|
||||
|
||||
fprintf( initfile, "\nvoid %sInit (Registry& reg) {\n", schnm );
|
||||
fprintf( initfile, "\nvoid %sInit (Registry& reg) {\n std::string str;\n", schnm );
|
||||
|
||||
fprintf( createall, "// Schema: %s\n", schnm );
|
||||
fprintf( createall, " %s::schema = new Schema(\"%s\");\n",
|
||||
@@ -471,11 +471,10 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
|
||||
tmpstr[0] = '\0';
|
||||
}
|
||||
|
||||
fprintf( createall,
|
||||
" gr = new Global_rule(\"%s\",%s::schema,\"%s\");\n",
|
||||
r->symbol.name,
|
||||
SCHEMAget_name( schema ),
|
||||
format_for_stringout( RULEto_string( r ), tmpstr ) );
|
||||
fprintf( createall, " str.clear();\n%s", format_for_std_stringout( RULEto_string( r ), tmpstr ) );
|
||||
fprintf( createall,
|
||||
" gr = new Global_rule(\"%s\",%s::schema, str.c_str() );\n",
|
||||
r->symbol.name, SCHEMAget_name( schema ) );
|
||||
fprintf( createall,
|
||||
" %s::schema->AddGlobal_rule(gr);\n", SCHEMAget_name( schema ) );
|
||||
fprintf( createall, "/*\n%s\n*/\n", RULEto_string( r ) );
|
||||
@@ -491,9 +490,11 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
|
||||
tmpstr_size = strlen( FUNCto_string( f ) ) * 2;
|
||||
tmpstr = ( char * )malloc( sizeof( char ) * tmpstr_size );
|
||||
}
|
||||
fprintf( createall, " str.clear();\n%s",
|
||||
format_for_std_stringout( FUNCto_string( f ), tmpstr ));
|
||||
fprintf( createall,
|
||||
"#ifndef MSWIN\n %s::schema->AddFunction(\"%s\");\n#endif\n",
|
||||
SCHEMAget_name( schema ), format_for_stringout( FUNCto_string( f ), tmpstr ) );
|
||||
"%s::schema->AddFunction( str.c_str() );\n",
|
||||
SCHEMAget_name( schema ) );
|
||||
fprintf( createall, "/*\n%s\n*/\n", FUNCto_string( f ) );
|
||||
}
|
||||
|
||||
@@ -507,9 +508,8 @@ void SCHEMAprint( Schema schema, FILES * files, Express model, void * complexCol
|
||||
tmpstr_size = strlen( PROCto_string( p ) ) * 2;
|
||||
tmpstr = ( char * )malloc( sizeof( char ) * tmpstr_size );
|
||||
}
|
||||
fprintf( createall,
|
||||
"#ifndef MSWIN\n %s::schema->AddProcedure(\"%s\");\n#endif\n",
|
||||
SCHEMAget_name( schema ), format_for_stringout( PROCto_string( p ), tmpstr ) );
|
||||
fprintf( createall, " str.clear();\n%s", format_for_std_stringout( PROCto_string( p ), tmpstr ) );
|
||||
fprintf( createall, " %s::schema->AddProcedure( str.c_str() );\n", SCHEMAget_name( schema ) );
|
||||
fprintf( createall, "/*\n%s\n*/\n", PROCto_string( p ) );
|
||||
}
|
||||
if( tmpstr_size > 0 ) {
|
||||
|
||||
@@ -72,7 +72,10 @@ void print_schemas_separate( Express express, void * complexCol, FILES * files )
|
||||
initializeMarks( express );
|
||||
|
||||
//FIXME SdaiAll.cc:12:24: warning: unused variable ‘is’ [-Wunused-variable] (also for ui & ri)
|
||||
fprintf( files->create, " Interface_spec_ptr is;\n Used_item_ptr ui;\n Referenced_item_ptr ri;\n Uniqueness_rule_ptr ur;\n Where_rule_ptr wr;\n Global_rule_ptr gr;\n" );
|
||||
fprintf( files->create, " Interface_spec_ptr is;\n Used_item_ptr ui;\n"
|
||||
" Referenced_item_ptr ri;\n Uniqueness_rule_ptr ur;\n"
|
||||
" Where_rule_ptr wr;\n Global_rule_ptr gr;\n"
|
||||
" std::string str; //for large strings such as functions or global rules\n");
|
||||
while( !complete ) {
|
||||
complete = TRUE;
|
||||
DICTdo_type_init( express->symbol_table, &de, OBJ_SCHEMA );
|
||||
|
||||
Reference in New Issue
Block a user