diff options
Diffstat (limited to 'vendor/modernc.org/ccgo/v3/lib/go.go')
-rw-r--r-- | vendor/modernc.org/ccgo/v3/lib/go.go | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/vendor/modernc.org/ccgo/v3/lib/go.go b/vendor/modernc.org/ccgo/v3/lib/go.go index 45ffc6e7..665f5ebe 100644 --- a/vendor/modernc.org/ccgo/v3/lib/go.go +++ b/vendor/modernc.org/ccgo/v3/lib/go.go @@ -9523,7 +9523,7 @@ func (p *project) postfixExpressionSelectPSelectStruct(f *function, n *cc.Postfi func (p *project) postfixExpressionSelectSelect(f *function, n *cc.PostfixExpression, t cc.Type, mode exprMode, flags flags) { // PostfixExpression '.' IDENTIFIER - switch k := p.opKind(f, n.PostfixExpression, n.PostfixExpression.Operand.Type()); k { + switch k := p.structOrUnion(n); k { case opUnion: p.postfixExpressionSelectSelectUnion(f, n, t, mode, flags) case opStruct: @@ -9533,6 +9533,40 @@ func (p *project) postfixExpressionSelectSelect(f *function, n *cc.PostfixExpres } } +func (p *project) structOrUnion(n *cc.PostfixExpression) opKind { + t := n.PostfixExpression.Operand.Type() + switch n.Case { + case cc.PostfixExpressionSelect: // PostfixExpression '.' IDENTIFIER + // ok + case cc.PostfixExpressionPSelect: // PostfixExpression "->" IDENTIFIER + if t.Kind() == cc.Ptr { + t = t.Elem() + break + } + + p.err(n, "expected pointer type: %s", t) + return opStruct + } + f, path, ok := t.FieldByName2(n.Token2.Src) + if !ok { + p.err(&n.Token, "unknown field: %s", n.Token2) + return opStruct + } + + for len(path) > 1 { + f = t.FieldByIndex(path[:1]) + path = path[1:] + t = f.Type() + } + if t.Kind() == cc.Union { + // trc("%v: %q %v", n.Token2.Position(), n.Token2.Src, opUnion) + return opUnion + } + + // trc("%v: %q %v", n.Token2.Position(), n.Token2.Src, opStruct) + return opStruct +} + func (p *project) postfixExpressionSelectSelectStruct(f *function, n *cc.PostfixExpression, t cc.Type, mode exprMode, flags flags) { // PostfixExpression '.' IDENTIFIER fld := n.Field @@ -12640,6 +12674,23 @@ func (p *project) iterationStatement(f *function, n *cc.IterationStatement) { } p.statement(f, n.Statement, true, false, false, 0) case cc.IterationStatementForDecl: // "for" '(' Declaration Expression ';' Expression ')' Statement + if !(f.hasJumps || n.Expression2 != nil && n.Expression2.Case == cc.ExpressionComma) { + p.w("{") + p.declaration(f, n.Declaration, false) + p.w("for ;") + if n.Expression != nil { + p.expression(f, n.Expression, n.Expression.Operand.Type(), exprBool, 0) + } + p.w(";") + if n.Expression2 != nil { + p.expression(f, n.Expression2, n.Expression2.Operand.Type(), exprVoid, fNoCondAssignment) + } + p.w("{") + p.statement(f, n.Statement, false, true, false, 0) + p.w("}};") + break + } + var ids []*cc.InitDeclarator for list := n.Declaration.InitDeclaratorList; list != nil; list = list.InitDeclaratorList { ids = append(ids, list.InitDeclarator) |