[refactoring] update ast structure of "Constant" nodes

This commit is contained in:
Vadym Slizov
2020-08-24 23:28:44 +03:00
parent 0285900fe5
commit c63213630a
19 changed files with 1457 additions and 1418 deletions

View File

@@ -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
}

View File

@@ -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))
}
}

View File

@@ -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{