mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Rename u32, io_reader, etc to base.u32, etc
This commit is contained in:
1 parent
fee97df698
commit
f95239f6e0
24 files changed
+394
-392
No files matched your search
@@ -456,7 +456,7 @@ func (g *gen) cName(name string) string {
|
||||
|
||||
func (g *gen) sizeof(typ *a.TypeExpr) (uint32, error) {
|
||||
if typ.Decorator() == 0 {
|
||||
if qid := typ.QID(); qid[0] == 0 {
|
||||
if qid := typ.QID(); qid[0] == t.IDBase {
|
||||
switch qid[1].Key() {
|
||||
case t.KeyU8:
|
||||
return 1, nil
|
||||
@@ -710,12 +710,14 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
|
||||
prefix := g.pkgPrefix
|
||||
qid := x.QID()
|
||||
if qid[0] != 0 {
|
||||
if qid[0] == t.IDBase {
|
||||
// Base types don't need further initialization.
|
||||
continue
|
||||
} else if qid[0] != 0 {
|
||||
// See gen.writeCTypeName for a related TODO with otherPkg.
|
||||
otherPkg := g.tm.ByID(qid[0])
|
||||
prefix = "wuffs_" + otherPkg + "__"
|
||||
} else if g.structMap[qid] == nil {
|
||||
// Skip field types like u32 and bool.
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeySuffix, 1) {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.writes("wuffs_base__slice_u8_suffix(")
|
||||
x := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, x, rp, parenthesesOptional, depth); err != nil {
|
||||
@@ -385,7 +385,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return err
|
||||
}
|
||||
if lTyp := n.LHS().Expr().MType(); lTyp.IsSliceType() {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.writes(".ptr")
|
||||
}
|
||||
b.writeb('[')
|
||||
@@ -411,7 +411,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
|
||||
lhsIsArray := lhs.MType().IsArrayType()
|
||||
if lhsIsArray {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.writes("((wuffs_base__slice_u8){.ptr=")
|
||||
}
|
||||
if err := g.writeExpr(b, lhs, rp, parenthesesOptional, depth); err != nil {
|
||||
@@ -538,11 +538,11 @@ func (g *gen) writeExprAssociativeOp(b *buffer, n *a.Expr, rp replacementPolicy,
|
||||
func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, varName string) error {
|
||||
// It may help to refer to http://unixwiz.net/techtips/reading-cdecl.html
|
||||
|
||||
// TODO: fix this, allow slices of all types, not just of u8's. Also allow
|
||||
// arrays of slices, slices of pointers, etc.
|
||||
// TODO: fix this, allow slices of all types, not just of base.u8's. Also
|
||||
// allow arrays of slices, slices of pointers, etc.
|
||||
if n.IsSliceType() {
|
||||
o := n.Inner()
|
||||
if o.Decorator() == 0 && o.QID() == (t.QID{0, t.IDU8}) && !o.IsRefined() {
|
||||
if o.Decorator() == 0 && o.QID() == (t.QID{t.IDBase, t.IDU8}) && !o.IsRefined() {
|
||||
b.writes("wuffs_base__slice_u8")
|
||||
b.writeb(' ')
|
||||
b.writes(varNamePrefix)
|
||||
@@ -574,7 +574,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
}
|
||||
|
||||
fallback := true
|
||||
if qid := innermost.QID(); qid[0] == 0 {
|
||||
if qid := innermost.QID(); qid[0] == t.IDBase {
|
||||
if key := qid[1].Key(); key < t.Key(len(cTypeNames)) {
|
||||
if s := cTypeNames[key]; s != "" {
|
||||
b.writes(s)
|
||||
@@ -585,7 +585,12 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
if fallback {
|
||||
prefix := g.pkgPrefix
|
||||
qid := innermost.QID()
|
||||
if qid[0] != 0 {
|
||||
if qid == (t.QID{t.IDBase, t.IDStatus}) {
|
||||
// No-op: special case "base.status" as being inside this package.
|
||||
//
|
||||
// TODO: change "base.status" in Wuffs code to just "status"? Or
|
||||
// change the C code's "wuffs_foo__status" to "wuffs_base__status"?
|
||||
} else if qid[0] != 0 {
|
||||
otherPkg := g.tm.ByID(qid[0])
|
||||
// TODO: map the "deflate" in "deflate.decoder" to the "deflate" in
|
||||
// `use "std/deflate"`, and use the latter "deflate".
|
||||
@@ -600,11 +605,6 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
// See gen.writeInitializerImpl for a similar use of otherPkg.
|
||||
prefix = "wuffs_" + otherPkg + "__"
|
||||
}
|
||||
// TODO: remove this hack when "image_config" in Wuffs code becomes
|
||||
// "base.image_config".
|
||||
if qid[1] == t.IDImageConfig {
|
||||
prefix = "wuffs_base__"
|
||||
}
|
||||
b.printf("%s%s", prefix, qid[1].Str(g.tm))
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if qid := oTyp.QID(); qid[0] == 0 {
|
||||
if qid := oTyp.QID(); qid[0] == t.IDBase {
|
||||
if key := qid[1].Key(); key < t.Key(len(numTypeBounds)) {
|
||||
ntb := numTypeBounds[key]
|
||||
for i := 0; i < 2; i++ {
|
||||
|
||||
@@ -165,9 +165,9 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
name := v.Name().Str(g.tm)
|
||||
b.writes("{\n")
|
||||
|
||||
// TODO: don't assume that the slice is a slice of u8. In particular,
|
||||
// the code gen can be subtle if the slice element type has zero size,
|
||||
// such as the empty struct.
|
||||
// TODO: don't assume that the slice is a slice of base.u8. In
|
||||
// particular, the code gen can be subtle if the slice element type has
|
||||
// zero size, such as the empty struct.
|
||||
b.printf("wuffs_base__slice_u8 %sslice_%s =", iPrefix, name)
|
||||
if err := g.writeExpr(b, v.Value(), replaceCallSuspendibles, parenthesesOptional, 0); err != nil {
|
||||
return err
|
||||
@@ -295,7 +295,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
} else if n.XType().IsSliceType() {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
b.printf("((wuffs_base__slice_u8){})")
|
||||
} else {
|
||||
b.writeb('0')
|
||||
|
||||
@@ -66,7 +66,7 @@ func (g *gen) findDerivedVars() {
|
||||
switch oTyp.QID() {
|
||||
default:
|
||||
continue
|
||||
case t.QID{0, t.IDIOReader}, t.QID{0, t.IDIOWriter}:
|
||||
case t.QID{t.IDBase, t.IDIOReader}, t.QID{t.IDBase, t.IDIOWriter}:
|
||||
// No-op.
|
||||
}
|
||||
if !g.needDerivedVar(o.Name()) {
|
||||
@@ -94,7 +94,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
}
|
||||
nameStr := name.Str(g.tm)
|
||||
switch typ.QID() {
|
||||
case t.QID{0, t.IDIOReader}:
|
||||
case t.QID{t.IDBase, t.IDIOReader}:
|
||||
if header {
|
||||
b.printf("uint8_t* %srptr_%s = NULL;", bPrefix, nameStr)
|
||||
b.printf("uint8_t* %srstart_%s = NULL;", bPrefix, nameStr)
|
||||
@@ -122,7 +122,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
|
||||
b.printf("}\n")
|
||||
|
||||
case t.QID{0, t.IDIOWriter}:
|
||||
case t.QID{t.IDBase, t.IDIOWriter}:
|
||||
if header {
|
||||
b.printf("uint8_t* %swptr_%s = NULL;", bPrefix, nameStr)
|
||||
b.printf("uint8_t* %swstart_%s = NULL;", bPrefix, nameStr)
|
||||
@@ -171,7 +171,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
}
|
||||
nameStr := name.Str(g.tm)
|
||||
switch typ.QID() {
|
||||
case t.QID{0, t.IDIOReader}:
|
||||
case t.QID{t.IDBase, t.IDIOReader}:
|
||||
b.printf("if (%s%s.buf) {", aPrefix, nameStr)
|
||||
|
||||
b.printf("size_t n = %srptr_%s - (%s%s.buf->ptr + %s%s.buf->ri);",
|
||||
@@ -192,7 +192,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
|
||||
b.printf("}\n")
|
||||
|
||||
case t.QID{0, t.IDIOWriter}:
|
||||
case t.QID{t.IDBase, t.IDIOWriter}:
|
||||
b.printf("if (%s%s.buf) {", aPrefix, nameStr)
|
||||
|
||||
b.printf("size_t n = %swptr_%s - (%s%s.buf->ptr + %s%s.buf->wi);",
|
||||
@@ -307,13 +307,13 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
|
||||
switch typ.Decorator().Key() {
|
||||
case 0:
|
||||
if qid := typ.QID(); qid[0] == 0 {
|
||||
if qid := typ.QID(); qid[0] == t.IDBase {
|
||||
if key := qid[1].Key(); key < t.Key(len(cTypeNames)) {
|
||||
rhs = cTypeNames[key]
|
||||
}
|
||||
}
|
||||
case t.KeySlice:
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
rhs = "wuffs_base__slice_u8"
|
||||
}
|
||||
if rhs != "" {
|
||||
@@ -327,7 +327,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
if !initBoolTypedVars {
|
||||
rhs = fmt.Sprintf("self->private_impl.%s%s[0].%s", cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
} else if typ.QID() != (t.QID{0, t.IDBool}) {
|
||||
} else if typ.QID() != (t.QID{t.IDBase, t.IDBool}) {
|
||||
return nil
|
||||
} else if typ.Decorator() != 0 {
|
||||
goto fail
|
||||
@@ -368,7 +368,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
break
|
||||
}
|
||||
qid := inner.QID()
|
||||
if qid[0] != 0 {
|
||||
if qid[0] != t.IDBase {
|
||||
break
|
||||
}
|
||||
switch qid[1].Key() {
|
||||
|
||||
Reference in new issue
Block a user