Ejemplo n.º 1
0
void constants_add( int code, TYPEDEF type, int value )
{
    CONSTANT * c;

    if ( constants_used == constants_reserved ) constants_alloc( 16 ) ;

    if ( varspace_search( &global, code ) )
    {
        token.code = code;
        token.type = IDENTIFIER;
        compile_error( MSG_VARIABLE_REDECLARED_AS_CONSTANT ) ;
    }

    if ( varspace_search( &local, code ) )
    {
        token.code = code;
        token.type = IDENTIFIER;
        compile_error( MSG_VARIABLE_REDECLARED_AS_CONSTANT ) ;
    }

    if (( c = constants_search( code ) ) && ( !typedef_is_equal( c->type, type ) || c->value != value ) )
    {
        token.code = string_new( identifier_name( code ) );
        token.type = STRING;
        compile_error( "Constant redefined" );
    }

    constants[constants_used].code = code ;
    constants[constants_used].type = type ;
    constants[constants_used].value = value ;
    constants_used++ ;
}
Ejemplo n.º 2
0
int typedef_is_equal( TYPEDEF a, TYPEDEF b )
{
    int n;

    if ( a.depth != b.depth ) return 0;

    for ( n = 0; n < a.depth; n++ )
    {
        if ( a.chunk[n].type == TYPE_STRUCT && b.chunk[n].type == TYPE_STRUCT && a.varspace != b.varspace )
        {
            int m;
            if ( a.varspace->count != b.varspace->count ) return 0;
            for ( m = 0; m < a.varspace->count; m++ )
            {
                if ( !typedef_is_equal( a.varspace->vars[m].type, b.varspace->vars[m].type ) ) return 0;
            }
            return 1;
        }
        if ( a.chunk[n].type != b.chunk[n].type ) return 0;
        if ( a.chunk[n].type == TYPE_ARRAY && a.chunk[n].count != b.chunk[n].count ) return 0;
    }
    return 1;
}