by default, don't print tail comments (enable with -t)

This commit is contained in:
Mark Pictor 2013-10-02 19:25:12 -04:00
parent debc95478e
commit aea964b568
10 changed files with 34 additions and 10 deletions

View file

@ -19,6 +19,7 @@ extern SC_EXPPP_EXPORT char * exppp_output_filename; /**< force output fi
extern SC_EXPPP_EXPORT bool exppp_output_filename_reset; /**< if true, force output filename */
extern SC_EXPPP_EXPORT bool exppp_print_to_stdout; /**< if true, print to stdout */
extern SC_EXPPP_EXPORT bool exppp_aggressively_wrap_consts; /**< for constants, print one item per line */
extern SC_EXPPP_EXPORT bool exppp_tail_comment; /**< print tail comment, such as END_ENTITY; --entity_name */
SC_EXPPP_EXPORT void EXPRESSout( Express e );
@ -63,6 +64,7 @@ SC_EXPPP_EXPORT int TYPEbody_to_buffer( Type t, char * buffer, int length );
SC_EXPPP_EXPORT int WHEREto_buffer( Linked_List w, char * buffer, int length );
SC_EXPPP_EXPORT int EXPRlength( Expression e );
extern SC_EXPPP_EXPORT void tail_comment( const char * name );
extern SC_EXPPP_EXPORT int count_newlines( char * s );
#endif

View file

@ -7,6 +7,7 @@ static void exppp_usage( void ) {
fprintf( stderr, "usage: %s [-v] [-d #] [-p <object_type>] {-w|-i <warning>} [-l <length>] [-c] [-o [file|--]] express_file\n", EXPRESSprogram_name );
fprintf( stderr, "\t-v produces a version description\n" );
fprintf( stderr, "\t-l specifies line length hint for output\n" );
fprintf( stderr, "\t-t enable tail comment for declarations - i.e. END_TYPE; -- axis2_placement\n" );
fprintf( stderr, "\t-c for constants, print one item per line (YMMV!)\n" );
fprintf( stderr, "\t-o specifies the name of the output file (-- for stdout)\n" );
fprintf( stderr, "\t-d turns on debugging (\"-d 0\" describes this further\n" );
@ -49,6 +50,9 @@ int Handle_Exppp_Args( int i, char * arg ) {
} else if( tolower( ( char )i ) == 'c' ) {
exppp_aggressively_wrap_consts = true;
return 0;
} else if( tolower( ( char )i ) == 't' ) {
exppp_tail_comment = true;
return 0;
}
return 1;
}
@ -57,6 +61,6 @@ void EXPRESSinit_init( void ) {
exppp_alphabetize = true;
EXPRESSbackend = EXPRESSout;
ERRORusage_function = exppp_usage;
strcat( EXPRESSgetopt_options, "o:l:c" );
strcat( EXPRESSgetopt_options, "o:l:ct" );
EXPRESSgetopt = Handle_Exppp_Args;
}

View file

@ -68,10 +68,9 @@ bool exppp_output_filename_reset = true; /* if true, force output filename */
bool exppp_print_to_stdout = false;
bool exppp_alphabetize = true;
bool exppp_aggressively_wrap_consts = false;
bool exppp_terse = false;
bool exppp_reference_info = false; /* if true, add commentary about where things came from */
bool exppp_tail_comment = false;
FILE * exppp_fp = NULL; /* output file */
char * exppp_buf = 0; /* output buffer */
@ -80,6 +79,18 @@ unsigned int exppp_buflen = 0; /* remaining space in expppbuf */
char * exppp_bufp = 0; /* pointer to write position in expppbuf,
* should usually be pointing to a "\0" */
/** used to print a comment containing the name of a structure at the
* end of the structure's declaration, if exppp_tail_comment (-t) is true
*
* prints a newline regardless
*/
void tail_comment( const char * name ) {
if( exppp_tail_comment ) {
raw( " -- %s", name );
}
raw( "\n" );
}
/** count newlines in a string */
int count_newlines( char * s ) {
int count = 0;

View file

@ -69,7 +69,8 @@ void ENTITY_out( Entity e, int level ) {
WHERE_out( TYPEget_where( e ), level );
level -= exppp_nesting_indent;
raw( "%*sEND_ENTITY; -- %s\n", level, "", e->symbol.name );
raw( "%*sEND_ENTITY;", level, "" );
tail_comment( e->symbol.name );
}
void ENTITYunique_out( Linked_List u, int level ) {

View file

@ -33,7 +33,8 @@ void FUNC_out( Function fn, int level ) {
ALGscope_out( fn, level + exppp_nesting_indent );
STMTlist_out( fn->u.proc->body, level + exppp_nesting_indent );
raw( "\n%*sEND_FUNCTION; -- %s\n", level, "", fn->symbol.name );
raw( "\n%*sEND_FUNCTION;", level, "" );
tail_comment( fn->symbol.name );
}
char * FUNCto_string( Function f ) {

View file

@ -48,6 +48,7 @@ void PROC_out( Procedure p, int level ) {
ALGscope_out( p, level + exppp_nesting_indent );
STMTlist_out( p->u.proc->body, level + exppp_nesting_indent );
raw( "\n%*sEND_PROCEDURE; -- %s\n", level, "", p->symbol.name );
raw( "\n%*sEND_PROCEDURE;", level, "" );
tail_comment( p->symbol.name );
}

View file

@ -53,5 +53,6 @@ void RULE_out( Rule r, int level ) {
raw( "\n" );
WHERE_out( RULEget_where( r ), level );
raw( "\n%*sEND_RULE; -- %s\n", level, "", r->symbol.name );
raw( "\n%*sEND_RULE;", level, "" );
tail_comment( r->symbol.name );
}

View file

@ -144,7 +144,8 @@ char * SCHEMAout( Schema s ) {
SCOPEentities_out( s, level + exppp_nesting_indent );
SCOPEalgs_out( s, level + exppp_nesting_indent );
raw( "\nEND_SCHEMA; -- %s\n", s->symbol.name );
raw( "\nEND_SCHEMA;");
tail_comment( s->symbol.name );
fclose( exppp_fp );

View file

@ -75,7 +75,8 @@ void STMT_out( Statement s, int level ) {
/* should be generalized reference */
s->u.alias->variable->name->symbol.name );
STMTlist_out( s->u.alias->statements, level + exppp_nesting_indent );
raw( "%*sEND_ALIAS; -- %s\n", level, "", s->symbol.name );
raw( "%*sEND_ALIAS;", level, "" );
tail_comment( s->symbol.name );
break;
case STMT_SKIP:
raw( "%*sSKIP;\n", level, "" );

View file

@ -29,7 +29,8 @@ void TYPE_out( Type t, int level ) {
WHERE_out( t->where, level );
raw( "%*sEND_TYPE; -- %s\n", level, "", t->symbol.name );
raw( "%*sEND_TYPE;", level, "" );
tail_comment( t->symbol.name );
}
/** prints type description (preceded by a space).