2019-01-09 10:17:42 +03:00
|
|
|
package ast
|
|
|
|
|
2019-01-11 12:16:34 +03:00
|
|
|
import "github.com/d5/tengo/source"
|
2019-01-09 10:17:42 +03:00
|
|
|
|
|
|
|
type IfStmt struct {
|
2019-01-11 12:16:34 +03:00
|
|
|
IfPos source.Pos
|
2019-01-09 10:17:42 +03:00
|
|
|
Init Stmt
|
|
|
|
Cond Expr
|
|
|
|
Body *BlockStmt
|
|
|
|
Else Stmt // else branch; or nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IfStmt) stmtNode() {}
|
|
|
|
|
2019-01-11 12:16:34 +03:00
|
|
|
func (s *IfStmt) Pos() source.Pos {
|
2019-01-09 10:17:42 +03:00
|
|
|
return s.IfPos
|
|
|
|
}
|
|
|
|
|
2019-01-11 12:16:34 +03:00
|
|
|
func (s *IfStmt) End() source.Pos {
|
2019-01-09 10:17:42 +03:00
|
|
|
if s.Else != nil {
|
|
|
|
return s.Else.End()
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.Body.End()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IfStmt) String() string {
|
|
|
|
var initStmt, elseStmt string
|
|
|
|
if s.Init != nil {
|
|
|
|
initStmt = s.Init.String() + "; "
|
|
|
|
}
|
|
|
|
if s.Else != nil {
|
|
|
|
elseStmt = " else " + s.Else.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
return "if " + initStmt + s.Cond.String() + " " + s.Body.String() + elseStmt
|
|
|
|
}
|