Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 2148

Show
Ignore:
Timestamp:
05/04/07 14:28:14 (2 years ago)
Author:
sean
Message:

Exposed ModuleInfo? in object.di. This closes ticket #433.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/compiler/dmd/genobj.d

    r2076 r2148  
    129129struct Interface 
    130130{ 
    131     ClassInfo classinfo;    /// .classinfo for this interface (not for containing class) 
    132     void *[] vtbl; 
    133     ptrdiff_t offset;       /// offset to Interface 'this' from Object 'this' 
     131    ClassInfo   classinfo;  /// .classinfo for this interface (not for containing class) 
     132    void*[]    vtbl; 
     133    ptrdiff_t   offset;     /// offset to Interface 'this' from Object 'this' 
    134134} 
    135135 
     
    141141class ClassInfo : Object 
    142142{ 
    143     byte[] init;                /** class static initializer 
     143    byte[]      init;           /** class static initializer 
    144144                                 * (init.length gives size in bytes of class) 
    145145                                 */ 
    146     char[] name;                /// class name 
    147     void *[] vtbl;              /// virtual function pointer table 
     146    char[]      name;           /// class name 
     147    void*[]     vtbl;           /// virtual function pointer table 
    148148    Interface[] interfaces;     /// interfaces this class implements 
    149     ClassInfo base;             /// base class 
    150     void *destructor; 
    151     void (*classInvariant)(Object)
    152     uint flags; 
     149    ClassInfo   base;           /// base class 
     150    void*       destructor; 
     151    void function(Object) classInvariant
     152    uint        flags; 
    153153    //  1:                      // IUnknown 
    154154    //  2:                      // has no possible pointers into GC memory 
    155155    //  4:                      // has offTi[] member 
    156156    //  8:                      // has constructors 
    157     void *deallocator; 
     157    void*       deallocator; 
    158158    OffsetTypeInfo[] offTi; 
    159159    void function(Object) defaultConstructor;   // default Constructor 
     
    165165    static ClassInfo find(char[] classname) 
    166166    { 
    167         foreach (m; ModuleInfo.modules()
     167        foreach (m; ModuleInfo
    168168        { 
    169169            //writefln("module %s, %d", m.name, m.localClasses.length); 
     
    200200struct OffsetTypeInfo 
    201201{ 
    202     size_t offset;      /// Offset of member from start of object 
     202    size_t   offset;    /// Offset of member from start of object 
    203203    TypeInfo ti;        /// TypeInfo for this member 
    204204} 
     
    930930class ModuleInfo 
    931931{ 
    932     char name[]; 
    933     ModuleInfo importedModules[]; 
    934     ClassInfo localClasses[]; 
    935  
    936     uint flags;         // initialization state 
    937  
    938     void (*ctor)(); 
    939     void (*dtor)(); 
    940     void (*unitTest)(); 
    941  
    942     static ModuleInfo[] modules() 
    943     { 
    944         return _moduleinfo_array; 
     932    char[]          name; 
     933    ModuleInfo[]    importedModules; 
     934    ClassInfo[]     localClasses; 
     935    uint            flags; 
     936 
     937    void function() ctor; 
     938    void function() dtor; 
     939    void function() unitTest; 
     940 
     941    static int opApply( int delegate( inout ModuleInfo ) dg ) 
     942    { 
     943        int ret = 0; 
     944 
     945        foreach( m; _moduleinfo_array ) 
     946        { 
     947            ret = dg( m ); 
     948            if( ret ) 
     949                break; 
     950        } 
     951        return ret; 
    945952    } 
    946953} 
     
    959966    { 
    960967        ModuleReference* next; 
    961         ModuleInfo mod; 
    962     } 
    963  
    964     extern (C) ModuleReference *_Dmodule_ref;   // start of linked list 
     968        ModuleInfo       mod; 
     969    } 
     970 
     971    extern (C) ModuleReference* _Dmodule_ref;   // start of linked list 
    965972} 
    966973 
    967974ModuleInfo[] _moduleinfo_dtors; 
    968 uint _moduleinfo_dtors_i; 
     975uint         _moduleinfo_dtors_i; 
    969976 
    970977// Register termination function pointers 
  • trunk/lib/compiler/gdc/genobj.d

    r2090 r2148  
    113113    int opEquals(Object o) 
    114114    { 
    115     return cast(int)(this is o); 
     115        return cast(int)(this is o); 
    116116    } 
    117117 
    118118    interface Monitor 
    119            
     119   
    120120        void lock(); 
    121121        void unlock(); 
    122        
    123    
     122   
     123
    124124 
    125125/** 
     
    129129struct Interface 
    130130{ 
    131     ClassInfo classinfo;        /// .classinfo for this interface (not for containing class) 
    132     void *[] vtbl; 
    133     ptrdiff_t offset;       /// offset to Interface 'this' from Object 'this' 
     131    ClassInfo   classinfo;  /// .classinfo for this interface (not for containing class) 
     132    void*[]    vtbl; 
     133    ptrdiff_t   offset;     /// offset to Interface 'this' from Object 'this' 
    134134} 
    135135 
     
    141141class ClassInfo : Object 
    142142{ 
    143     byte[] init;                /** class static initializer 
     143    byte[]      init;           /** class static initializer 
    144144                                 * (init.length gives size in bytes of class) 
    145145                                 */ 
    146     char[] name;                /// class name 
    147     void *[] vtbl;              /// virtual function pointer table 
     146    char[]      name;           /// class name 
     147    void*[]     vtbl;           /// virtual function pointer table 
    148148    Interface[] interfaces;     /// interfaces this class implements 
    149     ClassInfo base;             /// base class 
    150     void *destructor; 
    151     void (*classInvariant)(Object)
    152     uint flags; 
     149    ClassInfo   base;           /// base class 
     150    void*       destructor; 
     151    void function(Object) classInvariant
     152    uint        flags; 
    153153    //  1:                      // IUnknown 
    154154    //  2:                      // has no possible pointers into GC memory 
    155155    //  4:                      // has offTi[] member 
    156     void *deallocator; 
     156    //  8:                      // has constructors 
     157    void*       deallocator; 
    157158    OffsetTypeInfo[] offTi; 
    158 
    159  
     159/+ 
     160    void function(Object) defaultConstructor;   // default Constructor 
     161 
     162    /** 
     163     * Search all modules for ClassInfo corresponding to classname. 
     164     * Returns: null if not found 
     165     */ 
     166    static ClassInfo find(char[] classname) 
     167    { 
     168        foreach (m; ModuleInfo) 
     169        { 
     170            //writefln("module %s, %d", m.name, m.localClasses.length); 
     171            foreach (c; m.localClasses) 
     172            { 
     173                //writefln("\tclass %s", c.name); 
     174                if (c.name == classname) 
     175                    return c; 
     176            } 
     177        } 
     178        return null; 
     179    } 
     180 
     181    /** 
     182     * Create instance of Object represented by 'this'. 
     183     */ 
     184    Object create() 
     185    { 
     186        if (flags & 8 && !defaultConstructor) 
     187            return null; 
     188        Object o = _d_newclass(this); 
     189        if (flags & 8 && defaultConstructor) 
     190        { 
     191            defaultConstructor(o); 
     192        } 
     193        return o; 
     194    } 
     195+/ 
     196
    160197 
    161198/** 
     
    165202struct OffsetTypeInfo 
    166203{ 
    167     size_t offset;      /// Offset of member from start of object 
     204    size_t   offset;    /// Offset of member from start of object 
    168205    TypeInfo ti;        /// TypeInfo for this member 
    169206} 
    170  
    171207 
    172208/** 
     
    336372    {   TypeInfo_Array c; 
    337373 
    338     return cast(int) 
    339            (this is o || 
     374        return cast(int) 
     375               (this is o || 
    340376                ((c = cast(TypeInfo_Array)o) !is null && 
    341          this.value == c.value)); 
     377                 this.value == c.value)); 
    342378    } 
    343379 
     
    417453    {   TypeInfo_StaticArray c; 
    418454 
    419     return cast(int) 
    420            (this is o || 
     455        return cast(int) 
     456               (this is o || 
    421457                ((c = cast(TypeInfo_StaticArray)o) !is null && 
    422458                 this.len == c.len && 
    423          this.value == c.value)); 
     459                 this.value == c.value)); 
    424460    } 
    425461 
     
    899935enum 
    900936{ 
    901     MIctorstart = 1,    // we've started constructing it 
    902     MIctordone = 2,     // finished construction 
     937    MIctorstart = 1,   // we've started constructing it 
     938    MIctordone   = 2,   // finished construction 
    903939    MIstandalone = 4,   // module ctor does not depend on other module 
    904940                        // ctors being done first 
    905941} 
    906942 
     943 
    907944class ModuleInfo 
    908945{ 
    909     char name[]; 
    910     ModuleInfo importedModules[]; 
    911     ClassInfo localClasses[]; 
    912  
    913     uint flags;         // initialization state 
    914  
    915     void (*ctor)(); 
    916     void (*dtor)(); 
    917     void (*unitTest)(); 
    918  
    919     static ModuleInfo[] modules() 
    920     { 
    921         return _moduleinfo_array; 
     946    char[]          name; 
     947    ModuleInfo[]    importedModules; 
     948    ClassInfo[]     localClasses; 
     949    uint            flags; 
     950 
     951    void function() ctor; 
     952    void function() dtor; 
     953    void function() unitTest; 
     954 
     955    static int opApply( int delegate( inout ModuleInfo ) dg ) 
     956    { 
     957        int ret = 0; 
     958 
     959        foreach( m; _moduleinfo_array ) 
     960        { 
     961            ret = dg( m ); 
     962            if( ret ) 
     963                break; 
     964        } 
     965        return ret; 
    922966    } 
    923967} 
     
    943987    { 
    944988        ModuleReference* next; 
    945         ModuleInfo mod; 
    946     } 
    947  
    948     extern (C) ModuleReference *_Dmodule_ref;   // start of linked list 
     989        ModuleInfo       mod; 
     990    } 
     991 
     992    extern (C) ModuleReference* _Dmodule_ref;   // start of linked list 
    949993} 
    950994 
    951995ModuleInfo[] _moduleinfo_dtors; 
    952 uint _moduleinfo_dtors_i; 
     996uint         _moduleinfo_dtors_i; 
    953997 
    954998// Register termination function pointers 
     
    10761120} 
    10771121 
     1122 
    10781123//////////////////////////////////////////////////////////////////////////////// 
    10791124// Monitor 
  • trunk/object.di

    r2076 r2148  
    148148} 
    149149 
     150class ModuleInfo 
     151{ 
     152    char[]          name; 
     153    ModuleInfo[]    importedModules; 
     154    ClassInfo[]     localClasses; 
     155    uint            flags; 
     156 
     157    void function() ctor; 
     158    void function() dtor; 
     159    void function() unitTest; 
     160 
     161    static int opApply( int delegate( inout ModuleInfo ) ); 
     162} 
     163 
    150164class Exception : Object 
    151165{