mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Add FlagsCallImpure and FlagsCallSuspendible.
This commit is contained in:
1 parent
a6e8ff5736
commit
da133c02ce
5 files changed
+44
-26
No files matched your search
@@ -683,7 +683,7 @@ func (g *gen) writeExprOther(n *a.Expr, depth uint32) error {
|
|||||||
case t.KeyOpenParen:
|
case t.KeyOpenParen:
|
||||||
// n is a function call.
|
// n is a function call.
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||||
if isInSrcReadU8(g.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
if isInSrcReadU8(g.idMap, n.LHS().Expr()) && n.CallSuspendible() && len(n.Args()) == 0 {
|
||||||
// TODO.
|
// TODO.
|
||||||
g.writes("42")
|
g.writes("42")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+38
-19
@@ -68,12 +68,14 @@ var kindStrings = [...]string{
|
|||||||
type Flags uint32
|
type Flags uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FlagsImpure = Flags(0x00000001)
|
FlagsImpure = Flags(0x00000001)
|
||||||
FlagsSuspendible = Flags(0x00000002)
|
FlagsSuspendible = Flags(0x00000002)
|
||||||
FlagsPublic = Flags(0x00000004)
|
FlagsCallImpure = Flags(0x00000004)
|
||||||
FlagsTypeChecked = Flags(0x00000008)
|
FlagsCallSuspendible = Flags(0x00000008)
|
||||||
FlagsHasBreak = Flags(0x00000010)
|
FlagsPublic = Flags(0x00000010)
|
||||||
FlagsHasContinue = Flags(0x00000020)
|
FlagsTypeChecked = Flags(0x00000020)
|
||||||
|
FlagsHasBreak = Flags(0x00000040)
|
||||||
|
FlagsHasContinue = Flags(0x00000080)
|
||||||
)
|
)
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
@@ -165,8 +167,10 @@ func (n *Raw) SetFilenameLine(f string, l uint32) { n.filename, n.line = f, l }
|
|||||||
const MaxExprDepth = 255
|
const MaxExprDepth = 255
|
||||||
|
|
||||||
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
|
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
|
||||||
// - FlagsImpure is "f(x)" vs "f!(x)"
|
// - FlagsImpure is if it or a sub-expr is FlagsCallImpure
|
||||||
// - FlagsSuspendible is "f(x)" vs "f?(x)", it implies FlagsImpure
|
// - FlagsSuspendible is if it or a sub-expr is FlagsCallSuspendible
|
||||||
|
// - FlagsCallImpure is "f(x)" vs "f!(x)"
|
||||||
|
// - FlagsCallSuspendible is "f(x)" vs "f?(x)", it implies FlagsCallImpure
|
||||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
||||||
// - ID1: <0|ident|literal>
|
// - ID1: <0|ident|literal>
|
||||||
// - LHS: <nil|Expr>
|
// - LHS: <nil|Expr>
|
||||||
@@ -194,22 +198,37 @@ const MaxExprDepth = 255
|
|||||||
// For selectors, like "LHS.ID1", ID0 is IDDot.
|
// For selectors, like "LHS.ID1", ID0 is IDDot.
|
||||||
type Expr Node
|
type Expr Node
|
||||||
|
|
||||||
func (n *Expr) Node() *Node { return (*Node)(n) }
|
func (n *Expr) Node() *Node { return (*Node)(n) }
|
||||||
func (n *Expr) Impure() bool { return n.flags&FlagsImpure != 0 }
|
func (n *Expr) Impure() bool { return n.flags&FlagsImpure != 0 }
|
||||||
func (n *Expr) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
func (n *Expr) Suspendible() bool { return n.flags&FlagsSuspendible != 0 }
|
||||||
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
func (n *Expr) CallImpure() bool { return n.flags&FlagsCallImpure != 0 }
|
||||||
func (n *Expr) MType() *TypeExpr { return n.mType }
|
func (n *Expr) CallSuspendible() bool { return n.flags&FlagsCallSuspendible != 0 }
|
||||||
func (n *Expr) ID0() t.ID { return n.id0 }
|
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
||||||
func (n *Expr) ID1() t.ID { return n.id1 }
|
func (n *Expr) MType() *TypeExpr { return n.mType }
|
||||||
func (n *Expr) LHS() *Node { return n.lhs }
|
func (n *Expr) ID0() t.ID { return n.id0 }
|
||||||
func (n *Expr) MHS() *Node { return n.mhs }
|
func (n *Expr) ID1() t.ID { return n.id1 }
|
||||||
func (n *Expr) RHS() *Node { return n.rhs }
|
func (n *Expr) LHS() *Node { return n.lhs }
|
||||||
func (n *Expr) Args() []*Node { return n.list0 }
|
func (n *Expr) MHS() *Node { return n.mhs }
|
||||||
|
func (n *Expr) RHS() *Node { return n.rhs }
|
||||||
|
func (n *Expr) Args() []*Node { return n.list0 }
|
||||||
|
|
||||||
func (n *Expr) SetConstValue(x *big.Int) { n.constValue = x }
|
func (n *Expr) SetConstValue(x *big.Int) { n.constValue = x }
|
||||||
func (n *Expr) SetMType(x *TypeExpr) { n.mType = x }
|
func (n *Expr) SetMType(x *TypeExpr) { n.mType = x }
|
||||||
|
|
||||||
func NewExpr(flags Flags, operator t.ID, nameLiteralSelector t.ID, lhs *Node, mhs *Node, rhs *Node, args []*Node) *Expr {
|
func NewExpr(flags Flags, operator t.ID, nameLiteralSelector t.ID, lhs *Node, mhs *Node, rhs *Node, args []*Node) *Expr {
|
||||||
|
if lhs != nil {
|
||||||
|
flags |= lhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||||
|
}
|
||||||
|
if mhs != nil {
|
||||||
|
flags |= mhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||||
|
}
|
||||||
|
if rhs != nil {
|
||||||
|
flags |= rhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||||
|
}
|
||||||
|
for _, o := range args {
|
||||||
|
flags |= o.flags & (FlagsImpure | FlagsSuspendible)
|
||||||
|
}
|
||||||
|
|
||||||
return &Expr{
|
return &Expr{
|
||||||
kind: KExpr,
|
kind: KExpr,
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
|
|
||||||
case t.KeyOpenParen:
|
case t.KeyOpenParen:
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||||
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && n.CallSuspendible() && len(n.Args()) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
||||||
|
|||||||
+1
-1
@@ -294,7 +294,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
case t.KeyOpenParen:
|
case t.KeyOpenParen:
|
||||||
// n is a function call.
|
// n is a function call.
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||||
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && len(n.Args()) == 0 {
|
if isInSrcReadU8(q.idMap, n.LHS().Expr()) && n.CallSuspendible() && len(n.Args()) == 0 {
|
||||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -704,10 +704,9 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
|||||||
return lhs, nil
|
return lhs, nil
|
||||||
|
|
||||||
case t.KeyExclam, t.KeyQuestion:
|
case t.KeyExclam, t.KeyQuestion:
|
||||||
if p.src[0].Key() == t.KeyExclam {
|
flags |= a.FlagsImpure | a.FlagsCallImpure
|
||||||
flags |= a.FlagsImpure
|
if p.src[0].Key() == t.KeyQuestion {
|
||||||
} else {
|
flags |= a.FlagsSuspendible | a.FlagsCallSuspendible
|
||||||
flags |= a.FlagsImpure | a.FlagsSuspendible
|
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|||||||
Reference in new issue
Block a user