From a71344a970697692d6ad52a4230724669994e289 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 12 Sep 2026 20:35:04 +0800 Subject: [PATCH] cl: TestMockC ok --- cl/_testmockc/function/out.go | 7 +++++ cl/compile_test.go | 5 +--- cmd/llgogen/llgogen.go | 49 +++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 +-- 5 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 cl/_testmockc/function/out.go create mode 100644 cmd/llgogen/llgogen.go diff --git a/cl/_testmockc/function/out.go b/cl/_testmockc/function/out.go new file mode 100644 index 00000000..14ac025a --- /dev/null +++ b/cl/_testmockc/function/out.go @@ -0,0 +1,7 @@ +package foo + +import "github.com/goplus/lib/c" + +func f(a c.Int) c.Uint +func g() +func xprintf(fmt *c.Char, __llgo_va_list ...any) c.Int diff --git a/cl/compile_test.go b/cl/compile_test.go index 2ee892b2..b331cddc 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -18,7 +18,6 @@ package cl_test import ( "bytes" - "log" "os" "testing" @@ -44,13 +43,11 @@ func testDiff(t *testing.T, dir string, outfname string, b *bytes.Buffer, exp an } func testGenGo(t *testing.T, pkg *gogen.Package, dir string, exp any) { - log.Println("==> testGenGo", dir) var b bytes.Buffer err := pkg.WriteTo(&b) if err != nil { t.Fatal("gogen.WriteTo failed:", err) } - log.Println("==> testGenGo", dir, "len:", b.Len()) testDiff(t, dir, "/result.txt", &b, exp) } @@ -78,7 +75,7 @@ func testFromDir(t *testing.T, sel, relDir, lang string) { }) } -func _TestMockC(t *testing.T) { +func TestMockC(t *testing.T) { cl.SetDebug(cl.DbgFlagAll) testFromDir(t, "", "./_testmockc", "c") } diff --git a/cmd/llgogen/llgogen.go b/cmd/llgogen/llgogen.go new file mode 100644 index 00000000..58aaaaeb --- /dev/null +++ b/cmd/llgogen/llgogen.go @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "go/token" + "go/types" + "log" + "os" + + "github.com/goplus/gogen" + "github.com/goplus/gogen/packages" +) + +func main() { + pkg := gogen.NewPackage("", "foo", &gogen.Config{ + Importer: packages.NewImporter(nil), + LoadNamed: nil, + HandleErr: nil, + NewBuiltin: nil, + NodeInterpreter: nil, + CanImplicitCast: nil, + DefaultGoFile: "", + }) + pkg.SetRedeclarable(true) + sig := types.NewSignatureType(nil, nil, nil, nil, nil, false) + _, err := pkg.NewFuncWith(token.NoPos, "g", sig, nil) + if err != nil { + log.Panicln("compileFunc:", "g", err) + } + err = pkg.WriteTo(os.Stdout) + if err != nil { + log.Panicln("gogen.WriteTo failed:", err) + } +} diff --git a/go.mod b/go.mod index b31ab324..bf16f1d0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/goplus/llcppg go 1.27.0 require ( - github.com/goplus/gogen v1.23.5 + github.com/goplus/gogen v1.24.0 github.com/goplus/lib v0.5.2 github.com/qiniu/x v1.18.3 ) diff --git a/go.sum b/go.sum index f5c46251..a45cee18 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/goplus/gogen v1.23.5 h1:76w3zmAHI+ECI7bPr0enUd0du9+t1IYyXmp43CbIpSs= -github.com/goplus/gogen v1.23.5/go.mod h1:Y7ulYW3wonQ3d9er00b0uGFEV/IUZa6okWJZh892ACQ= +github.com/goplus/gogen v1.24.0 h1:nmGaSlXpDWJnC0z4twaSPhC1NZ1Nx86J5MpaSrSYLw4= +github.com/goplus/gogen v1.24.0/go.mod h1:Y7ulYW3wonQ3d9er00b0uGFEV/IUZa6okWJZh892ACQ= github.com/goplus/lib v0.5.2 h1:BUd3mUwTajDRBHVxMfS/y/hDJ6n/Pxwf6z7ikrOXvkE= github.com/goplus/lib v0.5.2/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0= github.com/qiniu/x v1.18.3 h1:trrBKBNszHGwV8XynnbddJr+A7Vca8/xlWP4F/Z4my8=