mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Un-special-case parsing base."etc"
This commit is contained in:
1 parent
4e2d0c1e5f
commit
74d291453d
5 files changed
+40
-31
No files matched your search
+22
-6
@@ -38,6 +38,8 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
b.writes("NULL")
|
||||
} else if typ.IsStatus() {
|
||||
b.writes("wuffs_base__make_status(NULL)")
|
||||
} else if !typ.IsBool() {
|
||||
return fmt.Errorf("cannot generate C expression for %v constant of type %q", n.Str(g.tm), n.MType().Str(g.tm))
|
||||
} else if cv.Cmp(zero) == 0 {
|
||||
b.writes("false")
|
||||
} else if cv.Cmp(one) == 0 {
|
||||
@@ -79,9 +81,9 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, depth uint32) error {
|
||||
b.writes("wuffs_base__make_status(")
|
||||
b.writes(z.cName)
|
||||
b.writes(")")
|
||||
} else {
|
||||
return fmt.Errorf("unrecognized status %s", n.StatusQID().Str(g.tm))
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unrecognized status %s", n.StatusQID().Str(g.tm))
|
||||
|
||||
} else if c, ok := g.scalarConstsMap[t.QID{0, n.Ident()}]; ok {
|
||||
b.writes(c.Value().ConstValue().String())
|
||||
@@ -212,6 +214,14 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, depth uint32) error {
|
||||
b.writes(aPrefix)
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
} else if (lhs.Operator() == 0) && n.Ident().IsDQStrLiteral(g.tm) {
|
||||
if z := g.statusMap[t.QID{lhs.Ident(), n.Ident()}]; z.cName != "" {
|
||||
b.writes("wuffs_base__make_status(")
|
||||
b.writes(z.cName)
|
||||
b.writes(")")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unrecognized status %s", n.Str(g.tm))
|
||||
}
|
||||
|
||||
if err := g.writeExpr(b, lhs, depth); err != nil {
|
||||
@@ -317,10 +327,16 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||
|
||||
func (g *gen) writeExprRepr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
isStatus := n.MType().IsStatus()
|
||||
if isStatus && (n.Operator() == 0) && n.Ident().IsDQStrLiteral(g.tm) {
|
||||
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
|
||||
b.writes(z.cName)
|
||||
return nil
|
||||
if isStatus {
|
||||
if op := n.Operator(); ((op == 0) || (op == t.IDDot)) && n.Ident().IsDQStrLiteral(g.tm) {
|
||||
qid := t.QID{0, n.Ident()}
|
||||
if op == t.IDDot {
|
||||
qid[0] = n.LHS().AsExpr().Ident()
|
||||
}
|
||||
if z := g.statusMap[qid]; z.cName != "" {
|
||||
b.writes(z.cName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := g.writeExpr(b, n, depth); err != nil {
|
||||
|
||||
@@ -487,12 +487,10 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
couldBeSuspension := false
|
||||
if retExpr.MType().IsStatus() && !n.RetsError() {
|
||||
couldBeSuspension = true
|
||||
if retExpr.Operator() == 0 {
|
||||
if id := retExpr.Ident(); id == t.IDOk {
|
||||
couldBeSuspension = false
|
||||
} else if s := g.tm.ByID(id); (len(s) > 1) && (s[0] == '"') {
|
||||
couldBeSuspension = s[1] == '$'
|
||||
}
|
||||
if s := g.tm.ByID(retExpr.Ident()); (len(s) > 1) && (s[0] == '"') {
|
||||
couldBeSuspension = s[1] == '$'
|
||||
} else if (retExpr.Operator() == 0) && (retExpr.Ident() == t.IDOk) {
|
||||
couldBeSuspension = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user