create ClassExtends ClassImplements InterfaceExtends nodes
This commit is contained in:
parent
cf4fb26764
commit
ac74ae3225
@ -98,7 +98,9 @@ nodes := &stmt.StmtList{
|
||||
&stmt.Class{
|
||||
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
|
||||
ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
Extends: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassMethod{
|
||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||
|
@ -11,13 +11,13 @@ type Class struct {
|
||||
ClassName node.Node
|
||||
Modifiers []node.Node
|
||||
ArgumentList *node.ArgumentList
|
||||
Extends node.Node
|
||||
Implements []node.Node
|
||||
Extends *ClassExtends
|
||||
Implements *ClassImplements
|
||||
Stmts []node.Node
|
||||
}
|
||||
|
||||
// NewClass node constructor
|
||||
func NewClass(ClassName node.Node, Modifiers []node.Node, ArgumentList *node.ArgumentList, Extends node.Node, Implements []node.Node, Stmts []node.Node, PhpDocComment string) *Class {
|
||||
func NewClass(ClassName node.Node, Modifiers []node.Node, ArgumentList *node.ArgumentList, Extends *ClassExtends, Implements *ClassImplements, Stmts []node.Node, PhpDocComment string) *Class {
|
||||
return &Class{
|
||||
PhpDocComment,
|
||||
ClassName,
|
||||
@ -69,11 +69,7 @@ func (n *Class) Walk(v walker.Visitor) {
|
||||
|
||||
if n.Implements != nil {
|
||||
vv := v.GetChildrenVisitor("Implements")
|
||||
for _, nn := range n.Implements {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
}
|
||||
}
|
||||
n.Implements.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Stmts != nil {
|
||||
|
38
node/stmt/n_class_extends.go
Normal file
38
node/stmt/n_class_extends.go
Normal file
@ -0,0 +1,38 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ClassExtends node
|
||||
type ClassExtends struct {
|
||||
ClassName node.Node
|
||||
}
|
||||
|
||||
// NewClassExtends node constructor
|
||||
func NewClassExtends(className node.Node) *ClassExtends {
|
||||
return &ClassExtends{
|
||||
className,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *ClassExtends) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *ClassExtends) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.ClassName != nil {
|
||||
vv := v.GetChildrenVisitor("ClassName")
|
||||
n.ClassName.Walk(vv)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
42
node/stmt/n_class_implements.go
Normal file
42
node/stmt/n_class_implements.go
Normal file
@ -0,0 +1,42 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ClassImplements node
|
||||
type ClassImplements struct {
|
||||
InterfaceNames []node.Node
|
||||
}
|
||||
|
||||
// NewClassImplements node constructor
|
||||
func NewClassImplements(interfaceNames []node.Node) *ClassImplements {
|
||||
return &ClassImplements{
|
||||
interfaceNames,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *ClassImplements) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *ClassImplements) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.InterfaceNames != nil {
|
||||
vv := v.GetChildrenVisitor("InterfaceNames")
|
||||
for _, nn := range n.InterfaceNames {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
@ -9,12 +9,12 @@ import (
|
||||
type Interface struct {
|
||||
PhpDocComment string
|
||||
InterfaceName node.Node
|
||||
Extends []node.Node
|
||||
Extends *InterfaceExtends
|
||||
Stmts []node.Node
|
||||
}
|
||||
|
||||
// NewInterface node constructor
|
||||
func NewInterface(InterfaceName node.Node, Extends []node.Node, Stmts []node.Node, PhpDocComment string) *Interface {
|
||||
func NewInterface(InterfaceName node.Node, Extends *InterfaceExtends, Stmts []node.Node, PhpDocComment string) *Interface {
|
||||
return &Interface{
|
||||
PhpDocComment,
|
||||
InterfaceName,
|
||||
@ -44,11 +44,7 @@ func (n *Interface) Walk(v walker.Visitor) {
|
||||
|
||||
if n.Extends != nil {
|
||||
vv := v.GetChildrenVisitor("Extends")
|
||||
for _, nn := range n.Extends {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
}
|
||||
}
|
||||
n.Extends.Walk(vv)
|
||||
}
|
||||
|
||||
if n.Stmts != nil {
|
||||
|
42
node/stmt/n_interface_extends.go
Normal file
42
node/stmt/n_interface_extends.go
Normal file
@ -0,0 +1,42 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// InterfaceExtends node
|
||||
type InterfaceExtends struct {
|
||||
InterfaceNames []node.Node
|
||||
}
|
||||
|
||||
// NewInterfaceExtends node constructor
|
||||
func NewInterfaceExtends(InterfaceNames []node.Node) *InterfaceExtends {
|
||||
return &InterfaceExtends{
|
||||
InterfaceNames,
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes returns node attributes as map
|
||||
func (n *InterfaceExtends) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
// Walk is invoked recursively until v.EnterNode returns true
|
||||
func (n *InterfaceExtends) Walk(v walker.Visitor) {
|
||||
if v.EnterNode(n) == false {
|
||||
return
|
||||
}
|
||||
|
||||
if n.InterfaceNames != nil {
|
||||
vv := v.GetChildrenVisitor("InterfaceNames")
|
||||
for _, nn := range n.InterfaceNames {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
}
|
@ -72,9 +72,11 @@ func TestClassExtends(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Extends: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{},
|
||||
@ -103,10 +105,12 @@ func TestClassImplement(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -136,15 +140,17 @@ func TestClassImplements(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -173,20 +179,24 @@ func TestAnonimousClass(t *testing.T) {
|
||||
Expr: &expr.New{
|
||||
Class: &stmt.Class{
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
Extends: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "foo"},
|
||||
},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
&name.NamePart{Value: "foo"},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -43,10 +43,12 @@ func TestInterfaceExtend(t *testing.T) {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "Foo"},
|
||||
Extends: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -74,15 +76,17 @@ func TestInterfaceExtends(t *testing.T) {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "Foo"},
|
||||
Extends: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
|
||||
@ -93,8 +95,8 @@ var nodesToTest = []struct {
|
||||
ClassName: &node.Identifier{},
|
||||
Modifiers: []node.Node{&stmt.Expression{}},
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
Extends: &node.Identifier{},
|
||||
Implements: []node.Node{&stmt.Expression{}},
|
||||
Extends: &stmt.ClassExtends{},
|
||||
Implements: &stmt.ClassImplements{},
|
||||
Stmts: []node.Node{&stmt.Expression{}},
|
||||
},
|
||||
[]string{"ClassName", "Modifiers", "ArgumentList", "Extends", "Implements", "Stmts"},
|
||||
@ -293,7 +295,7 @@ var nodesToTest = []struct {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "/** */",
|
||||
InterfaceName: &node.Identifier{},
|
||||
Extends: []node.Node{&stmt.Expression{}},
|
||||
Extends: &stmt.InterfaceExtends{},
|
||||
Stmts: []node.Node{&stmt.Expression{}},
|
||||
},
|
||||
[]string{"InterfaceName", "Extends", "Stmts"},
|
||||
@ -493,6 +495,31 @@ var nodesToTest = []struct {
|
||||
[]string{"Adaptations"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&stmt.ClassExtends{
|
||||
ClassName: &name.Name{},
|
||||
},
|
||||
[]string{"ClassName"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{},
|
||||
},
|
||||
},
|
||||
[]string{"InterfaceNames"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
{
|
||||
&stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{},
|
||||
},
|
||||
},
|
||||
[]string{"InterfaceNames"},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
type visitorMock struct {
|
||||
|
1289
php5/php5.go
1289
php5/php5.go
File diff suppressed because it is too large
Load Diff
44
php5/php5.y
44
php5/php5.y
@ -19,11 +19,15 @@ import (
|
||||
%}
|
||||
|
||||
%union{
|
||||
node node.Node
|
||||
token *scanner.Token
|
||||
list []node.Node
|
||||
foreachVariable foreachVariable
|
||||
node node.Node
|
||||
token *scanner.Token
|
||||
list []node.Node
|
||||
foreachVariable foreachVariable
|
||||
simpleIndirectReference simpleIndirectReference
|
||||
|
||||
ClassExtends *stmt.ClassExtends
|
||||
ClassImplements *stmt.ClassImplements
|
||||
InterfaceExtends *stmt.InterfaceExtends
|
||||
}
|
||||
|
||||
%type <token> $unk
|
||||
@ -235,7 +239,7 @@ import (
|
||||
%type <node> exit_expr yield_expr function_declaration_statement class_declaration_statement constant_declaration
|
||||
%type <node> else_single new_else_single unset_variable declare_statement
|
||||
%type <node> finally_statement additional_catch unticked_function_declaration_statement unticked_class_declaration_statement
|
||||
%type <node> optional_class_type parameter class_entry_type extends_from class_statement class_constant_declaration
|
||||
%type <node> optional_class_type parameter class_entry_type class_statement class_constant_declaration
|
||||
%type <node> trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias
|
||||
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
|
||||
%type <node> static_scalar_value static_operation
|
||||
@ -244,13 +248,16 @@ import (
|
||||
%type <node> switch_case_list
|
||||
%type <node> method_body
|
||||
%type <node> foreach_statement for_statement while_statement
|
||||
%type <ClassExtends> extends_from
|
||||
%type <ClassImplements> implements_list
|
||||
%type <InterfaceExtends> interface_extends_list
|
||||
|
||||
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
|
||||
%type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list
|
||||
%type <list> array_pair_list assignment_list lexical_var_list lexical_vars elseif_list new_elseif_list non_empty_for_expr
|
||||
%type <list> for_expr case_list echo_expr_list unset_variables declare_list catch_statement additional_catches
|
||||
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list implements_list
|
||||
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration interface_extends_list
|
||||
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
|
||||
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration
|
||||
%type <list> interface_list non_empty_function_call_parameter_list trait_list trait_adaptation_list non_empty_trait_adaptation_list
|
||||
%type <list> trait_reference_list non_empty_member_modifiers backticks_expr static_array_pair_list non_empty_static_array_pair_list
|
||||
|
||||
@ -912,7 +919,7 @@ catch_statement:
|
||||
variable := expr.NewVariable(identifier)
|
||||
yylex.(*Parser).positions.AddPosition(variable, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
|
||||
yylex.(*Parser).comments.AddComments(variable, $4.Comments())
|
||||
|
||||
|
||||
catch := stmt.NewCatch([]node.Node{$3}, variable, $7)
|
||||
yylex.(*Parser).positions.AddPosition(catch, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $8))
|
||||
yylex.(*Parser).comments.AddComments(catch, $1.Comments())
|
||||
@ -1085,7 +1092,12 @@ extends_from:
|
||||
/* empty */
|
||||
{ $$ = nil }
|
||||
| T_EXTENDS fully_qualified_class_name
|
||||
{ $$ = $2 }
|
||||
{
|
||||
$$ = stmt.NewClassExtends($2);
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
|
||||
}
|
||||
;
|
||||
|
||||
interface_entry:
|
||||
@ -1097,14 +1109,24 @@ interface_extends_list:
|
||||
/* empty */
|
||||
{ $$ = nil }
|
||||
| T_EXTENDS interface_list
|
||||
{ $$ = $2 }
|
||||
{
|
||||
$$ = stmt.NewInterfaceExtends($2);
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
|
||||
}
|
||||
;
|
||||
|
||||
implements_list:
|
||||
/* empty */
|
||||
{ $$ = nil }
|
||||
| T_IMPLEMENTS interface_list
|
||||
{ $$ = $2 }
|
||||
{
|
||||
$$ = stmt.NewClassImplements($2);
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
|
||||
}
|
||||
;
|
||||
|
||||
interface_list:
|
||||
|
@ -852,20 +852,8 @@ func TestPhp5(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Extends: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
@ -878,15 +866,33 @@ func TestPhp5(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1236,10 +1242,12 @@ func TestPhp5(t *testing.T) {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "Foo"},
|
||||
Extends: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1248,15 +1256,17 @@ func TestPhp5(t *testing.T) {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "Foo"},
|
||||
Extends: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
1294
php7/php7.go
1294
php7/php7.go
File diff suppressed because it is too large
Load Diff
61
php7/php7.y
61
php7/php7.y
@ -20,11 +20,15 @@ import (
|
||||
%}
|
||||
|
||||
%union{
|
||||
node node.Node
|
||||
token *scanner.Token
|
||||
list []node.Node
|
||||
foreachVariable foreachVariable
|
||||
str string
|
||||
node node.Node
|
||||
token *scanner.Token
|
||||
list []node.Node
|
||||
foreachVariable foreachVariable
|
||||
str string
|
||||
|
||||
ClassExtends *stmt.ClassExtends
|
||||
ClassImplements *stmt.ClassImplements
|
||||
InterfaceExtends *stmt.InterfaceExtends
|
||||
}
|
||||
|
||||
%type <token> $unk
|
||||
@ -243,7 +247,7 @@ import (
|
||||
%type <node> const_decl inner_statement
|
||||
%type <node> expr optional_expr
|
||||
%type <node> declare_statement finally_statement unset_variable variable
|
||||
%type <node> extends_from parameter optional_type argument expr_without_variable global_var
|
||||
%type <node> parameter optional_type argument expr_without_variable global_var
|
||||
%type <node> static_var class_statement trait_adaptation trait_precedence trait_alias
|
||||
%type <node> absolute_trait_method_reference trait_method_reference property echo_expr
|
||||
%type <node> new_expr anonymous_class class_name class_name_reference simple_variable
|
||||
@ -265,6 +269,9 @@ import (
|
||||
%type <node> switch_case_list
|
||||
%type <node> method_body
|
||||
%type <node> foreach_statement for_statement while_statement
|
||||
%type <ClassExtends> extends_from
|
||||
%type <ClassImplements> implements_list
|
||||
%type <InterfaceExtends> interface_extends_list
|
||||
|
||||
%type <node> member_modifier
|
||||
%type <node> use_type
|
||||
@ -278,7 +285,7 @@ import (
|
||||
%type <list> use_declarations lexical_var_list lexical_vars isset_variables non_empty_array_pair_list
|
||||
%type <list> array_pair_list non_empty_argument_list top_statement_list
|
||||
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list
|
||||
%type <list> interface_extends_list implements_list method_modifiers variable_modifiers
|
||||
%type <list> method_modifiers variable_modifiers
|
||||
%type <list> non_empty_member_modifiers name_list class_modifiers
|
||||
|
||||
%type <str> backup_doc_comment
|
||||
@ -1199,12 +1206,6 @@ class_declaration_statement:
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $2, comment.ClassToken)
|
||||
yylex.(*Parser).comments.AddFromToken(name, $3, comment.StringToken)
|
||||
if $4 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, $4)
|
||||
}
|
||||
if $5 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($5))
|
||||
}
|
||||
yylex.(*Parser).comments.AddFromToken($$, $7, comment.OpenCurlyBracesToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $9, comment.CloseCurlyBracesToken)
|
||||
}
|
||||
@ -1220,12 +1221,6 @@ class_declaration_statement:
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ClassToken)
|
||||
yylex.(*Parser).comments.AddFromToken(name, $2, comment.StringToken)
|
||||
if $3 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, $3)
|
||||
}
|
||||
if $4 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($4))
|
||||
}
|
||||
yylex.(*Parser).comments.AddFromToken($$, $6, comment.OpenCurlyBracesToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $8, comment.CloseCurlyBracesToken)
|
||||
}
|
||||
@ -1292,9 +1287,6 @@ interface_declaration_statement:
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.InterfaceToken)
|
||||
yylex.(*Parser).comments.AddFromToken(name, $2, comment.StringToken)
|
||||
if $3 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($3))
|
||||
}
|
||||
yylex.(*Parser).comments.AddFromToken($$, $5, comment.OpenCurlyBracesToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $7, comment.CloseCurlyBracesToken)
|
||||
}
|
||||
@ -1305,7 +1297,10 @@ extends_from:
|
||||
{ $$ = nil }
|
||||
| T_EXTENDS name
|
||||
{
|
||||
$$ = $2;
|
||||
$$ = stmt.NewClassExtends($2);
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ExtendsToken)
|
||||
@ -1317,10 +1312,13 @@ interface_extends_list:
|
||||
{ $$ = nil }
|
||||
| T_EXTENDS name_list
|
||||
{
|
||||
$$ = $2;
|
||||
$$ = stmt.NewInterfaceExtends($2);
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken(firstNode($$), $1, comment.ExtendsToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ExtendsToken)
|
||||
}
|
||||
;
|
||||
|
||||
@ -1329,10 +1327,13 @@ implements_list:
|
||||
{ $$ = nil }
|
||||
| T_IMPLEMENTS name_list
|
||||
{
|
||||
$$ = $2;
|
||||
$$ = stmt.NewClassImplements($2);
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken(firstNode($$), $1, comment.ImplementsToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ImplementsToken)
|
||||
}
|
||||
;
|
||||
|
||||
@ -2432,12 +2433,6 @@ anonymous_class:
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ClassToken)
|
||||
if $3 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, $3)
|
||||
}
|
||||
if $4 != nil {
|
||||
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($4))
|
||||
}
|
||||
yylex.(*Parser).comments.AddFromToken($$, $6, comment.OpenCurlyBracesToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $8, comment.CloseCurlyBracesToken)
|
||||
}
|
||||
|
@ -925,20 +925,8 @@ func TestPhp7(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Extends: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
@ -951,15 +939,33 @@ func TestPhp7(t *testing.T) {
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Class{
|
||||
ClassName: &node.Identifier{Value: "foo"},
|
||||
Modifiers: []node.Node{
|
||||
&node.Identifier{Value: "final"},
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -970,20 +976,24 @@ func TestPhp7(t *testing.T) {
|
||||
Class: &stmt.Class{
|
||||
|
||||
ArgumentList: &node.ArgumentList{},
|
||||
Extends: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "foo"},
|
||||
},
|
||||
},
|
||||
Implements: []node.Node{
|
||||
&name.Name{
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
&name.NamePart{Value: "foo"},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "bar"},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1294,10 +1304,12 @@ func TestPhp7(t *testing.T) {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "Foo"},
|
||||
Extends: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1306,15 +1318,17 @@ func TestPhp7(t *testing.T) {
|
||||
&stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "Foo"},
|
||||
Extends: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
&name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1553,12 +1553,12 @@ func (p *Printer) printStmtClass(n node.Node) {
|
||||
|
||||
if nn.Extends != nil {
|
||||
io.WriteString(p.w, " extends ")
|
||||
p.Print(nn.Extends)
|
||||
p.Print(nn.Extends.ClassName)
|
||||
}
|
||||
|
||||
if nn.Implements != nil {
|
||||
io.WriteString(p.w, " implements ")
|
||||
p.joinPrint(", ", nn.Implements)
|
||||
p.joinPrint(", ", nn.Implements.InterfaceNames)
|
||||
}
|
||||
|
||||
io.WriteString(p.w, "\n")
|
||||
@ -1910,7 +1910,7 @@ func (p *Printer) printStmtInterface(n node.Node) {
|
||||
|
||||
if nn.Extends != nil {
|
||||
io.WriteString(p.w, " extends ")
|
||||
p.joinPrint(", ", nn.Extends)
|
||||
p.joinPrint(", ", nn.Extends.InterfaceNames)
|
||||
}
|
||||
|
||||
io.WriteString(p.w, "\n")
|
||||
|
@ -35,9 +35,11 @@ func TestPrintFile(t *testing.T) {
|
||||
&name.NamePart{Value: "Bar"},
|
||||
},
|
||||
},
|
||||
Extends: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{
|
||||
Parts: []node.Node{
|
||||
&name.NamePart{Value: "Baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
@ -2482,10 +2484,14 @@ func TestPrintStmtClass(t *testing.T) {
|
||||
&stmt.Class{
|
||||
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
|
||||
ClassName: &node.Identifier{Value: "Foo"},
|
||||
Extends: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
Implements: []node.Node{
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassConstList{
|
||||
@ -2533,10 +2539,14 @@ func TestPrintStmtAnonymousClass(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Extends: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
Implements: []node.Node{
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Quuz"}}},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassConstList{
|
||||
@ -3382,9 +3392,11 @@ func TestPrintInterface(t *testing.T) {
|
||||
Stmts: []node.Node{
|
||||
&stmt.Interface{
|
||||
InterfaceName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}},
|
||||
Extends: []node.Node{
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}},
|
||||
&name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}},
|
||||
},
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.ClassMethod{
|
||||
|
@ -66,11 +66,13 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
|
||||
|
||||
case *stmt.Class:
|
||||
if n.Extends != nil {
|
||||
nsr.ResolveName(n.Extends, "")
|
||||
nsr.ResolveName(n.Extends.ClassName, "")
|
||||
}
|
||||
|
||||
for _, interfaceName := range n.Implements {
|
||||
nsr.ResolveName(interfaceName, "")
|
||||
if n.Implements != nil {
|
||||
for _, interfaceName := range n.Implements.InterfaceNames {
|
||||
nsr.ResolveName(interfaceName, "")
|
||||
}
|
||||
}
|
||||
|
||||
if n.ClassName != nil {
|
||||
@ -78,8 +80,10 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
|
||||
}
|
||||
|
||||
case *stmt.Interface:
|
||||
for _, interfaceName := range n.Extends {
|
||||
nsr.ResolveName(interfaceName, "")
|
||||
if n.Extends != nil {
|
||||
for _, interfaceName := range n.Extends.InterfaceNames {
|
||||
nsr.ResolveName(interfaceName, "")
|
||||
}
|
||||
}
|
||||
|
||||
nsr.AddNamespacedName(n, n.InterfaceName.(*node.Identifier).Value)
|
||||
|
@ -411,9 +411,13 @@ func TestResolveClassName(t *testing.T) {
|
||||
class := &stmt.Class{
|
||||
PhpDocComment: "",
|
||||
ClassName: &node.Identifier{Value: "A"},
|
||||
Extends: nameAB,
|
||||
Implements: []node.Node{
|
||||
nameBC,
|
||||
Extends: &stmt.ClassExtends{
|
||||
ClassName: nameAB,
|
||||
},
|
||||
Implements: &stmt.ClassImplements{
|
||||
InterfaceNames: []node.Node{
|
||||
nameBC,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -442,9 +446,11 @@ func TestResolveInterfaceName(t *testing.T) {
|
||||
interfaceNode := &stmt.Interface{
|
||||
PhpDocComment: "",
|
||||
InterfaceName: &node.Identifier{Value: "A"},
|
||||
Extends: []node.Node{
|
||||
nameAB,
|
||||
nameBC,
|
||||
Extends: &stmt.InterfaceExtends{
|
||||
InterfaceNames: []node.Node{
|
||||
nameAB,
|
||||
nameBC,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user