Ejemplo n.º 1
0
static void TestStruct1( void )
{
    dw_handle           struct_div_t;
    dw_loc_handle       field_loc;
    dw_handle           union_hdl;
    dw_handle           struct_foo;
    dw_handle           ptr_to_foo;
    dw_loc_id           id;

    /* struct div_t */
    struct_div_t = DWStruct( Client, DW_ST_STRUCT );
    DWBeginStruct( Client, struct_div_t, 8, "div_t", 0, 0 );
    id = DWLocInit( Client );
    field_loc = DWLocFini( Client, id );
    DWAddField( Client, FundamentalTypes[DW_FT_SIGNED], field_loc, "quot", 0 );
    DWLocTrash( Client, field_loc );
    id = DWLocInit( Client );
    DWLocOp( Client, id, DW_LOC_plus_uconst, 4 );
    field_loc = DWLocFini( Client, id );
    DWAddField( Client, FundamentalTypes[DW_FT_SIGNED], field_loc, "rem", 0 );
    DWLocTrash( Client, field_loc );
    DWEndStruct( Client );

    /*
        struct foo {
            struct foo *next;
            int         type;
            union {
                int     a;
                float   b;
            } x;
        };
    */
    struct_foo = DWStruct( Client, DW_ST_STRUCT );
    DWBeginStruct( Client, struct_foo, 12, "foo", 0, 0 );
    ptr_to_foo = DWPointer( Client, struct_foo, DW_PTR_TYPE_DEFAULT );
    id = DWLocInit( Client );
    field_loc = DWLocFini( Client, id );
    DWAddField( Client, ptr_to_foo, field_loc, "next", 0 );
    DWLocTrash( Client, field_loc );
    id = DWLocInit( Client );
    DWLocOp( Client, id, DW_LOC_plus_uconst, 4 );
    field_loc = DWLocFini( Client, id );
    DWAddField( Client, FundamentalTypes[DW_FT_SIGNED], field_loc, "type", 0 );
    DWLocTrash( Client, field_loc );
    union_hdl = DWStruct( Client, DW_ST_UNION );
    DWBeginStruct( Client, union_hdl, 4, "wombat", 0, 0 );
    DWAddField( Client, FundamentalTypes[DW_FT_SIGNED], NULL, "a", 0 );
    DWAddField( Client, FundamentalTypes[DW_FT_FLOAT], NULL, "b", 0 );
    DWEndStruct( Client );
    id = DWLocInit( Client );
    DWLocOp( Client, id, DW_LOC_plus_uconst, 8 );
    field_loc = DWLocFini( Client, id );
    DWAddField( Client, union_hdl, field_loc, "x", 0 );
    DWLocTrash( Client, field_loc );
    DWEndStruct( Client );
}
Ejemplo n.º 2
0
static void TestStruct3( void )
{
    dw_handle           class_1;
    dw_handle           class_2;
    dw_handle           class_3;
    dw_loc_handle       field_hdl;
    dw_loc_id           id;

    class_1 = DWStruct( Client, DW_ST_CLASS );
    class_2 = DWStruct( Client, DW_ST_CLASS );
    DWBeginStruct( Client, class_1, 4, "bugs", 0, 0 );
    DWAddFriend( Client, class_2 );
    /* static int a; */
    DWAddField( Client, FundamentalTypes[DW_FT_SIGNED], NULL, "a", DW_FLAG_PRIVATE );  // was DW_FLAG_STATIC ??

    /* private float b; */
    field_hdl = DWLocFini( Client, DWLocInit( Client ) );
    DWAddField( Client, FundamentalTypes[DW_FT_FLOAT], field_hdl, "b", DW_FLAG_PRIVATE );
    DWLocTrash( Client, field_hdl );
    DWEndStruct( Client );

    id = DWLocInit( Client );
    SymHandles[5] = 0x666UL;
    DWLocStatic( Client, id, (dw_sym_handle)5 );
    field_hdl = DWLocFini( Client, id );
    DWVariable( Client, FundamentalTypes[DW_FT_SIGNED], field_hdl, class_1, NULL, "a", 0, 0 );
    DWLocTrash( Client, field_hdl );

    DWBeginStruct( Client, class_2, 4, "beetles", 0, 0 );
    field_hdl = DWLocFini( Client, DWLocInit( Client ) );
    DWAddField( Client, FundamentalTypes[DW_FT_FLOAT], field_hdl, "b", DW_FLAG_PRIVATE );
    DWLocTrash( Client, field_hdl );
    DWEndStruct( Client );

    class_3 = DWStruct( Client, DW_ST_CLASS );
    DWBeginStruct( Client, class_3, 16, "ants", 0, 0 );
    field_hdl = DWLocFini( Client, DWLocInit( Client ) );
    DWAddInheritance( Client, class_2, field_hdl, 0 );
    DWLocTrash( Client, field_hdl );
    DWEndStruct( Client );
}
Ejemplo n.º 3
0
static dw_handle BIGetUnionType( sym_id ste_ptr ) {
//=================================================

// get a union type of a non named symbol

    struct fstruct      *fs;
    dw_handle           ret;
    symbol              data;
    long                max = 0;
    long                map = 0;
    char                buff[12];

    ret = DWStruct( cBIId, DW_ST_UNION );
    fs = ste_ptr->u.ns.xt.record;
    // find the largest size of map
    while( fs ) {
        if ( fs->size > max ) {
            max = fs->size;
        }
        fs = &fs->link->u.sd;
    }

    // Start the union declaration
    DWDeclPos( cBIId, CurrFile->rec, 0 );
    DWBeginStruct( cBIId, ret, max, ste_ptr->u.ns.name, 0, 0 );
    fs = ste_ptr->u.ns.xt.record;
    data.u.ns.xt.record = FMemAlloc( sizeof( fstruct) );
    while( fs ) {
        memset( data.u.ns.xt.record, 0, sizeof( fstruct ) );
        memcpy( data.u.ns.xt.record, fs, sizeof( fmap ) );
        data.u.ns.si.va.u.dim_ext = NULL;
        data.u.ns.u1.s.typ = FT_STRUCTURE;
        strcpy( data.u.ns.name, "MAP" );
        strcat( data.u.ns.name, itoa( map, buff, 10 ) );
        data.u.ns.u2.name_len = strlen( data.u.ns.name );
        strcpy( data.u.ns.xt.record->name, data.u.ns.name );
        data.u.ns.xt.record->name_len = data.u.ns.u2.name_len;
        map++;
        DWAddField( cBIId, BIGetType( &data ), justJunk, data.u.ns.name, 0 );
        fs = &fs->link->u.sd;
    }
    FMemFree( data.u.ns.xt.record );
    DWEndStruct( cBIId );
    return( ret );
}
Ejemplo n.º 4
0
static void TestStruct2( void )
{
    dw_loc_handle               field_loc;
    dw_loc_id                   id;

    /*
        struct date {
            unsigned short      day     : 5;
            unsigned short      month   : 4;
            unsigned short      year    : 7;
        };
    */
    DWBeginStruct( Client, DWStruct( Client, DW_ST_STRUCT ), 2, "date", 0, 0 );
    id = DWLocInit( Client );
    field_loc = DWLocFini( Client, id );
    DWAddBitField( Client, FundamentalTypes[DW_FT_UNSIGNED], field_loc, 0, 11, 5, "day", 0 );
    DWAddBitField( Client, FundamentalTypes[DW_FT_UNSIGNED], field_loc, 0, 7, 4, "month", 0 );
    DWAddBitField( Client, FundamentalTypes[DW_FT_UNSIGNED], field_loc, 0, 0, 7, "year", 0 );
    DWLocTrash( Client, field_loc );
    DWEndStruct( Client );
}
Ejemplo n.º 5
0
static dw_handle BIGetStructType( sym_id ste_ptr, dw_handle handle ) {
//====================================================================

// get a struct type of a non named symbol

    struct field        *fields;
    dw_handle           ret;
    sym_id              data = alloca( sizeof(symbol) + AllocName(MAX_SYMLEN) );
    char                *name;
    char                buffer[MAX_SYMLEN+1];
    long                un = 0;

    if ( handle ) {
        ret = handle;
    } else if ( ste_ptr->u.ns.xt.record->dbh ) {
        return( ste_ptr->u.ns.xt.record->dbh );
    } else {
        // consider: record /bar/ function x()
        //                       ....
        // we want to use the handle we used when the function
        // was defined
        if ( ste_ptr->u.ns.xt.record == SubProgId->u.ns.xt.record ) {
            ret = subProgTyHandle;
        } else {
            ret = DWStruct( cBIId, DW_ST_STRUCT );
        }
    }
    ste_ptr->u.ns.xt.record->dbh = ret;
    DWDeclPos( cBIId, CurrFile->rec, 0 );
    memset( buffer, 0, MAX_SYMLEN+1 );
    DWBeginStruct( cBIId, ret, ste_ptr->u.ns.xt.record->size,
                        strncpy( buffer, ste_ptr->u.ns.xt.record->name,
                                ste_ptr->u.ns.xt.record->name_len ),
                        0, 0 );
    fields = ste_ptr->u.ns.xt.record->fl.fields;
    while( fields ) {
        data->u.ns.u1.s.typ = fields->typ;
        data->u.ns.xt.record = fields->xt.record;
        name = NULL;
        if ( fields->typ == FT_UNION ) {
            data->u.ns.si.va.u.dim_ext = NULL;
            data->u.ns.u2.name_len = 0;
            data->u.ns.name[0] = 0;
            un++;
            name = data->u.ns.name;
        } else {
            data->u.ns.si.va.u.dim_ext = fields->dim_ext;
            data->u.ns.u2.name_len = fields->name_len;
            strncpy( data->u.ns.name, fields->name, fields->name_len );
            data->u.ns.name[ fields->name_len ] = 0;
            if ( *(data->u.ns.name) ) {
                name = data->u.ns.name;
            }
        }
        if ( data->u.ns.si.va.u.dim_ext ) {
            DWAddField(cBIId, BIGetArrayType(data), justJunk, name, 0);
        } else {
            DWAddField( cBIId, BIGetType( data ), justJunk, name, 0 );
        }
        fields = &fields->link->u.fd;
    }
    DWEndStruct( cBIId );
    return( ret );
}