refactoring: update ast structure of "Class", "Interface" and "Trait" nodes
This commit is contained in:
parent
2990f0cc2d
commit
c29e8ec0e0
@ -9945,14 +9945,7 @@ func TestStmtClass_ClassExtends(t *testing.T) {
|
||||
},
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 19,
|
||||
EndPos: 30,
|
||||
},
|
||||
ExtendTkn: &token.Token{
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
Position: &position.Position{
|
||||
@ -9974,7 +9967,7 @@ func TestStmtClass_ClassExtends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ClassName: &ast.NameName{
|
||||
Extends: &ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
@ -10015,7 +10008,6 @@ func TestStmtClass_ClassExtends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -10187,13 +10179,6 @@ func TestStmtClass_ClassImplement(t *testing.T) {
|
||||
},
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 19,
|
||||
EndPos: 33,
|
||||
},
|
||||
ImplementsTkn: &token.Token{
|
||||
ID: token.T_IMPLEMENTS,
|
||||
Value: []byte("implements"),
|
||||
@ -10216,7 +10201,7 @@ func TestStmtClass_ClassImplement(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Implements: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -10259,7 +10244,6 @@ func TestStmtClass_ClassImplement(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -10431,13 +10415,6 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 19,
|
||||
EndPos: 38,
|
||||
},
|
||||
ImplementsTkn: &token.Token{
|
||||
ID: token.T_IMPLEMENTS,
|
||||
Value: []byte("implements"),
|
||||
@ -10460,7 +10437,7 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Implements: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -10544,7 +10521,7 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
ImplementsSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
@ -10556,7 +10533,6 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -19076,13 +19052,6 @@ func TestStmtInterface_Extend(t *testing.T) {
|
||||
},
|
||||
Value: []byte("Foo"),
|
||||
},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 17,
|
||||
EndPos: 28,
|
||||
},
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
@ -19105,7 +19074,7 @@ func TestStmtInterface_Extend(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -19148,7 +19117,6 @@ func TestStmtInterface_Extend(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -19275,13 +19243,6 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
Value: []byte("Foo"),
|
||||
},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 17,
|
||||
EndPos: 33,
|
||||
},
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
@ -19304,7 +19265,7 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -19388,7 +19349,7 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
ExtendsSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
@ -19400,7 +19361,6 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
|
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -1280,36 +1280,55 @@ unticked_class_declaration_statement:
|
||||
{
|
||||
switch n := $1.(type) {
|
||||
case *ast.StmtClass :
|
||||
n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7)
|
||||
n.ClassName = &ast.Identifier{
|
||||
className := &ast.Identifier{
|
||||
Position: yylex.(*Parser).builder.NewTokenPosition($2),
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
n.Extends = $3
|
||||
n.Implements = $4
|
||||
|
||||
n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7)
|
||||
n.ClassName = className
|
||||
n.OpenCurlyBracketTkn = $5
|
||||
n.Stmts = $6
|
||||
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 :
|
||||
n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7)
|
||||
n.TraitName = &ast.Identifier{
|
||||
traitName := &ast.Identifier{
|
||||
Position: yylex.(*Parser).builder.NewTokenPosition($2),
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
n.Extends = $3
|
||||
n.Implements = $4
|
||||
|
||||
n.Position = yylex.(*Parser).builder.NewNodeTokenPosition($1, $7)
|
||||
n.TraitName = traitName
|
||||
n.OpenCurlyBracketTkn = $5
|
||||
n.Stmts = $6
|
||||
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
|
||||
}
|
||||
| interface_entry T_STRING interface_extends_list '{' class_statement_list '}'
|
||||
{
|
||||
$$ = &ast.StmtInterface{
|
||||
iface := &ast.StmtInterface{
|
||||
Position: yylex.(*Parser).builder.NewTokensPosition($1, $6),
|
||||
InterfaceTkn: $1,
|
||||
InterfaceName: &ast.Identifier{
|
||||
@ -1317,11 +1336,18 @@ unticked_class_declaration_statement:
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
Extends: $3,
|
||||
OpenCurlyBracketTkn: $4,
|
||||
Stmts: $5,
|
||||
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
|
||||
{
|
||||
$$ = &ast.StmtClassExtends{
|
||||
$$ = &ast.StmtClass{
|
||||
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
|
||||
ExtendTkn: $1,
|
||||
ClassName: $2,
|
||||
ExtendsTkn: $1,
|
||||
Extends: $2,
|
||||
}
|
||||
}
|
||||
;
|
||||
@ -1400,11 +1426,11 @@ interface_extends_list:
|
||||
}
|
||||
| T_EXTENDS interface_list
|
||||
{
|
||||
$$ = &ast.StmtInterfaceExtends{
|
||||
$$ = &ast.StmtInterface{
|
||||
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
|
||||
ExtendsTkn: $1,
|
||||
InterfaceNames: $2.(*ast.ParserSeparatedList).Items,
|
||||
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
Extends: $2.(*ast.ParserSeparatedList).Items,
|
||||
ExtendsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
};
|
||||
}
|
||||
;
|
||||
@ -1416,11 +1442,11 @@ implements_list:
|
||||
}
|
||||
| T_IMPLEMENTS interface_list
|
||||
{
|
||||
$$ = &ast.StmtClassImplements{
|
||||
$$ = &ast.StmtClass{
|
||||
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
|
||||
ImplementsTkn: $1,
|
||||
InterfaceNames: $2.(*ast.ParserSeparatedList).Items,
|
||||
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
Implements: $2.(*ast.ParserSeparatedList).Items,
|
||||
ImplementsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
@ -11108,14 +11108,7 @@ func TestStmtClass_ClassExtends(t *testing.T) {
|
||||
},
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 19,
|
||||
EndPos: 30,
|
||||
},
|
||||
ExtendTkn: &token.Token{
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
Position: &position.Position{
|
||||
@ -11137,7 +11130,7 @@ func TestStmtClass_ClassExtends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ClassName: &ast.NameName{
|
||||
Extends: &ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
@ -11178,7 +11171,6 @@ func TestStmtClass_ClassExtends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -11350,13 +11342,6 @@ func TestStmtClass_ClassImplement(t *testing.T) {
|
||||
},
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 19,
|
||||
EndPos: 33,
|
||||
},
|
||||
ImplementsTkn: &token.Token{
|
||||
ID: token.T_IMPLEMENTS,
|
||||
Value: []byte("implements"),
|
||||
@ -11379,7 +11364,7 @@ func TestStmtClass_ClassImplement(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Implements: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -11422,7 +11407,6 @@ func TestStmtClass_ClassImplement(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -11594,13 +11578,6 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 19,
|
||||
EndPos: 38,
|
||||
},
|
||||
ImplementsTkn: &token.Token{
|
||||
ID: token.T_IMPLEMENTS,
|
||||
Value: []byte("implements"),
|
||||
@ -11623,7 +11600,7 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Implements: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -11707,7 +11684,7 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
ImplementsSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
@ -11719,7 +11696,6 @@ func TestStmtClass_ClassImplements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -11883,14 +11859,7 @@ func TestStmtClass_AnonimousClass(t *testing.T) {
|
||||
EndPos: 14,
|
||||
},
|
||||
},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 15,
|
||||
EndPos: 26,
|
||||
},
|
||||
ExtendTkn: &token.Token{
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
Position: &position.Position{
|
||||
@ -11912,7 +11881,7 @@ func TestStmtClass_AnonimousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
ClassName: &ast.NameName{
|
||||
Extends: &ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
@ -11953,14 +11922,6 @@ func TestStmtClass_AnonimousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 27,
|
||||
EndPos: 46,
|
||||
},
|
||||
ImplementsTkn: &token.Token{
|
||||
ID: token.T_IMPLEMENTS,
|
||||
Value: []byte("implements"),
|
||||
@ -11983,7 +11944,7 @@ func TestStmtClass_AnonimousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Implements: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -12067,7 +12028,7 @@ func TestStmtClass_AnonimousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
ImplementsSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
@ -12079,7 +12040,6 @@ func TestStmtClass_AnonimousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -20762,13 +20722,6 @@ func TestStmtInterface_Extend(t *testing.T) {
|
||||
},
|
||||
Value: []byte("Foo"),
|
||||
},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 17,
|
||||
EndPos: 28,
|
||||
},
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
@ -20791,7 +20744,7 @@ func TestStmtInterface_Extend(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -20834,7 +20787,6 @@ func TestStmtInterface_Extend(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
@ -20961,13 +20913,6 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
Value: []byte("Foo"),
|
||||
},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 17,
|
||||
EndPos: 33,
|
||||
},
|
||||
ExtendsTkn: &token.Token{
|
||||
ID: token.T_EXTENDS,
|
||||
Value: []byte("extends"),
|
||||
@ -20990,7 +20935,7 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@ -21074,7 +21019,7 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
SeparatorTkns: []*token.Token{
|
||||
ExtendsSeparatorTkns: []*token.Token{
|
||||
{
|
||||
ID: token.ID(44),
|
||||
Value: []byte(","),
|
||||
@ -21086,7 +21031,6 @@ func TestStmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OpenCurlyBracketTkn: &token.Token{
|
||||
ID: token.ID(123),
|
||||
Value: []byte("{"),
|
||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -1203,7 +1203,7 @@ is_variadic:
|
||||
class_declaration_statement:
|
||||
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),
|
||||
Modifiers: $1,
|
||||
ClassTkn: $2,
|
||||
@ -1212,16 +1212,27 @@ class_declaration_statement:
|
||||
IdentifierTkn: $3,
|
||||
Value: $3.Value,
|
||||
},
|
||||
Extends: $4,
|
||||
Implements: $5,
|
||||
OpenCurlyBracketTkn: $7,
|
||||
Stmts: $8,
|
||||
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 '}'
|
||||
{
|
||||
$$ = &ast.StmtClass{
|
||||
class := &ast.StmtClass{
|
||||
Position: yylex.(*Parser).builder.NewTokensPosition($1, $8),
|
||||
ClassTkn: $1,
|
||||
ClassName: &ast.Identifier{
|
||||
@ -1229,12 +1240,23 @@ class_declaration_statement:
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
Extends: $3,
|
||||
Implements: $4,
|
||||
OpenCurlyBracketTkn: $6,
|
||||
Stmts: $7,
|
||||
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:
|
||||
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),
|
||||
InterfaceTkn: $1,
|
||||
InterfaceName: &ast.Identifier{
|
||||
@ -1297,11 +1319,18 @@ interface_declaration_statement:
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
Extends: $3,
|
||||
OpenCurlyBracketTkn: $5,
|
||||
Stmts: $6,
|
||||
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
|
||||
{
|
||||
$$ = &ast.StmtClassExtends{
|
||||
$$ = &ast.StmtClass{
|
||||
Position: yylex.(*Parser).builder.NewTokenNodePosition($1, $2),
|
||||
ExtendTkn: $1,
|
||||
ClassName: $2,
|
||||
ExtendsTkn: $1,
|
||||
Extends: $2,
|
||||
}
|
||||
}
|
||||
;
|
||||
@ -1327,11 +1356,11 @@ interface_extends_list:
|
||||
}
|
||||
| T_EXTENDS name_list
|
||||
{
|
||||
$$ = &ast.StmtInterfaceExtends{
|
||||
$$ = &ast.StmtInterface{
|
||||
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
|
||||
ExtendsTkn: $1,
|
||||
InterfaceNames: $2.(*ast.ParserSeparatedList).Items,
|
||||
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
Extends: $2.(*ast.ParserSeparatedList).Items,
|
||||
ExtendsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
};
|
||||
}
|
||||
;
|
||||
@ -1343,11 +1372,11 @@ implements_list:
|
||||
}
|
||||
| T_IMPLEMENTS name_list
|
||||
{
|
||||
$$ = &ast.StmtClassImplements{
|
||||
$$ = &ast.StmtClass{
|
||||
Position: yylex.(*Parser).builder.NewTokenNodeListPosition($1, $2.(*ast.ParserSeparatedList).Items),
|
||||
ImplementsTkn: $1,
|
||||
InterfaceNames: $2.(*ast.ParserSeparatedList).Items,
|
||||
SeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
Implements: $2.(*ast.ParserSeparatedList).Items,
|
||||
ImplementsSeparatorTkns: $2.(*ast.ParserSeparatedList).SeparatorTkns,
|
||||
};
|
||||
}
|
||||
;
|
||||
@ -2458,19 +2487,30 @@ non_empty_for_exprs:
|
||||
anonymous_class:
|
||||
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),
|
||||
ClassTkn: $1,
|
||||
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||
Arguments: $2.(*ast.ArgumentList).Arguments,
|
||||
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
|
||||
CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
|
||||
Extends: $3,
|
||||
Implements: $4,
|
||||
OpenCurlyBracketTkn: $6,
|
||||
Stmts: $7,
|
||||
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
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -31,8 +31,6 @@ type NodeVisitor interface {
|
||||
StmtCatch(n *StmtCatch)
|
||||
StmtClass(n *StmtClass)
|
||||
StmtClassConstList(n *StmtClassConstList)
|
||||
StmtClassExtends(n *StmtClassExtends)
|
||||
StmtClassImplements(n *StmtClassImplements)
|
||||
StmtClassMethod(n *StmtClassMethod)
|
||||
StmtConstList(n *StmtConstList)
|
||||
StmtConstant(n *StmtConstant)
|
||||
@ -54,7 +52,6 @@ type NodeVisitor interface {
|
||||
StmtIf(n *StmtIf)
|
||||
StmtInlineHtml(n *StmtInlineHtml)
|
||||
StmtInterface(n *StmtInterface)
|
||||
StmtInterfaceExtends(n *StmtInterfaceExtends)
|
||||
StmtLabel(n *StmtLabel)
|
||||
StmtNamespace(n *StmtNamespace)
|
||||
StmtNop(n *StmtNop)
|
||||
|
@ -293,8 +293,11 @@ type StmtClass struct {
|
||||
Arguments []Vertex
|
||||
SeparatorTkns []*token.Token
|
||||
CloseParenthesisTkn *token.Token
|
||||
ExtendsTkn *token.Token
|
||||
Extends Vertex
|
||||
Implements Vertex
|
||||
ImplementsTkn *token.Token
|
||||
Implements []Vertex
|
||||
ImplementsSeparatorTkns []*token.Token
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
@ -326,37 +329,6 @@ func (n *StmtClassConstList) GetPosition() *position.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
|
||||
type StmtClassMethod struct {
|
||||
Position *position.Position
|
||||
@ -744,7 +716,9 @@ type StmtInterface struct {
|
||||
Position *position.Position
|
||||
InterfaceTkn *token.Token
|
||||
InterfaceName Vertex
|
||||
Extends Vertex
|
||||
ExtendsTkn *token.Token
|
||||
Extends []Vertex
|
||||
ExtendsSeparatorTkns []*token.Token
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
@ -758,22 +732,6 @@ func (n *StmtInterface) GetPosition() *position.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
|
||||
type StmtLabel struct {
|
||||
Position *position.Position
|
||||
@ -966,8 +924,6 @@ type StmtTrait struct {
|
||||
Position *position.Position
|
||||
TraitTkn *token.Token
|
||||
TraitName Vertex
|
||||
Extends Vertex
|
||||
Implements Vertex
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
|
@ -170,9 +170,11 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
t.visitor.Leave("Extends", true)
|
||||
}
|
||||
if nn.Implements != nil {
|
||||
t.visitor.Enter("Implements", true)
|
||||
t.Traverse(nn.Implements)
|
||||
t.visitor.Leave("Implements", true)
|
||||
t.visitor.Enter("Implements", false)
|
||||
for _, c := range nn.Implements {
|
||||
t.Traverse(c)
|
||||
}
|
||||
t.visitor.Leave("Implements", false)
|
||||
}
|
||||
if nn.Stmts != nil {
|
||||
t.visitor.Enter("Stmts", false)
|
||||
@ -202,32 +204,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
}
|
||||
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:
|
||||
if nn == nil {
|
||||
return
|
||||
@ -599,9 +575,11 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
t.visitor.Leave("InterfaceName", true)
|
||||
}
|
||||
if nn.Extends != nil {
|
||||
t.visitor.Enter("Extends", true)
|
||||
t.Traverse(nn.Extends)
|
||||
t.visitor.Leave("Extends", true)
|
||||
t.visitor.Enter("Extends", false)
|
||||
for _, c := range nn.Extends {
|
||||
t.Traverse(c)
|
||||
}
|
||||
t.visitor.Leave("Extends", false)
|
||||
}
|
||||
if nn.Stmts != nil {
|
||||
t.visitor.Enter("Stmts", false)
|
||||
@ -610,20 +588,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
}
|
||||
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:
|
||||
if nn == nil {
|
||||
return
|
||||
|
@ -286,8 +286,11 @@ func (v *Dumper) StmtClass(n *ast.StmtClass) {
|
||||
v.dumpVertexList("Arguments", n.Arguments)
|
||||
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
|
||||
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
|
||||
v.dumpToken("ExtendsTkn", n.ExtendsTkn)
|
||||
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.dumpVertexList("Stmts", n.Stmts)
|
||||
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
|
||||
@ -311,31 +314,6 @@ func (v *Dumper) StmtClassConstList(n *ast.StmtClassConstList) {
|
||||
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) {
|
||||
v.print(0, "&ast.StmtClassMethod{\n")
|
||||
v.indent++
|
||||
@ -666,7 +644,9 @@ func (v *Dumper) StmtInterface(n *ast.StmtInterface) {
|
||||
v.dumpPosition(n.Position)
|
||||
v.dumpToken("InterfaceTkn", n.InterfaceTkn)
|
||||
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.dumpVertexList("Stmts", n.Stmts)
|
||||
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
|
||||
@ -675,19 +655,6 @@ func (v *Dumper) StmtInterface(n *ast.StmtInterface) {
|
||||
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) {
|
||||
v.print(0, "&ast.StmtLabel{\n")
|
||||
v.indent++
|
||||
@ -849,8 +816,6 @@ func (v *Dumper) StmtTrait(n *ast.StmtTrait) {
|
||||
v.dumpPosition(n.Position)
|
||||
v.dumpToken("TraitTkn", n.TraitTkn)
|
||||
v.dumpVertex("TraitName", n.TraitName)
|
||||
v.dumpVertex("Extends", n.Extends)
|
||||
v.dumpVertex("Implements", n.Implements)
|
||||
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
|
||||
v.dumpVertexList("Stmts", n.Stmts)
|
||||
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
|
||||
|
@ -281,12 +281,14 @@ func (f *formatter) StmtClass(n *ast.StmtClass) {
|
||||
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
if n.Extends != nil {
|
||||
n.ExtendsTkn = f.newToken(token.T_EXTENDS, []byte("extends"))
|
||||
n.Extends.Accept(f)
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
}
|
||||
|
||||
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(" "))
|
||||
}
|
||||
|
||||
@ -318,20 +320,6 @@ func (f *formatter) StmtClassConstList(n *ast.StmtClassConstList) {
|
||||
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) {
|
||||
for _, m := range n.Modifiers {
|
||||
m.Accept(f)
|
||||
@ -677,7 +665,8 @@ func (f *formatter) StmtInterface(n *ast.StmtInterface) {
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
|
||||
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(" "))
|
||||
}
|
||||
|
||||
@ -695,16 +684,6 @@ func (f *formatter) StmtInterface(n *ast.StmtInterface) {
|
||||
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) {
|
||||
n.LabelName.Accept(f)
|
||||
n.ColonTkn = f.newToken(':', []byte(":"))
|
||||
@ -865,16 +844,6 @@ func (f *formatter) StmtTrait(n *ast.StmtTrait) {
|
||||
n.TraitName.Accept(f)
|
||||
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("{"))
|
||||
|
||||
if len(n.Stmts) > 0 {
|
||||
|
@ -519,15 +519,13 @@ func TestFormatter_Class_Extends(t *testing.T) {
|
||||
ClassName: &ast.Identifier{
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
ClassName: &ast.NameName{
|
||||
Extends: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{
|
||||
Value: []byte("bar"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNop{},
|
||||
},
|
||||
@ -556,8 +554,7 @@ func TestFormatter_Class_Implements(t *testing.T) {
|
||||
ClassName: &ast.Identifier{
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Implements: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{
|
||||
@ -566,7 +563,6 @@ func TestFormatter_Class_Implements(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNop{},
|
||||
},
|
||||
@ -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) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
@ -1881,8 +1814,7 @@ func TestFormatter_StmtInterface_Extends(t *testing.T) {
|
||||
InterfaceName: &ast.Identifier{
|
||||
Value: []byte("foo"),
|
||||
},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
&ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{
|
||||
@ -1891,7 +1823,6 @@ func TestFormatter_StmtInterface_Extends(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNop{},
|
||||
},
|
||||
@ -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) {
|
||||
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) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
|
@ -73,11 +73,11 @@ func (nsr *NamespaceResolver) StmtGroupUse(n *ast.StmtGroupUse) {
|
||||
|
||||
func (nsr *NamespaceResolver) StmtClass(n *ast.StmtClass) {
|
||||
if n.Extends != nil {
|
||||
nsr.ResolveName(n.Extends.(*ast.StmtClassExtends).ClassName, "")
|
||||
nsr.ResolveName(n.Extends, "")
|
||||
}
|
||||
|
||||
if n.Implements != nil {
|
||||
for _, interfaceName := range n.Implements.(*ast.StmtClassImplements).InterfaceNames {
|
||||
for _, interfaceName := range n.Implements {
|
||||
nsr.ResolveName(interfaceName, "")
|
||||
}
|
||||
}
|
||||
@ -89,7 +89,7 @@ func (nsr *NamespaceResolver) StmtClass(n *ast.StmtClass) {
|
||||
|
||||
func (nsr *NamespaceResolver) StmtInterface(n *ast.StmtInterface) {
|
||||
if n.Extends != nil {
|
||||
for _, interfaceName := range n.Extends.(*ast.StmtInterfaceExtends).InterfaceNames {
|
||||
for _, interfaceName := range n.Extends {
|
||||
nsr.ResolveName(interfaceName, "")
|
||||
}
|
||||
}
|
||||
|
@ -401,14 +401,10 @@ func TestResolveClassName(t *testing.T) {
|
||||
|
||||
class := &ast.StmtClass{
|
||||
ClassName: &ast.Identifier{Value: []byte("A")},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
ClassName: nameAB,
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: nameAB,
|
||||
Implements: []ast.Vertex{
|
||||
nameBC,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
@ -436,12 +432,10 @@ func TestResolveInterfaceName(t *testing.T) {
|
||||
|
||||
interfaceNode := &ast.StmtInterface{
|
||||
InterfaceName: &ast.Identifier{Value: []byte("A")},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
nameAB,
|
||||
nameBC,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
|
@ -62,14 +62,6 @@ func (v *Null) StmtClassConstList(_ *ast.StmtClassConstList) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtClassExtends(_ *ast.StmtClassExtends) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtClassImplements(_ *ast.StmtClassImplements) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtClassMethod(_ *ast.StmtClassMethod) {
|
||||
// do nothing
|
||||
}
|
||||
@ -154,10 +146,6 @@ func (v *Null) StmtInterface(_ *ast.StmtInterface) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtInterfaceExtends(_ *ast.StmtInterfaceExtends) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) StmtLabel(_ *ast.StmtLabel) {
|
||||
// do nothing
|
||||
}
|
||||
|
@ -194,8 +194,10 @@ func (p *printer) StmtClass(n *ast.StmtClass) {
|
||||
p.printToken(n.OpenParenthesisTkn, p.ifNodeList(n.Arguments, []byte("(")))
|
||||
p.printSeparatedList(n.Arguments, n.SeparatorTkns, []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.Implements)
|
||||
p.printToken(n.ImplementsTkn, p.ifNodeList(n.Implements, []byte("implements")))
|
||||
p.printSeparatedList(n.Implements, n.ImplementsSeparatorTkns, []byte(","))
|
||||
p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
|
||||
p.printList(n.Stmts)
|
||||
p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
|
||||
@ -208,16 +210,6 @@ func (p *printer) StmtClassConstList(n *ast.StmtClassConstList) {
|
||||
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) {
|
||||
p.printList(n.Modifiers)
|
||||
p.printToken(n.FunctionTkn, []byte("function"))
|
||||
@ -436,17 +428,13 @@ func (p *printer) StmtInlineHtml(n *ast.StmtInlineHtml) {
|
||||
func (p *printer) StmtInterface(n *ast.StmtInterface) {
|
||||
p.printToken(n.InterfaceTkn, []byte("interface"))
|
||||
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.printList(n.Stmts)
|
||||
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) {
|
||||
p.printNode(n.LabelName)
|
||||
p.printToken(n.ColonTkn, []byte(":"))
|
||||
@ -525,8 +513,6 @@ func (p *printer) StmtThrow(n *ast.StmtThrow) {
|
||||
func (p *printer) StmtTrait(n *ast.StmtTrait) {
|
||||
p.printToken(n.TraitTkn, []byte("trait"))
|
||||
p.printNode(n.TraitName)
|
||||
p.printNode(n.Extends)
|
||||
p.printNode(n.Implements)
|
||||
p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
|
||||
p.printList(n.Stmts)
|
||||
p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
|
||||
|
@ -29,13 +29,11 @@ func TestPrinterPrintFile(t *testing.T) {
|
||||
&ast.NameNamePart{Value: []byte("Bar")},
|
||||
},
|
||||
},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
ClassName: &ast.NameName{
|
||||
Extends: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{Value: []byte("Baz")},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtClassMethod{
|
||||
Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("public")}},
|
||||
@ -3255,15 +3253,11 @@ func TestPrinterPrintStmtClass(t *testing.T) {
|
||||
n := &ast.StmtClass{
|
||||
Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("abstract")}},
|
||||
ClassName: &ast.Identifier{Value: []byte("Foo")},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
ClassName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
Implements: []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{
|
||||
&ast.StmtClassConstList{
|
||||
Modifiers: []ast.Vertex{
|
||||
@ -3307,15 +3301,11 @@ func TestPrinterPrintStmtAnonymousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
ClassName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
},
|
||||
Implements: &ast.StmtClassImplements{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
Implements: []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{
|
||||
&ast.StmtClassConstList{
|
||||
Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("public")}},
|
||||
@ -4122,12 +4112,10 @@ func TestPrinterPrintInterface(t *testing.T) {
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n := &ast.StmtInterface{
|
||||
InterfaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Extends: &ast.StmtInterfaceExtends{
|
||||
InterfaceNames: []ast.Vertex{
|
||||
Extends: []ast.Vertex{
|
||||
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Bar")}}},
|
||||
&ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Baz")}}},
|
||||
},
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtClassMethod{
|
||||
Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("public")}},
|
||||
|
Loading…
Reference in New Issue
Block a user