diff --git a/tools/gostd/_tests/gold/amd64-linux/gosrc.gold b/tools/gostd/_tests/gold/amd64-linux/gosrc.gold index 278ec23a3..2266e3aa5 100644 --- a/tools/gostd/_tests/gold/amd64-linux/gosrc.gold +++ b/tools/gostd/_tests/gold/amd64-linux/gosrc.gold @@ -152416,8 +152416,6 @@ func ExtractGoObjectSliceHeader(args []Object, index int) *reflect.SliceHeader { switch o := a.(type) { case GoObject: switch r := o.O.(type) { - case reflect.SliceHeader: - return &r case *reflect.SliceHeader: return r } @@ -152435,34 +152433,12 @@ func ExtractGo_go_std_reflect__SliceHeader(rcvr, arg string, args *ArraySeq, n i return } -func _mapToSliceHeader(o Map) *reflect.SliceHeader { - return &reflect.SliceHeader{ - Data: FieldAsUintPtr(o, "Data"), - Len: FieldAsInt(o, "Len"), - Cap: FieldAsInt(o, "Cap"), - } -} - -func _Ctor_SliceHeader(_v Object) *reflect.SliceHeader { - switch _o := _v.(type) { - case *ArrayMap, *HashMap: - return _mapToSliceHeader(_o.(Map)) - } - panic(RT.NewArgTypeError(0, _v, "GoObject[reflect.SliceHeader] or: Map")) -} - -func _Wrapped_Ctor_SliceHeader(_o Object) Object { - return MakeGoObject(_Ctor_SliceHeader(_o)) -} - GO TYPE reflect.StringHeader from reflect/value.go: func ExtractGoObjectStringHeader(args []Object, index int) *reflect.StringHeader { a := args[index] switch o := a.(type) { case GoObject: switch r := o.O.(type) { - case reflect.StringHeader: - return &r case *reflect.StringHeader: return r } @@ -152480,25 +152456,6 @@ func ExtractGo_go_std_reflect__StringHeader(rcvr, arg string, args *ArraySeq, n return } -func _mapToStringHeader(o Map) *reflect.StringHeader { - return &reflect.StringHeader{ - Data: FieldAsUintPtr(o, "Data"), - Len: FieldAsInt(o, "Len"), - } -} - -func _Ctor_StringHeader(_v Object) *reflect.StringHeader { - switch _o := _v.(type) { - case *ArrayMap, *HashMap: - return _mapToStringHeader(_o.(Map)) - } - panic(RT.NewArgTypeError(0, _v, "GoObject[reflect.StringHeader] or: Map")) -} - -func _Wrapped_Ctor_StringHeader(_o Object) Object { - return MakeGoObject(_Ctor_StringHeader(_o)) -} - GO TYPE reflect.StructField from reflect/type.go: func ExtractGoObjectStructField(args []Object, index int) *reflect.StructField { a := args[index] @@ -153705,7 +153662,6 @@ GO INFO FOR TYPE go.std.reflect/refToSelectDir from /usr/local/go/src/reflect/va GO INFO FOR TYPE go.std.reflect/SliceHeader from /usr/local/go/src/reflect/value.go:1994:6: info_SliceHeader = GoTypeInfo{Name: "go.std.reflect/SliceHeader", GoType: &GoType{T: &info_SliceHeader}, - Ctor: _Wrapped_Ctor_SliceHeader, Members: GoMembers{ }, } @@ -153714,7 +153670,6 @@ GO INFO FOR TYPE go.std.reflect/SliceHeader from /usr/local/go/src/reflect/value GO INFO FOR TYPE go.std.reflect/refToSliceHeader from /usr/local/go/src/reflect/value.go:1994:6: info_PtrTo_SliceHeader = GoTypeInfo{Name: "go.std.reflect/refToSliceHeader", GoType: &GoType{T: &info_PtrTo_SliceHeader}, - Ctor: _Wrapped_Ctor_SliceHeader, Members: GoMembers{ }, } @@ -153723,7 +153678,6 @@ GO INFO FOR TYPE go.std.reflect/refToSliceHeader from /usr/local/go/src/reflect/ GO INFO FOR TYPE go.std.reflect/StringHeader from /usr/local/go/src/reflect/value.go:1983:6: info_StringHeader = GoTypeInfo{Name: "go.std.reflect/StringHeader", GoType: &GoType{T: &info_StringHeader}, - Ctor: _Wrapped_Ctor_StringHeader, Members: GoMembers{ }, } @@ -153732,7 +153686,6 @@ GO INFO FOR TYPE go.std.reflect/StringHeader from /usr/local/go/src/reflect/valu GO INFO FOR TYPE go.std.reflect/refToStringHeader from /usr/local/go/src/reflect/value.go:1983:6: info_PtrTo_StringHeader = GoTypeInfo{Name: "go.std.reflect/refToStringHeader", GoType: &GoType{T: &info_PtrTo_StringHeader}, - Ctor: _Wrapped_Ctor_StringHeader, Members: GoMembers{ }, } @@ -176520,6 +176473,6 @@ Totals: functions=4055 generated=2987 (73.66%) receivers=2063 (50.88%) generated=1459 (70.72%) methods=397 (9.79%) generated=247 (62.22%) types=1841 - constructable=1674 ctors=887 (52.99%) + constructable=1674 ctors=883 (52.75%) constants=4394 generated=4356 (99.14%) variables=439 generated=439 (100.00%) diff --git a/tools/gostd/codegen.go b/tools/gostd/codegen.go index 75541230b..52325ea18 100644 --- a/tools/gostd/codegen.go +++ b/tools/gostd/codegen.go @@ -443,21 +443,27 @@ func ExtractGoObject%s(args []Object, index int) *%s { switch o := a.(type) { case GoObject: switch r := o.O.(type) { - case %s: - return &r - case *%s: +%s case *%s: return r } %s} panic(RT.NewArgTypeError(index, a, "GoObject[%s]")) } +` + const goExtractRefToTemplate = ` + case %s: + return &r ` baseTypeName := ts.Name.Name typeName := myGoImport + "." + baseTypeName others := maybeImplicitConvert(godb.GoFileForTypeSpec(ts), typeName, ts) - goc := fmt.Sprintf(goExtractTemplate, baseTypeName, typeName, typeName, typeName, others, t) + goExtractRefTo := "" + if !(ti.GoPackage() == "reflect" && (ti.GoBaseName() == "StringHeader" || ti.GoBaseName() == "SliceHeader")) { + goExtractRefTo = fmt.Sprintf(goExtractRefToTemplate[1:], typeName) + } + goc := fmt.Sprintf(goExtractTemplate, baseTypeName, typeName, goExtractRefTo, typeName, others, t) goc += goTypeExtractor(t, ti) @@ -474,6 +480,9 @@ func genCtor(tyi TypeInfo) { if !tyi.Custom() { return } + if tyi.GoPackage() == "reflect" && (tyi.GoBaseName() == "StringHeader" || tyi.GoBaseName() == "SliceHeader") { + return + } ts := tyi.TypeSpec() if ts == nil {