/**
 * look up an attribute reference
 * if strict false, anything can be returned, not just attributes
 */
Variable VARfind( Scope scope, char * name, int strict ) {
    Variable result;

    /* first look up locally */
    switch( scope->type ) {
        case OBJ_ENTITY:
            result = ENTITYfind_inherited_attribute( scope, name, 0 );
            if( result ) {
                if( strict && ( DICT_type != OBJ_VARIABLE ) ) {
                    fprintf( stderr, "ERROR: strict && ( DICT_type != OBJ_VARIABLE )\n" );
                }
                return result;
            }
            break;
        case OBJ_INCREMENT:
        case OBJ_QUERY:
        case OBJ_ALIAS:
            result = ( Variable )DICTlookup( scope->symbol_table, name );
            if( result ) {
                if( strict && ( DICT_type != OBJ_VARIABLE ) ) {
                    fprintf( stderr, "ERROR: strict && ( DICT_type != OBJ_VARIABLE )\n" );
                }
                return result;
            }
            return( VARfind( scope->superscope, name, strict ) );
    }
    return 0;
}
Exemplo n.º 2
0
/**
 * look up an attribute reference
 * if strict false, anything can be returned, not just attributes
 */
Variable VARfind( Scope scope, char * name, int strict ) {
    Variable result;

    /* first look up locally */
    switch( scope->type ) {
        case OBJ_ENTITY:
            result = ENTITYfind_inherited_attribute( scope, name, 0 );
            if( result ) {
                if( strict && ( DICT_type != OBJ_VARIABLE ) ) {
                    printf( "schema.c: press ^C now to trap to debugger\n" );
                    exp_pause();
                }
                return result;
            }
            break;
        case OBJ_INCREMENT:
        case OBJ_QUERY:
        case OBJ_ALIAS:
            result = ( Variable )DICTlookup( scope->symbol_table, name );
            if( result ) {
                if( strict && ( DICT_type != OBJ_VARIABLE ) ) {
                    printf( "schema.c: press ^C now to trap to debugger\n" );
                    exp_pause();
                }
                return result;
            }
            return( VARfind( scope->superscope, name, strict ) );
    }
    return 0;
}
void find_and_print( Express model ) {
    DictionaryEntry de;
    Schema s;
    Entity e;
    DICTdo_init( model->symbol_table, &de );
    while( 0 != ( s = DICTdo( &de ) ) ) {
        printf( "Schema %s\n", s->symbol.name );
        e = DICTlookup( s->symbol_table, entityName );
        if( e ) {
            print_attrs( e );
        }
    }
}
Exemplo n.º 4
0
/**
 * \sa SCOPEget_entities_superclass_order()
 */
void SCOPE_dfs( Dictionary symbols, Entity root, Linked_List result ) {
    Entity ent;

    if( ( ENTITYget_mark( root ) != ENTITY_MARK ) ) {
        ENTITYput_mark( root, ENTITY_MARK );
        LISTdo( ENTITYget_supertypes( root ), super, Entity )
        /* if super explicitly defined in scope, recurse. */
        /* this chops out USEd and REFd entities */
        if( ( ent = ( Entity )DICTlookup( symbols, ENTITYget_name( super ) ) ) != ENTITY_NULL ) {
            SCOPE_dfs( symbols, ent, result );
        }
        LISTod
        LISTadd_last( result, ( Generic )root );
    }
void SCHEMAdefine_use( Schema schema, Rename * r ) {
    Rename * old = 0;
    char * name = ( r->nnew ? r->nnew : r->old )->name;

    if( !schema->u.schema->usedict ) {
        schema->u.schema->usedict = DICTcreate( 20 );
    } else {
        old = ( Rename * )DICTlookup( schema->u.schema->usedict, name );
    }
    if( !old || ( DICT_type != OBJ_RENAME ) || ( old->object != r->object ) ) {
        DICTdefine( schema->u.schema->usedict, name,
                    ( Generic )r, r->old, OBJ_RENAME );
    }
}
Exemplo n.º 6
0
Type TYPEcreate_user_defined_tag( Type base, Scope scope, struct Symbol_ *symbol ) {
    Type t;
    extern int tag_count;

    t = ( Type )DICTlookup( scope->symbol_table, symbol->name );
    if( t ) {
        if( DICT_type == OBJ_TAG ) {
            return( t );
        } else {
            /* easiest to just generate the error this way!
             * following call WILL fail intentionally
             */
            DICTdefine( scope->symbol_table, symbol->name, 0, symbol, OBJ_TAG );
            return( 0 );
        }
    }

    /* tag is undefined
     * if we are outside a formal parameter list (hack, hack)
     * then we can only refer to existing tags, so produce an error
     */
    if( tag_count < 0 ) {
        ERRORreport_with_symbol( ERROR_undefined_tag, symbol,
                                 symbol->name );
        return( 0 );
    }

    /* otherwise, we're in a formal parameter list,
     * so it's ok to define it
     */
    t = TYPEcreate_nostab( symbol, scope, OBJ_TAG );
    t->u.type->head = base;

    /* count unique type tags inside PROC and FUNC headers */
    tag_count++;

    return( t );
}