[refactoring] update ast structure of "BitwiseNot", "BooleanNot", "ClassConstFetch" and "Clone" nodes

This commit is contained in:
Vadym Slizov 2020-12-01 09:51:47 +02:00
parent 4b8d431767
commit b90400d993
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 142 additions and 145 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -3220,13 +3220,13 @@ expr_without_variable:
}
| T_CLONE expr
{
$$ = &ast.ExprClone{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprClone{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
CloneTkn: $1,
Expr: $2,
}
}
| variable T_PLUS_EQUAL expr
{
@ -3609,23 +3609,23 @@ expr_without_variable:
}
| '!' expr
{
$$ = &ast.ExprBooleanNot{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprBooleanNot{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
ExclamationTkn: $1,
Expr: $2,
}
}
| '~' expr
{
$$ = &ast.ExprBitwiseNot{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprBitwiseNot{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
TildaTkn: $1,
Expr: $2,
}
}
| expr T_IS_IDENTICAL expr
{
@ -4665,21 +4665,20 @@ common_scalar:
static_class_constant:
class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;
@ -4867,23 +4866,23 @@ static_operation:
}
| '!' static_scalar_value
{
$$ = &ast.ExprBooleanNot{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprBooleanNot{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
ExclamationTkn: $1,
Expr: $2,
}
}
| '~' static_scalar_value
{
$$ = &ast.ExprBitwiseNot{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprBitwiseNot{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
TildaTkn: $1,
Expr: $2,
}
}
| static_scalar_value '|' static_scalar_value
{
@ -6445,81 +6444,77 @@ isset_variable:
class_constant:
class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;
static_class_name_scalar:
class_name T_PAAMAYIM_NEKUDOTAYIM T_CLASS
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;
class_name_scalar:
class_name T_PAAMAYIM_NEKUDOTAYIM T_CLASS
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -2866,13 +2866,13 @@ expr_without_variable:
}
| T_CLONE expr
{
$$ = &ast.ExprClone{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprClone{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
CloneTkn: $1,
Expr: $2,
}
}
| variable T_PLUS_EQUAL expr
{
@ -3267,23 +3267,23 @@ expr_without_variable:
}
| '!' expr
{
$$ = &ast.ExprBooleanNot{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprBooleanNot{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
ExclamationTkn: $1,
Expr: $2,
}
}
| '~' expr
{
$$ = &ast.ExprBitwiseNot{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprBitwiseNot{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
TildaTkn: $1,
Expr: $2,
}
}
| expr T_IS_IDENTICAL expr
{
@ -4112,39 +4112,37 @@ constant:
}
| class_name T_PAAMAYIM_NEKUDOTAYIM identifier
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier
{
target := &ast.Identifier{
$$ = &ast.ExprClassConstFetch{
Node: ast.Node{
Position: position.NewTokenPosition($3),
Position: position.NewNodeTokenPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
ConstantName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
},
IdentifierTkn: $3,
Value: $3.Value,
}
$$ = &ast.ExprClassConstFetch{ast.Node{}, $1, target}
// save position
$$.GetNode().Position = position.NewNodeTokenPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
}
;

View File

@ -1000,7 +1000,8 @@ func (n *ExprArrowFunction) Accept(v NodeVisitor) {
// ExprBitwiseNot node
type ExprBitwiseNot struct {
Node
Expr Vertex
TildaTkn *token.Token
Expr Vertex
}
func (n *ExprBitwiseNot) Accept(v NodeVisitor) {
@ -1010,7 +1011,8 @@ func (n *ExprBitwiseNot) Accept(v NodeVisitor) {
// ExprBooleanNot node
type ExprBooleanNot struct {
Node
Expr Vertex
ExclamationTkn *token.Token
Expr Vertex
}
func (n *ExprBooleanNot) Accept(v NodeVisitor) {
@ -1020,8 +1022,9 @@ func (n *ExprBooleanNot) Accept(v NodeVisitor) {
// ExprClassConstFetch node
type ExprClassConstFetch struct {
Node
Class Vertex
ConstantName Vertex
Class Vertex
DoubleColonTkn *token.Token
ConstantName Vertex
}
func (n *ExprClassConstFetch) Accept(v NodeVisitor) {
@ -1031,7 +1034,8 @@ func (n *ExprClassConstFetch) Accept(v NodeVisitor) {
// ExprClone node
type ExprClone struct {
Node
Expr Vertex
CloneTkn *token.Token
Expr Vertex
}
func (n *ExprClone) Accept(v NodeVisitor) {