Exemple #1
0
void ALGscope_out( Scope s, int level ) {
    SCOPEtypes_out( s, level );
    SCOPEentities_out( s, level );
    SCOPEalgs_out( s, level );

    SCOPEconsts_out( s, level );
    SCOPElocals_out( s, level );
}
Exemple #2
0
/** returns name of file written to in static storage */
char * SCHEMAout( Schema s ) {
    #define PP_SMALL_BUF_SZ 80
    char buf[PP_SMALL_BUF_SZ];
    char * p;
    int level = 0;
    char ** hp;
    bool described = false;
    if( exppp_print_to_stdout ) {
        exppp_fp = stdout;
    } else {
        FILE * f;
        if( exppp_output_filename_reset ) {
            exppp_output_filename = 0;
        }

        if( exppp_output_filename ) {
            if( !strcmp( input_filename, exppp_output_filename ) ) {
                fprintf( stderr, "Error: input filename and output filename are the same (%s)", exppp_output_filename );
                exit( EXIT_FAILURE );
            }
            strcpy( exppp_filename_buffer, exppp_output_filename );
        } else {
            /* when there is only a single file, allow user to find */
            /* out what it is */
            exppp_output_filename = exppp_filename_buffer;
            exppp_output_filename_reset = true;

            /* since we have to generate a filename, make sure we don't */
            /* overwrite a valuable file */

            sprintf( exppp_filename_buffer, "%s.exp", s->symbol.name );

            if( 0 != ( f = fopen( exppp_filename_buffer, "r" ) ) ) {
                char * result = fgets( buf, PP_SMALL_BUF_SZ, f );
                if( 0 != ( p = strchr( buf, '\n' ) ) ) {
                    *p = '\0';
                }
                if( ( !result ) || ( streq( buf, expheader[0] ) ) ) {
                    unlink( exppp_filename_buffer );
                } else {
                    fprintf( stderr, "%s: %s already exists and appears to be hand-written\n",
                             EXPRESSprogram_name, exppp_filename_buffer );
                    /*          strcat(bp,".pp");*/
                    strcat( exppp_filename_buffer, ".pp" );
                    fprintf( stderr, "%s: writing schema file %s instead\n",
                             EXPRESSprogram_name, exppp_filename_buffer );
                    described = true;
                }
            }
            if( f ) {
                fclose( f );
            }
        }
        error_sym.filename = exppp_filename_buffer;

        if( !described && !exppp_terse ) {
            fprintf( stdout, "%s: writing schema file %s\n", EXPRESSprogram_name, exppp_filename_buffer );
        }
        if( !( exppp_fp = f = fopen( exppp_filename_buffer, "w" ) ) ) {
            ERRORreport( ERROR_file_unwriteable, exppp_filename_buffer, strerror( errno ) );
            return 0;
        }
    }
    error_sym.line = 1;
    /* print our header - generated by exppp, don't edit, etc */
    for( hp = expheader; *hp; hp++ ) {
        if( ( **hp == '\0' ) && ( **( hp + 1 ) == '\0' ) ) {
            /* if this and the next lines are blank, put version string on this line */
            raw( "%s\n", sc_version );
        } else {
            raw( "%s\n", *hp );
        }
    }

    /*  first_newline();*/
    /*  raw("SCHEMA %s;\n",s->symbol.name);*/

    first_line = false;
    raw( "\nSCHEMA %s;\n", s->symbol.name );

    if( s->u.schema->usedict || s->u.schema->use_schemas
            || s->u.schema->refdict || s->u.schema->ref_schemas ) {
        raw( "\n" );
    }

    REFout( s->u.schema->usedict, s->u.schema->use_schemas, "USE", level + exppp_nesting_indent );
    REFout( s->u.schema->refdict, s->u.schema->ref_schemas, "REFERENCE", level + exppp_nesting_indent );

    /* output order for DIS & IS schemas:
     * CONSTANT
     * TYPE
     * ENTITY
     * RULE
     * FUNCTION
     * PROCEDURE
     *
     * Within each of those groups, declarations must be sorted alphabetically.
     */

    SCOPEconsts_out( s, level + exppp_nesting_indent );
    SCOPEtypes_out( s, level + exppp_nesting_indent );
    SCOPEentities_out( s, level + exppp_nesting_indent );
    SCOPEalgs_out( s, level + exppp_nesting_indent );

    raw( "\nEND_SCHEMA; -- %s\n", s->symbol.name );

    fclose( exppp_fp );

    return exppp_filename_buffer;
    #undef PP_SMALL_BUF_SZ
}