[refactoring] update ast structure of "Class" and "Trait" nodes
This commit is contained in:
parent
3bda40e8ce
commit
fe2e097d8f
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -1408,33 +1408,38 @@ unticked_function_declaration_statement:
|
||||
unticked_class_declaration_statement:
|
||||
class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}'
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
switch n := $1.(type) {
|
||||
case *ast.StmtClass :
|
||||
n.ClassName = name
|
||||
n.Stmts = $6
|
||||
n.Position = position.NewNodeTokenPosition($1, $7)
|
||||
n.ClassName = &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
n.Extends = $3
|
||||
n.Implements = $4
|
||||
|
||||
case *ast.StmtTrait :
|
||||
// TODO: is it possible that trait extend or implement
|
||||
n.TraitName = name
|
||||
n.OpenCurlyBracket = $5
|
||||
n.Stmts = $6
|
||||
n.CloseCurlyBracket = $7
|
||||
case *ast.StmtTrait :
|
||||
n.Position = position.NewNodeTokenPosition($1, $7)
|
||||
n.TraitName = &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
n.Extends = $3
|
||||
n.Implements = $4
|
||||
n.OpenCurlyBracket = $5
|
||||
n.Stmts = $6
|
||||
n.CloseCurlyBracket = $7
|
||||
}
|
||||
|
||||
$$ = $1
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $7)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Name, $5.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $7.SkippedTokens)
|
||||
}
|
||||
| interface_entry T_STRING interface_extends_list '{' class_statement_list '}'
|
||||
{
|
||||
@ -1461,59 +1466,57 @@ unticked_class_declaration_statement:
|
||||
class_entry_type:
|
||||
T_CLASS
|
||||
{
|
||||
$$ = &ast.StmtClass{ast.Node{}, nil, nil, nil, nil, nil, nil}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
$$ = &ast.StmtClass{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
ClassTkn: $1,
|
||||
}
|
||||
}
|
||||
| T_ABSTRACT T_CLASS
|
||||
{
|
||||
classModifier := &ast.Identifier{
|
||||
$$ = &ast.StmtClass{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
Position: position.NewTokensPosition($1, $2),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
Modifiers: []ast.Vertex{
|
||||
&ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
},
|
||||
ClassTkn: $2,
|
||||
}
|
||||
$$ = &ast.StmtClass{ast.Node{}, nil, []ast.Vertex{classModifier}, nil, nil, nil, nil}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.ModifierList, $2.SkippedTokens)
|
||||
}
|
||||
| T_TRAIT
|
||||
{
|
||||
$$ = &ast.Identifier{
|
||||
$$ = &ast.StmtTrait{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
TraitTkn: $1,
|
||||
}
|
||||
}
|
||||
| T_FINAL T_CLASS
|
||||
{
|
||||
classModifier := &ast.Identifier{
|
||||
$$ = &ast.StmtClass{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
Position: position.NewTokensPosition($1, $2),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
Modifiers: []ast.Vertex{
|
||||
&ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
},
|
||||
ClassTkn: $2,
|
||||
}
|
||||
$$ = &ast.StmtClass{ast.Node{}, nil, []ast.Vertex{classModifier}, nil, nil, nil, nil}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.ModifierList, $2.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -1271,40 +1271,46 @@ is_variadic:
|
||||
class_declaration_statement:
|
||||
class_modifiers T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
$$ = &ast.StmtClass{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($3),
|
||||
Position: position.NewOptionalListTokensPosition($1, $2, $9),
|
||||
},
|
||||
IdentifierTkn: $3,
|
||||
Value: $3.Value,
|
||||
Modifiers: $1,
|
||||
ClassTkn: $2,
|
||||
ClassName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($3),
|
||||
},
|
||||
IdentifierTkn: $3,
|
||||
Value: $3.Value,
|
||||
},
|
||||
Extends: $4,
|
||||
Implements: $5,
|
||||
OpenCurlyBracket: $7,
|
||||
Stmts: $8,
|
||||
CloseCurlyBracket: $9,
|
||||
}
|
||||
$$ = &ast.StmtClass{ast.Node{}, name, $1, nil, $4, $5, $8}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewOptionalListTokensPosition($1, $2, $9)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).MoveFreeFloating($1[0], $$)
|
||||
yylex.(*Parser).setFreeFloating($$, token.ModifierList, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $9.SkippedTokens)
|
||||
}
|
||||
| T_CLASS T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
$$ = &ast.StmtClass{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
Position: position.NewTokensPosition($1, $8),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
ClassTkn: $1,
|
||||
ClassName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
Extends: $3,
|
||||
Implements: $4,
|
||||
OpenCurlyBracket: $6,
|
||||
Stmts: $7,
|
||||
CloseCurlyBracket: $8,
|
||||
}
|
||||
$$ = &ast.StmtClass{ast.Node{}, name, nil, nil, $3, $4, $7}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $8)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $8.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
@ -1345,22 +1351,22 @@ class_modifier:
|
||||
trait_declaration_statement:
|
||||
T_TRAIT T_STRING backup_doc_comment '{' class_statement_list '}'
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
$$ = &ast.StmtTrait{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
Position: position.NewTokensPosition($1, $6),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
TraitTkn: $1,
|
||||
TraitName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
OpenCurlyBracket: $4,
|
||||
Stmts: $5,
|
||||
CloseCurlyBracket: $6,
|
||||
}
|
||||
$$ = &ast.StmtTrait{ast.Node{}, name, $5}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $6)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Name, $4.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $6.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
@ -2756,19 +2762,18 @@ non_empty_for_exprs:
|
||||
anonymous_class:
|
||||
T_CLASS ctor_arguments extends_from implements_list backup_doc_comment '{' class_statement_list '}'
|
||||
{
|
||||
if $2 != nil {
|
||||
$$ = &ast.StmtClass{ast.Node{}, nil, nil, $2.(*ast.ArgumentList), $3, $4, $7}
|
||||
} else {
|
||||
$$ = &ast.StmtClass{ast.Node{}, nil, nil, nil, $3, $4, $7}
|
||||
$$ = &ast.StmtClass{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $8),
|
||||
},
|
||||
ClassTkn: $1,
|
||||
ArgumentList: $2,
|
||||
Extends: $3,
|
||||
Implements: $4,
|
||||
OpenCurlyBracket: $6,
|
||||
Stmts: $7,
|
||||
CloseCurlyBracket: $8,
|
||||
}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $8)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Name, $6.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $8.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -238,12 +238,15 @@ func (n *StmtCatch) Accept(v NodeVisitor) {
|
||||
// StmtClass node
|
||||
type StmtClass struct {
|
||||
Node
|
||||
ClassName Vertex
|
||||
Modifiers []Vertex
|
||||
ArgumentList *ArgumentList
|
||||
Extends *StmtClassExtends
|
||||
Implements *StmtClassImplements
|
||||
Stmts []Vertex
|
||||
Modifiers []Vertex
|
||||
ClassTkn *token.Token
|
||||
ClassName Vertex
|
||||
ArgumentList Vertex
|
||||
Extends *StmtClassExtends
|
||||
Implements *StmtClassImplements
|
||||
OpenCurlyBracket *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracket *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtClass) Accept(v NodeVisitor) {
|
||||
@ -741,8 +744,13 @@ func (n *StmtThrow) Accept(v NodeVisitor) {
|
||||
// StmtTrait node
|
||||
type StmtTrait struct {
|
||||
Node
|
||||
TraitName Vertex
|
||||
Stmts []Vertex
|
||||
TraitTkn *token.Token
|
||||
TraitName Vertex
|
||||
Extends *StmtClassExtends
|
||||
Implements *StmtClassImplements
|
||||
OpenCurlyBracket *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracket *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtTrait) Accept(v NodeVisitor) {
|
||||
|
@ -1476,7 +1476,7 @@ func (p *PrettyPrinter) printStmtClass(n ast.Vertex) {
|
||||
|
||||
if nn.ArgumentList != nil {
|
||||
io.WriteString(p.w, "(")
|
||||
p.joinPrint(", ", nn.ArgumentList.Arguments)
|
||||
p.joinPrint(", ", nn.ArgumentList.(*ast.ArgumentList).Arguments)
|
||||
io.WriteString(p.w, ")")
|
||||
}
|
||||
|
||||
|
@ -2097,7 +2097,7 @@ func (p *Printer) printStmtClass(n ast.Vertex) {
|
||||
|
||||
if nn.ArgumentList != nil {
|
||||
p.printFreeFloatingOrDefault(nn.ArgumentList, token.Start, "(")
|
||||
p.joinPrint(",", nn.ArgumentList.Arguments)
|
||||
p.joinPrint(",", nn.ArgumentList.(*ast.ArgumentList).Arguments)
|
||||
p.printFreeFloatingOrDefault(nn.ArgumentList, token.End, ")")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user