rename AssignRef to Reference

This commit is contained in:
z7zmey 2018-04-05 12:03:32 +03:00
parent d19b16e161
commit 47c51ea022
11 changed files with 30 additions and 30 deletions

View File

@ -5,28 +5,28 @@ import (
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// AssignRef node // Reference node
type AssignRef struct { type Reference struct {
Variable node.Node Variable node.Node
Expression node.Node Expression node.Node
} }
// NewAssignRef node constuctor // NewReference node constuctor
func NewAssignRef(Variable node.Node, Expression node.Node) *AssignRef { func NewReference(Variable node.Node, Expression node.Node) *Reference {
return &AssignRef{ return &Reference{
Variable, Variable,
Expression, Expression,
} }
} }
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *AssignRef) Attributes() map[string]interface{} { func (n *Reference) Attributes() map[string]interface{} {
return nil return nil
} }
// Walk traverses nodes // Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true // Walk is invoked recursively until v.EnterNode returns true
func (n *AssignRef) Walk(v walker.Visitor) { func (n *Reference) Walk(v walker.Visitor) {
if v.EnterNode(n) == false { if v.EnterNode(n) == false {
return return
} }

View File

@ -29,13 +29,13 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
} }
} }
func TestAssignRef(t *testing.T) { func TestReference(t *testing.T) {
src := `<? $a =& $b;` src := `<? $a =& $b;`
expected := &stmt.StmtList{ expected := &stmt.StmtList{
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
}, },
@ -50,13 +50,13 @@ func TestAssignRef(t *testing.T) {
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestAssignRefNew(t *testing.T) { func TestReferenceNew(t *testing.T) {
src := `<? $a =& new Foo;` src := `<? $a =& new Foo;`
expected := &stmt.StmtList{ expected := &stmt.StmtList{
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.New{ Expression: &expr.New{
Class: &name.Name{ Class: &name.Name{
@ -77,13 +77,13 @@ func TestAssignRefNew(t *testing.T) {
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestAssignRefArgs(t *testing.T) { func TestReferenceArgs(t *testing.T) {
src := `<? $a =& new Foo($b);` src := `<? $a =& new Foo($b);`
expected := &stmt.StmtList{ expected := &stmt.StmtList{
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.New{ Expression: &expr.New{
Class: &name.Name{ Class: &name.Name{

View File

@ -19,7 +19,7 @@ var nodesToTest = []struct {
expectedAttributes map[string]interface{} expectedAttributes map[string]interface{}
}{ }{
{ {
&assign.AssignRef{ &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
}, },

View File

@ -4257,7 +4257,7 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line php5/php5.y:1866 //line php5/php5.y:1866
{ {
yyVAL.node = assign.NewAssignRef(yyDollar[1].node, yyDollar[4].node) yyVAL.node = assign.NewReference(yyDollar[1].node, yyDollar[4].node)
positions.AddPosition(yyVAL.node, positionBuilder.NewNodesPosition(yyDollar[1].node, yyDollar[4].node)) positions.AddPosition(yyVAL.node, positionBuilder.NewNodesPosition(yyDollar[1].node, yyDollar[4].node))
comments.AddComments(yyVAL.node, comments[yyDollar[1].node]) comments.AddComments(yyVAL.node, comments[yyDollar[1].node])
} }
@ -4274,7 +4274,7 @@ yydefault:
} }
comments.AddComments(_new, comments[yyDollar[1].node]) comments.AddComments(_new, comments[yyDollar[1].node])
yyVAL.node = assign.NewAssignRef(yyDollar[1].node, _new) yyVAL.node = assign.NewReference(yyDollar[1].node, _new)
positions.AddPosition(yyVAL.node, positionBuilder.NewNodesPosition(yyDollar[1].node, _new)) positions.AddPosition(yyVAL.node, positionBuilder.NewNodesPosition(yyDollar[1].node, _new))
comments.AddComments(yyVAL.node, comments[yyDollar[1].node]) comments.AddComments(yyVAL.node, comments[yyDollar[1].node])
} }

View File

@ -1864,7 +1864,7 @@ expr_without_variable:
} }
| variable '=' '&' variable | variable '=' '&' variable
{ {
$$ = assign.NewAssignRef($1, $4) $$ = assign.NewReference($1, $4)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, $4)) positions.AddPosition($$, positionBuilder.NewNodesPosition($1, $4))
comments.AddComments($$, comments[$1]) comments.AddComments($$, comments[$1])
} }
@ -1879,7 +1879,7 @@ expr_without_variable:
} }
comments.AddComments(_new, comments[$1]) comments.AddComments(_new, comments[$1])
$$ = assign.NewAssignRef($1, _new) $$ = assign.NewReference($1, _new)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, _new)) positions.AddPosition($$, positionBuilder.NewNodesPosition($1, _new))
comments.AddComments($$, comments[$1]) comments.AddComments($$, comments[$1])
} }

View File

@ -2849,13 +2849,13 @@ CAD;
}, },
}, },
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
}, },
}, },
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.New{ Expression: &expr.New{
Class: &name.Name{ Class: &name.Name{
@ -2867,7 +2867,7 @@ CAD;
}, },
}, },
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.New{ Expression: &expr.New{
Class: &name.Name{ Class: &name.Name{

View File

@ -4223,7 +4223,7 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line php7/php7.y:1512 //line php7/php7.y:1512
{ {
yyVAL.node = assign.NewAssignRef(yyDollar[1].node, yyDollar[4].node) yyVAL.node = assign.NewReference(yyDollar[1].node, yyDollar[4].node)
positions.AddPosition(yyVAL.node, positionBuilder.NewNodesPosition(yyDollar[1].node, yyDollar[4].node)) positions.AddPosition(yyVAL.node, positionBuilder.NewNodesPosition(yyDollar[1].node, yyDollar[4].node))
comments.AddComments(yyVAL.node, comments[yyDollar[1].node]) comments.AddComments(yyVAL.node, comments[yyDollar[1].node])
} }

View File

@ -1510,7 +1510,7 @@ expr_without_variable:
} }
| variable '=' '&' expr | variable '=' '&' expr
{ {
$$ = assign.NewAssignRef($1, $4) $$ = assign.NewReference($1, $4)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, $4)) positions.AddPosition($$, positionBuilder.NewNodesPosition($1, $4))
comments.AddComments($$, comments[$1]) comments.AddComments($$, comments[$1])
} }

View File

@ -2890,7 +2890,7 @@ CAD;
}, },
}, },
&stmt.Expression{ &stmt.Expression{
Expr: &assign.AssignRef{ Expr: &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
}, },

View File

@ -106,8 +106,8 @@ func (p *Printer) printNode(n node.Node) {
case *assign.Assign: case *assign.Assign:
p.printAssign(n) p.printAssign(n)
case *assign.AssignRef: case *assign.Reference:
p.printAssignRef(n) p.printReference(n)
case *assign.BitwiseAnd: case *assign.BitwiseAnd:
p.printAssignBitwiseAnd(n) p.printAssignBitwiseAnd(n)
case *assign.BitwiseOr: case *assign.BitwiseOr:
@ -544,8 +544,8 @@ func (p *Printer) printAssign(n node.Node) {
p.Print(nn.Expression) p.Print(nn.Expression)
} }
func (p *Printer) printAssignRef(n node.Node) { func (p *Printer) printReference(n node.Node) {
nn := n.(*assign.AssignRef) nn := n.(*assign.Reference)
p.Print(nn.Variable) p.Print(nn.Variable)
io.WriteString(p.w, " =& ") io.WriteString(p.w, " =& ")
p.Print(nn.Expression) p.Print(nn.Expression)

View File

@ -288,11 +288,11 @@ func TestPrintAssign(t *testing.T) {
} }
} }
func TestPrintAssignRef(t *testing.T) { func TestPrintReference(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")
p := printer.NewPrinter(o, " ") p := printer.NewPrinter(o, " ")
p.Print(&assign.AssignRef{ p.Print(&assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
}) })