Skip to content

Commit

Permalink
Merge pull request #12 from luoliwoshang/gogensig/refstdtypedef
Browse files Browse the repository at this point in the history
gogensig:header std incPath to pkg
  • Loading branch information
xushiwei authored Nov 29, 2024
2 parents 832b810 + 9afd79c commit bf2618a
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 21 deletions.
12 changes: 10 additions & 2 deletions cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
===== temp.go =====
package _systopkg

import _ "unsafe"

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



Expand All @@ -12,6 +14,12 @@ import _ "unsafe"



type Time struct {
T1 time.Tm
T2 time.TimeT
T3 time.ClockT
T4 time.Timespec
}



Expand Down
1 change: 0 additions & 1 deletion cmd/gogensig/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestFromTestdata(t *testing.T) {

// test sys type in stdinclude to package
func TestSysToPkg(t *testing.T) {
t.Skip("TODO")
name := "_systopkg"
dir, err := os.Getwd()
if err != nil {
Expand Down
25 changes: 14 additions & 11 deletions cmd/gogensig/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,14 @@ type PkgMapping struct {

const (
LLGO_C = "github.com/goplus/llgo/c"
LLGO_SYSTEM = "github.com/goplus/llgo/c/system"
LLGO_OS = "github.com/goplus/llgo/c/os"
LLGO_SETJMP = "github.com/goplus/llgo/c/setjmp"
LLGO_TIME = "github.com/goplus/llgo/c/time"
LLGO_MATH = "github.com/goplus/llgo/c/math"
LLGO_I18N = "github.com/goplus/llgo/c/i18n"
LLGO_COMPLEX = "github.com/goplus/llgo/c/math/cmplx"

// posix
LLGO_PTHREAD = "github.com/goplus/llgo/c/pthread"
LLGO_UNIX_NET = "github.com/goplus/llgo/c/unix/net"
)
Expand Down Expand Up @@ -555,22 +557,24 @@ func IncPathToPkg(incPath string) (pkg string, isDefault bool) {
{Pattern: `(^|[^a-zA-Z0-9])wctype[^a-zA-Z0-9]`, Package: LLGO_C},
{Pattern: `(^|[^a-zA-Z0-9])inttypes[^a-zA-Z0-9]`, Package: LLGO_C},

{Pattern: `(^|[^a-zA-Z0-9])signal[^a-zA-Z0-9]`, Package: LLGO_SYSTEM},
{Pattern: `(^|[^a-zA-Z0-9])setjmp[^a-zA-Z0-9]`, Package: LLGO_SYSTEM},
{Pattern: `(^|[^a-zA-Z0-9])assert[^a-zA-Z0-9]`, Package: LLGO_SYSTEM},
{Pattern: `(^|[^a-zA-Z0-9])stdalign[^a-zA-Z0-9]`, Package: LLGO_SYSTEM},
{Pattern: `(^|[^a-zA-Z0-9])signal[^a-zA-Z0-9]`, Package: LLGO_OS},
{Pattern: `(^|[^a-zA-Z0-9])sig[a-zA-Z]*[^a-zA-Z0-9]`, Package: LLGO_OS},
{Pattern: `(^|[^a-zA-Z0-9])assert[^a-zA-Z0-9]`, Package: LLGO_OS},
{Pattern: `(^|[^a-zA-Z0-9])stdalign[^a-zA-Z0-9]`, Package: LLGO_OS},

{Pattern: `(^|[^a-zA-Z0-9])setjmp[^a-zA-Z0-9]`, Package: LLGO_SETJMP},

{Pattern: `(^|[^a-zA-Z0-9])math[^a-zA-Z0-9]`, Package: LLGO_MATH},
{Pattern: `(^|[^a-zA-Z0-9])fenv[^a-zA-Z0-9]`, Package: LLGO_MATH},
{Pattern: `(^|[^a-zA-Z0-9])complex[^a-zA-Z0-9]`, Package: LLGO_COMPLEX},

{Pattern: `(^|[^a-zA-Z0-9])time[^a-zA-Z0-9]`, Package: LLGO_TIME},

{Pattern: `(^|[^a-zA-Z0-9])pthread[^a-zA-Z0-9]`, Package: LLGO_PTHREAD},
{Pattern: `(^|[^a-zA-Z0-9])pthread\w*`, Package: LLGO_PTHREAD},

{Pattern: `(^|[^a-zA-Z0-9])locale[^a-zA-Z0-9]`, Package: LLGO_I18N},

//c posix
// c posix
{Pattern: `(^|[^a-zA-Z0-9])socket[^a-zA-Z0-9]`, Package: LLGO_UNIX_NET},
{Pattern: `(^|[^a-zA-Z0-9])arpa[^a-zA-Z0-9]`, Package: LLGO_UNIX_NET},
{Pattern: `(^|[^a-zA-Z0-9])netinet6?[^a-zA-Z0-9]`, Package: LLGO_UNIX_NET},
Expand All @@ -587,15 +591,14 @@ func IncPathToPkg(incPath string) (pkg string, isDefault bool) {
{Pattern: `malloc`, Package: LLGO_C},
{Pattern: `alloc`, Package: LLGO_C},

{Pattern: `(^|[^a-zA-Z0-9])clock_t[^a-zA-Z0-9]`, Package: LLGO_TIME},
{Pattern: `(^|[^a-zA-Z0-9])clock(id_t|_t)`, Package: LLGO_TIME},
{Pattern: `(^|[^a-zA-Z0-9])(i)?time\w*`, Package: LLGO_TIME},
{Pattern: `(^|[^a-zA-Z0-9])tm[^a-zA-Z0-9]`, Package: LLGO_TIME},

// before must the special type.h such as _pthread_types.h ....
{Pattern: `\w+_t[^a-zA-Z0-9]`, Package: LLGO_C},
{Pattern: `(^|[^a-zA-Z0-9])types[^a-zA-Z0-9]`, Package: LLGO_C},
{Pattern: `(^|[^a-zA-Z0-9])sys[^a-zA-Z0-9]`, Package: LLGO_SYSTEM},

// {Pattern: `(^|[^a-zA-Z0-9])strings\.h$`, Package: LLGO_C},
{Pattern: `(^|[^a-zA-Z0-9])sys[^a-zA-Z0-9]`, Package: LLGO_OS},
}

for _, mapping := range pkgMappings {
Expand Down
121 changes: 114 additions & 7 deletions cmd/gogensig/convert/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1852,13 +1852,8 @@ func TestIncPathToPkg(t *testing.T) {
"sys/_types/_ptrdiff_t.h",
"sys/_types/_rsize_t.h",
"sys/_types/_rune_t.h",
"sys/_types/_sigaltstack.h",
"sys/_types/_sigset_t.h",
"sys/_types/_size_t.h",
"sys/_types/_ssize_t.h",
// posix
// "sys/_types/_timespec.h",
// "sys/_types/_timeval.h",
"sys/_types/_u_int16_t.h",
"sys/_types/_u_int32_t.h",
"sys/_types/_u_int64_t.h",
Expand All @@ -1882,9 +1877,10 @@ func TestIncPathToPkg(t *testing.T) {
"_locale.h",
"locale.h",
},
convert.LLGO_SYSTEM: []string{
convert.LLGO_OS: []string{
"sys/signal.h",
"setjmp.h",
"sys/_types/_sigaltstack.h",
"sys/_types/_sigset_t.h",
"signal.h",
"sys/errno.h",
"sys/resource.h",
Expand All @@ -1895,6 +1891,9 @@ func TestIncPathToPkg(t *testing.T) {
"time.h",
"sys/_types/_time_t.h",
"sys/_types/_clock_t.h",
//posix
"sys/_types/_timespec.h",
"sys/_types/_timeval.h",
},
convert.LLGO_UNIX_NET: []string{
"sys/socket.h",
Expand All @@ -1908,6 +1907,114 @@ func TestIncPathToPkg(t *testing.T) {
"math.h",
"fenv.h",
},
convert.LLGO_SETJMP: []string{
"setjmp.h",
},
},
// Ubuntu 24.04 LTS
"linux": {
convert.LLGO_C: []string{
"__stdarg_va_list.h",
"ctype.h",
"linux/types.h",
"bits/types/struct___jmp_buf_tag.h",
"bits/types/stack_t.h",
"bits/types/FILE.h",
"__stdarg___gnuc_va_list.h",
"__stddef_size_t.h",
"wchar.h",
"bits/types/struct_FILE.h",
"bits/types/mbstate_t.h",
"bits/types/__FILE.h",
"bits/stdint-uintn.h",
"bits/types.h",
"__stddef_wchar_t.h",
"__stddef_max_align_t.h",
"string.h",
"__stddef_ptrdiff_t.h",
"stdio.h",
"wctype.h",
"stdint.h",
"uchar.h",
"bits/stdint-least.h",
"bits/wctype-wchar.h",
"sys/types.h",
"bits/types/__mbstate_t.h",
"bits/types/wint_t.h",
"bits/types/__fpos_t.h",
"stdlib.h",
"bits/stdint-intn.h",
"inttypes.h",
"alloca.h",
"bits/floatn.h",
"bits/uintn-identity.h",
"stdatomic.h",
"errno.h",

// posix
"asm-generic/posix_types.h",
"asm/posix_types.h",
"strings.h",
"bits/thread-shared-types.h",

// linux
"bits/types/cookie_io_functions_t.h",
"bits/types/__fpos64_t.h",
"linux/posix_types.h",
"bits/byteswap.h",
"bits/procfs.h",
},
convert.LLGO_I18N: []string{
"bits/types/__locale_t.h",
"bits/types/locale_t.h",
"locale.h",
},
convert.LLGO_OS: []string{
"signal.h",
"assert.h",
"bits/types/sig_atomic_t.h",

// posix
"bits/types/sigset_t.h",
"bits/types/siginfo_t.h",
"bits/types/__sigval_t.h",
"bits/types/sigval_t.h",
"bits/types/sigevent_t.h",
"bits/types/struct_sigstack.h",
"bits/types/__sigset_t.h",
"bits/sigaction.h",
"asm/sigcontext.h",
"sys/select.h",
"sys/user.h",
"sys/procfs.h",
"sys/ucontext.h",
},
convert.LLGO_TIME: []string{
"time.h",
"sys/time.h",
"bits/types/clock_t.h",
"bits/types/struct_tm.h",
"bits/types/time_t.h",
// posix
"bits/types/timer_t.h",
"bits/types/struct_timespec.h",
"bits/types/struct_timeval.h",
"bits/types/clockid_t.h",
"bits/types/struct_itimerspec.h",
},
convert.LLGO_MATH: []string{
"bits/math-vector.h",
"math.h",
"fenv.h",
"bits/fenv.h",
},
convert.LLGO_SETJMP: []string{
"setjmp.h",
},
convert.LLGO_PTHREAD: []string{
"pthread.h",
"bits/pthreadtypes.h",
},
},
}
for testVer, pkgMap := range testCases {
Expand Down

0 comments on commit bf2618a

Please sign in to comment.