refactoring: remove "StmtTraitMethodRef" node

This commit is contained in:
Vadym Slizov 2020-12-28 10:47:09 +02:00
parent c29e8ec0e0
commit c0465f9605
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
17 changed files with 456 additions and 555 deletions

View File

@ -24032,44 +24032,36 @@ func TestStmtTraitUse_Modifier(t *testing.T) {
StartPos: 30,
EndPos: 43,
},
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
Method: &ast.Identifier{
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
AsTkn: &token.Token{
ID: token.T_AS,
@ -24453,44 +24445,36 @@ func TestStmtTraitUse_AliasModifier(t *testing.T) {
StartPos: 30,
EndPos: 47,
},
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
Method: &ast.Identifier{
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
AsTkn: &token.Token{
ID: token.T_AS,
@ -24905,83 +24889,75 @@ func TestStmtTraitUse_Adaptions(t *testing.T) {
StartPos: 30,
EndPos: 58,
},
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 38,
EndPos: 33,
},
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
Parts: []ast.Vertex{
&ast.NameNamePart{
Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Bar"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Bar"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
Value: []byte("Bar"),
},
Value: []byte("Bar"),
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 35,
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 35,
},
Method: &ast.Identifier{
},
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
InsteadofTkn: &token.Token{
ID: token.T_INSTEADOF,
@ -25119,83 +25095,75 @@ func TestStmtTraitUse_Adaptions(t *testing.T) {
StartPos: 60,
EndPos: 75,
},
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 68,
EndPos: 63,
},
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
Parts: []ast.Vertex{
&ast.NameNamePart{
Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Baz"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Baz"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 59,
EndPos: 60,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 59,
EndPos: 60,
},
},
},
Value: []byte("Baz"),
},
Value: []byte("Baz"),
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 63,
EndPos: 65,
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 63,
EndPos: 65,
},
Method: &ast.Identifier{
},
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 65,
EndPos: 68,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 65,
EndPos: 68,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 65,
EndPos: 68,
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
AsTkn: &token.Token{
ID: token.T_AS,

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -2295,10 +2295,12 @@ trait_precedence:
{
$$ = &ast.StmtTraitUsePrecedence{
Position: yylex.(*Parser).builder.NewNodeNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
Ref: $1,
InsteadofTkn: $2,
Insteadof: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
InsteadofTkn: $2,
Insteadof: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
}
}
;
@ -2322,7 +2324,7 @@ trait_reference_list:
trait_method_reference:
T_STRING
{
$$ = &ast.StmtTraitMethodRef{
$$ = &ast.TraitMethodRef{
Position: yylex.(*Parser).builder.NewTokenPosition($1),
Method: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($1),
@ -2340,7 +2342,7 @@ trait_method_reference:
trait_method_reference_fully_qualified:
fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING
{
$$ = &ast.StmtTraitMethodRef{
$$ = &ast.TraitMethodRef{
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $3),
Trait: $1,
DoubleColonTkn: $2,
@ -2357,10 +2359,12 @@ trait_alias:
trait_method_reference T_AS trait_modifiers T_STRING
{
$$ = &ast.StmtTraitUseAlias{
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $4),
Ref: $1,
AsTkn: $2,
Modifier: $3,
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $4),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
AsTkn: $2,
Modifier: $3,
Alias: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($4),
IdentifierTkn: $4,
@ -2371,10 +2375,12 @@ trait_alias:
| trait_method_reference T_AS member_modifier
{
$$ = &ast.StmtTraitUseAlias{
Position: yylex.(*Parser).builder.NewNodesPosition($1, $3),
Ref: $1,
AsTkn: $2,
Modifier: $3,
Position: yylex.(*Parser).builder.NewNodesPosition($1, $3),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
AsTkn: $2,
Modifier: $3,
}
}
;

View File

@ -26000,44 +26000,36 @@ func TestStmtTraitUse_Modifier(t *testing.T) {
StartPos: 30,
EndPos: 43,
},
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
Method: &ast.Identifier{
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
AsTkn: &token.Token{
ID: token.T_AS,
@ -26421,44 +26413,36 @@ func TestStmtTraitUse_AliasModifier(t *testing.T) {
StartPos: 30,
EndPos: 47,
},
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
Method: &ast.Identifier{
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
AsTkn: &token.Token{
ID: token.T_AS,
@ -26873,83 +26857,75 @@ func TestStmtTraitUse_Adaptions(t *testing.T) {
StartPos: 30,
EndPos: 58,
},
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 38,
EndPos: 33,
},
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
Parts: []ast.Vertex{
&ast.NameNamePart{
Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Bar"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Bar"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
Value: []byte("Bar"),
},
Value: []byte("Bar"),
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 35,
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 35,
},
Method: &ast.Identifier{
},
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
InsteadofTkn: &token.Token{
ID: token.T_INSTEADOF,
@ -27087,83 +27063,75 @@ func TestStmtTraitUse_Adaptions(t *testing.T) {
StartPos: 60,
EndPos: 75,
},
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 68,
EndPos: 63,
},
Trait: &ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
Parts: []ast.Vertex{
&ast.NameNamePart{
Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Baz"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Baz"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 63,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 59,
EndPos: 60,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 59,
EndPos: 60,
},
},
},
Value: []byte("Baz"),
},
Value: []byte("Baz"),
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 63,
EndPos: 65,
},
},
DoubleColonTkn: &token.Token{
ID: token.T_PAAMAYIM_NEKUDOTAYIM,
Value: []byte("::"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 63,
EndPos: 65,
},
Method: &ast.Identifier{
},
Method: &ast.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 65,
EndPos: 68,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 65,
EndPos: 68,
},
IdentifierTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("one"),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 65,
EndPos: 68,
},
},
Value: []byte("one"),
},
Value: []byte("one"),
},
AsTkn: &token.Token{
ID: token.T_AS,

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -2132,11 +2132,13 @@ trait_precedence:
absolute_trait_method_reference T_INSTEADOF name_list
{
$$ = &ast.StmtTraitUsePrecedence{
Position: yylex.(*Parser).builder.NewNodeNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
Ref: $1,
InsteadofTkn: $2,
Insteadof: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
Position: yylex.(*Parser).builder.NewNodeNodeListPosition($1, $3.(*ast.ParserSeparatedList).Items),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
InsteadofTkn: $2,
Insteadof: $3.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
}
}
;
@ -2145,9 +2147,11 @@ trait_alias:
trait_method_reference T_AS T_STRING
{
$$ = &ast.StmtTraitUseAlias{
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $3),
Ref: $1,
AsTkn: $2,
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $3),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
AsTkn: $2,
Alias: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($3),
IdentifierTkn: $3,
@ -2158,9 +2162,11 @@ trait_alias:
| trait_method_reference T_AS reserved_non_modifiers
{
$$ = &ast.StmtTraitUseAlias{
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $3),
Ref: $1,
AsTkn: $2,
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $3),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
AsTkn: $2,
Alias: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($3),
IdentifierTkn: $3,
@ -2171,10 +2177,12 @@ trait_alias:
| trait_method_reference T_AS member_modifier identifier
{
$$ = &ast.StmtTraitUseAlias{
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $4),
Ref: $1,
AsTkn: $2,
Modifier: $3,
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $4),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
AsTkn: $2,
Modifier: $3,
Alias: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($4),
IdentifierTkn: $4,
@ -2185,10 +2193,12 @@ trait_alias:
| trait_method_reference T_AS member_modifier
{
$$ = &ast.StmtTraitUseAlias{
Position: yylex.(*Parser).builder.NewNodesPosition($1, $3),
Ref: $1,
AsTkn: $2,
Modifier: $3,
Position: yylex.(*Parser).builder.NewNodesPosition($1, $3),
Trait: $1.(*ast.TraitMethodRef).Trait,
DoubleColonTkn: $1.(*ast.TraitMethodRef).DoubleColonTkn,
Method: $1.(*ast.TraitMethodRef).Method,
AsTkn: $2,
Modifier: $3,
}
}
;
@ -2196,7 +2206,7 @@ trait_alias:
trait_method_reference:
identifier
{
$$ = &ast.StmtTraitMethodRef{
$$ = &ast.TraitMethodRef{
Position: yylex.(*Parser).builder.NewTokenPosition($1),
Method: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($1),
@ -2214,7 +2224,7 @@ trait_method_reference:
absolute_trait_method_reference:
name T_PAAMAYIM_NEKUDOTAYIM identifier
{
$$ = &ast.StmtTraitMethodRef{
$$ = &ast.TraitMethodRef{
Position: yylex.(*Parser).builder.NewNodeTokenPosition($1, $3),
Trait: $1,
DoubleColonTkn: $2,

View File

@ -64,7 +64,6 @@ type NodeVisitor interface {
StmtSwitch(n *StmtSwitch)
StmtThrow(n *StmtThrow)
StmtTrait(n *StmtTrait)
StmtTraitMethodRef(n *StmtTraitMethodRef)
StmtTraitUse(n *StmtTraitUse)
StmtTraitUseAlias(n *StmtTraitUseAlias)
StmtTraitUsePrecedence(n *StmtTraitUsePrecedence)

View File

@ -937,22 +937,6 @@ func (n *StmtTrait) GetPosition() *position.Position {
return n.Position
}
// StmtTraitMethodRef node
type StmtTraitMethodRef struct {
Position *position.Position
Trait Vertex
DoubleColonTkn *token.Token
Method Vertex
}
func (n *StmtTraitMethodRef) Accept(v NodeVisitor) {
v.StmtTraitMethodRef(n)
}
func (n *StmtTraitMethodRef) GetPosition() *position.Position {
return n.Position
}
// StmtTraitUse node
type StmtTraitUse struct {
Position *position.Position
@ -975,12 +959,14 @@ func (n *StmtTraitUse) GetPosition() *position.Position {
// StmtTraitUseAlias node
type StmtTraitUseAlias struct {
Position *position.Position
Ref Vertex
AsTkn *token.Token
Modifier Vertex
Alias Vertex
SemiColonTkn *token.Token
Position *position.Position
Trait Vertex
DoubleColonTkn *token.Token
Method Vertex
AsTkn *token.Token
Modifier Vertex
Alias Vertex
SemiColonTkn *token.Token
}
func (n *StmtTraitUseAlias) Accept(v NodeVisitor) {
@ -993,12 +979,14 @@ func (n *StmtTraitUseAlias) GetPosition() *position.Position {
// StmtTraitUsePrecedence node
type StmtTraitUsePrecedence struct {
Position *position.Position
Ref Vertex
InsteadofTkn *token.Token
Insteadof []Vertex
SeparatorTkns []*token.Token
SemiColonTkn *token.Token
Position *position.Position
Trait Vertex
DoubleColonTkn *token.Token
Method Vertex
InsteadofTkn *token.Token
Insteadof []Vertex
SeparatorTkns []*token.Token
SemiColonTkn *token.Token
}
func (n *StmtTraitUsePrecedence) Accept(v NodeVisitor) {
@ -2734,3 +2722,19 @@ func (n *ReturnType) Accept(v NodeVisitor) {
func (n *ReturnType) GetPosition() *position.Position {
return n.Position
}
// TraitMethodRef node
type TraitMethodRef struct {
Position *position.Position
Trait Vertex
DoubleColonTkn *token.Token
Method Vertex
}
func (n *TraitMethodRef) Accept(v NodeVisitor) {
// do nothing
}
func (n *TraitMethodRef) GetPosition() *position.Position {
return n.Position
}

View File

@ -776,23 +776,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
}
t.visitor.Leave("Stmts", false)
}
case *ast.StmtTraitMethodRef:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Trait != nil {
t.visitor.Enter("Trait", true)
t.Traverse(nn.Trait)
t.visitor.Leave("Trait", true)
}
if nn.Method != nil {
t.visitor.Enter("Method", true)
t.Traverse(nn.Method)
t.visitor.Leave("Method", true)
}
case *ast.StmtTraitUse:
if nn == nil {
return
@ -821,10 +804,15 @@ func (t *DFS) Traverse(n ast.Vertex) {
if !t.visitor.EnterNode(nn) {
return
}
if nn.Ref != nil {
t.visitor.Enter("Ref", true)
t.Traverse(nn.Ref)
t.visitor.Leave("Ref", true)
if nn.Trait != nil {
t.visitor.Enter("Trait", true)
t.Traverse(nn.Trait)
t.visitor.Leave("Trait", true)
}
if nn.Method != nil {
t.visitor.Enter("Method", true)
t.Traverse(nn.Method)
t.visitor.Leave("Method", true)
}
if nn.Modifier != nil {
t.visitor.Enter("Modifier", true)
@ -843,10 +831,15 @@ func (t *DFS) Traverse(n ast.Vertex) {
if !t.visitor.EnterNode(nn) {
return
}
if nn.Ref != nil {
t.visitor.Enter("Ref", true)
t.Traverse(nn.Ref)
t.visitor.Leave("Ref", true)
if nn.Trait != nil {
t.visitor.Enter("Trait", true)
t.Traverse(nn.Trait)
t.visitor.Leave("Trait", true)
}
if nn.Method != nil {
t.visitor.Enter("Method", true)
t.Traverse(nn.Method)
t.visitor.Leave("Method", true)
}
if nn.Insteadof != nil {
t.visitor.Enter("Insteadof", false)

View File

@ -824,19 +824,6 @@ func (v *Dumper) StmtTrait(n *ast.StmtTrait) {
v.print(v.indent, "},\n")
}
func (v *Dumper) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
v.print(0, "&ast.StmtTraitMethodRef{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpVertex("Trait", n.Trait)
v.dumpToken("DoubleColonTkn", n.DoubleColonTkn)
v.dumpVertex("Method", n.Method)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) StmtTraitUse(n *ast.StmtTraitUse) {
v.print(0, "&ast.StmtTraitUse{\n")
v.indent++
@ -859,7 +846,9 @@ func (v *Dumper) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertex("Ref", n.Ref)
v.dumpVertex("Trait", n.Trait)
v.dumpToken("DoubleColonTkn", n.DoubleColonTkn)
v.dumpVertex("Method", n.Method)
v.dumpToken("AsTkn", n.AsTkn)
v.dumpVertex("Modifier", n.Modifier)
v.dumpVertex("Alias", n.Alias)
@ -874,7 +863,9 @@ func (v *Dumper) StmtTraitUsePrecedence(n *ast.StmtTraitUsePrecedence) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertex("Ref", n.Ref)
v.dumpVertex("Trait", n.Trait)
v.dumpToken("DoubleColonTkn", n.DoubleColonTkn)
v.dumpVertex("Method", n.Method)
v.dumpToken("InsteadofTkn", n.InsteadofTkn)
v.dumpVertexList("Insteadof", n.Insteadof)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)

View File

@ -858,15 +858,6 @@ func (f *formatter) StmtTrait(n *ast.StmtTrait) {
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
}
func (f *formatter) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
if n.Trait != nil {
n.Trait.Accept(f)
n.DoubleColonTkn = f.newToken(token.T_PAAMAYIM_NEKUDOTAYIM, []byte("::"))
}
n.Method.Accept(f)
}
func (f *formatter) StmtTraitUse(n *ast.StmtTraitUse) {
n.UseTkn = f.newToken(token.T_USE, []byte("use"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@ -897,7 +888,12 @@ func (f *formatter) StmtTraitUse(n *ast.StmtTraitUse) {
}
func (f *formatter) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
n.Ref.Accept(f)
if n.Trait != nil {
n.Trait.Accept(f)
n.DoubleColonTkn = f.newToken(token.T_PAAMAYIM_NEKUDOTAYIM, []byte("::"))
}
n.Method.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
n.AsTkn = f.newToken(token.T_AS, []byte("as"))
@ -915,7 +911,12 @@ func (f *formatter) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
}
func (f *formatter) StmtTraitUsePrecedence(n *ast.StmtTraitUsePrecedence) {
n.Ref.Accept(f)
if n.Trait != nil {
n.Trait.Accept(f)
n.DoubleColonTkn = f.newToken(token.T_PAAMAYIM_NEKUDOTAYIM, []byte("::"))
}
n.Method.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
n.InsteadofTkn = f.newToken(token.T_INSTEADOF, []byte("insteadof"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))

View File

@ -2360,59 +2360,6 @@ func TestFormatter_StmtTrait(t *testing.T) {
}
}
func TestFormatter_StmtTraitMethodRef(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Value: []byte("foo"),
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `foo`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtTraitMethodRef_Trait(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitMethodRef{
Trait: &ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("foo"),
},
},
},
Method: &ast.Identifier{
Value: []byte("bar"),
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `foo::bar`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtTraitUse(t *testing.T) {
o := bytes.NewBufferString("")
@ -2471,10 +2418,8 @@ func TestFormatter_StmtTraitUse_Adaptations(t *testing.T) {
},
Adaptations: []ast.Vertex{
&ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Value: []byte("foo"),
},
Method: &ast.Identifier{
Value: []byte("foo"),
},
Alias: &ast.Identifier{
Value: []byte("baz"),
@ -2503,10 +2448,8 @@ func TestFormatter_StmtTraitUseAlias(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Value: []byte("foo"),
},
Method: &ast.Identifier{
Value: []byte("foo"),
},
Modifier: &ast.Identifier{
Value: []byte("public"),
@ -2530,14 +2473,48 @@ func TestFormatter_StmtTraitUseAlias(t *testing.T) {
}
}
func TestFormatter_StmtTraitUseAlias_Trait(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitUseAlias{
Trait: &ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("foo"),
},
},
},
Method: &ast.Identifier{
Value: []byte("bar"),
},
Modifier: &ast.Identifier{
Value: []byte("public"),
},
Alias: &ast.Identifier{
Value: []byte("baz"),
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `foo::bar as public baz;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtTraitUseAlias_Alias(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Value: []byte("foo"),
},
Method: &ast.Identifier{
Value: []byte("foo"),
},
Alias: &ast.Identifier{
Value: []byte("bar"),
@ -2562,10 +2539,8 @@ func TestFormatter_StmtTraitUseAlias_Modifier(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Value: []byte("foo"),
},
Method: &ast.Identifier{
Value: []byte("foo"),
},
Modifier: &ast.Identifier{
Value: []byte("public"),
@ -2590,10 +2565,8 @@ func TestFormatter_StmtTraitUsePrecedence(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitUsePrecedence{
Ref: &ast.StmtTraitMethodRef{
Method: &ast.Identifier{
Value: []byte("foo"),
},
Method: &ast.Identifier{
Value: []byte("foo"),
},
Insteadof: []ast.Vertex{
&ast.NameName{
@ -2627,6 +2600,45 @@ func TestFormatter_StmtTraitUsePrecedence(t *testing.T) {
}
}
func TestFormatter_StmtTraitUsePrecedence_Trait(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTraitUsePrecedence{
Trait: &ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("foo"),
},
},
},
Method: &ast.Identifier{
Value: []byte("bar"),
},
Insteadof: []ast.Vertex{
&ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("baz"),
},
},
},
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `foo::bar insteadof baz;`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtTry(t *testing.T) {
o := bytes.NewBufferString("")

View File

@ -187,7 +187,7 @@ func (nsr *NamespaceResolver) StmtTraitUse(n *ast.StmtTraitUse) {
for _, a := range n.Adaptations {
switch aa := a.(type) {
case *ast.StmtTraitUsePrecedence:
refTrait := aa.Ref.(*ast.StmtTraitMethodRef).Trait
refTrait := aa.Trait
if refTrait != nil {
nsr.ResolveName(refTrait, "")
}
@ -196,7 +196,7 @@ func (nsr *NamespaceResolver) StmtTraitUse(n *ast.StmtTraitUse) {
}
case *ast.StmtTraitUseAlias:
refTrait := aa.Ref.(*ast.StmtTraitMethodRef).Trait
refTrait := aa.Trait
if refTrait != nil {
nsr.ResolveName(refTrait, "")
}

View File

@ -356,18 +356,14 @@ func TestResolveTraitUse(t *testing.T) {
},
Adaptations: []ast.Vertex{
&ast.StmtTraitUsePrecedence{
Ref: &ast.StmtTraitMethodRef{
Trait: fullyQualifiedNameB,
Method: &ast.Identifier{Value: []byte("foo")},
},
Trait: fullyQualifiedNameB,
Method: &ast.Identifier{Value: []byte("foo")},
Insteadof: []ast.Vertex{fullyQualifiedNameBC},
},
&ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Trait: relativeNameBC,
Method: &ast.Identifier{Value: []byte("foo")},
},
Alias: &ast.Identifier{Value: []byte("bar")},
Trait: relativeNameBC,
Method: &ast.Identifier{Value: []byte("foo")},
Alias: &ast.Identifier{Value: []byte("bar")},
},
},
},

View File

@ -194,10 +194,6 @@ func (v *Null) StmtTrait(_ *ast.StmtTrait) {
// do nothing
}
func (v *Null) StmtTraitMethodRef(_ *ast.StmtTraitMethodRef) {
// do nothing
}
func (v *Null) StmtTraitUse(_ *ast.StmtTraitUse) {
// do nothing
}

View File

@ -518,12 +518,6 @@ func (p *printer) StmtTrait(n *ast.StmtTrait) {
p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
}
func (p *printer) StmtTraitMethodRef(n *ast.StmtTraitMethodRef) {
p.printNode(n.Trait)
p.printToken(n.DoubleColonTkn, p.ifNode(n.Trait, []byte("::")))
p.printNode(n.Method)
}
func (p *printer) StmtTraitUse(n *ast.StmtTraitUse) {
p.printToken(n.UseTkn, []byte("use"))
p.printSeparatedList(n.Traits, n.SeparatorTkns, []byte(","))
@ -534,7 +528,9 @@ func (p *printer) StmtTraitUse(n *ast.StmtTraitUse) {
}
func (p *printer) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
p.printNode(n.Ref)
p.printNode(n.Trait)
p.printToken(n.DoubleColonTkn, p.ifNode(n.Trait, []byte("::")))
p.printNode(n.Method)
p.printToken(n.AsTkn, []byte("as"))
p.printNode(n.Modifier)
p.printNode(n.Alias)
@ -542,7 +538,9 @@ func (p *printer) StmtTraitUseAlias(n *ast.StmtTraitUseAlias) {
}
func (p *printer) StmtTraitUsePrecedence(n *ast.StmtTraitUsePrecedence) {
p.printNode(n.Ref)
p.printNode(n.Trait)
p.printToken(n.DoubleColonTkn, p.ifNode(n.Trait, []byte("::")))
p.printNode(n.Method)
p.printToken(n.InsteadofTkn, []byte("insteadof"))
p.printSeparatedList(n.Insteadof, n.SeparatorTkns, []byte(","))
p.printToken(n.SemiColonTkn, []byte(";"))

View File

@ -4452,50 +4452,13 @@ func TestPrinterPrintStmtThrow(t *testing.T) {
}
}
func TestPrinterPrintStmtTraitMethodRef(t *testing.T) {
o := bytes.NewBufferString("")
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.StmtTraitMethodRef{
Method: &ast.Identifier{Value: []byte("a")},
}
n.Accept(p)
expected := `a`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintStmtTraitMethodRefFull(t *testing.T) {
o := bytes.NewBufferString("")
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.StmtTraitMethodRef{
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
}
n.Accept(p)
expected := `Foo::a`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestPrinterPrintStmtTraitUseAlias(t *testing.T) {
o := bytes.NewBufferString("")
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
},
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
Modifier: &ast.Identifier{Value: []byte("public")},
Alias: &ast.Identifier{Value: []byte("b")},
}
@ -4514,10 +4477,8 @@ func TestPrinterPrintStmtTraitUsePrecedence(t *testing.T) {
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.StmtTraitUsePrecedence{
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
},
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
Insteadof: []ast.Vertex{
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
@ -4564,11 +4525,9 @@ func TestPrinterPrintStmtTraitAdaptations(t *testing.T) {
},
Adaptations: []ast.Vertex{
&ast.StmtTraitUseAlias{
Ref: &ast.StmtTraitMethodRef{
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
},
Alias: &ast.Identifier{Value: []byte("b")},
Trait: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Method: &ast.Identifier{Value: []byte("a")},
Alias: &ast.Identifier{Value: []byte("b")},
},
},
}