Skip to content

Commit

Permalink
gogensig:defafult struct
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Dec 4, 2024
1 parent 5bcc419 commit dcafd8f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
24 changes: 18 additions & 6 deletions cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ import (
_ "unsafe"
)

type Fenv struct {
Unused [8]uint8
}

type Stddef struct {
Unused [8]uint8
}

type Stdint struct {
Unused [8]uint8
}





type Stdio struct {
Unused [8]uint8
}

type Time struct {
T1 time.Tm
Expand All @@ -21,9 +29,13 @@ type Time struct {
T4 time.Timespec
}

type Uchar struct {
Unused [8]uint8
}



type Wchar struct {
Unused [8]uint8
}

===== llcppg.pub =====
fenv Fenv
Expand Down
8 changes: 6 additions & 2 deletions cmd/gogensig/convert/_testdata/lua/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"unsafe"
)


type Buffer struct {
Unused [8]uint8
}

type Reg struct {
Name *int8
Expand Down Expand Up @@ -103,7 +105,9 @@ func Pushresultsize(B *Buffer, sz uintptr)
//go:linkname Buffinitsize C.luaL_buffinitsize
func Buffinitsize(L *State, B *Buffer, sz uintptr) *int8


type Stream struct {
Unused [8]uint8
}

===== lua.go =====
package lua
Expand Down
4 changes: 4 additions & 0 deletions cmd/gogensig/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ import (
)
type NormalType c.Int
type Foo struct {
Unused [8]uint8
}
`
if strings.TrimSpace(expectedOutput) != strings.TrimSpace(buf.String()) {
t.Errorf("does not match expected.\nExpected:\n%s\nGot:\n%s", expectedOutput, buf.String())
Expand Down
5 changes: 3 additions & 2 deletions cmd/gogensig/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,14 @@ func (p *Package) handleTypeDecl(name string, typeDecl *ast.TypeDecl, changed bo
}

func (p *Package) handleCompleteType(decl *gogen.TypeDecl, typ *ast.RecordType, name string) error {
defer delete(p.incomplete, name)
structType, err := p.cvt.RecordTypeToStruct(typ)
if err != nil {
decl.Delete()
// For incomplete type's conerter error, we use default struct type
decl.InitType(p.p, types.NewStruct(p.cvt.defaultRecordField(), nil))
return err
}
decl.InitType(p.p, structType)
delete(p.incomplete, name)
return nil
}

Expand Down

0 comments on commit dcafd8f

Please sign in to comment.