-
Notifications
You must be signed in to change notification settings - Fork 11
fix: correct block comment parsing and update gogen to v1.20.2 #634
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
base: main
Are you sure you want to change the base?
Conversation
Fix ParseComment() to keep block comments (/* ... */) as single ast.Comment nodes instead of splitting them by newline. Fix NewCommentGroupFromC() to reassemble legacy split block comments into single Go ast.Comment nodes. This resolves invalid Go code generation exposed by gogen v1.20.2's stricter comment handling. Closes #618 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
|
ci: test (ubuntu-latest, 19, v0.12.0, 1.23) got fail,check this problem panic: failed generated package demos: _llcppgtest/cjson,_llcppgtest/luasee https://github.com/goplus/llcppg/actions/runs/21896344268/artifacts/5461453809 |
CI Failure FixRoot Cause: Downloaded the CI artifact logs and found the actual error: When a C function has a block comment doc ( /* Create an iterator *///go:linkname Foo C.Foo
func Foo()While Fix (f4bf522): Insert an empty /* Create an iterator */ //
//go:linkname Foo C.Foo
func Foo()Changes:
Verification:
|
When a C function has a block comment doc (/* ... */), gogen v1.20.2 outputs the block comment and the following //go:linkname directive on the same line (e.g., `*///go:linkname Foo C.Foo`). The Go/LLGo compiler rejects this as "misplaced compiler directive" because //go:linkname must be on its own line. Fix: insert an empty // line comment between block comment docs and //go:linkname (or // llgo:link) directives to ensure the directive gets its own line in the generated output. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
|
@xgopilot is the |
Updated Parser Test Expected ResultsYes, the 3 files updated:
Key format changes:
Verification:
|
Update expect.json files to match the new ParseComment() behavior: - Block comments (/* ... */) are now kept as single ast.Comment nodes instead of being split by newline - Line comments (// ...) no longer have trailing \n - Consecutive block comments are merged into a single node Files updated: - testdata/comment/expect.json - testdata/forwarddecl1/expect.json - testdata/typeof/expect.json Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
|
@xgopilot The |
Updated
|
| File | Change |
|---|---|
gettext/gogensig.expect |
Block comment separator (//) added before //go:linkname |
gpgerror/gogensig.expect |
Block comment separators added before // llgo:link and //go:linkname directives |
issue507/gogensig.expect |
Single-line /** ... */ block comments now inline with type declarations (as formatted by go fmt) |
keepcomment/gogensig.expect |
Block comments properly reassembled (/**\n...*/ instead of split nodes); separators added before compiler directives |
xml2/gogensig.expect |
Block comment separators added before //go:linkname and // llgo:link directives |
Verification:
go build ./...- passgo vet ./...- pass- Unit tests (
config,internal/name,internal/arg,internal/unmarshal) - pass TestFromTestdata(all 27 subtests) - pass- All
cl/internal/converttests - pass
Commit: 3f8c2dd pushed to branch xgopilot/issue-618-1770793666.
Regenerate gogensig.expect files to match the new block comment handling in NewCommentGroupFromC and gogen v1.20.2's printer output. Affected test cases: gettext, gpgerror, issue507, keepcomment, xml2. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Requested by @luoliwoshang
Closes #618
Summary
ParseComment()in_xtool/internal/parser/parser.goto keep/* */block comments as singleast.Commentnodes instead of incorrectly splitting by newlineNewCommentGroupFromC()incl/internal/convert/comments.goto reassemble legacy split block comments from existingllcppsigfetchbuilds into single Goast.Commentnodesgithub.com/goplus/gogenfrom v1.19.7 to v1.20.2ParseCommentGroup()named return parameterNewCommentGroupFromCand gogen integrationRoot Cause
Go's
ast.Commentspecification requires each/* */block comment to be a single Comment node. The oldParseComment()function split all comments by newline, creating multiple nodes for block comments. This violated the spec and produced invalid Go code with gogen v1.20.2's stricter printer.Changes
_xtool/internal/parser/parser.goParseComment()to distinguish block vs line comments; clean upParseCommentGroup()cl/internal/convert/comments.goNewCommentGroupFromC()to reassemble split block comments for backward compatibilitycl/internal/convert/comments_test.gogo.mod/go.sumTest Plan
NewCommentGroupFromCunit tests pass (9 cases: nil, empty, single block, multi-line block, legacy 2-node split, legacy 3-node split, javadoc style, single line, multiple lines)config,internal/name,internal/arg,internal/unmarshalcl/internal/converttests pass (excludingTestFromTestdatawhich requiresllcppsigfetch)go build ./...passesgo vet ./...passesTestFromTestdatatests (requiresllcppsigfetchrebuild with LLGo - CI will validate)