Skip to content

Commit

Permalink
rename emptyTypeDecl to NewEmptyTypeDecl and reuse it
Browse files Browse the repository at this point in the history
  • Loading branch information
tsingbx committed Jan 5, 2025
1 parent d904684 commit 1c7d285
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 54 deletions.
6 changes: 0 additions & 6 deletions cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@ import (
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
T2 time.TimeT
T3 time.ClockT
T4 time.Timespec
}

type Uchar struct {
Unused [8]uint8
}

type Wchar struct {
Unused [8]uint8
}
Expand Down
1 change: 0 additions & 1 deletion cmd/gogensig/convert/_testdata/cjson/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type JSON struct {
Valuedouble float64
String *int8
}

type Hooks struct {
MallocFn unsafe.Pointer
FreeFn unsafe.Pointer
Expand Down
1 change: 1 addition & 0 deletions cmd/gogensig/convert/_testdata/enum/hfile/temp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enum { enum1, enum2 };

enum spectrum { red, orange, yello, green, blue, violet };

enum kids { nippy, slats, skippy, nina, liz };
Expand Down
12 changes: 0 additions & 12 deletions cmd/gogensig/convert/_testdata/forwarddecl/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
type Foo struct {
A c.Long
}

type File struct {
PMethods *IoMethods
}

type IoMethods struct {
XUnfetch unsafe.Pointer
}
Expand All @@ -29,16 +27,13 @@ import (
type Bar struct {
A *Foo
}

type PcachePage struct {
PBuf unsafe.Pointer
PExtra unsafe.Pointer
}

type Pcache struct {
Unused [8]uint8
}

type PcacheMethods2 struct {
IVersion c.Int
PArg unsafe.Pointer
Expand All @@ -54,11 +49,9 @@ type PcacheMethods2 struct {
XDestroy unsafe.Pointer
XShrink unsafe.Pointer
}

type State struct {
Unused [8]uint8
}

type Debug struct {
Event c.Int
Name *int8
Expand All @@ -83,24 +76,19 @@ func Getstack(L *State, level c.Int, ar *Debug) c.Int
type CallInfo struct {
Unused [8]uint8
}

type Fts5ExtensionApi struct {
Unused [8]uint8
}

type Fts5Context struct {
Unused [8]uint8
}

type Fts5PhraseIter struct {
A *int8
B *int8
}

type Value struct {
Unused [8]uint8
}

type Context struct {
Unused [8]uint8
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/gogensig/convert/_testdata/funcrefer/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type Hooks struct {
MallocFn unsafe.Pointer
FreeFn unsafe.Pointer
}

type Stream struct {
F *c.FILE
Cb unsafe.Pointer
Expand All @@ -29,7 +28,6 @@ func ProviderInit2(__llgo_va_list ...interface{})
type OSSLCOREHANDLE struct {
Unused [8]uint8
}

type OSSLDISPATCH struct {
Unused [8]uint8
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/gogensig/convert/_testdata/lua/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Buffer struct {
B [1024]int8
}
}

type Reg struct {
Name *int8
Func unsafe.Pointer
Expand Down Expand Up @@ -143,7 +142,6 @@ type Writer func(*State, unsafe.Pointer, uintptr, unsafe.Pointer) c.Int
type Alloc func(unsafe.Pointer, unsafe.Pointer, uintptr, uintptr) unsafe.Pointer
// llgo:type C
type WarnFunction func(unsafe.Pointer, *int8, c.Int)

type Debug struct {
Event c.Int
Name *int8
Expand Down
3 changes: 0 additions & 3 deletions cmd/gogensig/convert/_testdata/nested/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Struct1 struct {
B [60]int8
}
}

type Struct2 struct {
B *int8
Size uintptr
Expand All @@ -24,15 +23,13 @@ type Struct2 struct {
Rec Struct1
}
}

type Union1 struct {
Init struct {
L c.Long
B [60]int8
Rec Struct2
}
}

type Union2 struct {
Init struct {
Rec Struct2
Expand Down
2 changes: 0 additions & 2 deletions cmd/gogensig/convert/_testdata/pubfile/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ type Point struct {
X c.Int
Y c.Int
}

type Capital struct {
X c.Int
Y c.Int
}

type CustomData struct {
Str [20]int8
}
Expand Down
1 change: 0 additions & 1 deletion cmd/gogensig/convert/_testdata/receiver/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
type InAddr1 struct {
SAddr c.Uint
}

type AresIn6Addr struct {
X_S6Un struct {
X_S6U8 [16]int8
Expand Down
12 changes: 0 additions & 12 deletions cmd/gogensig/convert/_testdata/sqlite/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (recv_ *Sqlite3) Exec(sql *int8, callback func(unsafe.Pointer, c.Int, **int
type File struct {
PMethods *IoMethods
}

type IoMethods struct {
IVersion c.Int
XClose unsafe.Pointer
Expand All @@ -65,11 +64,9 @@ type IoMethods struct {
XFetch unsafe.Pointer
XUnfetch unsafe.Pointer
}

type Mutex struct {
Unused [8]uint8
}

type ApiRoutines struct {
AggregateContext unsafe.Pointer
AggregateCount unsafe.Pointer
Expand Down Expand Up @@ -339,15 +336,12 @@ type ApiRoutines struct {
GetClientdata unsafe.Pointer
SetClientdata unsafe.Pointer
}

type Value struct {
Unused [8]uint8
}

type Context struct {
Unused [8]uint8
}

type Fts5ExtensionApi struct {
IVersion c.Int
XUserData unsafe.Pointer
Expand All @@ -374,35 +368,29 @@ type Fts5ExtensionApi struct {
XColumnLocale unsafe.Pointer
XTokenizeV2 unsafe.Pointer
}

type Fts5Context struct {
Unused [8]uint8
}

type Fts5PhraseIter struct {
A *int8
B *int8
}
// llgo:type C
type Fts5ExtensionFunction func(*Fts5ExtensionApi, *Fts5Context, *Context, c.Int, **Value)

type Fts5Tokenizer struct {
Unused [8]uint8
}

type Fts5TokenizerV2 struct {
IVersion c.Int
XCreate unsafe.Pointer
XDelete unsafe.Pointer
XTokenize unsafe.Pointer
}

type Fts5Tokenizer__1 struct {
XCreate unsafe.Pointer
XDelete unsafe.Pointer
XTokenize unsafe.Pointer
}

type Fts5Api struct {
IVersion c.Int
XCreateTokenizer unsafe.Pointer
Expand Down
3 changes: 0 additions & 3 deletions cmd/gogensig/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ func (p *AstConvert) VisitUnion(unionName *ast.Ident, fields *ast.FieldList, typ
}

func (p *AstConvert) VisitEnumTypeDecl(enumTypeDecl *ast.EnumTypeDecl) {
if enumTypeDecl == nil || enumTypeDecl.Name == nil || len(enumTypeDecl.Name.Name) == 0 {
return
}
err := p.Pkg.NewEnumTypeDecl(enumTypeDecl)
if err != nil {
if name := enumTypeDecl.Name; name != nil {
Expand Down
20 changes: 10 additions & 10 deletions cmd/gogensig/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (p *Package) handleTypeDecl(pubname string, cname string, typeDecl *ast.Typ
if existDecl, exists := p.incomplete[cname]; exists {
return existDecl
}
_, decl := p.emptyTypeDecl(pubname, typeDecl.Doc)
_, decl := p.NewEmptyTypeDecl(pubname, typeDecl.Doc)
inc := &Incomplete{
file: p.curFile,
decl: decl,
Expand Down Expand Up @@ -377,7 +377,7 @@ func (p *Package) handleImplicitForwardDecl(name string) *gogen.TypeDecl {
return decl.decl
}
pubName := p.nameMapper.GetGoName(name, p.trimPrefixes())
typdef, decl := p.emptyTypeDecl(pubName, nil)
typdef, decl := p.NewEmptyTypeDecl(pubName, nil)
p.incomplete[name] = &Incomplete{
file: p.curFile,
decl: decl,
Expand All @@ -387,9 +387,11 @@ func (p *Package) handleImplicitForwardDecl(name string) *gogen.TypeDecl {
return decl
}

func (p *Package) emptyTypeDecl(name string, doc *ast.CommentGroup) (*gogen.TypeDefs, *gogen.TypeDecl) {
func (p *Package) NewEmptyTypeDecl(name string, doc *ast.CommentGroup) (*gogen.TypeDefs, *gogen.TypeDecl) {
typeBlock := p.p.NewTypeDefs()
typeBlock.SetComments(CommentGroup(doc).CommentGroup)
if doc != nil {
typeBlock.SetComments(CommentGroup(doc).CommentGroup)
}
return typeBlock, typeBlock.NewType(name)
}

Expand Down Expand Up @@ -417,8 +419,7 @@ func (p *Package) NewTypedefDecl(typedefDecl *ast.TypedefDecl) error {
genDecl = incompleteDecl.typdef
typeSpecdecl = incompleteDecl.decl

Check warning on line 420 in cmd/gogensig/convert/package.go

View check run for this annotation

Codecov / codecov/patch

cmd/gogensig/convert/package.go#L419-L420

Added lines #L419 - L420 were not covered by tests
} else {
genDecl = p.p.NewTypeDefs()
typeSpecdecl = genDecl.NewType(name)
genDecl, typeSpecdecl = p.NewEmptyTypeDecl(name, nil)
}

if changed {
Expand Down Expand Up @@ -483,16 +484,15 @@ func (p *Package) ToType(expr ast.Expr) (types.Type, error) {
return p.cvt.ToType(expr)
}

func (p *Package) NewTypedefs(name string, typ types.Type, cname string) *gogen.TypeDecl {
func (p *Package) NewEnumTypedefs(name string, typ types.Type, cname string) *gogen.TypeDecl {
var def *gogen.TypeDefs
var t *gogen.TypeDecl
var incompleteDecl *Incomplete
if incompleteDecl = p.incomplete[cname]; incompleteDecl != nil {
def = incompleteDecl.typdef
t = incompleteDecl.decl

Check warning on line 493 in cmd/gogensig/convert/package.go

View check run for this annotation

Codecov / codecov/patch

cmd/gogensig/convert/package.go#L492-L493

Added lines #L492 - L493 were not covered by tests
} else {
def = p.p.NewTypeDefs()
t = def.NewType(name)
def, t = p.NewEmptyTypeDecl(name, nil)
}
if incompleteDecl != nil {
incompleteDecl.inited = true
Expand Down Expand Up @@ -540,7 +540,7 @@ func (p *Package) createEnumType(enumName *ast.Ident) (types.Type, string, error
}
enumType := p.cvt.ToDefaultEnumType()
if name != "" {
t = p.NewTypedefs(name, enumType, enumName.Name)
t = p.NewEnumTypedefs(name, enumType, enumName.Name)
enumType = p.p.Types.Scope().Lookup(name).Type()
}
if changed {
Expand Down

0 comments on commit 1c7d285

Please sign in to comment.