]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add pointer word to CommonType
authorRuss Cox <rsc@golang.org>
Thu, 24 Feb 2011 22:11:20 +0000 (17:11 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 24 Feb 2011 22:11:20 +0000 (17:11 -0500)
The pointer will eventually let us find *T given T.
This CL just makes room for it, always storing a zero.

R=r, r2
CC=golang-dev
https://golang.org/cl/4221046

src/cmd/gc/reflect.c
src/cmd/ld/dwarf.c
src/pkg/reflect/type.go
src/pkg/runtime/type.go
src/pkg/runtime/type.h

index 36c245d4782e3bd3c33dcd07bc8156a3d3a07355..4dbe9d28d7ff3380bb938b017a3ce09eb42a0d06 100644 (file)
@@ -592,7 +592,8 @@ dcommontype(Sym *s, int ot, Type *t)
        //              fieldAlign uint8;
        //              kind uint8;
        //              string *string;
-       //              *nameInfo;
+       //              *extraType;
+       //              ptrToThis *Type
        //      }
        ot = duintptr(s, ot, t->width);
        ot = duint32(s, ot, typehash(t));
@@ -616,7 +617,7 @@ dcommontype(Sym *s, int ot, Type *t)
                ot = dsymptr(s, ot, s1, 0);     // extraType
        else
                ot = duintptr(s, ot, 0);
-
+       ot = duintptr(s, ot, 0);  // ptr type (placeholder for now)
        return ot;
 }
 
index 8c53d7d133ada99565b199b7ba8803516cf5780d..5ba4b7c643c6cd1d3d5ebbaa7697364f7236651e 100644 (file)
@@ -772,6 +772,9 @@ enum {
        KindUnsafePointer,
 
        KindNoPointers = 1<<7,
+
+       // size of Type interface header + CommonType structure.
+       CommonSize = 2*PtrSize+ 4*PtrSize + 8,
 };
 
 static Reloc*
@@ -849,59 +852,59 @@ decodetype_size(Sym *s)
 static Sym*
 decodetype_arrayelem(Sym *s)
 {
-       return decode_reloc_sym(s, 5*PtrSize + 8);      // 0x1c / 0x30
+       return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
 }
 
 static vlong
 decodetype_arraylen(Sym *s)
 {
-       return decode_inuxi(s->p + 6*PtrSize + 8, PtrSize);
+       return decode_inuxi(s->p + CommonSize+PtrSize, PtrSize);
 }
 
 // Type.PtrType.elem
 static Sym*
 decodetype_ptrelem(Sym *s)
 {
-       return decode_reloc_sym(s, 5*PtrSize + 8);      // 0x1c / 0x30
+       return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
 }
 
 // Type.MapType.key, elem
 static Sym*
 decodetype_mapkey(Sym *s)
 {
-       return decode_reloc_sym(s, 5*PtrSize + 8);      // 0x1c / 0x30
+       return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
 }
 static Sym*
 decodetype_mapvalue(Sym *s)
 {
-       return decode_reloc_sym(s, 6*PtrSize + 8);      // 0x20 / 0x38
+       return decode_reloc_sym(s, CommonSize+PtrSize); // 0x20 / 0x38
 }
 
 // Type.ChanType.elem
 static Sym*
 decodetype_chanelem(Sym *s)
 {
-       return decode_reloc_sym(s, 5*PtrSize + 8);      // 0x1c / 0x30
+       return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30
 }
 
 // Type.FuncType.dotdotdot
 static int
 decodetype_funcdotdotdot(Sym *s)
 {
-       return s->p[5*PtrSize + 8];
+       return s->p[CommonSize];
 }
 
 // Type.FuncType.in.len
 static int
 decodetype_funcincount(Sym *s)
 {
-       return decode_inuxi(s->p + 7*PtrSize + 8, 4);
+       return decode_inuxi(s->p + CommonSize+2*PtrSize, 4);
 }
 
 static int
 decodetype_funcoutcount(Sym *s)
 {
-       return decode_inuxi(s->p + 8*PtrSize + 16, 4);
+       return decode_inuxi(s->p + CommonSize+3*PtrSize + 2*4, 4);
 }
 
 static Sym*
@@ -909,7 +912,7 @@ decodetype_funcintype(Sym *s, int i)
 {
        Reloc *r;
 
-       r = decode_reloc(s, 6*PtrSize + 8);
+       r = decode_reloc(s, CommonSize + PtrSize);
        if (r == nil)
                return nil;
        return decode_reloc_sym(r->sym, r->add + i * PtrSize);
@@ -920,7 +923,7 @@ decodetype_funcouttype(Sym *s, int i)
 {
        Reloc *r;
 
-       r = decode_reloc(s, 7*PtrSize + 16);
+       r = decode_reloc(s, CommonSize + 2*PtrSize + 2*4);
        if (r == nil)
                return nil;
        return decode_reloc_sym(r->sym, r->add + i * PtrSize);
@@ -930,15 +933,18 @@ decodetype_funcouttype(Sym *s, int i)
 static int
 decodetype_structfieldcount(Sym *s)
 {
-       return decode_inuxi(s->p + 6*PtrSize + 8, 4);  //  0x20 / 0x38
+       return decode_inuxi(s->p + CommonSize + PtrSize, 4);
 }
 
-// Type.StructType.fields[]-> name, typ and offset. sizeof(structField) =  5*PtrSize
+enum {
+       StructFieldSize = 5*PtrSize
+};
+// Type.StructType.fields[]-> name, typ and offset.
 static char*
 decodetype_structfieldname(Sym *s, int i)
 {
        // go.string."foo"  0x28 / 0x40
-       s = decode_reloc_sym(s, 6*PtrSize + 0x10 + i*5*PtrSize);
+       s = decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize);
        if (s == nil)                   // embedded structs have a nil name.
                return nil;
        s = decode_reloc_sym(s, 0);     // string."foo"
@@ -950,20 +956,20 @@ decodetype_structfieldname(Sym *s, int i)
 static Sym*
 decodetype_structfieldtype(Sym *s, int i)
 {
-       return decode_reloc_sym(s, 8*PtrSize + 0x10 + i*5*PtrSize);     //   0x30 / 0x50
+       return decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize + 2*PtrSize);
 }
 
 static vlong
 decodetype_structfieldoffs(Sym *s, int i)
 {
-       return decode_inuxi(s->p + 10*PtrSize + 0x10 + i*5*PtrSize, 4);  // 0x38  / 0x60
+       return decode_inuxi(s->p + CommonSize + PtrSize + 2*4 + i*StructFieldSize + 4*PtrSize, 4);
 }
 
 // InterfaceTYpe.methods.len
 static vlong
 decodetype_ifacemethodcount(Sym *s)
 {
-       return decode_inuxi(s->p + 6*PtrSize + 8, 4);
+       return decode_inuxi(s->p + CommonSize + PtrSize, 4);
 }
 
 
index 9ccee3ae9d2c0e6605f72b2ece3e75b69ca2e018..efe0238eaa6c5b77a4d41b319bf077d177870378 100644 (file)
@@ -48,6 +48,7 @@ type commonType struct {
        kind       uint8
        string     *string
        *uncommonType
+       ptrToThis *runtime.Type
 }
 
 type method struct {
index 87268db4cf842b96e3d81af73cfcc1b9d7d502a8..71ad4e7a54648d562848c416a925f5ecde9cb31c 100644 (file)
@@ -9,7 +9,7 @@
  * data structures and must be kept in sync with this file:
  *
  *     ../../cmd/gc/reflect.c
- *     ../../cmd/ld/dwarf.c
+ *     ../../cmd/ld/dwarf.c decodetype_*
  *     ../reflect/type.go
  *     type.h
  */
@@ -35,6 +35,7 @@ type commonType struct {
        kind          uint8   // enumeration for C
        string        *string // string form; unnecessary  but undeniably useful
        *uncommonType         // (relatively) uncommon fields
+       ptrToThis     *Type   // pointer to this type, if used in binary or has methods
 }
 
 // Values for commonType.kind.
index c7d9dace27c980be8ffb8567bb2062a3e37671e5..1adb6dc2e7345f7a34d28f746f0bcd1730d74ae1 100644 (file)
@@ -31,6 +31,7 @@ struct CommonType
        uint8 kind;
        String *string;
        UncommonType *x;
+       Type *ptrto;
 };
 
 enum {