[refactoring] update ast structure of "Return" node

This commit is contained in:
Vadym Slizov 2020-09-06 13:09:00 +03:00
parent e817f8dd8d
commit 59ef622082
7 changed files with 45 additions and 49 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -992,39 +992,35 @@ unticked_statement:
} }
| T_RETURN ';' | T_RETURN ';'
{ {
$$ = &ast.StmtReturn{ast.Node{}, nil} $$ = &ast.StmtReturn{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $2),
$$.GetNode().Position = position.NewTokensPosition($1, $2) },
ReturnTkn: $1,
// save comments SemiColonTkn: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
} }
| T_RETURN expr_without_variable ';' | T_RETURN expr_without_variable ';'
{ {
$$ = &ast.StmtReturn{ast.Node{}, $2} $$ = &ast.StmtReturn{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $3),
$$.GetNode().Position = position.NewTokensPosition($1, $3) },
ReturnTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) SemiColonTkn: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) }
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
} }
| T_RETURN variable ';' | T_RETURN variable ';'
{ {
$$ = &ast.StmtReturn{ast.Node{}, $2} $$ = &ast.StmtReturn{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $3),
$$.GetNode().Position = position.NewTokensPosition($1, $3) },
ReturnTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) SemiColonTkn: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) }
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
} }
| yield_expr ';' | yield_expr ';'
{ {

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -941,15 +941,14 @@ statement:
} }
| T_RETURN optional_expr ';' | T_RETURN optional_expr ';'
{ {
$$ = &ast.StmtReturn{ast.Node{}, $2} $$ = &ast.StmtReturn{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $3),
$$.GetNode().Position = position.NewTokensPosition($1, $3) },
ReturnTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) SemiColonTkn: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens) }
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
} }
| T_GLOBAL global_var_list ';' | T_GLOBAL global_var_list ';'
{ {

View File

@ -618,7 +618,9 @@ func (n *StmtPropertyList) Accept(v NodeVisitor) {
// StmtReturn node // StmtReturn node
type StmtReturn struct { type StmtReturn struct {
Node Node
Expr Vertex ReturnTkn *token.Token
Expr Vertex
SemiColonTkn *token.Token
} }
func (n *StmtReturn) Accept(v NodeVisitor) { func (n *StmtReturn) Accept(v NodeVisitor) {

View File

@ -173,3 +173,8 @@ func (v *FilterTokens) StmtContinue(n *ast.StmtContinue) {
n.ContinueTkn = nil n.ContinueTkn = nil
n.SemiColonTkn = nil n.SemiColonTkn = nil
} }
func (v *FilterTokens) StmtReturn(n *ast.StmtReturn) {
n.ReturnTkn = nil
n.SemiColonTkn = nil
}

View File

@ -2690,21 +2690,15 @@ func (p *Printer) printStmtProperty(n ast.Vertex) {
p.printFreeFloating(nn, token.End) p.printFreeFloating(nn, token.End)
} }
func (p *Printer) printStmtReturn(n ast.Vertex) { func (p *Printer) printStmtReturn(n *ast.StmtReturn) {
nn := n.(*ast.StmtReturn) p.printToken(n.ReturnTkn, "return")
p.printFreeFloating(nn, token.Start)
io.WriteString(p.w, "return") if n.Expr != nil {
p.bufStart = " " p.bufStart = " "
p.Print(nn.Expr)
p.printFreeFloating(nn, token.Expr)
p.printFreeFloating(nn, token.SemiColon)
if n.GetNode().Tokens.IsEmpty() {
io.WriteString(p.w, ";")
} }
p.Print(n.Expr)
p.printFreeFloating(nn, token.End) p.printToken(n.SemiColonTkn, ";")
} }
func (p *Printer) printStmtStaticVar(n ast.Vertex) { func (p *Printer) printStmtStaticVar(n ast.Vertex) {