mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Ban unlabeled break/continue for labeled loop
This commit is contained in:
1 parent
c5b3a9e08e
commit
2d2a880c18
4 files changed
+10
-3
No files matched your search
@@ -240,6 +240,7 @@ type Loop interface {
|
||||
AsNode() *Node
|
||||
HasBreak() bool
|
||||
HasContinue() bool
|
||||
Keyword() t.ID
|
||||
Label() t.ID
|
||||
Asserts() []*Node
|
||||
Body() []*Node
|
||||
@@ -513,6 +514,7 @@ type Iterate Node
|
||||
func (n *Iterate) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *Iterate) HasBreak() bool { return n.flags&FlagsHasBreak != 0 }
|
||||
func (n *Iterate) HasContinue() bool { return n.flags&FlagsHasContinue != 0 }
|
||||
func (n *Iterate) Keyword() t.ID { return t.IDIterate }
|
||||
func (n *Iterate) Unroll() t.ID { return n.id0 }
|
||||
func (n *Iterate) Label() t.ID { return n.id1 }
|
||||
func (n *Iterate) Length() t.ID { return n.id2 }
|
||||
@@ -551,6 +553,7 @@ type While Node
|
||||
func (n *While) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *While) HasBreak() bool { return n.flags&FlagsHasBreak != 0 }
|
||||
func (n *While) HasContinue() bool { return n.flags&FlagsHasContinue != 0 }
|
||||
func (n *While) Keyword() t.ID { return t.IDWhile }
|
||||
func (n *While) Label() t.ID { return n.id1 }
|
||||
func (n *While) Condition() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *While) Asserts() []*Node { return n.list1 }
|
||||
|
||||
+5
-1
@@ -151,13 +151,17 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
}
|
||||
} else if nj := len(q.jumpTargets); nj > 0 {
|
||||
jumpTarget = q.jumpTargets[nj-1]
|
||||
if jumpTarget.Label() != 0 {
|
||||
return fmt.Errorf("check: unlabeled %s for labeled %s.%s",
|
||||
n.Keyword().Str(q.tm), jumpTarget.Keyword().Str(q.tm), jumpTarget.Label().Str(q.tm))
|
||||
}
|
||||
}
|
||||
if jumpTarget == nil {
|
||||
sepStr, labelStr := "", ""
|
||||
if id := n.Label(); id != 0 {
|
||||
sepStr, labelStr = ":", id.Str(q.tm)
|
||||
}
|
||||
return fmt.Errorf("no matching while/iterate statement for %s%s%s",
|
||||
return fmt.Errorf("check: no matching while/iterate statement for %s%s%s",
|
||||
n.Keyword().Str(q.tm), sepStr, labelStr)
|
||||
}
|
||||
if n.Keyword() == t.IDBreak {
|
||||
|
||||
Reference in new issue
Block a user