[refactoring] update ast structure of "Switch", "Case", "Default" nodes; remove "CaseList" node

This commit is contained in:
Vadym Slizov
2020-09-06 12:49:08 +03:00
parent 0e73cd8852
commit f6cb2bff4d
21 changed files with 1882 additions and 2254 deletions
+149 -187
View File
@@ -9431,78 +9431,68 @@ func TestStmtSwitch(t *testing.T) {
},
Value: []byte("1"),
},
CaseList: &ast.StmtCaseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 17,
EndPos: 58,
CaseList: []ast.Vertex{
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 22,
EndPos: 36,
},
},
},
Cases: []ast.Vertex{
&ast.StmtCase{
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 22,
EndPos: 36,
StartPos: 27,
EndPos: 28,
},
},
Cond: &ast.ScalarLnumber{
Value: []byte("1"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 27,
EndPos: 28,
},
},
Value: []byte("1"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 30,
EndPos: 36,
},
StartPos: 30,
EndPos: 36,
},
},
},
},
&ast.StmtCase{
},
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 40,
EndPos: 54,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 40,
EndPos: 54,
StartPos: 45,
EndPos: 46,
},
},
Cond: &ast.ScalarLnumber{
Value: []byte("2"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 45,
EndPos: 46,
},
},
Value: []byte("2"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 48,
EndPos: 54,
},
StartPos: 48,
EndPos: 54,
},
},
},
@@ -9560,78 +9550,68 @@ func TestStmtSwitch_Semicolon(t *testing.T) {
},
Value: []byte("1"),
},
CaseList: &ast.StmtCaseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 17,
EndPos: 59,
CaseList: []ast.Vertex{
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 23,
EndPos: 37,
},
},
},
Cases: []ast.Vertex{
&ast.StmtCase{
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 23,
EndPos: 37,
StartPos: 28,
EndPos: 29,
},
},
Cond: &ast.ScalarLnumber{
Value: []byte("1"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 28,
EndPos: 29,
},
},
Value: []byte("1"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 31,
EndPos: 37,
},
StartPos: 31,
EndPos: 37,
},
},
},
},
&ast.StmtCase{
},
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
EndPos: 55,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
EndPos: 55,
StartPos: 46,
EndPos: 47,
},
},
Cond: &ast.ScalarLnumber{
Value: []byte("2"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 46,
EndPos: 47,
},
},
Value: []byte("2"),
},
Stmts: []ast.Vertex{
&ast.StmtBreak{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 49,
EndPos: 55,
},
StartPos: 49,
EndPos: 55,
},
},
},
@@ -9670,7 +9650,7 @@ func TestStmtSwitch_Alt(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtAltSwitch{
&ast.StmtSwitch{
Node: ast.Node{
Position: &position.Position{
StartLine: 2,
@@ -9679,6 +9659,7 @@ func TestStmtSwitch_Alt(t *testing.T) {
EndPos: 65,
},
},
Alt: true,
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
@@ -9690,71 +9671,61 @@ func TestStmtSwitch_Alt(t *testing.T) {
},
Value: []byte("1"),
},
CaseList: &ast.StmtCaseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 22,
EndPos: -1,
CaseList: []ast.Vertex{
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 22,
EndPos: -1,
},
},
},
Cases: []ast.Vertex{
&ast.StmtCase{
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 22,
EndPos: -1,
EndLine: 3,
StartPos: 27,
EndPos: 28,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 27,
EndPos: 28,
},
},
Value: []byte("1"),
},
Stmts: []ast.Vertex{},
Value: []byte("1"),
},
&ast.StmtDefault{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 33,
EndPos: -1,
},
Stmts: []ast.Vertex{},
},
&ast.StmtDefault{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 33,
EndPos: -1,
},
Stmts: []ast.Vertex{},
},
&ast.StmtCase{
Stmts: []ast.Vertex{},
},
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 45,
EndPos: -1,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 45,
EndPos: -1,
EndLine: 5,
StartPos: 50,
EndPos: 51,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
StartPos: 50,
EndPos: 51,
},
},
Value: []byte("2"),
},
Stmts: []ast.Vertex{},
Value: []byte("2"),
},
Stmts: []ast.Vertex{},
},
},
},
@@ -9788,7 +9759,7 @@ func TestStmtSwitch_AltSemicolon(t *testing.T) {
},
},
Stmts: []ast.Vertex{
&ast.StmtAltSwitch{
&ast.StmtSwitch{
Node: ast.Node{
Position: &position.Position{
StartLine: 2,
@@ -9797,6 +9768,7 @@ func TestStmtSwitch_AltSemicolon(t *testing.T) {
EndPos: 54,
},
},
Alt: true,
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
@@ -9808,60 +9780,50 @@ func TestStmtSwitch_AltSemicolon(t *testing.T) {
},
Value: []byte("1"),
},
CaseList: &ast.StmtCaseList{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 23,
EndPos: -1,
CaseList: []ast.Vertex{
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 23,
EndPos: -1,
},
},
},
Cases: []ast.Vertex{
&ast.StmtCase{
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 23,
EndPos: -1,
EndLine: 3,
StartPos: 28,
EndPos: 29,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 28,
EndPos: 29,
},
},
Value: []byte("1"),
},
Stmts: []ast.Vertex{},
Value: []byte("1"),
},
&ast.StmtCase{
Stmts: []ast.Vertex{},
},
&ast.StmtCase{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 34,
EndPos: -1,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 34,
EndPos: -1,
EndLine: 4,
StartPos: 39,
EndPos: 40,
},
},
Cond: &ast.ScalarLnumber{
Node: ast.Node{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 39,
EndPos: 40,
},
},
Value: []byte("2"),
},
Stmts: []ast.Vertex{},
Value: []byte("2"),
},
Stmts: []ast.Vertex{},
},
},
},