Skip to content

Commit

Permalink
Merge pull request #95 from luoliwoshang/gogensig/receiver
Browse files Browse the repository at this point in the history
gogensig:fix unexpect receiver duplicate init
  • Loading branch information
tsingbx authored Dec 26, 2024
2 parents ba626a8 + fd8a0a3 commit f62be6d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/conf/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "comment",
"include": ["temp.h","use.h"],
"cplusplus":false
}
12 changes: 12 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"mangle": "ares_dns_pton",
"c++": "ares_dns_pton(const char *, struct ares_addr *, int *)",
"go": "AresDnsPton"
},
{
"mangle": "ares_dns_addr_to_ptr",
"c++": "ares_dns_addr_to_ptr(const struct ares_addr *)",
"go": "(*aresAddr).AresDnsAddrToPtr"
}
]
40 changes: 40 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/gogensig.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
===== temp.go =====
package receiver

import (
"github.com/goplus/llgo/c"
_ "unsafe"
)

type InAddr1 struct {
SAddr c.Uint
}

type AresIn6Addr struct {
X_S6Un struct {
X_S6U8 [16]int8
}
}

===== use.go =====
package receiver

import "unsafe"

type AresAddr struct {
Family c.Int
Addr struct {
Addr6 AresIn6Addr
}
}
//go:linkname AresDnsPton C.ares_dns_pton
func AresDnsPton(ipaddr *int8, addr *AresAddr) unsafe.Pointer
// llgo:link (*aresAddr).AresDnsAddrToPtr C.ares_dns_addr_to_ptr
func (p *AresAddr) AresDnsAddrToPtr() *int8 {
return nil
}

===== llcppg.pub =====
ares_addr AresAddr
ares_in6_addr AresIn6Addr
in_addr1 InAddr1
20 changes: 20 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/hfile/temp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct in_addr1 {
unsigned int s_addr;
};

struct ares_in6_addr {
union {
unsigned char _S6_u8[16];
} _S6_un;
};

struct ares_addr {
int family;

union {
struct in_addr1 addr4;
struct ares_in6_addr addr6;
} addr;
};

#include "use.h"
3 changes: 3 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/hfile/use.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// todo(zzy): ares_addr need generate in the temp.go
const void *ares_dns_pton(const char *ipaddr, struct ares_addr *addr);
char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
3 changes: 3 additions & 0 deletions cmd/gogensig/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ func (p *Package) handleCompleteType(decl *gogen.TypeDecl, typ *ast.RecordType,
// For such declarations, create a empty type decl and store it in the
// incomplete map, but not in the public symbol table.
func (p *Package) handleImplicitForwardDecl(name string) *gogen.TypeDecl {
if decl, ok := p.incomplete[name]; ok {
return decl
}
pubName := p.nameMapper.GetGoName(name, p.trimPrefixes())
decl := p.emptyTypeDecl(pubName, nil)
p.incomplete[name] = decl
Expand Down
6 changes: 5 additions & 1 deletion cmd/gogensig/convert/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,13 @@ func (p *TypeConv) ToSignature(funcType *ast.FuncType, recv *types.Var) (*types.
ctx := p.ctx
p.ctx = Param
defer func() { p.ctx = ctx }()
params, variadic, err := p.fieldListToParams(funcType.Params)
var params *types.Tuple
var variadic bool
var err error
if recv != nil {
params, variadic, err = p.fieldListToParams(&ast.FieldList{List: funcType.Params.List[1:]})
} else {
params, variadic, err = p.fieldListToParams(funcType.Params)
}
if err != nil {
return nil, err
Expand Down

0 comments on commit f62be6d

Please sign in to comment.