mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Remove token ID/Key distinction, part 11 of N
This commit is contained in:
1 parent
b24a929ec7
commit
eeebd58d7b
20 files changed
+1218
-1425
No files matched your search
@@ -254,7 +254,7 @@ func (g *gen) genHeader(b *buffer) error {
|
||||
|
||||
for i, z := range builtin.StatusList {
|
||||
code := uint32(0)
|
||||
if z.Keyword.Key() == t.KeyError {
|
||||
if z.Keyword == t.IDError {
|
||||
code |= 1 << 31
|
||||
}
|
||||
code |= uint32(i)
|
||||
@@ -267,7 +267,7 @@ func (g *gen) genHeader(b *buffer) error {
|
||||
}
|
||||
for i, s := range g.statusList {
|
||||
code := pkgID << statusCodeNamespaceShift
|
||||
if s.keyword.Key() == t.KeyError {
|
||||
if s.keyword == t.IDError {
|
||||
code |= 1 << 31
|
||||
}
|
||||
code |= uint32(i)
|
||||
@@ -467,14 +467,14 @@ 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] == t.IDBase {
|
||||
switch qid[1].Key() {
|
||||
case t.KeyU8:
|
||||
switch qid[1] {
|
||||
case t.IDU8:
|
||||
return 1, nil
|
||||
case t.KeyU16:
|
||||
case t.IDU16:
|
||||
return 2, nil
|
||||
case t.KeyU32:
|
||||
case t.IDU32:
|
||||
return 4, nil
|
||||
case t.KeyU64:
|
||||
case t.IDU64:
|
||||
return 8, nil
|
||||
}
|
||||
}
|
||||
@@ -489,7 +489,7 @@ func (g *gen) gatherStatuses(b *buffer, n *a.Status) error {
|
||||
return fmt.Errorf("bad status message %q", raw)
|
||||
}
|
||||
prefix := "SUSPENSION_"
|
||||
if n.Keyword().Key() == t.KeyError {
|
||||
if n.Keyword() == t.IDError {
|
||||
prefix = "ERROR_"
|
||||
}
|
||||
s := status{
|
||||
@@ -519,7 +519,7 @@ func (g *gen) writeConst(b *buffer, n *a.Const) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
if n.Operator().Key() == t.KeyDollar {
|
||||
if n.Operator() == t.IDDollar {
|
||||
b.writeb('{')
|
||||
for _, o := range n.Args() {
|
||||
if err := g.writeConstList(b, o.Expr()); err != nil {
|
||||
|
||||
+103
-103
@@ -69,9 +69,9 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
||||
}
|
||||
|
||||
func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
switch n.Operator().Key() {
|
||||
switch n.Operator() {
|
||||
case 0:
|
||||
if id1 := n.Ident(); id1.Key() == t.KeyThis {
|
||||
if id1 := n.Ident(); id1 == t.IDThis {
|
||||
b.writes("self")
|
||||
} else {
|
||||
if n.GlobalIdent() {
|
||||
@@ -83,10 +83,10 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
return nil
|
||||
|
||||
case t.KeyOpenParen:
|
||||
case t.IDOpenParen:
|
||||
// n is a function call.
|
||||
// TODO: delete this hack that only matches "foo.bar_bits(etc)".
|
||||
if isThatMethod(g.tm, n, t.KeyLowBits, 1) {
|
||||
if isThatMethod(g.tm, n, t.IDLowBits, 1) {
|
||||
// "x.low_bits(n:etc)" in C is "((x) & ((1 << (n)) - 1))".
|
||||
x := n.LHS().Expr().LHS().Expr()
|
||||
b.writes("((")
|
||||
@@ -100,7 +100,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")) - 1))")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyHighBits, 1) {
|
||||
if isThatMethod(g.tm, n, t.IDHighBits, 1) {
|
||||
// "x.high_bits(n:etc)" in C is "((x) >> (8*sizeof(x) - (n)))".
|
||||
x := n.LHS().Expr().LHS().Expr()
|
||||
b.writes("((")
|
||||
@@ -120,8 +120,8 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")))")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyIsError, 0) || isThatMethod(g.tm, n, t.KeyIsOK, 0) ||
|
||||
isThatMethod(g.tm, n, t.KeyIsSuspension, 0) {
|
||||
if isThatMethod(g.tm, n, t.IDIsError, 0) || isThatMethod(g.tm, n, t.IDIsOK, 0) ||
|
||||
isThatMethod(g.tm, n, t.IDIsSuspension, 0) {
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
@@ -129,22 +129,22 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
if err := g.writeExpr(b, x, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
switch key := n.LHS().Expr().Ident().Key(); key {
|
||||
case t.KeyIsError:
|
||||
switch key := n.LHS().Expr().Ident(); key {
|
||||
case t.IDIsError:
|
||||
b.writes(" < 0")
|
||||
case t.KeyIsOK:
|
||||
case t.IDIsOK:
|
||||
b.writes(" == 0")
|
||||
case t.KeyIsSuspension:
|
||||
case t.IDIsSuspension:
|
||||
b.writes(" > 0")
|
||||
default:
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther's IsXxx", key)
|
||||
return fmt.Errorf("unrecognized token (0x%X) for writeExprOther's IsXxx", key)
|
||||
}
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb(')')
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeySuffix, 1) {
|
||||
if isThatMethod(g.tm, n, t.IDSuffix, 1) {
|
||||
// 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()
|
||||
@@ -158,14 +158,14 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")")
|
||||
return nil
|
||||
}
|
||||
if isInSrc(g.tm, n, t.KeyLimit, 1) {
|
||||
if isInSrc(g.tm, n, t.IDLimit, 1) {
|
||||
return fmt.Errorf(`TODO: cgen an "in.src.limit" expression`)
|
||||
}
|
||||
if isInSrc(g.tm, n, t.KeyMark, 0) {
|
||||
if isInSrc(g.tm, n, t.IDMark, 0) {
|
||||
b.printf("wuffs_base__io_reader__mark(&%ssrc, %srptr_src)", aPrefix, bPrefix)
|
||||
return nil
|
||||
}
|
||||
if isInSrc(g.tm, n, t.KeySinceMark, 0) {
|
||||
if isInSrc(g.tm, n, t.IDSinceMark, 0) {
|
||||
b.printf("((wuffs_base__slice_u8){ "+
|
||||
".ptr = %ssrc.private_impl.mark, "+
|
||||
".len = %ssrc.private_impl.mark ? (size_t)(%srptr_src - %ssrc.private_impl.mark) : 0, })",
|
||||
@@ -173,10 +173,10 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
// TODO: io_reader.is_marked, not just io_writer.is_marked?
|
||||
if isInDst(g.tm, n, t.KeyLimit, 1) {
|
||||
if isInDst(g.tm, n, t.IDLimit, 1) {
|
||||
return fmt.Errorf(`TODO: cgen an "in.dst.limit" expression`)
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyMark, 0) {
|
||||
if isInDst(g.tm, n, t.IDMark, 0) {
|
||||
// TODO: is a private_impl.mark the right representation? What if
|
||||
// the function is passed a (ptr io_writer) instead of a
|
||||
// (io_writer)? Do we still want to have that mark live outside of
|
||||
@@ -184,7 +184,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.printf("wuffs_base__io_writer__mark(&%sdst, %swptr_dst)", aPrefix, bPrefix)
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeySinceMark, 0) {
|
||||
if isInDst(g.tm, n, t.IDSinceMark, 0) {
|
||||
// Write .len as either "foo ? bar : baz" or "bar".
|
||||
//
|
||||
// TODO: drop the "true" in the "if true", provided that the
|
||||
@@ -200,7 +200,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
aPrefix, len0, bPrefix, aPrefix, len1)
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyIsMarked, 0) {
|
||||
if isInDst(g.tm, n, t.IDIsMarked, 0) {
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) {
|
||||
if isInDst(g.tm, n, t.IDCopyFromReader32, 2) {
|
||||
b.printf("wuffs_base__io_writer__copy_from_reader32(&%swptr_dst, %swend_dst",
|
||||
bPrefix, bPrefix)
|
||||
// TODO: don't assume that the first argument is "in.src".
|
||||
@@ -222,7 +222,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writeb(')')
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromHistory32, 2) {
|
||||
if isInDst(g.tm, n, t.IDCopyFromHistory32, 2) {
|
||||
bco := ""
|
||||
if n.BoundsCheckOptimized() {
|
||||
bco = "__bco"
|
||||
@@ -239,7 +239,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writeb(')')
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromSlice32, 2) {
|
||||
if isInDst(g.tm, n, t.IDCopyFromSlice32, 2) {
|
||||
b.printf("wuffs_base__io_writer__copy_from_slice32("+
|
||||
"&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
for _, o := range n.Args() {
|
||||
@@ -251,7 +251,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writeb(')')
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromSlice, 1) {
|
||||
if isInDst(g.tm, n, t.IDCopyFromSlice, 1) {
|
||||
b.printf("wuffs_base__io_writer__copy_from_slice(&%swptr_dst, %swend_dst,", bPrefix, bPrefix)
|
||||
a := n.Args()[0].Arg().Value()
|
||||
if err := g.writeExpr(b, a, rp, parenthesesOptional, depth); err != nil {
|
||||
@@ -260,7 +260,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writeb(')')
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyCopyFromSlice, 1) {
|
||||
if isThatMethod(g.tm, n, t.IDCopyFromSlice, 1) {
|
||||
b.writes("wuffs_base__slice_u8__copy_from_slice(")
|
||||
receiver := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, receiver, rp, parenthesesOptional, depth); err != nil {
|
||||
@@ -274,7 +274,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")\n")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyLength, 0) {
|
||||
if isThatMethod(g.tm, n, t.IDLength, 0) {
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyAvailable, 0) {
|
||||
if isThatMethod(g.tm, n, t.IDAvailable, 0) {
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
@@ -313,7 +313,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("update").Key(), 1) {
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("update"), 1) {
|
||||
// TODO: don't hard-code the class name or this.checksum.
|
||||
class := "wuffs_crc32__ieee"
|
||||
if g.pkgName == "zlib" {
|
||||
@@ -327,7 +327,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")\n")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("set_literal_width").Key(), 1) {
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("set_literal_width"), 1) {
|
||||
// TODO: don't hard-code lzw.
|
||||
b.printf("%slzw_decoder__set_literal_width(&self->private_impl.f_lzw, ", g.pkgPrefix)
|
||||
a := n.Args()[0].Arg().Value()
|
||||
@@ -337,22 +337,22 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(")\n")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyLimit, 1) {
|
||||
if isThatMethod(g.tm, n, t.IDLimit, 1) {
|
||||
return fmt.Errorf(`TODO: cgen a "foo.limit" expression`)
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyMark, 0) {
|
||||
if isThatMethod(g.tm, n, t.IDMark, 0) {
|
||||
// TODO: don't hard-code v_r or b_rptr_src.
|
||||
b.printf("wuffs_base__io_reader__mark(&v_r, b_rptr_src)")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeySinceMark, 0) {
|
||||
if isThatMethod(g.tm, n, t.IDSinceMark, 0) {
|
||||
// TODO: don't hard-code v_r or b_rptr_src.
|
||||
b.printf("((wuffs_base__slice_u8){ " +
|
||||
".ptr = v_r.private_impl.mark, " +
|
||||
".len = v_r.private_impl.mark ? (size_t)(b_rptr_src - v_r.private_impl.mark) : 0, })")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("initialize").Key(), 5) {
|
||||
if isThatMethod(g.tm, n, g.tm.ByName("initialize"), 5) {
|
||||
// TODO: don't hard-code a_dst.
|
||||
b.printf("wuffs_base__image_config__initialize(a_dst")
|
||||
for _, o := range n.Args() {
|
||||
@@ -366,7 +366,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
// TODO.
|
||||
|
||||
case t.KeyOpenBracket:
|
||||
case t.IDOpenBracket:
|
||||
// n is an index.
|
||||
if err := g.writeExpr(b, n.LHS().Expr(), rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
@@ -382,7 +382,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writeb(']')
|
||||
return nil
|
||||
|
||||
case t.KeyColon:
|
||||
case t.IDColon:
|
||||
// n is a slice.
|
||||
lhs := n.LHS().Expr()
|
||||
mhs := n.MHS().Expr()
|
||||
@@ -425,9 +425,9 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
return nil
|
||||
|
||||
case t.KeyDot:
|
||||
case t.IDDot:
|
||||
lhs := n.LHS().Expr()
|
||||
if lhs.Ident().Key() == t.KeyIn {
|
||||
if lhs.Ident() == t.IDIn {
|
||||
b.writes(aPrefix)
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
@@ -436,7 +436,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
if err := g.writeExpr(b, lhs, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
if key := lhs.MType().Decorator().Key(); key == t.KeyPtr || key == t.KeyNptr {
|
||||
if key := lhs.MType().Decorator(); key == t.IDPtr || key == t.IDNptr {
|
||||
b.writes("->")
|
||||
} else {
|
||||
b.writes(".")
|
||||
@@ -445,7 +445,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
|
||||
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
status := g.statusMap[n.StatusQID()]
|
||||
if status.name == "" {
|
||||
msg, _ := t.Unescape(n.Ident().Str(g.tm))
|
||||
@@ -458,17 +458,17 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(status.name)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.Operator().Key())
|
||||
return fmt.Errorf("unrecognized token (0x%X) for writeExprOther", n.Operator())
|
||||
}
|
||||
|
||||
func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
b.writes(cOpNames[0xFF&n.Operator().Key()])
|
||||
b.writes(cOpNames[0xFF&n.Operator()])
|
||||
return g.writeExpr(b, n.RHS().Expr(), rp, parenthesesMandatory, depth)
|
||||
}
|
||||
|
||||
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
op := n.Operator()
|
||||
if op.Key() == t.KeyXBinaryAs {
|
||||
if op == t.IDXBinaryAs {
|
||||
return g.writeExprAs(b, n.LHS().Expr(), n.RHS().TypeExpr(), rp, depth)
|
||||
}
|
||||
if pp == parenthesesMandatory {
|
||||
@@ -478,7 +478,7 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp p
|
||||
return err
|
||||
}
|
||||
// TODO: does KeyXBinaryAmpHat need special consideration?
|
||||
b.writes(cOpNames[0xFF&op.Key()])
|
||||
b.writes(cOpNames[0xFF&op])
|
||||
if err := g.writeExpr(b, n.RHS().Expr(), rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -507,7 +507,7 @@ func (g *gen) writeExprAssociativeOp(b *buffer, n *a.Expr, rp replacementPolicy,
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
opName := cOpNames[0xFF&n.Operator().Key()]
|
||||
opName := cOpNames[0xFF&n.Operator()]
|
||||
for i, o := range n.Args() {
|
||||
if i != 0 {
|
||||
b.writes(opName)
|
||||
@@ -549,7 +549,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
numPointers, innermost := 0, x
|
||||
for ; innermost != nil && innermost.Inner() != nil; innermost = innermost.Inner() {
|
||||
// TODO: "nptr T", not just "ptr T".
|
||||
if p := innermost.Decorator().Key(); p == t.KeyPtr {
|
||||
if p := innermost.Decorator(); p == t.IDPtr {
|
||||
if numPointers == maxNumPointers {
|
||||
return fmt.Errorf("cannot convert Wuffs type %q to C: too many ptr's", n.Str(g.tm))
|
||||
}
|
||||
@@ -562,7 +562,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
|
||||
fallback := true
|
||||
if qid := innermost.QID(); qid[0] == t.IDBase {
|
||||
if key := qid[1].Key(); key < t.Key(len(cTypeNames)) {
|
||||
if key := qid[1]; key < t.ID(len(cTypeNames)) {
|
||||
if s := cTypeNames[key]; s != "" {
|
||||
b.writes(s)
|
||||
fallback = false
|
||||
@@ -614,67 +614,67 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
}
|
||||
|
||||
var cTypeNames = [...]string{
|
||||
t.KeyI8: "int8_t",
|
||||
t.KeyI16: "int16_t",
|
||||
t.KeyI32: "int32_t",
|
||||
t.KeyI64: "int64_t",
|
||||
t.KeyU8: "uint8_t",
|
||||
t.KeyU16: "uint16_t",
|
||||
t.KeyU32: "uint32_t",
|
||||
t.KeyU64: "uint64_t",
|
||||
t.KeyBool: "bool",
|
||||
t.KeyIOReader: "wuffs_base__io_reader",
|
||||
t.KeyIOWriter: "wuffs_base__io_writer",
|
||||
t.IDI8: "int8_t",
|
||||
t.IDI16: "int16_t",
|
||||
t.IDI32: "int32_t",
|
||||
t.IDI64: "int64_t",
|
||||
t.IDU8: "uint8_t",
|
||||
t.IDU16: "uint16_t",
|
||||
t.IDU32: "uint32_t",
|
||||
t.IDU64: "uint64_t",
|
||||
t.IDBool: "bool",
|
||||
t.IDIOReader: "wuffs_base__io_reader",
|
||||
t.IDIOWriter: "wuffs_base__io_writer",
|
||||
}
|
||||
|
||||
var cOpNames = [256]string{
|
||||
t.KeyEq: " = ",
|
||||
t.KeyPlusEq: " += ",
|
||||
t.KeyMinusEq: " -= ",
|
||||
t.KeyStarEq: " *= ",
|
||||
t.KeySlashEq: " /= ",
|
||||
t.KeyShiftLEq: " <<= ",
|
||||
t.KeyShiftREq: " >>= ",
|
||||
t.KeyAmpEq: " &= ",
|
||||
t.KeyAmpHatEq: " no_such_amp_hat_C_operator ",
|
||||
t.KeyPipeEq: " |= ",
|
||||
t.KeyHatEq: " ^= ",
|
||||
t.KeyPercentEq: " %= ",
|
||||
t.KeyTildePlusEq: " += ",
|
||||
t.IDEq: " = ",
|
||||
t.IDPlusEq: " += ",
|
||||
t.IDMinusEq: " -= ",
|
||||
t.IDStarEq: " *= ",
|
||||
t.IDSlashEq: " /= ",
|
||||
t.IDShiftLEq: " <<= ",
|
||||
t.IDShiftREq: " >>= ",
|
||||
t.IDAmpEq: " &= ",
|
||||
t.IDAmpHatEq: " no_such_amp_hat_C_operator ",
|
||||
t.IDPipeEq: " |= ",
|
||||
t.IDHatEq: " ^= ",
|
||||
t.IDPercentEq: " %= ",
|
||||
t.IDTildePlusEq: " += ",
|
||||
|
||||
t.KeyXUnaryPlus: " + ",
|
||||
t.KeyXUnaryMinus: " - ",
|
||||
t.KeyXUnaryNot: " ! ",
|
||||
t.KeyXUnaryRef: " & ",
|
||||
t.KeyXUnaryDeref: " * ",
|
||||
t.IDXUnaryPlus: " + ",
|
||||
t.IDXUnaryMinus: " - ",
|
||||
t.IDXUnaryNot: " ! ",
|
||||
t.IDXUnaryRef: " & ",
|
||||
t.IDXUnaryDeref: " * ",
|
||||
|
||||
t.KeyXBinaryPlus: " + ",
|
||||
t.KeyXBinaryMinus: " - ",
|
||||
t.KeyXBinaryStar: " * ",
|
||||
t.KeyXBinarySlash: " / ",
|
||||
t.KeyXBinaryShiftL: " << ",
|
||||
t.KeyXBinaryShiftR: " >> ",
|
||||
t.KeyXBinaryAmp: " & ",
|
||||
t.KeyXBinaryAmpHat: " no_such_amp_hat_C_operator ",
|
||||
t.KeyXBinaryPipe: " | ",
|
||||
t.KeyXBinaryHat: " ^ ",
|
||||
t.KeyXBinaryPercent: " % ",
|
||||
t.KeyXBinaryNotEq: " != ",
|
||||
t.KeyXBinaryLessThan: " < ",
|
||||
t.KeyXBinaryLessEq: " <= ",
|
||||
t.KeyXBinaryEqEq: " == ",
|
||||
t.KeyXBinaryGreaterEq: " >= ",
|
||||
t.KeyXBinaryGreaterThan: " > ",
|
||||
t.KeyXBinaryAnd: " && ",
|
||||
t.KeyXBinaryOr: " || ",
|
||||
t.KeyXBinaryAs: " no_such_as_C_operator ",
|
||||
t.KeyXBinaryTildePlus: " + ",
|
||||
t.IDXBinaryPlus: " + ",
|
||||
t.IDXBinaryMinus: " - ",
|
||||
t.IDXBinaryStar: " * ",
|
||||
t.IDXBinarySlash: " / ",
|
||||
t.IDXBinaryShiftL: " << ",
|
||||
t.IDXBinaryShiftR: " >> ",
|
||||
t.IDXBinaryAmp: " & ",
|
||||
t.IDXBinaryAmpHat: " no_such_amp_hat_C_operator ",
|
||||
t.IDXBinaryPipe: " | ",
|
||||
t.IDXBinaryHat: " ^ ",
|
||||
t.IDXBinaryPercent: " % ",
|
||||
t.IDXBinaryNotEq: " != ",
|
||||
t.IDXBinaryLessThan: " < ",
|
||||
t.IDXBinaryLessEq: " <= ",
|
||||
t.IDXBinaryEqEq: " == ",
|
||||
t.IDXBinaryGreaterEq: " >= ",
|
||||
t.IDXBinaryGreaterThan: " > ",
|
||||
t.IDXBinaryAnd: " && ",
|
||||
t.IDXBinaryOr: " || ",
|
||||
t.IDXBinaryAs: " no_such_as_C_operator ",
|
||||
t.IDXBinaryTildePlus: " + ",
|
||||
|
||||
t.KeyXAssociativePlus: " + ",
|
||||
t.KeyXAssociativeStar: " * ",
|
||||
t.KeyXAssociativeAmp: " & ",
|
||||
t.KeyXAssociativePipe: " | ",
|
||||
t.KeyXAssociativeHat: " ^ ",
|
||||
t.KeyXAssociativeAnd: " && ",
|
||||
t.KeyXAssociativeOr: " || ",
|
||||
t.IDXAssociativePlus: " + ",
|
||||
t.IDXAssociativeStar: " * ",
|
||||
t.IDXAssociativeAmp: " & ",
|
||||
t.IDXAssociativePipe: " | ",
|
||||
t.IDXAssociativeHat: " ^ ",
|
||||
t.IDXAssociativeAnd: " && ",
|
||||
t.IDXAssociativeOr: " || ",
|
||||
}
|
||||
@@ -332,13 +332,13 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error {
|
||||
for _, o := range n.In().Fields() {
|
||||
o := o.Field()
|
||||
oTyp := o.XType()
|
||||
if oTyp.Decorator().Key() != t.KeyPtr && !oTyp.IsRefined() {
|
||||
if oTyp.Decorator() != t.IDPtr && !oTyp.IsRefined() {
|
||||
// TODO: Also check elements, for array-typed arguments.
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case oTyp.Decorator().Key() == t.KeyPtr:
|
||||
case oTyp.Decorator() == t.IDPtr:
|
||||
checks = append(checks, fmt.Sprintf("!%s%s", aPrefix, o.Name().Str(g.tm)))
|
||||
|
||||
case oTyp.IsRefined():
|
||||
@@ -351,7 +351,7 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error {
|
||||
}
|
||||
}
|
||||
if qid := oTyp.QID(); qid[0] == t.IDBase {
|
||||
if key := qid[1].Key(); key < t.Key(len(numTypeBounds)) {
|
||||
if key := qid[1]; key < t.ID(len(numTypeBounds)) {
|
||||
ntb := numTypeBounds[key]
|
||||
for i := 0; i < 2; i++ {
|
||||
if bounds[i] != nil && ntb[i] != nil && bounds[i].Cmp(ntb[i]) == 0 {
|
||||
@@ -401,13 +401,13 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error {
|
||||
}
|
||||
|
||||
var numTypeBounds = [256][2]*big.Int{
|
||||
t.KeyI8: {big.NewInt(-1 << 7), big.NewInt(1<<7 - 1)},
|
||||
t.KeyI16: {big.NewInt(-1 << 15), big.NewInt(1<<15 - 1)},
|
||||
t.KeyI32: {big.NewInt(-1 << 31), big.NewInt(1<<31 - 1)},
|
||||
t.KeyI64: {big.NewInt(-1 << 63), big.NewInt(1<<63 - 1)},
|
||||
t.KeyU8: {zero, big.NewInt(0).SetUint64(1<<8 - 1)},
|
||||
t.KeyU16: {zero, big.NewInt(0).SetUint64(1<<16 - 1)},
|
||||
t.KeyU32: {zero, big.NewInt(0).SetUint64(1<<32 - 1)},
|
||||
t.KeyU64: {zero, big.NewInt(0).SetUint64(1<<64 - 1)},
|
||||
t.KeyBool: {zero, one},
|
||||
t.IDI8: {big.NewInt(-1 << 7), big.NewInt(1<<7 - 1)},
|
||||
t.IDI16: {big.NewInt(-1 << 15), big.NewInt(1<<15 - 1)},
|
||||
t.IDI32: {big.NewInt(-1 << 31), big.NewInt(1<<31 - 1)},
|
||||
t.IDI64: {big.NewInt(-1 << 63), big.NewInt(1<<63 - 1)},
|
||||
t.IDU8: {zero, big.NewInt(0).SetUint64(1<<8 - 1)},
|
||||
t.IDU16: {zero, big.NewInt(0).SetUint64(1<<16 - 1)},
|
||||
t.IDU32: {zero, big.NewInt(0).SetUint64(1<<32 - 1)},
|
||||
t.IDU64: {zero, big.NewInt(0).SetUint64(1<<64 - 1)},
|
||||
t.IDBool: {zero, one},
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
// TODO: does KeyAmpHatEq need special consideration?
|
||||
b.writes(cOpNames[0xFF&n.Operator().Key()])
|
||||
b.writes(cOpNames[0xFF&n.Operator()])
|
||||
if err := g.writeExpr(b, n.RHS(), replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
keyword := "continue"
|
||||
if n.Keyword().Key() == t.KeyBreak {
|
||||
if n.Keyword() == t.IDBreak {
|
||||
keyword = "break"
|
||||
}
|
||||
b.printf("goto label_%d_%s;\n", jt, keyword)
|
||||
@@ -225,11 +225,11 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
|
||||
if g.currFunk.suspendible {
|
||||
b.writes("status = ")
|
||||
retKeyword := t.KeyStatus
|
||||
retKeyword := t.IDStatus
|
||||
if retExpr == nil {
|
||||
b.printf("%s%s", g.PKGPREFIX, "STATUS_OK")
|
||||
} else {
|
||||
retKeyword = retExpr.Operator().Key()
|
||||
retKeyword = retExpr.Operator()
|
||||
// TODO: check that retExpr has no call-suspendibles.
|
||||
if err := g.writeExpr(
|
||||
b, retExpr, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
@@ -238,14 +238,14 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
}
|
||||
b.writes(";")
|
||||
|
||||
if n.Keyword().Key() == t.KeyYield {
|
||||
if n.Keyword() == t.IDYield {
|
||||
return g.writeCoroSuspPoint(b, true)
|
||||
}
|
||||
|
||||
switch retKeyword {
|
||||
case t.KeyError:
|
||||
case t.IDError:
|
||||
b.writes("goto exit;")
|
||||
case t.KeyStatus:
|
||||
case t.IDStatus:
|
||||
b.writes("goto ok;")
|
||||
default:
|
||||
b.printf("if (status == 0) { goto ok; } else if (status > 0) { "+
|
||||
@@ -443,7 +443,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
// TODO: delete these hacks that only matches "in.src.read_u8?()" etc.
|
||||
//
|
||||
// TODO: check io_reader.buf and io_writer.buf is non-NULL.
|
||||
if isInSrc(g.tm, n, t.KeyReadU8, 0) {
|
||||
if isInSrc(g.tm, n, t.IDReadU8, 0) {
|
||||
if g.currFunk.tempW > maxTemp {
|
||||
return fmt.Errorf("too many temporary variables required")
|
||||
}
|
||||
@@ -463,26 +463,26 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
b.printf(" = *%srptr_src++;\n", bPrefix)
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeyUnreadU8, 0) {
|
||||
} else if isInSrc(g.tm, n, t.IDUnreadU8, 0) {
|
||||
b.printf("if (%srptr_src == %srstart_src) { status = %sERROR_INVALID_I_O_OPERATION;",
|
||||
bPrefix, bPrefix, g.PKGPREFIX)
|
||||
b.writes("goto exit;")
|
||||
b.writes("}\n")
|
||||
b.printf("%srptr_src--;\n", bPrefix)
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeyReadU16BE, 0) {
|
||||
} else if isInSrc(g.tm, n, t.IDReadU16BE, 0) {
|
||||
return g.writeReadUXX(b, n, "src", 16, "be")
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeyReadU16LE, 0) {
|
||||
} else if isInSrc(g.tm, n, t.IDReadU16LE, 0) {
|
||||
return g.writeReadUXX(b, n, "src", 16, "le")
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeyReadU32BE, 0) {
|
||||
} else if isInSrc(g.tm, n, t.IDReadU32BE, 0) {
|
||||
return g.writeReadUXX(b, n, "src", 32, "be")
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeyReadU32LE, 0) {
|
||||
} else if isInSrc(g.tm, n, t.IDReadU32LE, 0) {
|
||||
return g.writeReadUXX(b, n, "src", 32, "le")
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeySkip32, 1) {
|
||||
} else if isInSrc(g.tm, n, t.IDSkip32, 1) {
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_impl.%s%s[0].scratch",
|
||||
@@ -508,7 +508,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
g.currFunk.shortReads = append(g.currFunk.shortReads, "src")
|
||||
b.printf("%srptr_src += %s;\n", bPrefix, scratchName)
|
||||
|
||||
} else if isInDst(g.tm, n, t.KeyWriteU8, 1) {
|
||||
} else if isInDst(g.tm, n, t.IDWriteU8, 1) {
|
||||
if !n.ProvenNotToSuspend() {
|
||||
b.printf("if (%swptr_dst == %swend_dst) { status = %sSUSPENSION_SHORT_WRITE;",
|
||||
bPrefix, bPrefix, g.PKGPREFIX)
|
||||
@@ -646,8 +646,8 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
b.writes("if (status) { goto suspend; }\n")
|
||||
|
||||
} else if isThatMethod(g.tm, n, g.tm.ByName("decode").Key(), 2) ||
|
||||
isThatMethod(g.tm, n, g.tm.ByName("decode").Key(), 3) {
|
||||
} else if isThatMethod(g.tm, n, g.tm.ByName("decode"), 2) ||
|
||||
isThatMethod(g.tm, n, g.tm.ByName("decode"), 3) {
|
||||
|
||||
switch g.pkgName {
|
||||
case "gzip", "zlib":
|
||||
@@ -784,74 +784,74 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
|
||||
return nil
|
||||
}
|
||||
|
||||
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
callSuspendible := methodName != t.KeySinceMark &&
|
||||
methodName != t.KeyMark &&
|
||||
methodName != t.KeyLimit
|
||||
if n.Operator().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
func isInSrc(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
callSuspendible := methodName != t.IDSinceMark &&
|
||||
methodName != t.IDMark &&
|
||||
methodName != t.IDLimit
|
||||
if n.Operator() != t.IDOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident().Key() != methodName {
|
||||
if n.Operator() != t.IDDot || n.Ident() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident() != tm.ByName("src") {
|
||||
if n.Operator() != t.IDDot || n.Ident() != tm.ByName("src") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.Operator() == 0 && n.Ident().Key() == t.KeyIn
|
||||
return n.Operator() == 0 && n.Ident() == t.IDIn
|
||||
}
|
||||
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
callSuspendible := methodName != t.KeyCopyFromReader32 &&
|
||||
methodName != t.KeyCopyFromHistory32 &&
|
||||
methodName != t.KeyCopyFromSlice32 &&
|
||||
methodName != t.KeyCopyFromSlice &&
|
||||
methodName != t.KeySinceMark &&
|
||||
methodName != t.KeyIsMarked &&
|
||||
methodName != t.KeyMark &&
|
||||
methodName != t.KeyLimit
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
callSuspendible := methodName != t.IDCopyFromReader32 &&
|
||||
methodName != t.IDCopyFromHistory32 &&
|
||||
methodName != t.IDCopyFromSlice32 &&
|
||||
methodName != t.IDCopyFromSlice &&
|
||||
methodName != t.IDSinceMark &&
|
||||
methodName != t.IDIsMarked &&
|
||||
methodName != t.IDMark &&
|
||||
methodName != t.IDLimit
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.Operator().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
if n.Operator() != t.IDOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident().Key() != methodName {
|
||||
if n.Operator() != t.IDDot || n.Ident() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident() != tm.ByName("dst") {
|
||||
if n.Operator() != t.IDDot || n.Ident() != tm.ByName("dst") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.Operator() == 0 && n.Ident().Key() == t.KeyIn
|
||||
return n.Operator() == 0 && n.Ident() == t.IDIn
|
||||
}
|
||||
|
||||
func isThisMethod(tm *t.Map, n *a.Expr, methodName string, nArgs int) bool {
|
||||
// TODO: check that n.Args() is "(src:in.src)".
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
if k := n.Operator(); k != t.IDOpenParen && k != t.IDTry {
|
||||
return false
|
||||
}
|
||||
if len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident() != tm.ByName(methodName) {
|
||||
if n.Operator() != t.IDDot || n.Ident() != tm.ByName(methodName) {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.Operator() == 0 && n.Ident().Key() == t.KeyThis
|
||||
return n.Operator() == 0 && n.Ident() == t.IDThis
|
||||
}
|
||||
|
||||
// isThatMethod is like isThisMethod but for foo.bar(etc), not this.bar(etc).
|
||||
func isThatMethod(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
func isThatMethod(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
if k := n.Operator(); k != t.IDOpenParen && k != t.IDTry {
|
||||
return false
|
||||
}
|
||||
if len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.Operator().Key() == t.KeyDot && n.Ident().Key() == methodName
|
||||
return n.Operator() == t.IDDot && n.Ident() == methodName
|
||||
}
|
||||
@@ -32,19 +32,19 @@ func (g *gen) needDerivedVar(name t.ID) bool {
|
||||
return nil
|
||||
}
|
||||
q := p.Expr()
|
||||
if q.Operator().Key() != t.KeyOpenParen {
|
||||
if q.Operator() != t.IDOpenParen {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().Expr()
|
||||
if q.Operator().Key() != t.KeyDot {
|
||||
if q.Operator() != t.IDDot {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().Expr()
|
||||
if q.Operator().Key() != t.KeyDot || q.Ident() != name {
|
||||
if q.Operator() != t.IDDot || q.Ident() != name {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().Expr()
|
||||
if q.Operator() != 0 || q.Ident().Key() != t.KeyIn {
|
||||
if q.Operator() != 0 || q.Ident() != t.IDIn {
|
||||
return nil
|
||||
}
|
||||
return errNeedDerivedVar
|
||||
@@ -220,7 +220,7 @@ func (g *gen) writeLoadExprDerivedVars(b *buffer, n *a.Expr) error {
|
||||
if g.currFunk.derivedVars == nil {
|
||||
return nil
|
||||
}
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
if k := n.Operator(); k != t.IDOpenParen && k != t.IDTry {
|
||||
return nil
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
@@ -240,7 +240,7 @@ func (g *gen) writeSaveExprDerivedVars(b *buffer, n *a.Expr) error {
|
||||
if g.currFunk.derivedVars == nil {
|
||||
return nil
|
||||
}
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
if k := n.Operator(); k != t.IDOpenParen && k != t.IDTry {
|
||||
return nil
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
@@ -305,14 +305,14 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
}
|
||||
rhs := ""
|
||||
|
||||
switch typ.Decorator().Key() {
|
||||
switch typ.Decorator() {
|
||||
case 0:
|
||||
if qid := typ.QID(); qid[0] == t.IDBase {
|
||||
if key := qid[1].Key(); key < t.Key(len(cTypeNames)) {
|
||||
if key := qid[1]; key < t.ID(len(cTypeNames)) {
|
||||
rhs = cTypeNames[key]
|
||||
}
|
||||
}
|
||||
case t.KeySlice:
|
||||
case t.IDSlice:
|
||||
// TODO: don't assume that the slice is a slice of base.u8.
|
||||
rhs = "wuffs_base__slice_u8"
|
||||
}
|
||||
@@ -358,11 +358,11 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
lhs, rhs = rhs, lhs
|
||||
}
|
||||
|
||||
switch typ.Decorator().Key() {
|
||||
switch typ.Decorator() {
|
||||
case 0:
|
||||
b.printf("%s = %s;\n", lhs, rhs)
|
||||
return nil
|
||||
case t.KeyArray:
|
||||
case t.IDArray:
|
||||
inner := typ.Inner()
|
||||
if inner.Decorator() != 0 {
|
||||
break
|
||||
@@ -371,8 +371,8 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
|
||||
if qid[0] != t.IDBase {
|
||||
break
|
||||
}
|
||||
switch qid[1].Key() {
|
||||
case t.KeyU8, t.KeyU16, t.KeyU32, t.KeyU64:
|
||||
switch qid[1] {
|
||||
case t.IDU8, t.IDU16, t.IDU32, t.IDU64:
|
||||
b.printf("memcpy(%s, %s, sizeof(%s));\n", lhs, rhs, local)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user