[refactoring] update ast structure of "Lnumber" and "Dnumber" nodes

This commit is contained in:
Vadym Slizov 2020-11-20 23:08:30 +02:00
parent 7e2965f53b
commit e3ad9747f4
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 133 additions and 105 deletions

72
internal/php5/php5.go generated
View File

@ -347,7 +347,7 @@ const yyEofCode = 1
const yyErrCode = 2
const yyInitialStackSize = 16
// line internal/php5/php5.y:6400
// line internal/php5/php5.y:6406
type simpleIndirectReference struct {
all []*ast.ExprVariable
@ -6923,25 +6923,25 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php5/php5.y:4495
{
yyVAL.node = &ast.ScalarLnumber{ast.Node{}, yyDollar[1].token.Value}
// save position
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
// save comments
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens)
yyVAL.node = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
NumberTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
}
case 354:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php5/php5.y:4505
{
yyVAL.node = &ast.ScalarDnumber{ast.Node{}, yyDollar[1].token.Value}
// save position
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
// save comments
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens)
yyVAL.node = &ast.ScalarDnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
NumberTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
}
case 355:
yyDollar = yyS[yypt-1 : yypt+1]
@ -8748,7 +8748,13 @@ yydefault:
{
// TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string(yyDollar[1].token.Value)); err == nil {
yyVAL.node = &ast.ScalarLnumber{ast.Node{}, yyDollar[1].token.Value}
yyVAL.node = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
NumberTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
} else {
yyVAL.node = &ast.ScalarString{ast.Node{}, yyDollar[1].token.Value}
}
@ -8761,7 +8767,7 @@ yydefault:
}
case 504:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php5/php5.y:6161
// line internal/php5/php5.y:6167
{
identifier := &ast.Identifier{
Node: ast.Node{
@ -8780,7 +8786,7 @@ yydefault:
}
case 505:
yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php5/php5.y:6181
// line internal/php5/php5.y:6187
{
yyVAL.node = &ast.ExprIsset{ast.Node{}, yyDollar[3].list}
@ -8794,7 +8800,7 @@ yydefault:
}
case 506:
yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php5/php5.y:6193
// line internal/php5/php5.y:6199
{
exprBrackets := &ast.ParserBrackets{
Node: ast.Node{
@ -8816,7 +8822,7 @@ yydefault:
}
case 507:
yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php5/php5.y:6213
// line internal/php5/php5.y:6219
{
exprBrackets := &ast.ParserBrackets{
Node: ast.Node{
@ -8838,7 +8844,7 @@ yydefault:
}
case 508:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php5/php5.y:6233
// line internal/php5/php5.y:6239
{
yyVAL.node = &ast.ExprInclude{ast.Node{}, yyDollar[2].node}
@ -8850,7 +8856,7 @@ yydefault:
}
case 509:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php5/php5.y:6243
// line internal/php5/php5.y:6249
{
yyVAL.node = &ast.ExprIncludeOnce{ast.Node{}, yyDollar[2].node}
@ -8862,7 +8868,7 @@ yydefault:
}
case 510:
yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php5/php5.y:6253
// line internal/php5/php5.y:6259
{
exprBrackets := &ast.ParserBrackets{
Node: ast.Node{
@ -8884,7 +8890,7 @@ yydefault:
}
case 511:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php5/php5.y:6273
// line internal/php5/php5.y:6279
{
yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node}
@ -8896,7 +8902,7 @@ yydefault:
}
case 512:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php5/php5.y:6283
// line internal/php5/php5.y:6289
{
yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node}
@ -8908,13 +8914,13 @@ yydefault:
}
case 513:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php5/php5.y:6296
// line internal/php5/php5.y:6302
{
yyVAL.list = []ast.Vertex{yyDollar[1].node}
}
case 514:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:6300
// line internal/php5/php5.y:6306
{
yyVAL.list = append(yyDollar[1].list, yyDollar[3].node)
@ -8923,19 +8929,19 @@ yydefault:
}
case 515:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php5/php5.y:6310
// line internal/php5/php5.y:6316
{
yyVAL.node = yyDollar[1].node
}
case 516:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php5/php5.y:6314
// line internal/php5/php5.y:6320
{
yyVAL.node = yyDollar[1].node
}
case 517:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:6321
// line internal/php5/php5.y:6327
{
target := &ast.Identifier{
Node: ast.Node{
@ -8955,7 +8961,7 @@ yydefault:
}
case 518:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:6339
// line internal/php5/php5.y:6345
{
target := &ast.Identifier{
Node: ast.Node{
@ -8975,7 +8981,7 @@ yydefault:
}
case 519:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:6360
// line internal/php5/php5.y:6366
{
target := &ast.Identifier{
Node: ast.Node{
@ -8995,7 +9001,7 @@ yydefault:
}
case 520:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php5/php5.y:6381
// line internal/php5/php5.y:6387
{
target := &ast.Identifier{
Node: ast.Node{

View File

@ -4493,23 +4493,23 @@ ctor_arguments:
common_scalar:
T_LNUMBER
{
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_DNUMBER
{
$$ = &ast.ScalarDnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarDnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_CONSTANT_ENCAPSED_STRING
{
@ -6146,7 +6146,13 @@ encaps_var_offset:
{
// TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string($1.Value)); err == nil {
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
} else {
$$ = &ast.ScalarString{ast.Node{}, $1.Value}
}

75
internal/php7/php7.go generated
View File

@ -347,7 +347,7 @@ const yyEofCode = 1
const yyErrCode = 2
const yyInitialStackSize = 16
// line internal/php7/php7.y:4964
// line internal/php7/php7.y:4971
// line yacctab:1
var yyExca = [...]int{
@ -6549,25 +6549,25 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3942
{
yyVAL.node = &ast.ScalarLnumber{ast.Node{}, yyDollar[1].token.Value}
// save position
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
// save comments
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens)
yyVAL.node = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
NumberTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
}
case 403:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:3952
{
yyVAL.node = &ast.ScalarDnumber{ast.Node{}, yyDollar[1].token.Value}
// save position
yyVAL.node.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
// save comments
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Start, yyDollar[1].token.SkippedTokens)
yyVAL.node = &ast.ScalarDnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
NumberTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
}
case 404:
yyDollar = yyS[yypt-1 : yypt+1]
@ -7494,7 +7494,13 @@ yydefault:
{
// TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string(yyDollar[1].token.Value)); err == nil {
yyVAL.node = &ast.ScalarLnumber{ast.Node{}, yyDollar[1].token.Value}
yyVAL.node = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token),
},
NumberTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
}
} else {
yyVAL.node = &ast.ScalarString{ast.Node{}, yyDollar[1].token.Value}
}
@ -7507,15 +7513,19 @@ yydefault:
}
case 483:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4800
// line internal/php7/php7.y:4806
{
var lnumber *ast.ScalarLnumber
// TODO: add option to handle 64 bit integer
_, err := strconv.Atoi(string(yyDollar[2].token.Value))
isInt := err == nil
if isInt {
lnumber = &ast.ScalarLnumber{ast.Node{}, yyDollar[2].token.Value}
lnumber := &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[2].token),
},
NumberTkn: yyDollar[2].token,
Value: yyDollar[2].token.Value,
}
yyVAL.node = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
} else {
yyDollar[2].token.Value = append([]byte("-"), yyDollar[2].token.Value...)
@ -7523,9 +7533,6 @@ yydefault:
}
// save position
if isInt {
lnumber.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)
}
yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[2].token)
// save comments
@ -7533,7 +7540,7 @@ yydefault:
}
case 484:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4824
// line internal/php7/php7.y:4831
{
identifier := &ast.Identifier{
Node: ast.Node{
@ -7552,7 +7559,7 @@ yydefault:
}
case 485:
yyDollar = yyS[yypt-5 : yypt+1]
// line internal/php7/php7.y:4844
// line internal/php7/php7.y:4851
{
yyVAL.node = &ast.ExprIsset{ast.Node{}, yyDollar[3].list}
@ -7570,7 +7577,7 @@ yydefault:
}
case 486:
yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4860
// line internal/php7/php7.y:4867
{
exprBrackets := &ast.ParserBrackets{
Node: ast.Node{
@ -7592,7 +7599,7 @@ yydefault:
}
case 487:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4880
// line internal/php7/php7.y:4887
{
yyVAL.node = &ast.ExprInclude{ast.Node{}, yyDollar[2].node}
@ -7604,7 +7611,7 @@ yydefault:
}
case 488:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4890
// line internal/php7/php7.y:4897
{
yyVAL.node = &ast.ExprIncludeOnce{ast.Node{}, yyDollar[2].node}
@ -7616,7 +7623,7 @@ yydefault:
}
case 489:
yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4900
// line internal/php7/php7.y:4907
{
exprBrackets := &ast.ParserBrackets{
Node: ast.Node{
@ -7638,7 +7645,7 @@ yydefault:
}
case 490:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4920
// line internal/php7/php7.y:4927
{
yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node}
@ -7650,7 +7657,7 @@ yydefault:
}
case 491:
yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4930
// line internal/php7/php7.y:4937
{
yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node}
@ -7662,13 +7669,13 @@ yydefault:
}
case 492:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4943
// line internal/php7/php7.y:4950
{
yyVAL.list = []ast.Vertex{yyDollar[1].node}
}
case 493:
yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4947
// line internal/php7/php7.y:4954
{
yyVAL.list = append(yyDollar[1].list, yyDollar[3].node)
@ -7677,7 +7684,7 @@ yydefault:
}
case 494:
yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4957
// line internal/php7/php7.y:4964
{
yyVAL.node = yyDollar[1].node
}

View File

@ -3940,23 +3940,23 @@ dereferencable_scalar:
scalar:
T_LNUMBER
{
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_DNUMBER
{
$$ = &ast.ScalarDnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarDnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_LINE
{
@ -4785,7 +4785,13 @@ encaps_var_offset:
{
// TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string($1.Value)); err == nil {
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
} else {
$$ = &ast.ScalarString{ast.Node{}, $1.Value}
}
@ -4798,13 +4804,17 @@ encaps_var_offset:
}
| '-' T_NUM_STRING
{
var lnumber *ast.ScalarLnumber
// TODO: add option to handle 64 bit integer
_, err := strconv.Atoi(string($2.Value));
isInt := err == nil
if isInt {
lnumber = &ast.ScalarLnumber{ast.Node{}, $2.Value}
lnumber := &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
NumberTkn: $2,
Value: $2.Value,
}
$$ = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
} else {
$2.Value = append([]byte("-"), $2.Value...)
@ -4812,9 +4822,6 @@ encaps_var_offset:
}
// save position
if isInt {
lnumber.GetNode().Position = position.NewTokensPosition($1, $2)
}
$$.GetNode().Position = position.NewTokensPosition($1, $2)
// save comments

View File

@ -115,7 +115,8 @@ func (n *Argument) Accept(v NodeVisitor) {
// ScalarDnumber node
type ScalarDnumber struct {
Node
Value []byte
NumberTkn *token.Token
Value []byte
}
func (n *ScalarDnumber) Accept(v NodeVisitor) {
@ -156,7 +157,8 @@ func (n *ScalarHeredoc) Accept(v NodeVisitor) {
// ScalarLnumber node
type ScalarLnumber struct {
Node
Value []byte
NumberTkn *token.Token
Value []byte
}
func (n *ScalarLnumber) Accept(v NodeVisitor) {