mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Merge Break and Continue as Jump.
This commit is contained in:
1 parent
23020e7d60
commit
d9fc8a1114
3 files changed
+14
-35
No files matched your search
+11
-24
@@ -23,13 +23,12 @@ const (
|
|||||||
|
|
||||||
KAssert
|
KAssert
|
||||||
KAssign
|
KAssign
|
||||||
KBreak
|
|
||||||
KContinue
|
|
||||||
KExpr
|
KExpr
|
||||||
KField
|
KField
|
||||||
KFile
|
KFile
|
||||||
KFunc
|
KFunc
|
||||||
KIf
|
KIf
|
||||||
|
KJump
|
||||||
KReturn
|
KReturn
|
||||||
KStruct
|
KStruct
|
||||||
KTypeExpr
|
KTypeExpr
|
||||||
@@ -50,13 +49,12 @@ var kindStrings = [...]string{
|
|||||||
|
|
||||||
KAssert: "KAssert",
|
KAssert: "KAssert",
|
||||||
KAssign: "KAssign",
|
KAssign: "KAssign",
|
||||||
KBreak: "KBreak",
|
|
||||||
KContinue: "KContinue",
|
|
||||||
KExpr: "KExpr",
|
KExpr: "KExpr",
|
||||||
KField: "KField",
|
KField: "KField",
|
||||||
KFile: "KFile",
|
KFile: "KFile",
|
||||||
KFunc: "KFunc",
|
KFunc: "KFunc",
|
||||||
KIf: "KIf",
|
KIf: "KIf",
|
||||||
|
KJump: "KJump",
|
||||||
KReturn: "KReturn",
|
KReturn: "KReturn",
|
||||||
KStruct: "KStruct",
|
KStruct: "KStruct",
|
||||||
KTypeExpr: "KTypeExpr",
|
KTypeExpr: "KTypeExpr",
|
||||||
@@ -94,13 +92,12 @@ func (n *Node) Kind() Kind { return n.kind }
|
|||||||
|
|
||||||
func (n *Node) Assert() *Assert { return (*Assert)(n) }
|
func (n *Node) Assert() *Assert { return (*Assert)(n) }
|
||||||
func (n *Node) Assign() *Assign { return (*Assign)(n) }
|
func (n *Node) Assign() *Assign { return (*Assign)(n) }
|
||||||
func (n *Node) Break() *Break { return (*Break)(n) }
|
|
||||||
func (n *Node) Continue() *Continue { return (*Continue)(n) }
|
|
||||||
func (n *Node) Expr() *Expr { return (*Expr)(n) }
|
func (n *Node) Expr() *Expr { return (*Expr)(n) }
|
||||||
func (n *Node) Field() *Field { return (*Field)(n) }
|
func (n *Node) Field() *Field { return (*Field)(n) }
|
||||||
func (n *Node) File() *File { return (*File)(n) }
|
func (n *Node) File() *File { return (*File)(n) }
|
||||||
func (n *Node) Func() *Func { return (*Func)(n) }
|
func (n *Node) Func() *Func { return (*Func)(n) }
|
||||||
func (n *Node) If() *If { return (*If)(n) }
|
func (n *Node) If() *If { return (*If)(n) }
|
||||||
|
func (n *Node) Jump() *Jump { return (*Jump)(n) }
|
||||||
func (n *Node) Raw() *Raw { return (*Raw)(n) }
|
func (n *Node) Raw() *Raw { return (*Raw)(n) }
|
||||||
func (n *Node) Return() *Return { return (*Return)(n) }
|
func (n *Node) Return() *Return { return (*Return)(n) }
|
||||||
func (n *Node) Struct() *Struct { return (*Struct)(n) }
|
func (n *Node) Struct() *Struct { return (*Struct)(n) }
|
||||||
@@ -340,27 +337,17 @@ func NewReturn(value *Expr) *Return {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Break is "break":
|
// Jump is "break" or "continue":
|
||||||
// TODO: label?
|
// TODO: label?
|
||||||
type Break Node
|
type Jump Node
|
||||||
|
|
||||||
func (n *Break) Node() *Node { return (*Node)(n) }
|
func (n *Jump) Node() *Node { return (*Node)(n) }
|
||||||
|
func (n *Jump) Keyword() t.ID { return n.id0 }
|
||||||
|
|
||||||
func NewBreak() *Break {
|
func NewJump(keyword t.ID) *Jump {
|
||||||
return &Break{
|
return &Jump{
|
||||||
kind: KBreak,
|
kind: KJump,
|
||||||
}
|
id0: keyword,
|
||||||
}
|
|
||||||
|
|
||||||
// Continue is "continue":
|
|
||||||
// TODO: label?
|
|
||||||
type Continue Node
|
|
||||||
|
|
||||||
func (n *Continue) Node() *Node { return (*Node)(n) }
|
|
||||||
|
|
||||||
func NewContinue() *Continue {
|
|
||||||
return &Continue{
|
|
||||||
kind: KContinue,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-5
@@ -124,11 +124,7 @@ func (c *typeChecker) checkStatement(n *a.Node) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case a.KBreak:
|
case a.KJump:
|
||||||
// TODO: check that we're in a for loop.
|
|
||||||
return nil
|
|
||||||
|
|
||||||
case a.KContinue:
|
|
||||||
// TODO: check that we're in a for loop.
|
// TODO: check that we're in a for loop.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-6
@@ -403,13 +403,9 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
|||||||
case t.IDAssert, t.IDPre, t.IDPost:
|
case t.IDAssert, t.IDPre, t.IDPost:
|
||||||
return p.parseAssertNode()
|
return p.parseAssertNode()
|
||||||
|
|
||||||
case t.IDBreak:
|
case t.IDBreak, t.IDContinue:
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
return a.NewBreak().Node(), nil
|
return a.NewJump(x).Node(), nil
|
||||||
|
|
||||||
case t.IDContinue:
|
|
||||||
p.src = p.src[1:]
|
|
||||||
return a.NewContinue().Node(), nil
|
|
||||||
|
|
||||||
case t.IDWhile:
|
case t.IDWhile:
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
|
|||||||
Reference in new issue
Block a user