From c63213630a3faf3de16a7e72c6b48662fc6b58a0 Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Mon, 24 Aug 2020 23:28:44 +0300 Subject: [PATCH] [refactoring] update ast structure of "Constant" nodes --- internal/php5/parser_test.go | 16 +- internal/php5/php5.go | Bin 295716 -> 295135 bytes internal/php5/php5.y | 199 ++++++++++++--------- internal/php5/php5_test.go | 16 +- internal/php7/parser_test.go | 20 +-- internal/php7/php7.go | Bin 251010 -> 251161 bytes internal/php7/php7.y | 94 +++++----- internal/php7/php7_test.go | 18 +- pkg/ast/node.go | 16 +- pkg/ast/traverser/dfs.go | 12 +- pkg/ast/visitor/filter_tokens.go | 15 ++ pkg/ast/visitor/namespace_resolver.go | 2 +- pkg/ast/visitor/namespace_resolver_test.go | 16 +- pkg/printer/pretty_printer.go | 2 +- pkg/printer/pretty_printer_test.go | 32 ++-- pkg/printer/printer.go | 78 ++------ pkg/printer/printer_parsed_php5_test.go | 5 +- pkg/printer/printer_parsed_php7_test.go | 5 +- pkg/printer/printer_test.go | 40 ++--- 19 files changed, 298 insertions(+), 288 deletions(-) diff --git a/internal/php5/parser_test.go b/internal/php5/parser_test.go index ab1446d..52dc6df 100644 --- a/internal/php5/parser_test.go +++ b/internal/php5/parser_test.go @@ -4154,7 +4154,7 @@ func TestStmtClassConstList_WithoutModifiers(t *testing.T) { EndPos: 27, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -4186,7 +4186,7 @@ func TestStmtClassConstList_WithoutModifiers(t *testing.T) { EndPos: 36, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5124,7 +5124,7 @@ func TestStmtConstList(t *testing.T) { EndPos: 16, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5156,7 +5156,7 @@ func TestStmtConstList(t *testing.T) { EndPos: 25, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5451,7 +5451,7 @@ func TestStmtDeclare(t *testing.T) { EndPos: 18, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5530,7 +5530,7 @@ func TestStmtDeclare_Stmts(t *testing.T) { EndPos: 18, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5562,7 +5562,7 @@ func TestStmtDeclare_Stmts(t *testing.T) { EndPos: 34, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5642,7 +5642,7 @@ func TestStmtDeclare_Alt(t *testing.T) { EndPos: 18, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, diff --git a/internal/php5/php5.go b/internal/php5/php5.go index 926e1bebabfb0937d9f5ece935e29a3d8e94ac78..f836b8b6f3ba8c2b0999e5a704be6ac12529220a 100644 GIT binary patch delta 10677 zcmeHNXLyxWwtm*$UlMZ&X%G<74pB-}lGAenga9e1K@$|I0*O+jB>@767zpSLUKxso zEOA7NI$$LzxNWr2JMt)MP!W{@f?Nkt2C$5GR2=TR_jk@oM4jihANR-g2j*M5t-b2I z);^E^Hu>n{fy>ic|IdDT%mefQm%W&l|>w3|`fT3YBXBJwrS%NJZr0 znSJPH-n~NhX6MJUADbA$RVN<$kU@ zAyT=aJ6UFHc3w&E^YTKlAzp7gpwIk@nC4NYo>=_T6HkJV$VU3i_JXZaoaM96{Z9W4 zR(;f;>jz_X^JC;R2Pz!cg$%FuH_myQxVQ`)EDp$4)-E{lG5&rC#1hEo{g2t##F5j= zsU*tdh>cyqE0&AiJh_6}$KM>*M2=C!z};dX*RB+?GB!4r7gtc%4mrIptD0S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IDd7{J!yyymIuS6%hWhSoiBZ`7F2i>B3W^sa*c9*3*t zHMAmmjtA{|gF#&JdN-fWcrJb=-pb~j##TKpj|9pxeUat~dV-(lH?IF%p5CQ`DvRa6k zG{3QD-R>Jd)-iDmZ|I3XFc_F(6;fE5tuk)cOf**iy44B~l%`4ibX%)=^_%8sUi}B_ zMUCXq0J=k!x3$J;@Tu!Ndty(g^(QbBd@6|J{Z0$5X@dk?s!plaOmLN|155UAg{V_V z$0#{!Vh_U8R+FN2WZH@jgx|`>Lu{?^r1`tTcXoiz@RtmUovjS@O$W<`hx0Ur(LSNk z8-C2;lyC3~lim?Z1p=2yvhxG@OmMa2(B9+Kn{|Kk{`O~-bv^JqogqD8GSn&kpBEF*!bZOq%9%B48L9FhZ zMKJ2XhFq9|P7a=9@MN?Df8JK@%?OwF%lxtlUp&sLqd~lv<$2(sUjnsmH7J6r110`*L0#wal@D-_E`IGen61UHO zMCvX3{1$T&YT^*=j{J`TzOlm7ds|~R)o>greIOcOZq;Ih)l2B$ikh*X$+QYjVR)tq zJb*18WhDqM%7?3Pp*2j^9b?%KV2>7Bcj{5Lz_T`Vh4uteutPmN!73n`rk^}@Z=vNx zYn+z2!u(Uh4)&%UW^t3LR+!p|I}@uZCdAa>4tyJ@dAOk=`_42(j9HWM@P2Ir8Y?== zGhSy_@!?{8xH2X9?9y*KhUi-bdKJ4d)Q>L))U)FUgo^nyU=dDVdTm;#*_wu~Xsvk{ M=3*)21X8*94?0P0BLDyZ diff --git a/internal/php5/php5.y b/internal/php5/php5.y index 5d11a5d..181e9a4 100644 --- a/internal/php5/php5.y +++ b/internal/php5/php5.y @@ -447,14 +447,9 @@ top_statement: } | constant_declaration ';' { + $1.(*ast.StmtConstList).SemiColonTkn = $2 + $1.(*ast.StmtConstList).Node.Position = position.NewNodeTokenPosition($1, $2) $$ = $1 - - // save position - $$.GetNode().Position = position.NewNodeTokenPosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Stmts, $2.SkippedTokens) - yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens) } ; @@ -725,39 +720,52 @@ use_const_declaration: constant_declaration: constant_declaration ',' T_STRING '=' static_scalar { - name := &ast.Identifier{ast.Node{}, $3.Value} - constant := &ast.StmtConstant{ast.Node{}, name, $5} constList := $1.(*ast.StmtConstList) - lastConst := lastNode(constList.Consts) - constList.Consts = append(constList.Consts, constant) + constList.Node.Position = position.NewNodesPosition($1, $5) + lastNode(constList.Consts).(*ast.StmtConstant).CommaTkn = $2 + constList.Consts = append(constList.Consts, &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($3, $5), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($3), + }, + Value: $3.Value, + }, + EqualTkn: $4, + Expr: $5, + }) + $$ = $1 - // save position - name.GetNode().Position = position.NewTokenPosition($3) - constant.GetNode().Position = position.NewTokenNodePosition($3, $5) - $$.GetNode().Position = position.NewNodeNodeListPosition($1, constList.Consts) - - // save comments - yylex.(*Parser).setFreeFloating(lastConst, token.End, $2.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Start, $3.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Name, $4.SkippedTokens) + yylex.(*Parser).setFreeFloating(lastNode($$.(*ast.StmtConstList).Consts).(*ast.StmtConstant).Name, token.Start, $3.SkippedTokens) } | T_CONST T_STRING '=' static_scalar { - name := &ast.Identifier{ast.Node{}, $2.Value} - constant := &ast.StmtConstant{ast.Node{}, name, $4} - constList := []ast.Vertex{constant} - $$ = &ast.StmtConstList{ast.Node{}, constList} + $$ = &ast.StmtConstList{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $4), + }, + ConstTkn: $1, + Consts: []ast.Vertex{ + &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($2, $4), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($2), + }, + Value: $2.Value, + }, + EqualTkn: $3, + Expr: $4, + }, + }, + } - // save position - name.GetNode().Position = position.NewTokenPosition($2) - constant.GetNode().Position = position.NewTokenNodePosition($2, $4) - $$.GetNode().Position = position.NewTokenNodeListPosition($1, constList) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Start, $2.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Name, $3.SkippedTokens) + yylex.(*Parser).setFreeFloating(lastNode($$.(*ast.StmtConstList).Consts).(*ast.StmtConstant).Name, token.Start, $2.SkippedTokens) } ; @@ -1735,32 +1743,42 @@ declare_statement: declare_list: T_STRING '=' static_scalar { - name := &ast.Identifier{ast.Node{}, $1.Value} - constant := &ast.StmtConstant{ast.Node{}, name, $3} - $$ = []ast.Vertex{constant} + $$ = []ast.Vertex{ + &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $3), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($1), + }, + Value: $1.Value, + }, + EqualTkn: $2, + Expr: $3, + }, + } - // save position - name.GetNode().Position = position.NewTokenPosition($1) - constant.GetNode().Position = position.NewTokenNodePosition($1, $3) - - // save comments - yylex.(*Parser).setFreeFloating(constant, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Name, $2.SkippedTokens) + yylex.(*Parser).setFreeFloating(lastNode($$).(*ast.StmtConstant).Name, token.Start, $1.SkippedTokens) } | declare_list ',' T_STRING '=' static_scalar { - name := &ast.Identifier{ast.Node{}, $3.Value} - constant := &ast.StmtConstant{ast.Node{}, name, $5} - $$ = append($1, constant) + lastNode($1).(*ast.StmtConstant).CommaTkn = $2 + $$ = append($1, &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($3, $5), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($3), + }, + Value: $3.Value, + }, + EqualTkn: $4, + Expr: $5, + }) - // save position - name.GetNode().Position = position.NewTokenPosition($3) - constant.GetNode().Position = position.NewTokenNodePosition($3, $5) - - // save comments - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Start, $3.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Name, $4.SkippedTokens) + yylex.(*Parser).setFreeFloating(lastNode($$).(*ast.StmtConstant).Name, token.Start, $3.SkippedTokens) } ; @@ -2359,14 +2377,9 @@ class_statement: } | class_constant_declaration ';' { + $1.(*ast.StmtClassConstList).SemiColonTkn = $2 + $1.(*ast.StmtClassConstList).Node.Position = position.NewNodeTokenPosition($1, $2) $$ = $1 - - // save position - $$.GetNode().Position = position.NewNodeTokenPosition($1, $2) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.ConstList, $2.SkippedTokens) - yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens) } | trait_use_statement { @@ -2797,38 +2810,52 @@ class_variable_declaration: class_constant_declaration: class_constant_declaration ',' T_STRING '=' static_scalar { - name := &ast.Identifier{ast.Node{}, $3.Value} - constant := &ast.StmtConstant{ast.Node{}, name, $5} constList := $1.(*ast.StmtClassConstList) - lastConst := lastNode(constList.Consts) - constList.Consts = append(constList.Consts, constant) + constList.Node.Position = position.NewNodesPosition($1, $5) + lastNode($$.(*ast.StmtClassConstList).Consts).(*ast.StmtConstant).CommaTkn = $2 + constList.Consts = append(constList.Consts, &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($3, $5), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($3), + }, + Value: $3.Value, + }, + EqualTkn: $4, + Expr: $5, + }) + $$ = $1 - // save position - name.GetNode().Position = position.NewTokenPosition($3) - constant.GetNode().Position = position.NewTokenNodePosition($3, $5) - $1.GetNode().Position = position.NewNodesPosition($1, $5) - - // save comments - yylex.(*Parser).setFreeFloating(lastConst, token.End, $2.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Start, $3.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Name, $4.SkippedTokens) + yylex.(*Parser).setFreeFloating(lastNode($$.(*ast.StmtClassConstList).Consts).(*ast.StmtConstant).Name, token.Start, $3.SkippedTokens) } | T_CONST T_STRING '=' static_scalar { - name := &ast.Identifier{ast.Node{}, $2.Value} - constant := &ast.StmtConstant{ast.Node{}, name, $4} - $$ = &ast.StmtClassConstList{ast.Node{}, nil, []ast.Vertex{constant}} + $$ = &ast.StmtClassConstList{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $4), + }, + ConstTkn: $1, + Consts: []ast.Vertex{ + &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($2, $4), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($2), + }, + Value: $2.Value, + }, + EqualTkn: $3, + Expr: $4, + }, + }, + } - // save position - name.GetNode().Position = position.NewTokenPosition($2) - constant.GetNode().Position = position.NewTokenNodePosition($2, $4) - $$.GetNode().Position = position.NewTokenNodePosition($1, $4) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Start, $2.SkippedTokens) - yylex.(*Parser).setFreeFloating(constant, token.Name, $3.SkippedTokens) + yylex.(*Parser).setFreeFloating(lastNode($$.(*ast.StmtClassConstList).Consts).(*ast.StmtConstant).Name, token.Start, $2.SkippedTokens) } ; diff --git a/internal/php5/php5_test.go b/internal/php5/php5_test.go index a8b3fcb..ad42cb2 100644 --- a/internal/php5/php5_test.go +++ b/internal/php5/php5_test.go @@ -3134,7 +3134,7 @@ func TestPhp5(t *testing.T) { EndPos: 1071, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 58, @@ -3166,7 +3166,7 @@ func TestPhp5(t *testing.T) { EndPos: 1080, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 58, @@ -3793,7 +3793,7 @@ func TestPhp5(t *testing.T) { EndPos: 1409, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 67, @@ -3825,7 +3825,7 @@ func TestPhp5(t *testing.T) { EndPos: 1418, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 67, @@ -4020,7 +4020,7 @@ func TestPhp5(t *testing.T) { EndPos: 1512, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 71, @@ -4074,7 +4074,7 @@ func TestPhp5(t *testing.T) { EndPos: 1530, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 72, @@ -4106,7 +4106,7 @@ func TestPhp5(t *testing.T) { EndPos: 1546, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 72, @@ -4162,7 +4162,7 @@ func TestPhp5(t *testing.T) { EndPos: 1566, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 73, diff --git a/internal/php7/parser_test.go b/internal/php7/parser_test.go index 4cb66c8..b0e66dd 100644 --- a/internal/php7/parser_test.go +++ b/internal/php7/parser_test.go @@ -4318,7 +4318,7 @@ func TestStmtClassConstList(t *testing.T) { EndPos: 34, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -4350,7 +4350,7 @@ func TestStmtClassConstList(t *testing.T) { EndPos: 43, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -4442,7 +4442,7 @@ func TestStmtClassConstList_WithoutModifiers(t *testing.T) { EndPos: 27, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -4474,7 +4474,7 @@ func TestStmtClassConstList_WithoutModifiers(t *testing.T) { EndPos: 36, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5721,7 +5721,7 @@ func TestStmtConstList(t *testing.T) { EndPos: 16, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -5753,7 +5753,7 @@ func TestStmtConstList(t *testing.T) { EndPos: 25, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -6048,7 +6048,7 @@ func TestStmtDeclare(t *testing.T) { EndPos: 18, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -6127,7 +6127,7 @@ func TestStmtDeclare_Stmts(t *testing.T) { EndPos: 18, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -6159,7 +6159,7 @@ func TestStmtDeclare_Stmts(t *testing.T) { EndPos: 34, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, @@ -6239,7 +6239,7 @@ func TestStmtDeclare_Alt(t *testing.T) { EndPos: 18, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 1, diff --git a/internal/php7/php7.go b/internal/php7/php7.go index f9ec7d41e2833796643a118937546f7677979e72..39c787688584d5c9527277dfd352e7f8c8151870 100644 GIT binary patch delta 12046 zcmd5?dvw>uu|K<;Hwk%=gg`=mzd(fWNc_DY5C{>eD2gD85d;$iDi8w!tULq(L9781 zXvqkQ5=EZoih`~dkf2sk)DY!XTQ4nIxku}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internal/php7/php7.y index 3013dfd..ab3d550 100644 --- a/internal/php7/php7.y +++ b/internal/php7/php7.y @@ -536,15 +536,14 @@ top_statement: } | T_CONST const_list ';' { - $$ = &ast.StmtConstList{ast.Node{}, $2} - - // save position - $$.GetNode().Position = position.NewTokensPosition($1, $3) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.SkippedTokens) - yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens) + $$ = &ast.StmtConstList{ + Node: ast.Node{ + Position: position.NewTokensPosition($1, $3), + }, + ConstTkn: $1, + Consts: $2, + SemiColonTkn: $3, + } } ; @@ -782,10 +781,9 @@ use_declaration: const_list: const_list ',' const_decl { - $$ = append($1, $3) + lastNode($1).(*ast.StmtConstant).CommaTkn = $2 - // save comments - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) + $$ = append($1, $3) } | const_decl { @@ -2198,20 +2196,15 @@ class_statement: } | method_modifiers T_CONST class_const_list ';' { - $$ = &ast.StmtClassConstList{ast.Node{}, $1, $3} - - // save position - $$.GetNode().Position = position.NewOptionalListTokensPosition($1, $2, $4) - - // save comments - if len($1) > 0 { - yylex.(*Parser).MoveFreeFloating($1[0], $$) - yylex.(*Parser).setFreeFloating($$, token.ModifierList, $2.SkippedTokens) - } else { - yylex.(*Parser).setFreeFloating($$, token.Start, $2.SkippedTokens) + $$ = &ast.StmtClassConstList{ + Node: ast.Node{ + Position: position.NewOptionalListTokensPosition($1, $2, $4), + }, + Modifiers: $1, + ConstTkn: $2, + Consts: $3, + SemiColonTkn: $4, } - yylex.(*Parser).setFreeFloating($$, token.ConstList, $4.SkippedTokens) - yylex.(*Parser).setToken($$, token.SemiColon, $4.SkippedTokens) } | T_USE name_list trait_adaptations { @@ -2616,10 +2609,9 @@ property: class_const_list: class_const_list ',' class_const_decl { - $$ = append($1, $3) + lastNode($1).(*ast.StmtConstant).CommaTkn = $2 - // save comments - yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens) + $$ = append($1, $3) } | class_const_decl { @@ -2630,32 +2622,42 @@ class_const_list: class_const_decl: identifier '=' expr backup_doc_comment { - name := &ast.Identifier{ast.Node{}, $1.Value} - $$ = &ast.StmtConstant{ast.Node{}, name, $3} + $$ = &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $3), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($1), + }, + Value: $1.Value, + }, + EqualTkn: $2, + Expr: $3, + } - // save position - name.GetNode().Position = position.NewTokenPosition($1) - $$.GetNode().Position = position.NewTokenNodePosition($1, $3) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens) + yylex.(*Parser).setFreeFloating($$.(*ast.StmtConstant).Name, token.Start, $1.SkippedTokens) } ; const_decl: T_STRING '=' expr backup_doc_comment { - name := &ast.Identifier{ast.Node{}, $1.Value} - $$ = &ast.StmtConstant{ast.Node{}, name, $3} + $$ = &ast.StmtConstant{ + Node: ast.Node{ + Position: position.NewTokenNodePosition($1, $3), + }, + Name: &ast.Identifier{ + Node: ast.Node{ + Position: position.NewTokenPosition($1), + }, + Value: $1.Value, + }, + EqualTkn: $2, + Expr: $3, + } - // save position - name.GetNode().Position = position.NewTokenPosition($1) - $$.GetNode().Position = position.NewTokenNodePosition($1, $3) - - // save comments - yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) - yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens) + yylex.(*Parser).setFreeFloating($$.(*ast.StmtConstant).Name, token.Start, $1.SkippedTokens) } ; diff --git a/internal/php7/php7_test.go b/internal/php7/php7_test.go index d717743..8f474fa 100644 --- a/internal/php7/php7_test.go +++ b/internal/php7/php7_test.go @@ -3919,7 +3919,7 @@ func TestPhp7(t *testing.T) { EndPos: 1322, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 70, @@ -3951,7 +3951,7 @@ func TestPhp7(t *testing.T) { EndPos: 1331, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 70, @@ -4018,7 +4018,7 @@ func TestPhp7(t *testing.T) { EndPos: 1359, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 71, @@ -4050,7 +4050,7 @@ func TestPhp7(t *testing.T) { EndPos: 1368, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 71, @@ -4732,7 +4732,7 @@ func TestPhp7(t *testing.T) { EndPos: 1693, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 81, @@ -4764,7 +4764,7 @@ func TestPhp7(t *testing.T) { EndPos: 1702, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 81, @@ -4959,7 +4959,7 @@ func TestPhp7(t *testing.T) { EndPos: 1796, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 85, @@ -5013,7 +5013,7 @@ func TestPhp7(t *testing.T) { EndPos: 1814, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 86, @@ -5069,7 +5069,7 @@ func TestPhp7(t *testing.T) { EndPos: 1834, }, }, - ConstantName: &ast.Identifier{ + Name: &ast.Identifier{ Node: ast.Node{ Position: &position.Position{ StartLine: 87, diff --git a/pkg/ast/node.go b/pkg/ast/node.go index 4b633fe..038dc46 100644 --- a/pkg/ast/node.go +++ b/pkg/ast/node.go @@ -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) { diff --git a/pkg/ast/traverser/dfs.go b/pkg/ast/traverser/dfs.go index 7e41a44..3d9d5a5 100644 --- a/pkg/ast/traverser/dfs.go +++ b/pkg/ast/traverser/dfs.go @@ -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 { diff --git a/pkg/ast/visitor/filter_tokens.go b/pkg/ast/visitor/filter_tokens.go index ff7f336..5cd2215 100644 --- a/pkg/ast/visitor/filter_tokens.go +++ b/pkg/ast/visitor/filter_tokens.go @@ -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 +} diff --git a/pkg/ast/visitor/namespace_resolver.go b/pkg/ast/visitor/namespace_resolver.go index fb5659d..3eac4a1 100644 --- a/pkg/ast/visitor/namespace_resolver.go +++ b/pkg/ast/visitor/namespace_resolver.go @@ -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)) } } diff --git a/pkg/ast/visitor/namespace_resolver_test.go b/pkg/ast/visitor/namespace_resolver_test.go index 5b01ecc..8e84e88 100644 --- a/pkg/ast/visitor/namespace_resolver_test.go +++ b/pkg/ast/visitor/namespace_resolver_test.go @@ -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{ diff --git a/pkg/printer/pretty_printer.go b/pkg/printer/pretty_printer.go index fca19fd..cd5d20f 100644 --- a/pkg/printer/pretty_printer.go +++ b/pkg/printer/pretty_printer.go @@ -1603,7 +1603,7 @@ func (p *PrettyPrinter) printStmtClassConstList(n ast.Vertex) { func (p *PrettyPrinter) printStmtConstant(n ast.Vertex) { nn := n.(*ast.StmtConstant) - p.Print(nn.ConstantName) + p.Print(nn.Name) io.WriteString(p.w, " = ") p.Print(nn.Expr) } diff --git a/pkg/printer/pretty_printer_test.go b/pkg/printer/pretty_printer_test.go index c457cb8..343703b 100644 --- a/pkg/printer/pretty_printer_test.go +++ b/pkg/printer/pretty_printer_test.go @@ -2530,8 +2530,8 @@ func TestPrintStmtClass(t *testing.T) { Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("public")}}, Consts: []ast.Vertex{ &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'bar'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'bar'")}, }, }, }, @@ -2585,8 +2585,8 @@ func TestPrintStmtAnonymousClass(t *testing.T) { Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("public")}}, Consts: []ast.Vertex{ &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'bar'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'bar'")}, }, }, }, @@ -2616,12 +2616,12 @@ func TestPrintStmtClassConstList(t *testing.T) { Modifiers: []ast.Vertex{&ast.Identifier{Value: []byte("public")}}, Consts: []ast.Vertex{ &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'a'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'a'")}, }, &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("BAR")}, - Expr: &ast.ScalarString{Value: []byte("'b'")}, + Name: &ast.Identifier{Value: []byte("BAR")}, + Expr: &ast.ScalarString{Value: []byte("'b'")}, }, }, }) @@ -2639,8 +2639,8 @@ func TestPrintStmtConstant(t *testing.T) { p := printer.NewPrettyPrinter(o, " ") p.Print(&ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'BAR'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'BAR'")}, }) expected := "FOO = 'BAR'" @@ -2676,8 +2676,8 @@ func TestPrintStmtDeclareStmts(t *testing.T) { &ast.StmtDeclare{ Consts: []ast.Vertex{ &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'bar'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'bar'")}, }, }, Stmt: &ast.StmtStmtList{ @@ -2710,8 +2710,8 @@ func TestPrintStmtDeclareExpr(t *testing.T) { &ast.StmtDeclare{ Consts: []ast.Vertex{ &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'bar'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'bar'")}, }, }, Stmt: &ast.StmtExpression{Expr: &ast.ScalarString{Value: []byte("'bar'")}}, @@ -2737,8 +2737,8 @@ func TestPrintStmtDeclareNop(t *testing.T) { p.Print(&ast.StmtDeclare{ Consts: []ast.Vertex{ &ast.StmtConstant{ - ConstantName: &ast.Identifier{Value: []byte("FOO")}, - Expr: &ast.ScalarString{Value: []byte("'bar'")}, + Name: &ast.Identifier{Value: []byte("FOO")}, + Expr: &ast.ScalarString{Value: []byte("'bar'")}, }, }, Stmt: &ast.StmtNop{}, diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 450f928..f87cd9b 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -2421,69 +2421,27 @@ func (p *Printer) printStmtClass(n ast.Vertex) { p.printFreeFloating(nn, token.End) } -func (p *Printer) printStmtClassConstList(n ast.Vertex) { - nn := n.(*ast.StmtClassConstList) - p.printFreeFloating(nn, token.Start) - - if nn.Modifiers != nil { - for k, m := range nn.Modifiers { - if k > 0 && m.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.Print(m) - } - - if nn.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - } - p.printFreeFloating(nn, token.ModifierList) - io.WriteString(p.w, "const") - - if nn.Consts[0].GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.joinPrint(",", nn.Consts) - p.printFreeFloating(nn, token.ConstList) - - p.printFreeFloating(nn, token.SemiColon) - if nn.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, ";") - } - - p.printFreeFloating(nn, token.End) +func (p *Printer) printStmtClassConstList(n *ast.StmtClassConstList) { + p.joinPrintRefactored(" ", n.Modifiers) + p.bufStart = " " + p.printToken(n.ConstTkn, "const") + p.bufStart = " " + p.joinPrintRefactored(",", n.Consts) + p.printToken(n.SemiColonTkn, ";") } -func (p *Printer) printStmtConstList(n ast.Vertex) { - nn := n.(*ast.StmtConstList) - p.printFreeFloating(nn, token.Start) - - io.WriteString(p.w, "const") - - if nn.Consts[0].GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, " ") - } - p.joinPrint(",", nn.Consts) - p.printFreeFloating(nn, token.Stmts) - - p.printFreeFloating(nn, token.SemiColon) - if nn.GetNode().Tokens.IsEmpty() { - io.WriteString(p.w, ";") - } - - p.printFreeFloating(nn, token.End) +func (p *Printer) printStmtConstList(n *ast.StmtConstList) { + p.printToken(n.ConstTkn, "const") + p.bufStart = " " + p.joinPrintRefactored(",", n.Consts) + p.printToken(n.SemiColonTkn, ";") } -func (p *Printer) printStmtConstant(n ast.Vertex) { - nn := n.(*ast.StmtConstant) - p.printFreeFloating(nn, token.Start) - - p.Print(nn.ConstantName) - p.printFreeFloating(nn, token.Name) - io.WriteString(p.w, "=") - p.Print(nn.Expr) - - p.printFreeFloating(nn, token.End) +func (p *Printer) printStmtConstant(n *ast.StmtConstant) { + p.Print(n.Name) + p.printToken(n.EqualTkn, "=") + p.Print(n.Expr) + p.printToken(n.CommaTkn, "") } func (p *Printer) printStmtContinue(n ast.Vertex) { @@ -2515,7 +2473,7 @@ func (p *Printer) printStmtDeclare(n ast.Vertex) { io.WriteString(p.w, "declare") p.printFreeFloating(nn, token.Declare) io.WriteString(p.w, "(") - p.joinPrint(",", nn.Consts) + p.joinPrintRefactored(",", nn.Consts) p.printFreeFloating(nn, token.ConstList) io.WriteString(p.w, ")") diff --git a/pkg/printer/printer_parsed_php5_test.go b/pkg/printer/printer_parsed_php5_test.go index a65bd6b..5c14c0f 100644 --- a/pkg/printer/printer_parsed_php5_test.go +++ b/pkg/printer/printer_parsed_php5_test.go @@ -896,7 +896,8 @@ func TestParseAndPrintPhp5ClassConstList(t *testing.T) { } func TestParseAndPrintPhp5ConstList(t *testing.T) { - src := `