Skip to content

Commit

Permalink
remove c2go support
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed May 18, 2024
1 parent 7468f9e commit 22f89bf
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 270 deletions.
4 changes: 2 additions & 2 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,6 @@ retry:
case *tyTypeAsParams:
return matchFuncCall(pkg, chgObject(pkg, ft.obj, fn), args, flags|instrFlagGopxFunc)
}
} else if IsCSignature(t) {
sig = types.NewSignatureType(nil, nil, nil, t.Params(), t.Results(), t.Variadic())
} else {
sig = t
}
Expand Down Expand Up @@ -950,11 +948,13 @@ func restoreArgs(args []*internal.Elem, backup []backupElem) {
}
}

/*
func copyArgs(args []*internal.Elem) []*internal.Elem {
backup := make([]*internal.Elem, len(args))
copy(backup, args)
return backup
}
*/

func untypeBig(pkg *Package, cval constant.Value, tyRet types.Type) (*internal.Elem, bool) {
switch tyRet {
Expand Down
67 changes: 2 additions & 65 deletions builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,6 @@ func TestGetSrcPos(t *testing.T) {
}
}

func TestExportFields(t *testing.T) {
pkg := NewPackage("", "foo", nil)
fields := []*types.Var{
types.NewField(token.NoPos, pkg.Types, "Y", types.Typ[types.Int], false),
types.NewField(token.NoPos, pkg.Types, "X__u", types.Typ[types.String], false),
}
tyT := pkg.NewType("T").InitType(pkg, types.NewStruct(fields, nil))
pkg.ExportFields(tyT)
if name := pkg.cb.getFieldName(tyT, "y"); name != "Y" {
t.Fatal("getFieldName y:", name)
}
if name := pkg.cb.getFieldName(tyT, "__u"); name != "X__u" {
t.Fatal("getFieldName __u:", name)
}
if CPubName("123") != "123" {
t.Fatal("CPubName(123) failed")
}
}

func TestIsTypeEx(t *testing.T) {
pkg := types.NewPackage("", "foo")
o := NewInstruction(0, pkg, "bar", lenInstr{})
Expand Down Expand Up @@ -699,13 +680,6 @@ func TestToVariadic(t *testing.T) {

func TestToType(t *testing.T) {
pkg := NewPackage("", "foo", gblConf)
cf := NewCSignature(nil, nil, false)
if !IsCSignature(cf) {
t.Fatal("IsCSignature failed: not c function?")
}
if v := typString(pkg, cf); v != "func()" {
t.Fatal("toType failed:", v)
}
toType(pkg, &unboundType{tBound: tyInt})
defer func() {
if e := recover(); e == nil {
Expand All @@ -715,6 +689,7 @@ func TestToType(t *testing.T) {
toType(pkg, &unboundType{})
}

/*
func typString(pkg *Package, t types.Type) string {
v := toType(pkg, t)
var b bytes.Buffer
Expand All @@ -724,6 +699,7 @@ func typString(pkg *Package, t types.Type) string {
}
return b.String()
}
*/

func TestMethodAutoProperty(t *testing.T) {
pkg := types.NewPackage("", "")
Expand Down Expand Up @@ -786,16 +762,11 @@ func TestHasAutoProperty(t *testing.T) {

func TestTypeEx(t *testing.T) {
subst := &TySubst{}
bfReft := &bfRefType{typ: tyInt}
if typ, ok := DerefType(bfReft); !ok || typ != tyInt {
t.Fatal("TestDerefType failed")
}
pkg := NewPackage("example.com/foo", "foo", gblConf)
tyInt := types.Typ[types.Int]
typs := []types.Type{
&refType{},
subst,
bfReft,
&unboundType{},
&unboundMapElemType{},
&TyOverloadFunc{},
Expand All @@ -811,9 +782,6 @@ func TestTypeEx(t *testing.T) {
&TemplateParamType{},
&TemplateSignature{},
}
if v := bfReft.String(); v != "bfRefType{typ: int:0 off: 0}" {
t.Fatal("bfRefType.String:", v)
}
if v := subst.String(); v != "substType{real: <nil>}" {
t.Fatal("substType.String:", v)
}
Expand Down Expand Up @@ -1307,37 +1275,6 @@ func TestCallIncDec(t *testing.T) {
callIncDec(pkg, args, token.INC)

Check warning on line 1275 in builtin_test.go

View check run for this annotation

qiniu-x / golangci-lint

builtin_test.go#L1275

Error return value is not checked (errcheck)
}

func TestVFields(t *testing.T) {
pkg := NewPackage("", "foo", gblConf)
typ := types.NewNamed(types.NewTypeName(token.NoPos, pkg.Types, "bar", nil), tyInt, nil)
_, ok := pkg.VFields(typ)
if ok {
t.Fatal("VFields?")
}
{
flds := NewUnionFields([]*UnionField{
{Name: "foo"},
})
if flds.Len() != 1 {
t.Fatal("UnionFields.len != 1")
}
if flds.At(0).Name != "foo" {
t.Fatal("UnionField.name != foo")
}
}
{
flds := NewBitFields([]*BitField{
{Name: "foo"},
})
if flds.Len() != 1 {
t.Fatal("BitFields.len != 1")
}
if flds.At(0).Name != "foo" {
t.Fatal("BitField.name != foo")
}
}
}

func TestTypeAST(t *testing.T) {
pkg := NewPackage("", "foo", gblConf)
fset := token.NewFileSet()
Expand Down
27 changes: 27 additions & 0 deletions c.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

package gogen

import (
"go/ast"
"go/types"
)

/*
import (
"go/ast"
"go/token"
Expand Down Expand Up @@ -266,5 +272,26 @@ func IsMethodRecv(recv *types.Var) bool {
func isCSigRecv(recv *types.Var) bool {
return recv.Type() == types.Typ[types.UntypedNil]
}
*/

type none = struct{}

// ----------------------------------------------------------------------------

func (p *CodeBuilder) getFieldName(t *types.Named, name string) string {
return name
}

func (p *CodeBuilder) findVField(t *types.Named, name string, arg *Element, src ast.Node) MemberKind {
return MemberInvalid
}

func (p *CodeBuilder) refVField(t *types.Named, name string, src ast.Node) MemberKind {
return MemberInvalid
}

func IsMethodRecv(recv *types.Var) bool {
return recv != nil
}

// ----------------------------------------------------------------------------
3 changes: 2 additions & 1 deletion c_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package gogen_test

/*
import (
"go/token"
"go/types"
Expand Down Expand Up @@ -175,5 +176,5 @@ func test() {
}
`)
}

*/
// ----------------------------------------------------------------------------
23 changes: 0 additions & 23 deletions codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ type CodeBuilder struct {
loadNamed LoadNamedFunc
handleErr func(err error)
closureParamInsts
vFieldsMgr
iotav int
commentOnce bool
noSkipConst bool
Expand Down Expand Up @@ -2116,24 +2115,11 @@ func (p *CodeBuilder) doAssignWith(lhs, rhs int, src ast.Node) *CodeBuilder {
}
}
if lhs == rhs {
mkBlockStmt = hasBfRefType(args)
if mkBlockStmt { // {
args = copyArgs(args)
p.stk.PopN(lhs << 1)
p.Block()
}
for i := 0; i < lhs; i++ {
lhsType := args[i].Type
bfr, bfAssign := lhsType.(*bfRefType)
if bfAssign {
lhsType = &refType{typ: bfr.typ}
}
checkAssignType(p.pkg, lhsType, args[lhs+i])
stmt.Lhs[i] = args[i].Val
stmt.Rhs[i] = args[lhs+i].Val
if bfAssign {
bfr.assign(p, &stmt.Lhs[i], &stmt.Rhs[i])
}
}
} else {
pos := getSrcPos(src)
Expand All @@ -2150,15 +2136,6 @@ done:
return p
}

func hasBfRefType(args []*internal.Elem) bool {
for _, arg := range args {
if _, ok := arg.Type.(*bfRefType); ok {
return true
}
}
return false
}

func lookupMethod(t *types.Named, name string) types.Object {
for i, n := 0, t.NumMethods(); i < n; i++ {
m := t.Method(i)
Expand Down
86 changes: 0 additions & 86 deletions cpackages/import.go

This file was deleted.

Loading

0 comments on commit 22f89bf

Please sign in to comment.