diff --git a/cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect b/cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect index f48620e9..01bfcfb9 100644 --- a/cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect +++ b/cmd/gogensig/convert/_testdata/_systopkg/gogensig.expect @@ -1,8 +1,10 @@ ===== temp.go ===== package _systopkg -import _ "unsafe" - +import ( + "github.com/goplus/llgo/c/time" + _ "unsafe" +) @@ -12,6 +14,12 @@ import _ "unsafe" +type Time struct { + T1 time.Tm + T2 time.TimeT + T3 time.ClockT + T4 time.Timespec +} diff --git a/cmd/gogensig/convert/convert_test.go b/cmd/gogensig/convert/convert_test.go index 745e97d5..c31d572d 100644 --- a/cmd/gogensig/convert/convert_test.go +++ b/cmd/gogensig/convert/convert_test.go @@ -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 { diff --git a/cmd/gogensig/convert/package.go b/cmd/gogensig/convert/package.go index 5c74614e..6a09d50b 100644 --- a/cmd/gogensig/convert/package.go +++ b/cmd/gogensig/convert/package.go @@ -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" ) @@ -555,10 +557,12 @@ 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}, @@ -566,11 +570,11 @@ func IncPathToPkg(incPath string) (pkg string, isDefault bool) { {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}, @@ -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 { diff --git a/cmd/gogensig/convert/package_test.go b/cmd/gogensig/convert/package_test.go index a90445ea..d0abf813 100644 --- a/cmd/gogensig/convert/package_test.go +++ b/cmd/gogensig/convert/package_test.go @@ -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", @@ -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", @@ -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", @@ -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 {