node: add bailout cases for eval() and extract()
This commit is contained in:
parent
2fdd3a919c
commit
9253058a73
11
node.go
11
node.go
@ -14,6 +14,8 @@ import (
|
|||||||
"github.com/z7zmey/php-parser/node/name"
|
"github.com/z7zmey/php-parser/node/name"
|
||||||
"github.com/z7zmey/php-parser/node/scalar"
|
"github.com/z7zmey/php-parser/node/scalar"
|
||||||
"github.com/z7zmey/php-parser/node/stmt"
|
"github.com/z7zmey/php-parser/node/stmt"
|
||||||
|
|
||||||
|
"php2go/parseutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func nodeTypeString(n node.Node) string {
|
func nodeTypeString(n node.Node) string {
|
||||||
@ -1192,6 +1194,10 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
|
|||||||
callParams = append(callParams, `-1`) // replaceAll
|
callParams = append(callParams, `-1`) // replaceAll
|
||||||
// There is a strings.ReplaceAll() added in go1.12 (2018), which is still pretty recent i.e. not in Debian Stable (buster)
|
// There is a strings.ReplaceAll() added in go1.12 (2018), which is still pretty recent i.e. not in Debian Stable (buster)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if funcName == `extract` {
|
||||||
|
return "", parseErr{n, fmt.Errorf("Unsupported dynamic function `\\extract()`")}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return funcName + "(" + strings.Join(callParams, ", ") + ")", nil // expr only, no semicolon/newline
|
return funcName + "(" + strings.Join(callParams, ", ") + ")", nil // expr only, no semicolon/newline
|
||||||
@ -1320,6 +1326,9 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
|
|||||||
return "os.Exit(" + child + ")", nil
|
return "os.Exit(" + child + ")", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case *expr.Eval:
|
||||||
|
return "", parseErr{n, fmt.Errorf("Unsupported use of eval()")}
|
||||||
|
|
||||||
case *expr.PreInc:
|
case *expr.PreInc:
|
||||||
// """In Go, i++ is a statement, not an expression. So you can't use its value in another expression such as a function call."""
|
// """In Go, i++ is a statement, not an expression. So you can't use its value in another expression such as a function call."""
|
||||||
v, err := this.convert(n.Variable)
|
v, err := this.convert(n.Variable)
|
||||||
@ -2105,7 +2114,7 @@ func (this *conversionState) convertFunctionCommon(params []node.Node, returnTyp
|
|||||||
// any assignment expressions
|
// any assignment expressions
|
||||||
func hasInteriorAssignment(n node.Node) (hasAnyAssign bool, err error) {
|
func hasInteriorAssignment(n node.Node) (hasAnyAssign bool, err error) {
|
||||||
|
|
||||||
err = walk(n, func(n node.Node) error {
|
err = parseutil.SimpleWalk(n, func(n node.Node) error {
|
||||||
if _, ok := n.(*assign.Assign); ok {
|
if _, ok := n.(*assign.Assign); ok {
|
||||||
hasAnyAssign = true
|
hasAnyAssign = true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user