mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Make SubExprHasEffect an ast.Flags not ast.Effect
This commit is contained in:
1 parent
dd28f3c0f9
commit
eb0cbd802a
2 files changed
+5
-7
No files matched your search
+4
-6
@@ -98,6 +98,7 @@ const (
|
|||||||
FlagsHasContinue = Flags(0x00000400)
|
FlagsHasContinue = Flags(0x00000400)
|
||||||
FlagsGlobalIdent = Flags(0x00000800)
|
FlagsGlobalIdent = Flags(0x00000800)
|
||||||
FlagsClassy = Flags(0x00001000)
|
FlagsClassy = Flags(0x00001000)
|
||||||
|
FlagsSubExprHasEffect = Flags(0x00002000)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f Flags) AsEffect() Effect { return Effect(f) }
|
func (f Flags) AsEffect() Effect { return Effect(f) }
|
||||||
@@ -109,19 +110,15 @@ const (
|
|||||||
EffectOptional = Effect(0x02) // TODO: rename to Statusful or Throws?
|
EffectOptional = Effect(0x02) // TODO: rename to Statusful or Throws?
|
||||||
EffectCoroutine = Effect(0x04)
|
EffectCoroutine = Effect(0x04)
|
||||||
|
|
||||||
EffectSubExprHasEffect = Effect(0x08)
|
|
||||||
|
|
||||||
effectMask = Effect(0xFF)
|
effectMask = Effect(0xFF)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e Effect) AsFlags() Flags { return Flags(e) }
|
func (e Effect) AsFlags() Flags { return Flags(e) }
|
||||||
|
|
||||||
// TODO: replace Pure calls with the stronger "e == 0"?
|
func (e Effect) Pure() bool { return e == 0 }
|
||||||
func (e Effect) Pure() bool { return e&EffectImpure == 0 }
|
|
||||||
func (e Effect) Impure() bool { return e&EffectImpure != 0 }
|
func (e Effect) Impure() bool { return e&EffectImpure != 0 }
|
||||||
func (e Effect) Optional() bool { return e&EffectOptional != 0 }
|
func (e Effect) Optional() bool { return e&EffectOptional != 0 }
|
||||||
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
|
func (e Effect) Coroutine() bool { return e&EffectCoroutine != 0 }
|
||||||
func (e Effect) SubExprHasEffect() bool { return e&EffectSubExprHasEffect != 0 }
|
|
||||||
|
|
||||||
func (e Effect) String() string {
|
func (e Effect) String() string {
|
||||||
switch e & effectMask {
|
switch e & effectMask {
|
||||||
@@ -331,6 +328,7 @@ type Expr Node
|
|||||||
func (n *Expr) AsNode() *Node { return (*Node)(n) }
|
func (n *Expr) AsNode() *Node { return (*Node)(n) }
|
||||||
func (n *Expr) Effect() Effect { return Effect(n.flags) }
|
func (n *Expr) Effect() Effect { return Effect(n.flags) }
|
||||||
func (n *Expr) GlobalIdent() bool { return n.flags&FlagsGlobalIdent != 0 }
|
func (n *Expr) GlobalIdent() bool { return n.flags&FlagsGlobalIdent != 0 }
|
||||||
|
func (n *Expr) SubExprHasEffect() bool { return n.flags&FlagsSubExprHasEffect != 0 }
|
||||||
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
||||||
func (n *Expr) MBounds() Bounds { return n.mBounds }
|
func (n *Expr) MBounds() Bounds { return n.mBounds }
|
||||||
func (n *Expr) MType() *TypeExpr { return n.mType }
|
func (n *Expr) MType() *TypeExpr { return n.mType }
|
||||||
@@ -362,7 +360,7 @@ func NewExpr(flags Flags, operator t.ID, statusPkg t.ID, ident t.ID, lhs *Node,
|
|||||||
subExprEffect |= o.flags & Flags(effectMask)
|
subExprEffect |= o.flags & Flags(effectMask)
|
||||||
}
|
}
|
||||||
if subExprEffect != 0 {
|
if subExprEffect != 0 {
|
||||||
flags |= subExprEffect | EffectSubExprHasEffect.AsFlags()
|
flags |= subExprEffect | FlagsSubExprHasEffect
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Expr{
|
return &Expr{
|
||||||
|
|||||||
+1
-1
@@ -987,7 +987,7 @@ func (p *parser) parseExpr() (*a.Expr, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if e.Effect().SubExprHasEffect() {
|
if e.SubExprHasEffect() {
|
||||||
return nil, fmt.Errorf(`parse: expression %q has an effect-ful sub-expression at %s:%d`,
|
return nil, fmt.Errorf(`parse: expression %q has an effect-ful sub-expression at %s:%d`,
|
||||||
e.Str(p.tm), p.filename, p.line())
|
e.Str(p.tm), p.filename, p.line())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user