mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Generate C code for "x as T".
This commit is contained in:
1 parent
e87cdaa9f5
commit
db41d789a5
4 files changed
+30
-4
No files matched your search
+23
-2
@@ -706,8 +706,7 @@ func (g *gen) writeExprUnaryOp(n *a.Expr, depth uint32) error {
|
||||
func (g *gen) writeExprBinaryOp(n *a.Expr, depth uint32) error {
|
||||
op := n.ID0()
|
||||
if op.Key() == t.KeyXBinaryAs {
|
||||
// TODO.
|
||||
return nil
|
||||
return g.writeExprAs(n.LHS().Expr(), n.RHS().TypeExpr(), depth)
|
||||
}
|
||||
g.writeb('(')
|
||||
if err := g.writeExpr(n.LHS().Expr(), depth); err != nil {
|
||||
@@ -722,6 +721,28 @@ func (g *gen) writeExprBinaryOp(n *a.Expr, depth uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeExprAs(lhs *a.Expr, rhs *a.TypeExpr, depth uint32) error {
|
||||
g.writes("((")
|
||||
for {
|
||||
if rhs.PackageOrDecorator() == 0 {
|
||||
if k := rhs.Name().Key(); k < t.Key(len(cTypeNames)) {
|
||||
if s := cTypeNames[k]; s != "" {
|
||||
g.writes(s)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: fix this.
|
||||
return fmt.Errorf("cannot convert Puffs type %q to C", rhs.String(g.idMap))
|
||||
}
|
||||
g.writes(")(")
|
||||
if err := g.writeExpr(lhs, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes("))")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||
// TODO.
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user