refactoring: update ast structure of "Class", "Interface" and "Trait" nodes

This commit is contained in:
Vadym Slizov 2020-12-28 10:10:15 +02:00
parent 2990f0cc2d
commit c29e8ec0e0
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
17 changed files with 903 additions and 1307 deletions

View File

@ -9945,74 +9945,66 @@ func TestStmtClass_ClassExtends(t *testing.T) {
}, },
Value: []byte("foo"), Value: []byte("foo"),
}, },
Extends: &ast.StmtClassExtends{ ExtendsTkn: &token.Token{
ID: token.T_EXTENDS,
Value: []byte("extends"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 19, StartPos: 19,
EndPos: 30, EndPos: 26,
}, },
ExtendTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_EXTENDS, {
Value: []byte("extends"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 19, EndLine: 1,
EndPos: 26, StartPos: 18,
}, EndPos: 19,
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 19,
},
}, },
}, },
}, },
ClassName: &ast.NameName{ },
Position: &position.Position{ Extends: &ast.NameName{
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 27, EndLine: 1,
EndPos: 30, StartPos: 27,
}, EndPos: 30,
Parts: []ast.Vertex{ },
&ast.NameNamePart{ Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 30,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("bar"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 27, StartPos: 27,
EndPos: 30, EndPos: 30,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("bar"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 27, EndLine: 1,
EndPos: 30, StartPos: 26,
}, EndPos: 27,
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 27,
},
}, },
}, },
}, },
Value: []byte("bar"),
}, },
Value: []byte("bar"),
}, },
}, },
}, },
@ -10187,75 +10179,67 @@ func TestStmtClass_ClassImplement(t *testing.T) {
}, },
Value: []byte("foo"), Value: []byte("foo"),
}, },
Implements: &ast.StmtClassImplements{ ImplementsTkn: &token.Token{
ID: token.T_IMPLEMENTS,
Value: []byte("implements"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 19, StartPos: 19,
EndPos: 33, EndPos: 29,
}, },
ImplementsTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_IMPLEMENTS, {
Value: []byte("implements"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 29,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 19,
},
},
},
},
InterfaceNames: []ast.Vertex{
&ast.NameName{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 30, StartPos: 18,
EndPos: 33, EndPos: 19,
}, },
Parts: []ast.Vertex{ },
&ast.NameNamePart{ },
},
Implements: []ast.Vertex{
&ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
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{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 30, StartPos: 30,
EndPos: 33, EndPos: 33,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("bar"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 30, EndLine: 1,
EndPos: 33, 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"),
}, },
}, },
}, },
@ -10431,129 +10415,121 @@ func TestStmtClass_ClassImplements(t *testing.T) {
}, },
Value: []byte("foo"), Value: []byte("foo"),
}, },
Implements: &ast.StmtClassImplements{ ImplementsTkn: &token.Token{
ID: token.T_IMPLEMENTS,
Value: []byte("implements"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 19, StartPos: 19,
EndPos: 38, EndPos: 29,
}, },
ImplementsTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_IMPLEMENTS, {
Value: []byte("implements"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 29,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 19,
},
},
},
},
InterfaceNames: []ast.Vertex{
&ast.NameName{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 30, StartPos: 18,
EndPos: 33, EndPos: 19,
}, },
Parts: []ast.Vertex{ },
&ast.NameNamePart{ },
},
Implements: []ast.Vertex{
&ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 33,
},
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{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 30, StartPos: 30,
EndPos: 33, EndPos: 33,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("bar"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 30, EndLine: 1,
EndPos: 33, 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"),
}, },
}, },
&ast.NameName{ },
Position: &position.Position{ &ast.NameName{
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 35, EndLine: 1,
EndPos: 38, StartPos: 35,
}, EndPos: 38,
Parts: []ast.Vertex{ },
&ast.NameNamePart{ Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 38,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("baz"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 35, StartPos: 35,
EndPos: 38, EndPos: 38,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("baz"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 35, EndLine: 1,
EndPos: 38, StartPos: 34,
}, EndPos: 35,
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
EndPos: 35,
},
}, },
}, },
}, },
Value: []byte("baz"),
}, },
Value: []byte("baz"),
}, },
}, },
}, },
SeparatorTkns: []*token.Token{ },
{ ImplementsSeparatorTkns: []*token.Token{
ID: token.ID(44), {
Value: []byte(","), ID: token.ID(44),
Position: &position.Position{ Value: []byte(","),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 33, EndLine: 1,
EndPos: 34, StartPos: 33,
}, EndPos: 34,
}, },
}, },
}, },
@ -19076,75 +19052,67 @@ func TestStmtInterface_Extend(t *testing.T) {
}, },
Value: []byte("Foo"), Value: []byte("Foo"),
}, },
Extends: &ast.StmtInterfaceExtends{ ExtendsTkn: &token.Token{
ID: token.T_EXTENDS,
Value: []byte("extends"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 17, StartPos: 17,
EndPos: 28, EndPos: 24,
}, },
ExtendsTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_EXTENDS, {
Value: []byte("extends"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1,
EndLine: 1,
StartPos: 17,
EndPos: 24,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 17,
},
},
},
},
InterfaceNames: []ast.Vertex{
&ast.NameName{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 25, StartPos: 16,
EndPos: 28, EndPos: 17,
}, },
Parts: []ast.Vertex{ },
&ast.NameNamePart{ },
},
Extends: []ast.Vertex{
&ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 28,
},
Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 28,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Bar"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 25, StartPos: 25,
EndPos: 28, EndPos: 28,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("Bar"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 25, EndLine: 1,
EndPos: 28, StartPos: 24,
}, EndPos: 25,
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 25,
},
}, },
}, },
}, },
Value: []byte("Bar"),
}, },
Value: []byte("Bar"),
}, },
}, },
}, },
@ -19275,129 +19243,121 @@ func TestStmtInterface_Extends(t *testing.T) {
}, },
Value: []byte("Foo"), Value: []byte("Foo"),
}, },
Extends: &ast.StmtInterfaceExtends{ ExtendsTkn: &token.Token{
ID: token.T_EXTENDS,
Value: []byte("extends"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 17, StartPos: 17,
EndPos: 33, EndPos: 24,
}, },
ExtendsTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_EXTENDS, {
Value: []byte("extends"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1,
EndLine: 1,
StartPos: 17,
EndPos: 24,
},
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 17,
},
},
},
},
InterfaceNames: []ast.Vertex{
&ast.NameName{
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 25, StartPos: 16,
EndPos: 28, EndPos: 17,
}, },
Parts: []ast.Vertex{ },
&ast.NameNamePart{ },
},
Extends: []ast.Vertex{
&ast.NameName{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 28,
},
Parts: []ast.Vertex{
&ast.NameNamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 28,
},
StringTkn: &token.Token{
ID: token.T_STRING,
Value: []byte("Bar"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 25, StartPos: 25,
EndPos: 28, EndPos: 28,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("Bar"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 25, EndLine: 1,
EndPos: 28, StartPos: 24,
}, EndPos: 25,
FreeFloating: []*token.Token{
{
ID: token.T_WHITESPACE,
Value: []byte(" "),
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 25,
},
}, },
}, },
}, },
Value: []byte("Bar"),
}, },
Value: []byte("Bar"),
}, },
}, },
&ast.NameName{ },
Position: &position.Position{ &ast.NameName{
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 30, EndLine: 1,
EndPos: 33, 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("Baz"),
Position: &position.Position{ Position: &position.Position{
StartLine: 1, StartLine: 1,
EndLine: 1, EndLine: 1,
StartPos: 30, StartPos: 30,
EndPos: 33, EndPos: 33,
}, },
StringTkn: &token.Token{ FreeFloating: []*token.Token{
ID: token.T_STRING, {
Value: []byte("Baz"), ID: token.T_WHITESPACE,
Position: &position.Position{ Value: []byte(" "),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 30, EndLine: 1,
EndPos: 33, 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("Baz"),
}, },
Value: []byte("Baz"),
}, },
}, },
}, },
SeparatorTkns: []*token.Token{ },
{ ExtendsSeparatorTkns: []*token.Token{
ID: token.ID(44), {
Value: []byte(","), ID: token.ID(44),
Position: &position.Position{ Value: []byte(","),
StartLine: 1, Position: &position.Position{
EndLine: 1, StartLine: 1,
StartPos: 28, EndLine: 1,
EndPos: 29, StartPos: 28,
}, EndPos: 29,
}, },
}, },
}, },

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -1280,36 +1280,55 @@ unticked_class_declaration_statement:
{ {
switch n := $1.(type) { switch n := $1.(type) {
case *ast.StmtClass : case *ast.StmtClass :
n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7) className := &ast.Identifier{
n.ClassName = &ast.Identifier{ Position: yylex.(*Parser).builder.NewTokenPosition($2),
Position: yylex.(*Parser).builder.NewTokenPosition($2),
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
} }
n.Extends = $3
n.Implements = $4 n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7)
n.OpenCurlyBracketTkn = $5 n.ClassName = className
n.Stmts = $6 n.OpenCurlyBracketTkn = $5
n.Stmts = $6
n.CloseCurlyBracketTkn = $7 n.CloseCurlyBracketTkn = $7
if $3 != nil {
n.ExtendsTkn = $3.(*ast.StmtClass).ExtendsTkn
n.Extends = $3.(*ast.StmtClass).Extends
}
if $4 != nil {
n.ImplementsTkn = $4.(*ast.StmtClass).ImplementsTkn
n.Implements = $4.(*ast.StmtClass).Implements
n.ImplementsSeparatorTkns = $4.(*ast.StmtClass).ImplementsSeparatorTkns
}
case *ast.StmtTrait : case *ast.StmtTrait :
n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7) traitName := &ast.Identifier{
n.TraitName = &ast.Identifier{ Position: yylex.(*Parser).builder.NewTokenPosition($2),
Position: yylex.(*Parser).builder.NewTokenPosition($2),
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
} }
n.Extends = $3
n.Implements = $4 n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7)
n.OpenCurlyBracketTkn = $5 n.TraitName = traitName
n.Stmts = $6 n.OpenCurlyBracketTkn = $5
n.Stmts = $6
n.CloseCurlyBracketTkn = $7 n.CloseCurlyBracketTkn = $7
if $3 != nil {
yylex.(*Parser).errHandlerFunc(errors.NewError("A trait cannot extend a class. Traits can only be composed from other traits with the 'use' keyword", $3.(*ast.StmtClass).Position))
}
if $4 != nil {
yylex.(*Parser).errHandlerFunc(errors.NewError("A trait cannot implement an interface", $4.(*ast.StmtClass).Position))
}
} }
$$ = $1 $$ = $1
} }
| interface_entry T_STRING interface_extends_list '{' class_statement_list '}' | interface_entry T_STRING interface_extends_list '{' class_statement_list '}'
{ {
$$ = &ast.StmtInterface{ iface := &ast.StmtInterface{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $6), Position: yylex.(*Parser).builder.NewTokensPosition($1, $6),
InterfaceTkn: $1, InterfaceTkn: $1,
InterfaceName: &ast.Identifier{ InterfaceName: &ast.Identifier{
@ -1317,11 +1336,18 @@ unticked_class_declaration_statement:
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
}, },
Extends: $3,
OpenCurlyBracketTkn: $4, OpenCurlyBracketTkn: $4,
Stmts: $5, Stmts: $5,
CloseCurlyBracketTkn: $6, CloseCurlyBracketTkn: $6,
} }
if $3 != nil {
iface.ExtendsTkn = $3.(*ast.StmtInterface).ExtendsTkn
iface.Extends = $3.(*ast.StmtInterface).Extends
iface.ExtendsSeparatorTkns = $3.(*ast.StmtInterface).ExtendsSeparatorTkns
}
$$ = iface
} }
; ;
@ -1378,10 +1404,10 @@ extends_from:
} }
| T_EXTENDS fully_qualified_class_name | T_EXTENDS fully_qualified_class_name
{ {
$$ = &ast.StmtClassExtends{ $$ = &ast.StmtClass{
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2), Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
ExtendTkn: $1, ExtendsTkn: $1,
ClassName: $2, Extends: $2,
} }
} }
; ;
@ -1400,11 +1426,11 @@ interface_extends_list:
} }
| T_EXTENDS interface_list | T_EXTENDS interface_list
{ {
$$ = &ast.StmtInterfaceExtends{ $$ = &ast.StmtInterface{
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
ExtendsTkn: $1, ExtendsTkn: $1,
InterfaceNames: $2.(*ast.ParserSeparatedList).Items, Extends: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, ExtendsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}; };
} }
; ;
@ -1416,11 +1442,11 @@ implements_list:
} }
| T_IMPLEMENTS interface_list | T_IMPLEMENTS interface_list
{ {
$$ = &ast.StmtClassImplements{ $$ = &ast.StmtClass{
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
ImplementsTkn: $1, ImplementsTkn: $1,
InterfaceNames: $2.(*ast.ParserSeparatedList).Items, Implements: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, ImplementsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}; };
} }
; ;

File diff suppressed because it is too large Load Diff

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -1203,7 +1203,7 @@ is_variadic:
class_declaration_statement: class_declaration_statement:
class_modifiers T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}' class_modifiers T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ {
$$ = &ast.StmtClass{ class := &ast.StmtClass{
Position: yylex.(*Parser).builder.NewOptionalListTokensPosition($1, $2, $9), Position: yylex.(*Parser).builder.NewOptionalListTokensPosition($1, $2, $9),
Modifiers: $1, Modifiers: $1,
ClassTkn: $2, ClassTkn: $2,
@ -1212,16 +1212,27 @@ class_declaration_statement:
IdentifierTkn: $3, IdentifierTkn: $3,
Value: $3.Value, Value: $3.Value,
}, },
Extends: $4,
Implements: $5,
OpenCurlyBracketTkn: $7, OpenCurlyBracketTkn: $7,
Stmts: $8, Stmts: $8,
CloseCurlyBracketTkn: $9, CloseCurlyBracketTkn: $9,
} }
if $4 != nil {
class.ExtendsTkn = $4.(*ast.StmtClass).ExtendsTkn
class.Extends = $4.(*ast.StmtClass).Extends
}
if $5 != nil {
class.ImplementsTkn = $5.(*ast.StmtClass).ImplementsTkn
class.Implements = $5.(*ast.StmtClass).Implements
class.ImplementsSeparatorTkns = $5.(*ast.StmtClass).ImplementsSeparatorTkns
}
$$ = class
} }
| T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}' | T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ {
$$ = &ast.StmtClass{ class := &ast.StmtClass{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $8), Position: yylex.(*Parser).builder.NewTokensPosition($1, $8),
ClassTkn: $1, ClassTkn: $1,
ClassName: &ast.Identifier{ ClassName: &ast.Identifier{
@ -1229,12 +1240,23 @@ class_declaration_statement:
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
}, },
Extends: $3,
Implements: $4,
OpenCurlyBracketTkn: $6, OpenCurlyBracketTkn: $6,
Stmts: $7, Stmts: $7,
CloseCurlyBracketTkn: $8, CloseCurlyBracketTkn: $8,
} }
if $3 != nil {
class.ExtendsTkn = $3.(*ast.StmtClass).ExtendsTkn
class.Extends = $3.(*ast.StmtClass).Extends
}
if $4 != nil {
class.ImplementsTkn = $4.(*ast.StmtClass).ImplementsTkn
class.Implements = $4.(*ast.StmtClass).Implements
class.ImplementsSeparatorTkns = $4.(*ast.StmtClass).ImplementsSeparatorTkns
}
$$ = class
} }
; ;
@ -1289,7 +1311,7 @@ trait_declaration_statement:
interface_declaration_statement: interface_declaration_statement:
T_INTERFACE T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}' T_INTERFACE T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
{ {
$$ = &ast.StmtInterface{ iface := &ast.StmtInterface{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $7), Position: yylex.(*Parser).builder.NewTokensPosition($1, $7),
InterfaceTkn: $1, InterfaceTkn: $1,
InterfaceName: &ast.Identifier{ InterfaceName: &ast.Identifier{
@ -1297,11 +1319,18 @@ interface_declaration_statement:
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
}, },
Extends: $3,
OpenCurlyBracketTkn: $5, OpenCurlyBracketTkn: $5,
Stmts: $6, Stmts: $6,
CloseCurlyBracketTkn: $7, CloseCurlyBracketTkn: $7,
} }
if $3 != nil {
iface.ExtendsTkn = $3.(*ast.StmtInterface).ExtendsTkn
iface.Extends = $3.(*ast.StmtInterface).Extends
iface.ExtendsSeparatorTkns = $3.(*ast.StmtInterface).ExtendsSeparatorTkns
}
$$ = iface
} }
; ;
@ -1312,10 +1341,10 @@ extends_from:
} }
| T_EXTENDS name | T_EXTENDS name
{ {
$$ = &ast.StmtClassExtends{ $$ = &ast.StmtClass{
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2), Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
ExtendTkn: $1, ExtendsTkn: $1,
ClassName: $2, Extends: $2,
} }
} }
; ;
@ -1327,11 +1356,11 @@ interface_extends_list:
} }
| T_EXTENDS name_list | T_EXTENDS name_list
{ {
$$ = &ast.StmtInterfaceExtends{ $$ = &ast.StmtInterface{
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
ExtendsTkn: $1, ExtendsTkn: $1,
InterfaceNames: $2.(*ast.ParserSeparatedList).Items, Extends: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, ExtendsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}; };
} }
; ;
@ -1343,11 +1372,11 @@ implements_list:
} }
| T_IMPLEMENTS name_list | T_IMPLEMENTS name_list
{ {
$$ = &ast.StmtClassImplements{ $$ = &ast.StmtClass{
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items), Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
ImplementsTkn: $1, ImplementsTkn: $1,
InterfaceNames: $2.(*ast.ParserSeparatedList).Items, Implements: $2.(*ast.ParserSeparatedList).Items,
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns, ImplementsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
}; };
} }
; ;
@ -2458,19 +2487,30 @@ non_empty_for_exprs:
anonymous_class: anonymous_class:
T_CLASS ctor_arguments extends_from implements_list backup_doc_comment '{' class_statement_list '}' T_CLASS ctor_arguments extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ {
$$ = &ast.StmtClass{ class := &ast.StmtClass{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $8), Position: yylex.(*Parser).builder.NewTokensPosition($1, $8),
ClassTkn: $1, ClassTkn: $1,
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn, CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
Extends: $3,
Implements: $4,
OpenCurlyBracketTkn: $6, OpenCurlyBracketTkn: $6,
Stmts: $7, Stmts: $7,
CloseCurlyBracketTkn: $8, CloseCurlyBracketTkn: $8,
} }
if $3 != nil {
class.ExtendsTkn = $3.(*ast.StmtClass).ExtendsTkn
class.Extends = $3.(*ast.StmtClass).Extends
}
if $4 != nil {
class.ImplementsTkn = $4.(*ast.StmtClass).ImplementsTkn
class.Implements = $4.(*ast.StmtClass).Implements
class.ImplementsSeparatorTkns = $4.(*ast.StmtClass).ImplementsSeparatorTkns
}
$$ = class
} }
; ;

View File

@ -31,8 +31,6 @@ type NodeVisitor interface {
StmtCatch(n *StmtCatch) StmtCatch(n *StmtCatch)
StmtClass(n *StmtClass) StmtClass(n *StmtClass)
StmtClassConstList(n *StmtClassConstList) StmtClassConstList(n *StmtClassConstList)
StmtClassExtends(n *StmtClassExtends)
StmtClassImplements(n *StmtClassImplements)
StmtClassMethod(n *StmtClassMethod) StmtClassMethod(n *StmtClassMethod)
StmtConstList(n *StmtConstList) StmtConstList(n *StmtConstList)
StmtConstant(n *StmtConstant) StmtConstant(n *StmtConstant)
@ -54,7 +52,6 @@ type NodeVisitor interface {
StmtIf(n *StmtIf) StmtIf(n *StmtIf)
StmtInlineHtml(n *StmtInlineHtml) StmtInlineHtml(n *StmtInlineHtml)
StmtInterface(n *StmtInterface) StmtInterface(n *StmtInterface)
StmtInterfaceExtends(n *StmtInterfaceExtends)
StmtLabel(n *StmtLabel) StmtLabel(n *StmtLabel)
StmtNamespace(n *StmtNamespace) StmtNamespace(n *StmtNamespace)
StmtNop(n *StmtNop) StmtNop(n *StmtNop)

View File

@ -285,19 +285,22 @@ func (n *StmtCatch) GetPosition() *position.Position {
// StmtClass node // StmtClass node
type StmtClass struct { type StmtClass struct {
Position *position.Position Position *position.Position
Modifiers []Vertex Modifiers []Vertex
ClassTkn *token.Token ClassTkn *token.Token
ClassName Vertex ClassName Vertex
OpenParenthesisTkn *token.Token OpenParenthesisTkn *token.Token
Arguments []Vertex Arguments []Vertex
SeparatorTkns []*token.Token SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token CloseParenthesisTkn *token.Token
Extends Vertex ExtendsTkn *token.Token
Implements Vertex Extends Vertex
OpenCurlyBracketTkn *token.Token ImplementsTkn *token.Token
Stmts []Vertex Implements []Vertex
CloseCurlyBracketTkn *token.Token ImplementsSeparatorTkns []*token.Token
OpenCurlyBracketTkn *token.Token
Stmts []Vertex
CloseCurlyBracketTkn *token.Token
} }
func (n *StmtClass) Accept(v NodeVisitor) { func (n *StmtClass) Accept(v NodeVisitor) {
@ -326,37 +329,6 @@ func (n *StmtClassConstList) GetPosition() *position.Position {
return n.Position return n.Position
} }
// StmtClassExtends node
type StmtClassExtends struct {
Position *position.Position
ExtendTkn *token.Token
ClassName Vertex
}
func (n *StmtClassExtends) Accept(v NodeVisitor) {
v.StmtClassExtends(n)
}
func (n *StmtClassExtends) GetPosition() *position.Position {
return n.Position
}
// StmtClassImplements node
type StmtClassImplements struct {
Position *position.Position
ImplementsTkn *token.Token
InterfaceNames []Vertex
SeparatorTkns []*token.Token
}
func (n *StmtClassImplements) Accept(v NodeVisitor) {
v.StmtClassImplements(n)
}
func (n *StmtClassImplements) GetPosition() *position.Position {
return n.Position
}
// StmtClassMethod node // StmtClassMethod node
type StmtClassMethod struct { type StmtClassMethod struct {
Position *position.Position Position *position.Position
@ -744,7 +716,9 @@ type StmtInterface struct {
Position *position.Position Position *position.Position
InterfaceTkn *token.Token InterfaceTkn *token.Token
InterfaceName Vertex InterfaceName Vertex
Extends Vertex ExtendsTkn *token.Token
Extends []Vertex
ExtendsSeparatorTkns []*token.Token
OpenCurlyBracketTkn *token.Token OpenCurlyBracketTkn *token.Token
Stmts []Vertex Stmts []Vertex
CloseCurlyBracketTkn *token.Token CloseCurlyBracketTkn *token.Token
@ -758,22 +732,6 @@ func (n *StmtInterface) GetPosition() *position.Position {
return n.Position return n.Position
} }
// StmtInterfaceExtends node
type StmtInterfaceExtends struct {
Position *position.Position
ExtendsTkn *token.Token
InterfaceNames []Vertex
SeparatorTkns []*token.Token
}
func (n *StmtInterfaceExtends) Accept(v NodeVisitor) {
v.StmtInterfaceExtends(n)
}
func (n *StmtInterfaceExtends) GetPosition() *position.Position {
return n.Position
}
// StmtLabel node // StmtLabel node
type StmtLabel struct { type StmtLabel struct {
Position *position.Position Position *position.Position
@ -966,8 +924,6 @@ type StmtTrait struct {
Position *position.Position Position *position.Position
TraitTkn *token.Token TraitTkn *token.Token
TraitName Vertex TraitName Vertex
Extends Vertex
Implements Vertex
OpenCurlyBracketTkn *token.Token OpenCurlyBracketTkn *token.Token
Stmts []Vertex Stmts []Vertex
CloseCurlyBracketTkn *token.Token CloseCurlyBracketTkn *token.Token

View File

@ -170,9 +170,11 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.visitor.Leave("Extends", true) t.visitor.Leave("Extends", true)
} }
if nn.Implements != nil { if nn.Implements != nil {
t.visitor.Enter("Implements", true) t.visitor.Enter("Implements", false)
t.Traverse(nn.Implements) for _, c := range nn.Implements {
t.visitor.Leave("Implements", true) t.Traverse(c)
}
t.visitor.Leave("Implements", false)
} }
if nn.Stmts != nil { if nn.Stmts != nil {
t.visitor.Enter("Stmts", false) t.visitor.Enter("Stmts", false)
@ -202,32 +204,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
} }
t.visitor.Leave("Consts", false) t.visitor.Leave("Consts", false)
} }
case *ast.StmtClassExtends:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.ClassName != nil {
t.visitor.Enter("ClassName", true)
t.Traverse(nn.ClassName)
t.visitor.Leave("ClassName", true)
}
case *ast.StmtClassImplements:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.InterfaceNames != nil {
t.visitor.Enter("InterfaceNames", false)
for _, c := range nn.InterfaceNames {
t.Traverse(c)
}
t.visitor.Leave("InterfaceNames", false)
}
case *ast.StmtClassMethod: case *ast.StmtClassMethod:
if nn == nil { if nn == nil {
return return
@ -599,9 +575,11 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.visitor.Leave("InterfaceName", true) t.visitor.Leave("InterfaceName", true)
} }
if nn.Extends != nil { if nn.Extends != nil {
t.visitor.Enter("Extends", true) t.visitor.Enter("Extends", false)
t.Traverse(nn.Extends) for _, c := range nn.Extends {
t.visitor.Leave("Extends", true) t.Traverse(c)
}
t.visitor.Leave("Extends", false)
} }
if nn.Stmts != nil { if nn.Stmts != nil {
t.visitor.Enter("Stmts", false) t.visitor.Enter("Stmts", false)
@ -610,20 +588,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
} }
t.visitor.Leave("Stmts", false) t.visitor.Leave("Stmts", false)
} }
case *ast.StmtInterfaceExtends:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.InterfaceNames != nil {
t.visitor.Enter("InterfaceNames", false)
for _, c := range nn.InterfaceNames {
t.Traverse(c)
}
t.visitor.Leave("InterfaceNames", false)
}
case *ast.StmtLabel: case *ast.StmtLabel:
if nn == nil { if nn == nil {
return return

View File

@ -286,8 +286,11 @@ func (v *Dumper) StmtClass(n *ast.StmtClass) {
v.dumpVertexList("Arguments", n.Arguments) v.dumpVertexList("Arguments", n.Arguments)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns) v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn) v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
v.dumpToken("ExtendsTkn", n.ExtendsTkn)
v.dumpVertex("Extends", n.Extends) v.dumpVertex("Extends", n.Extends)
v.dumpVertex("Implements", n.Implements) v.dumpToken("ImplementsTkn", n.ImplementsTkn)
v.dumpVertexList("Implements", n.Implements)
v.dumpTokenList("ImplementsSeparatorTkns", n.ImplementsSeparatorTkns)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn) v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.dumpVertexList("Stmts", n.Stmts) v.dumpVertexList("Stmts", n.Stmts)
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn) v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
@ -311,31 +314,6 @@ func (v *Dumper) StmtClassConstList(n *ast.StmtClassConstList) {
v.print(v.indent, "},\n") v.print(v.indent, "},\n")
} }
func (v *Dumper) StmtClassExtends(n *ast.StmtClassExtends) {
v.print(0, "&ast.StmtClassExtends{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("ExtendTkn", n.ExtendTkn)
v.dumpVertex("ClassName", n.ClassName)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) StmtClassImplements(n *ast.StmtClassImplements) {
v.print(0, "&ast.StmtClassImplements{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("ImplementsTkn", n.ImplementsTkn)
v.dumpVertexList("InterfaceNames", n.InterfaceNames)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) StmtClassMethod(n *ast.StmtClassMethod) { func (v *Dumper) StmtClassMethod(n *ast.StmtClassMethod) {
v.print(0, "&ast.StmtClassMethod{\n") v.print(0, "&ast.StmtClassMethod{\n")
v.indent++ v.indent++
@ -666,7 +644,9 @@ func (v *Dumper) StmtInterface(n *ast.StmtInterface) {
v.dumpPosition(n.Position) v.dumpPosition(n.Position)
v.dumpToken("InterfaceTkn", n.InterfaceTkn) v.dumpToken("InterfaceTkn", n.InterfaceTkn)
v.dumpVertex("InterfaceName", n.InterfaceName) v.dumpVertex("InterfaceName", n.InterfaceName)
v.dumpVertex("Extends", n.Extends) v.dumpToken("ExtendsTkn", n.ExtendsTkn)
v.dumpVertexList("Extends", n.Extends)
v.dumpTokenList("ExtendsSeparatorTkns", n.ExtendsSeparatorTkns)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn) v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.dumpVertexList("Stmts", n.Stmts) v.dumpVertexList("Stmts", n.Stmts)
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn) v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
@ -675,19 +655,6 @@ func (v *Dumper) StmtInterface(n *ast.StmtInterface) {
v.print(v.indent, "},\n") v.print(v.indent, "},\n")
} }
func (v *Dumper) StmtInterfaceExtends(n *ast.StmtInterfaceExtends) {
v.print(0, "&ast.StmtInterfaceExtends{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("ExtendsTkn", n.ExtendsTkn)
v.dumpVertexList("InterfaceNames", n.InterfaceNames)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) StmtLabel(n *ast.StmtLabel) { func (v *Dumper) StmtLabel(n *ast.StmtLabel) {
v.print(0, "&ast.StmtLabel{\n") v.print(0, "&ast.StmtLabel{\n")
v.indent++ v.indent++
@ -849,8 +816,6 @@ func (v *Dumper) StmtTrait(n *ast.StmtTrait) {
v.dumpPosition(n.Position) v.dumpPosition(n.Position)
v.dumpToken("TraitTkn", n.TraitTkn) v.dumpToken("TraitTkn", n.TraitTkn)
v.dumpVertex("TraitName", n.TraitName) v.dumpVertex("TraitName", n.TraitName)
v.dumpVertex("Extends", n.Extends)
v.dumpVertex("Implements", n.Implements)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn) v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.dumpVertexList("Stmts", n.Stmts) v.dumpVertexList("Stmts", n.Stmts)
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn) v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)

View File

@ -281,12 +281,14 @@ func (f *formatter) StmtClass(n *ast.StmtClass) {
f.addFreeFloating(token.T_WHITESPACE, []byte(" ")) f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
if n.Extends != nil { if n.Extends != nil {
n.ExtendsTkn = f.newToken(token.T_EXTENDS, []byte("extends"))
n.Extends.Accept(f) n.Extends.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" ")) f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
} }
if n.Implements != nil { if n.Implements != nil {
n.Implements.Accept(f) n.ImplementsTkn = f.newToken(token.T_IMPLEMENTS, []byte("implements"))
n.ImplementsSeparatorTkns = f.formatList(n.Implements, ',')
f.addFreeFloating(token.T_WHITESPACE, []byte(" ")) f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
} }
@ -318,20 +320,6 @@ func (f *formatter) StmtClassConstList(n *ast.StmtClassConstList) {
n.SemiColonTkn = f.newSemicolonTkn() n.SemiColonTkn = f.newSemicolonTkn()
} }
func (f *formatter) StmtClassExtends(n *ast.StmtClassExtends) {
n.ExtendTkn = f.newToken(token.T_EXTENDS, []byte("extends"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
n.ClassName.Accept(f)
}
func (f *formatter) StmtClassImplements(n *ast.StmtClassImplements) {
n.ImplementsTkn = f.newToken(token.T_IMPLEMENTS, []byte("implements"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
n.SeparatorTkns = f.formatList(n.InterfaceNames, ',')
}
func (f *formatter) StmtClassMethod(n *ast.StmtClassMethod) { func (f *formatter) StmtClassMethod(n *ast.StmtClassMethod) {
for _, m := range n.Modifiers { for _, m := range n.Modifiers {
m.Accept(f) m.Accept(f)
@ -677,7 +665,8 @@ func (f *formatter) StmtInterface(n *ast.StmtInterface) {
f.addFreeFloating(token.T_WHITESPACE, []byte(" ")) f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
if n.Extends != nil { if n.Extends != nil {
n.Extends.Accept(f) n.ExtendsTkn = f.newToken(token.T_EXTENDS, []byte("extends"))
n.ExtendsSeparatorTkns = f.formatList(n.Extends, ',')
f.addFreeFloating(token.T_WHITESPACE, []byte(" ")) f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
} }
@ -695,16 +684,6 @@ func (f *formatter) StmtInterface(n *ast.StmtInterface) {
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}")) n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
} }
func (f *formatter) StmtInterfaceExtends(n *ast.StmtInterfaceExtends) {
n.ExtendsTkn = f.newToken(token.T_EXTENDS, []byte("extends"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
n.SeparatorTkns = nil
if len(n.InterfaceNames) > 0 {
n.SeparatorTkns = f.formatList(n.InterfaceNames, ',')
}
}
func (f *formatter) StmtLabel(n *ast.StmtLabel) { func (f *formatter) StmtLabel(n *ast.StmtLabel) {
n.LabelName.Accept(f) n.LabelName.Accept(f)
n.ColonTkn = f.newToken(':', []byte(":")) n.ColonTkn = f.newToken(':', []byte(":"))
@ -865,16 +844,6 @@ func (f *formatter) StmtTrait(n *ast.StmtTrait) {
n.TraitName.Accept(f) n.TraitName.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" ")) f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
if n.Extends != nil {
n.Extends.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
}
if n.Implements != nil {
n.Implements.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
}
n.OpenCurlyBracketTkn = f.newToken('{', []byte("{")) n.OpenCurlyBracketTkn = f.newToken('{', []byte("{"))
if len(n.Stmts) > 0 { if len(n.Stmts) > 0 {

View File

@ -519,12 +519,10 @@ func TestFormatter_Class_Extends(t *testing.T) {
ClassName: &ast.Identifier{ ClassName: &ast.Identifier{
Value: []byte("foo"), Value: []byte("foo"),
}, },
Extends: &ast.StmtClassExtends{ Extends: &ast.NameName{
ClassName: &ast.NameName{ Parts: []ast.Vertex{
Parts: []ast.Vertex{ &ast.NameNamePart{
&ast.NameNamePart{ Value: []byte("bar"),
Value: []byte("bar"),
},
}, },
}, },
}, },
@ -556,13 +554,11 @@ func TestFormatter_Class_Implements(t *testing.T) {
ClassName: &ast.Identifier{ ClassName: &ast.Identifier{
Value: []byte("foo"), Value: []byte("foo"),
}, },
Implements: &ast.StmtClassImplements{ Implements: []ast.Vertex{
InterfaceNames: []ast.Vertex{ &ast.NameName{
&ast.NameName{ Parts: []ast.Vertex{
Parts: []ast.Vertex{ &ast.NameNamePart{
&ast.NameNamePart{ Value: []byte("bar"),
Value: []byte("bar"),
},
}, },
}, },
}, },
@ -669,69 +665,6 @@ func TestFormatter_StmtClassConstList_Modifier(t *testing.T) {
} }
} }
func TestFormatter_ClassExtends(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtClassExtends{
ClassName: &ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
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 := `extends foo`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_ClassImplements(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtClassImplements{
InterfaceNames: []ast.Vertex{
&ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("foo"),
},
},
},
&ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
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 := `implements foo, bar`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_ClassMethod(t *testing.T) { func TestFormatter_ClassMethod(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")
@ -1881,13 +1814,11 @@ func TestFormatter_StmtInterface_Extends(t *testing.T) {
InterfaceName: &ast.Identifier{ InterfaceName: &ast.Identifier{
Value: []byte("foo"), Value: []byte("foo"),
}, },
Extends: &ast.StmtInterfaceExtends{ Extends: []ast.Vertex{
InterfaceNames: []ast.Vertex{ &ast.NameName{
&ast.NameName{ Parts: []ast.Vertex{
Parts: []ast.Vertex{ &ast.NameNamePart{
&ast.NameNamePart{ Value: []byte("bar"),
Value: []byte("bar"),
},
}, },
}, },
}, },
@ -1913,42 +1844,6 @@ func TestFormatter_StmtInterface_Extends(t *testing.T) {
} }
} }
func TestFormatter_StmtInterfaceExtends(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtInterfaceExtends{
InterfaceNames: []ast.Vertex{
&ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("foo"),
},
},
},
&ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
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 := `extends foo, bar`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtLabel(t *testing.T) { func TestFormatter_StmtLabel(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")
@ -2465,82 +2360,6 @@ func TestFormatter_StmtTrait(t *testing.T) {
} }
} }
func TestFormatter_StmtTrait_Extends(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTrait{
TraitName: &ast.Identifier{
Value: []byte("foo"),
},
Extends: &ast.StmtClassExtends{
ClassName: &ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("bar"),
},
},
},
},
Stmts: []ast.Vertex{
&ast.StmtNop{},
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `trait foo extends bar {
;
}`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtTrait_Implements(t *testing.T) {
o := bytes.NewBufferString("")
n := &ast.StmtTrait{
TraitName: &ast.Identifier{
Value: []byte("foo"),
},
Implements: &ast.StmtClassImplements{
InterfaceNames: []ast.Vertex{
&ast.NameName{
Parts: []ast.Vertex{
&ast.NameNamePart{
Value: []byte("bar"),
},
},
},
},
},
Stmts: []ast.Vertex{
&ast.StmtNop{},
},
}
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
n.Accept(f)
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n.Accept(p)
expected := `trait foo implements bar {
;
}`
actual := o.String()
if expected != actual {
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
}
}
func TestFormatter_StmtTraitMethodRef(t *testing.T) { func TestFormatter_StmtTraitMethodRef(t *testing.T) {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")

View File

@ -73,11 +73,11 @@ func (nsr *NamespaceResolver) StmtGroupUse(n *ast.StmtGroupUse) {
func (nsr *NamespaceResolver) StmtClass(n *ast.StmtClass) { func (nsr *NamespaceResolver) StmtClass(n *ast.StmtClass) {
if n.Extends != nil { if n.Extends != nil {
nsr.ResolveName(n.Extends.(*ast.StmtClassExtends).ClassName, "") nsr.ResolveName(n.Extends, "")
} }
if n.Implements != nil { if n.Implements != nil {
for _, interfaceName := range n.Implements.(*ast.StmtClassImplements).InterfaceNames { for _, interfaceName := range n.Implements {
nsr.ResolveName(interfaceName, "") nsr.ResolveName(interfaceName, "")
} }
} }
@ -89,7 +89,7 @@ func (nsr *NamespaceResolver) StmtClass(n *ast.StmtClass) {
func (nsr *NamespaceResolver) StmtInterface(n *ast.StmtInterface) { func (nsr *NamespaceResolver) StmtInterface(n *ast.StmtInterface) {
if n.Extends != nil { if n.Extends != nil {
for _, interfaceName := range n.Extends.(*ast.StmtInterfaceExtends).InterfaceNames { for _, interfaceName := range n.Extends {
nsr.ResolveName(interfaceName, "") nsr.ResolveName(interfaceName, "")
} }
} }

View File

@ -401,13 +401,9 @@ func TestResolveClassName(t *testing.T) {
class := &ast.StmtClass{ class := &ast.StmtClass{
ClassName: &ast.Identifier{Value: []byte("A")}, ClassName: &ast.Identifier{Value: []byte("A")},
Extends: &ast.StmtClassExtends{ Extends: nameAB,
ClassName: nameAB, Implements: []ast.Vertex{
}, nameBC,
Implements: &ast.StmtClassImplements{
InterfaceNames: []ast.Vertex{
nameBC,
},
}, },
} }
@ -436,11 +432,9 @@ func TestResolveInterfaceName(t *testing.T) {
interfaceNode := &ast.StmtInterface{ interfaceNode := &ast.StmtInterface{
InterfaceName: &ast.Identifier{Value: []byte("A")}, InterfaceName: &ast.Identifier{Value: []byte("A")},
Extends: &ast.StmtInterfaceExtends{ Extends: []ast.Vertex{
InterfaceNames: []ast.Vertex{ nameAB,
nameAB, nameBC,
nameBC,
},
}, },
} }

View File

@ -62,14 +62,6 @@ func (v *Null) StmtClassConstList(_ *ast.StmtClassConstList) {
// do nothing // do nothing
} }
func (v *Null) StmtClassExtends(_ *ast.StmtClassExtends) {
// do nothing
}
func (v *Null) StmtClassImplements(_ *ast.StmtClassImplements) {
// do nothing
}
func (v *Null) StmtClassMethod(_ *ast.StmtClassMethod) { func (v *Null) StmtClassMethod(_ *ast.StmtClassMethod) {
// do nothing // do nothing
} }
@ -154,10 +146,6 @@ func (v *Null) StmtInterface(_ *ast.StmtInterface) {
// do nothing // do nothing
} }
func (v *Null) StmtInterfaceExtends(_ *ast.StmtInterfaceExtends) {
// do nothing
}
func (v *Null) StmtLabel(_ *ast.StmtLabel) { func (v *Null) StmtLabel(_ *ast.StmtLabel) {
// do nothing // do nothing
} }

View File

@ -194,8 +194,10 @@ func (p *printer) StmtClass(n *ast.StmtClass) {
p.printToken(n.OpenParenthesisTkn, p.ifNodeList(n.Arguments, []byte("("))) p.printToken(n.OpenParenthesisTkn, p.ifNodeList(n.Arguments, []byte("(")))
p.printSeparatedList(n.Arguments, n.SeparatorTkns, []byte(",")) p.printSeparatedList(n.Arguments, n.SeparatorTkns, []byte(","))
p.printToken(n.CloseParenthesisTkn, p.ifNodeList(n.Arguments, []byte(")"))) p.printToken(n.CloseParenthesisTkn, p.ifNodeList(n.Arguments, []byte(")")))
p.printToken(n.ExtendsTkn, p.ifNode(n.Extends, []byte("extends")))
p.printNode(n.Extends) p.printNode(n.Extends)
p.printNode(n.Implements) p.printToken(n.ImplementsTkn, p.ifNodeList(n.Implements, []byte("implements")))
p.printSeparatedList(n.Implements, n.ImplementsSeparatorTkns, []byte(","))
p.printToken(n.OpenCurlyBracketTkn, []byte("{")) p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
p.printList(n.Stmts) p.printList(n.Stmts)
p.printToken(n.CloseCurlyBracketTkn, []byte("}")) p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
@ -208,16 +210,6 @@ func (p *printer) StmtClassConstList(n *ast.StmtClassConstList) {
p.printToken(n.SemiColonTkn, []byte(";")) p.printToken(n.SemiColonTkn, []byte(";"))
} }
func (p *printer) StmtClassExtends(n *ast.StmtClassExtends) {
p.printToken(n.ExtendTkn, []byte("extends"))
p.printNode(n.ClassName)
}
func (p *printer) StmtClassImplements(n *ast.StmtClassImplements) {
p.printToken(n.ImplementsTkn, []byte("implements"))
p.printSeparatedList(n.InterfaceNames, n.SeparatorTkns, []byte(","))
}
func (p *printer) StmtClassMethod(n *ast.StmtClassMethod) { func (p *printer) StmtClassMethod(n *ast.StmtClassMethod) {
p.printList(n.Modifiers) p.printList(n.Modifiers)
p.printToken(n.FunctionTkn, []byte("function")) p.printToken(n.FunctionTkn, []byte("function"))
@ -436,17 +428,13 @@ func (p *printer) StmtInlineHtml(n *ast.StmtInlineHtml) {
func (p *printer) StmtInterface(n *ast.StmtInterface) { func (p *printer) StmtInterface(n *ast.StmtInterface) {
p.printToken(n.InterfaceTkn, []byte("interface")) p.printToken(n.InterfaceTkn, []byte("interface"))
p.printNode(n.InterfaceName) p.printNode(n.InterfaceName)
p.printNode(n.Extends) p.printToken(n.ExtendsTkn, p.ifNodeList(n.Extends, []byte("extends")))
p.printSeparatedList(n.Extends, n.ExtendsSeparatorTkns, []byte(","))
p.printToken(n.OpenCurlyBracketTkn, []byte("{")) p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
p.printList(n.Stmts) p.printList(n.Stmts)
p.printToken(n.CloseCurlyBracketTkn, []byte("}")) p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
} }
func (p *printer) StmtInterfaceExtends(n *ast.StmtInterfaceExtends) {
p.printToken(n.ExtendsTkn, []byte("extends"))
p.printSeparatedList(n.InterfaceNames, n.SeparatorTkns, []byte(","))
}
func (p *printer) StmtLabel(n *ast.StmtLabel) { func (p *printer) StmtLabel(n *ast.StmtLabel) {
p.printNode(n.LabelName) p.printNode(n.LabelName)
p.printToken(n.ColonTkn, []byte(":")) p.printToken(n.ColonTkn, []byte(":"))
@ -525,8 +513,6 @@ func (p *printer) StmtThrow(n *ast.StmtThrow) {
func (p *printer) StmtTrait(n *ast.StmtTrait) { func (p *printer) StmtTrait(n *ast.StmtTrait) {
p.printToken(n.TraitTkn, []byte("trait")) p.printToken(n.TraitTkn, []byte("trait"))
p.printNode(n.TraitName) p.printNode(n.TraitName)
p.printNode(n.Extends)
p.printNode(n.Implements)
p.printToken(n.OpenCurlyBracketTkn, []byte("{")) p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
p.printList(n.Stmts) p.printList(n.Stmts)
p.printToken(n.CloseCurlyBracketTkn, []byte("}")) p.printToken(n.CloseCurlyBracketTkn, []byte("}"))

View File

@ -29,11 +29,9 @@ func TestPrinterPrintFile(t *testing.T) {
&ast.NameNamePart{Value: []byte("Bar")}, &ast.NameNamePart{Value: []byte("Bar")},
}, },
}, },
Extends: &ast.StmtClassExtends{ Extends: &ast.NameName{
ClassName: &ast.NameName{ Parts: []ast.Vertex{
Parts: []ast.Vertex{ &ast.NameNamePart{Value: []byte("Baz")},
&ast.NameNamePart{Value: []byte("Baz")},
},
}, },
}, },
Stmts: []ast.Vertex{ Stmts: []ast.Vertex{
@ -3255,14 +3253,10 @@ func TestPrinterPrintStmtClass(t *testing.T) {
n := &ast.StmtClass{ n := &ast.StmtClass{
Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("abstract")}}, Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("abstract")}},
ClassName: &ast.Identifier{Value: []byte("Foo")}, ClassName: &ast.Identifier{Value: []byte("Foo")},
Extends: &ast.StmtClassExtends{ Extends: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
ClassName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}}, Implements: []ast.Vertex{
}, &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
Implements: &ast.StmtClassImplements{ &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Quuz")}}},
InterfaceNames: []ast.Vertex{
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Quuz")}}},
},
}, },
Stmts: []ast.Vertex{ Stmts: []ast.Vertex{
&ast.StmtClassConstList{ &ast.StmtClassConstList{
@ -3307,14 +3301,10 @@ func TestPrinterPrintStmtAnonymousClass(t *testing.T) {
}, },
}, },
}, },
Extends: &ast.StmtClassExtends{ Extends: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
ClassName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}}, Implements: []ast.Vertex{
}, &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
Implements: &ast.StmtClassImplements{ &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Quuz")}}},
InterfaceNames: []ast.Vertex{
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Quuz")}}},
},
}, },
Stmts: []ast.Vertex{ Stmts: []ast.Vertex{
&ast.StmtClassConstList{ &ast.StmtClassConstList{
@ -4122,11 +4112,9 @@ func TestPrinterPrintInterface(t *testing.T) {
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP) p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
n := &ast.StmtInterface{ n := &ast.StmtInterface{
InterfaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}}, InterfaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
Extends: &ast.StmtInterfaceExtends{ Extends: []ast.Vertex{
InterfaceNames: []ast.Vertex{ &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}}, &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
},
}, },
Stmts: []ast.Vertex{ Stmts: []ast.Vertex{
&ast.StmtClassMethod{ &ast.StmtClassMethod{