goplus / c2go

Convert C to Go
Apache License 2.0
306 stars 21 forks source link

cl: compileForStmt support multi init decl stmt #177

Closed visualfc closed 1 year ago

visualfc commented 1 year ago

fix https://github.com/goplus/c2go/issues/176

main.c

int main() {
    for (int i = 0, j = 1; i < 5; ++i, j += 7)
    {
        printf("%d %d\n",i,j);
    }
    return 0;
}

Added a block and move init before forstmt if has multi init decl.

func _cgo_main() int32 {
    {
        var i int32 = int32(0)
        var j int32 = int32(1)
        for ; i < int32(5); func() int32 {
            i++
            return func() (_cgo_ret int32) {
                _cgo_addr := &j
                *_cgo_addr += int32(7)
                return *_cgo_addr
            }()
        }() {
            printf((*int8)(unsafe.Pointer(&[7]int8{'%', 'd', ' ', '%', 'd', '\n', '\x00'})), i, j)
        }
    }
    return int32(0)
}
codecov-commenter commented 1 year ago

Codecov Report

Base: 89.02% // Head: 89.18% // Increases project coverage by +0.15% :tada:

Coverage data is based on head (a430ad6) compared to base (4f582df). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #177 +/- ## ========================================== + Coverage 89.02% 89.18% +0.15% ========================================== Files 10 10 Lines 3390 3403 +13 ========================================== + Hits 3018 3035 +17 + Misses 291 288 -3 + Partials 81 80 -1 ``` | [Impacted Files](https://codecov.io/gh/goplus/c2go/pull/177?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus) | Coverage Δ | | |---|---|---| | [cl/stmt.go](https://codecov.io/gh/goplus/c2go/pull/177/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus#diff-Y2wvc3RtdC5nbw==) | `94.64% <100.00%> (+0.44%)` | :arrow_up: | | [cl/type\_and\_var.go](https://codecov.io/gh/goplus/c2go/pull/177/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus#diff-Y2wvdHlwZV9hbmRfdmFyLmdv) | `89.46% <0.00%> (+0.57%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goplus)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.