-
Notifications
You must be signed in to change notification settings - Fork 11
cl: newPointer #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cl: newPointer #703
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module foo | ||
|
|
||
| go 1.20 | ||
|
|
||
| require github.com/goplus/lib v0.5.2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| github.com/goplus/lib v0.5.2 h1:BUd3mUwTajDRBHVxMfS/y/hDJ6n/Pxwf6z7ikrOXvkE= | ||
| github.com/goplus/lib v0.5.2/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package foo | ||
|
|
||
| import _ "github.com/goplus/lib/c" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "log" | ||
|
|
||
| "github.com/goplus/gogen" | ||
| "github.com/goplus/llcppg/clang" | ||
| lc "github.com/goplus/llcppg/lib/clang" | ||
| ) | ||
|
|
||
|
|
@@ -35,8 +36,41 @@ const ( | |
| flagRetType | ||
| ) | ||
|
|
||
| var ( | ||
| tyVoid = types.Typ[types.UntypedNil] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] tyVoid bound to UntypedNil is surprising
|
||
| ) | ||
|
|
||
| func newPointer(typ types.Type) types.Type { | ||
| switch t := typ.(type) { | ||
| case *types.Basic: | ||
| if t == tyVoid { | ||
| return types.Typ[types.UnsafePointer] | ||
| } | ||
| case *types.Signature: | ||
| panic("todo: newPointer for signature") | ||
| /* if gogen.IsCSignature(t) { | ||
| return types.NewSignature(nil, t.Params(), t.Results(), t.Variadic()) | ||
| } */ | ||
| case *types.Named: | ||
| panic("todo: newPointer for named type") | ||
| /* if typ == ValistTag { | ||
| return Valist | ||
| } */ | ||
| } | ||
| return types.NewPointer(typ) | ||
| } | ||
|
|
||
| func toType(ctx *blockCtx, typ lc.Type, flags int) types.Type { | ||
| panic("todo: toType") | ||
| switch typ.Kind { | ||
| case lc.TypeInt: | ||
| return ctx.c.Ref("Int").Type() | ||
| case lc.TypeUInt: | ||
| return ctx.c.Ref("UInt").Type() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P0] Ref("UInt") does not exist; symbol is Uint
return ctx.c.Ref("Uint").Type()The adjacent |
||
| case lc.TypePointer: | ||
| pointee := toType(ctx, typ.PointeeType(), flags) | ||
| return newPointer(pointee) | ||
| } | ||
| panic("todo: toType " + clang.String(typ)) | ||
| } | ||
|
|
||
| // ----------------------------------------------------------------------------- | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P0] Wrong import path breaks c package resolution
This imports
github.com/lib/c, but the package isgithub.com/goplus/lib/ceverywhere else — the file's own import atcompile.go:27, the test stubcl/_mod/stub.go:3, andcl/_mod/go.mod(require github.com/goplus/lib v0.5.2).This PkgRef is stored in
blockCtx.cand used bytoTypeto resolveInt/UInt, so the mismatched path prevents type resolution from working.