Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php8: added property in constructor #33

Merged
merged 3 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions internal/php8/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func (b *Builder) NewExpressionStmt(
}
}

func (b *Builder) NewIdentifier(
IdentifierTkn *token.Token,
) *ast.Identifier {
return &ast.Identifier{
Position: b.Pos.NewTokenPosition(IdentifierTkn),
IdentifierTkn: IdentifierTkn,
Value: IdentifierTkn.Value,
}
}

func (b *Builder) NewMethodCall(
Expr ast.Vertex,
ObjectOperatorTkn *token.Token,
Expand Down Expand Up @@ -462,3 +472,60 @@ func (b *Builder) NewThrowExpr(
Expr: Expr,
}
}

func (b *Builder) NewParameter(
Visibility ast.Vertex,
Type ast.Vertex,
AmpersandTkn *token.Token,
VariadicTkn *token.Token,
VarTkn *token.Token,
EqualTkn *token.Token,
DefaultValue ast.Vertex,
WithDefault bool,
) *ast.Parameter {
var pos *position2.Position

if WithDefault {
if Visibility != nil {
pos = b.Pos.NewNodesPosition(Visibility, DefaultValue)
} else if Type != nil {
pos = b.Pos.NewNodesPosition(Type, DefaultValue)
} else if AmpersandTkn != nil {
pos = b.Pos.NewTokenNodePosition(AmpersandTkn, DefaultValue)
} else if VariadicTkn != nil {
pos = b.Pos.NewTokenNodePosition(VariadicTkn, DefaultValue)
} else {
pos = b.Pos.NewTokenNodePosition(VarTkn, DefaultValue)
}
} else {
if Visibility != nil {
pos = b.Pos.NewNodeTokenPosition(Visibility, VarTkn)
} else if Type != nil {
pos = b.Pos.NewNodeTokenPosition(Type, VarTkn)
} else if AmpersandTkn != nil {
pos = b.Pos.NewTokensPosition(AmpersandTkn, VarTkn)
} else if VariadicTkn != nil {
pos = b.Pos.NewTokensPosition(VariadicTkn, VarTkn)
} else {
pos = b.Pos.NewTokenPosition(VarTkn)
}
}

return &ast.Parameter{
Position: pos,
Visibility: Visibility,
Type: Type,
AmpersandTkn: AmpersandTkn,
VariadicTkn: VariadicTkn,
Var: &ast.ExprVariable{
Position: b.Pos.NewTokenPosition(VarTkn),
Name: &ast.Identifier{
Position: b.Pos.NewTokenPosition(VarTkn),
IdentifierTkn: VarTkn,
Value: VarTkn.Value,
},
},
EqualTkn: EqualTkn,
DefaultValue: DefaultValue,
}
}
Loading