[refactoring] update ast structure of "Constant" nodes
This commit is contained in:
@@ -318,8 +318,10 @@ func (n *StmtClass) Accept(v NodeVisitor) {
|
||||
// StmtClassConstList node
|
||||
type StmtClassConstList struct {
|
||||
Node
|
||||
Modifiers []Vertex
|
||||
Consts []Vertex
|
||||
Modifiers []Vertex
|
||||
ConstTkn *token.Token
|
||||
Consts []Vertex
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtClassConstList) Accept(v NodeVisitor) {
|
||||
@@ -364,7 +366,9 @@ func (n *StmtClassMethod) Accept(v NodeVisitor) {
|
||||
// StmtConstList node
|
||||
type StmtConstList struct {
|
||||
Node
|
||||
Consts []Vertex
|
||||
ConstTkn *token.Token
|
||||
Consts []Vertex
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtConstList) Accept(v NodeVisitor) {
|
||||
@@ -374,8 +378,10 @@ func (n *StmtConstList) Accept(v NodeVisitor) {
|
||||
// StmtConstant node
|
||||
type StmtConstant struct {
|
||||
Node
|
||||
ConstantName Vertex
|
||||
Expr Vertex
|
||||
Name Vertex
|
||||
EqualTkn *token.Token
|
||||
Expr Vertex
|
||||
CommaTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtConstant) Accept(v NodeVisitor) {
|
||||
|
||||
@@ -487,10 +487,10 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
if nn.ConstantName != nil {
|
||||
t.visitor.Enter("ConstantName", true)
|
||||
t.Traverse(nn.ConstantName)
|
||||
t.visitor.Leave("ConstantName", true)
|
||||
if nn.Name != nil {
|
||||
t.visitor.Enter("Name", true)
|
||||
t.Traverse(nn.Name)
|
||||
t.visitor.Leave("Name", true)
|
||||
}
|
||||
if nn.Expr != nil {
|
||||
t.visitor.Enter("Expr", true)
|
||||
@@ -1334,9 +1334,9 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
t.visitor.Leave("Class", true)
|
||||
}
|
||||
if nn.ConstantName != nil {
|
||||
t.visitor.Enter("ConstantName", true)
|
||||
t.visitor.Enter("Name", true)
|
||||
t.Traverse(nn.ConstantName)
|
||||
t.visitor.Leave("ConstantName", true)
|
||||
t.visitor.Leave("Name", true)
|
||||
}
|
||||
case *ast.ExprClone:
|
||||
if nn == nil {
|
||||
|
||||
@@ -67,3 +67,18 @@ func (v *FilterTokens) StmtHaltCompiler(n *ast.StmtHaltCompiler) {
|
||||
n.CloseParenthesisTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtConstList(n *ast.StmtConstList) {
|
||||
n.ConstTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtClassConstList(n *ast.StmtClassConstList) {
|
||||
n.ConstTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtConstant(n *ast.StmtConstant) {
|
||||
n.EqualTkn = nil
|
||||
n.CommaTkn = nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (nsr *NamespaceResolver) StmtPropertyList(n *ast.StmtPropertyList) {
|
||||
|
||||
func (nsr *NamespaceResolver) StmtConstList(n *ast.StmtConstList) {
|
||||
for _, constant := range n.Consts {
|
||||
nsr.AddNamespacedName(constant, string(constant.(*ast.StmtConstant).ConstantName.(*ast.Identifier).Value))
|
||||
nsr.AddNamespacedName(constant, string(constant.(*ast.StmtConstant).Name.(*ast.Identifier).Value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -594,12 +594,12 @@ func TestResolveConstantsName(t *testing.T) {
|
||||
nameAB := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("A")}, &ast.NameNamePart{Value: []byte("B")}}}
|
||||
|
||||
constantB := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
Name: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
constantC := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
Name: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
@@ -638,12 +638,12 @@ func TestResolveNamespaces(t *testing.T) {
|
||||
relativeNameCE := &ast.NameRelative{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("C")}, &ast.NameNamePart{Value: []byte("E")}}}
|
||||
|
||||
constantB := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
Name: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
constantC := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
Name: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
|
||||
Reference in New Issue
Block a user