rename AssignRef to Reference
This commit is contained in:
		
							parent
							
								
									d19b16e161
								
							
						
					
					
						commit
						47c51ea022
					
				| @ -5,28 +5,28 @@ import ( | ||||
| 	"github.com/z7zmey/php-parser/walker" | ||||
| ) | ||||
| 
 | ||||
| // AssignRef node | ||||
| type AssignRef struct { | ||||
| // Reference node | ||||
| type Reference struct { | ||||
| 	Variable   node.Node | ||||
| 	Expression node.Node | ||||
| } | ||||
| 
 | ||||
| // NewAssignRef node constuctor | ||||
| func NewAssignRef(Variable node.Node, Expression node.Node) *AssignRef { | ||||
| 	return &AssignRef{ | ||||
| // NewReference node constuctor | ||||
| func NewReference(Variable node.Node, Expression node.Node) *Reference { | ||||
| 	return &Reference{ | ||||
| 		Variable, | ||||
| 		Expression, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Attributes returns node attributes as map | ||||
| func (n *AssignRef) Attributes() map[string]interface{} { | ||||
| func (n *Reference) Attributes() map[string]interface{} { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| // Walk traverses nodes | ||||
| // 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 { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| @ -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;` | ||||
| 
 | ||||
| 	expected := &stmt.StmtList{ | ||||
| 		Stmts: []node.Node{ | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable:   &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, | ||||
| 				}, | ||||
| @ -50,13 +50,13 @@ func TestAssignRef(t *testing.T) { | ||||
| 	assertEqual(t, expected, actual) | ||||
| } | ||||
| 
 | ||||
| func TestAssignRefNew(t *testing.T) { | ||||
| func TestReferenceNew(t *testing.T) { | ||||
| 	src := `<? $a =& new Foo;` | ||||
| 
 | ||||
| 	expected := &stmt.StmtList{ | ||||
| 		Stmts: []node.Node{ | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.New{ | ||||
| 						Class: &name.Name{ | ||||
| @ -77,13 +77,13 @@ func TestAssignRefNew(t *testing.T) { | ||||
| 	assertEqual(t, expected, actual) | ||||
| } | ||||
| 
 | ||||
| func TestAssignRefArgs(t *testing.T) { | ||||
| func TestReferenceArgs(t *testing.T) { | ||||
| 	src := `<? $a =& new Foo($b);` | ||||
| 
 | ||||
| 	expected := &stmt.StmtList{ | ||||
| 		Stmts: []node.Node{ | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.New{ | ||||
| 						Class: &name.Name{ | ||||
|  | ||||
| @ -19,7 +19,7 @@ var nodesToTest = []struct { | ||||
| 	expectedAttributes  map[string]interface{} | ||||
| }{ | ||||
| 	{ | ||||
| 		&assign.AssignRef{ | ||||
| 		&assign.Reference{ | ||||
| 			Variable:   &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 			Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, | ||||
| 		}, | ||||
|  | ||||
| @ -4257,7 +4257,7 @@ yydefault: | ||||
| 		yyDollar = yyS[yypt-4 : yypt+1] | ||||
| 		//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)) | ||||
| 			comments.AddComments(yyVAL.node, comments[yyDollar[1].node]) | ||||
| 		} | ||||
| @ -4274,7 +4274,7 @@ yydefault: | ||||
| 			} | ||||
| 			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)) | ||||
| 			comments.AddComments(yyVAL.node, comments[yyDollar[1].node]) | ||||
| 		} | ||||
|  | ||||
| @ -1864,7 +1864,7 @@ expr_without_variable: | ||||
|             } | ||||
|     |   variable '=' '&' variable | ||||
|             { | ||||
|                 $$ = assign.NewAssignRef($1, $4) | ||||
|                 $$ = assign.NewReference($1, $4) | ||||
|                 positions.AddPosition($$, positionBuilder.NewNodesPosition($1, $4)) | ||||
|                 comments.AddComments($$, comments[$1]) | ||||
|             } | ||||
| @ -1879,7 +1879,7 @@ expr_without_variable: | ||||
|                 } | ||||
|                 comments.AddComments(_new, comments[$1]) | ||||
| 
 | ||||
|                 $$ = assign.NewAssignRef($1, _new) | ||||
|                 $$ = assign.NewReference($1, _new) | ||||
|                 positions.AddPosition($$, positionBuilder.NewNodesPosition($1, _new)) | ||||
|                 comments.AddComments($$, comments[$1]) | ||||
|             } | ||||
|  | ||||
| @ -2849,13 +2849,13 @@ CAD; | ||||
| 				}, | ||||
| 			}, | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable:   &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.New{ | ||||
| 						Class: &name.Name{ | ||||
| @ -2867,7 +2867,7 @@ CAD; | ||||
| 				}, | ||||
| 			}, | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.New{ | ||||
| 						Class: &name.Name{ | ||||
|  | ||||
| @ -4223,7 +4223,7 @@ yydefault: | ||||
| 		yyDollar = yyS[yypt-4 : yypt+1] | ||||
| 		//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)) | ||||
| 			comments.AddComments(yyVAL.node, comments[yyDollar[1].node]) | ||||
| 		} | ||||
|  | ||||
| @ -1510,7 +1510,7 @@ expr_without_variable: | ||||
|         } | ||||
|     |   variable '=' '&' expr | ||||
|         { | ||||
|             $$ = assign.NewAssignRef($1, $4) | ||||
|             $$ = assign.NewReference($1, $4) | ||||
|             positions.AddPosition($$, positionBuilder.NewNodesPosition($1, $4)) | ||||
|             comments.AddComments($$, comments[$1]) | ||||
|         } | ||||
|  | ||||
| @ -2890,7 +2890,7 @@ CAD; | ||||
| 				}, | ||||
| 			}, | ||||
| 			&stmt.Expression{ | ||||
| 				Expr: &assign.AssignRef{ | ||||
| 				Expr: &assign.Reference{ | ||||
| 					Variable:   &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 					Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, | ||||
| 				}, | ||||
|  | ||||
| @ -106,8 +106,8 @@ func (p *Printer) printNode(n node.Node) { | ||||
| 
 | ||||
| 	case *assign.Assign: | ||||
| 		p.printAssign(n) | ||||
| 	case *assign.AssignRef: | ||||
| 		p.printAssignRef(n) | ||||
| 	case *assign.Reference: | ||||
| 		p.printReference(n) | ||||
| 	case *assign.BitwiseAnd: | ||||
| 		p.printAssignBitwiseAnd(n) | ||||
| 	case *assign.BitwiseOr: | ||||
| @ -544,8 +544,8 @@ func (p *Printer) printAssign(n node.Node) { | ||||
| 	p.Print(nn.Expression) | ||||
| } | ||||
| 
 | ||||
| func (p *Printer) printAssignRef(n node.Node) { | ||||
| 	nn := n.(*assign.AssignRef) | ||||
| func (p *Printer) printReference(n node.Node) { | ||||
| 	nn := n.(*assign.Reference) | ||||
| 	p.Print(nn.Variable) | ||||
| 	io.WriteString(p.w, " =& ") | ||||
| 	p.Print(nn.Expression) | ||||
|  | ||||
| @ -288,11 +288,11 @@ func TestPrintAssign(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestPrintAssignRef(t *testing.T) { | ||||
| func TestPrintReference(t *testing.T) { | ||||
| 	o := bytes.NewBufferString("") | ||||
| 
 | ||||
| 	p := printer.NewPrinter(o, "    ") | ||||
| 	p.Print(&assign.AssignRef{ | ||||
| 	p.Print(&assign.Reference{ | ||||
| 		Variable:   &expr.Variable{VarName: &node.Identifier{Value: "a"}}, | ||||
| 		Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, | ||||
| 	}) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user