Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cl/_testmockc/function/out.go
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cl_test

import (
"bytes"
"log"
"os"
"testing"

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that TestMockC is enabled and run on every go test, the unconditional cl.SetDebug(cl.DbgFlagAll) will emit debug log.Println output (from compileFunc / param handling in cl/compile.go) on every run, adding CI noise with no assertion value — the golden-file diff is what asserts correctness.

Also note SetDebug mutates package-level globals (debugCompileDecl/debugLoadDeps) and is never reset. It's harmless today because TestMockC is the only test in cl_test, but if another test is later added to this package it would silently inherit DbgFlagAll depending on run order. Consider dropping the call, gating it behind testing.Verbose(), and/or defer cl.SetDebug(0).

testFromDir(t, "", "./_testmockc", "c")
}
Expand Down
49 changes: 49 additions & 0 deletions cmd/llgogen/llgogen.go
Original file line number Diff line number Diff line change
@@ -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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these six fields (LoadNamed, HandleErr, NewBuiltin, NodeInterpreter, CanImplicitCast, DefaultGoFile) are all set to their zero values, so they're no-ops. Trimming the literal to just Importer: packages.NewImporter(nil) makes the meaningful config clearer and avoids a needless compile break if gogen renames/removes any of these fields in a future bump. Optional.

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)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
Loading