stmt/class: support self::
calling our renamed static methods
This commit is contained in:
parent
564be76bef
commit
c6f70b1e66
@ -43,7 +43,8 @@ The goal is to produce idiomatic, maintainable Go code as part of a one-off conv
|
|||||||
- [X] super
|
- [X] super
|
||||||
- [X] Need to track current conversion state through into function generator, to select the concrete parent
|
- [X] Need to track current conversion state through into function generator, to select the concrete parent
|
||||||
- [X] parent::
|
- [X] parent::
|
||||||
- [ ] static, self
|
- [X] self::
|
||||||
|
- [ ] static::
|
||||||
- [ ] Traits / `use`
|
- [ ] Traits / `use`
|
||||||
- [ ] Abstract methods
|
- [ ] Abstract methods
|
||||||
[ ] Type inference
|
[ ] Type inference
|
||||||
|
29
node.go
29
node.go
@ -538,12 +538,21 @@ func (this *conversionState) convert(n_ node.Node) (string, error) {
|
|||||||
return "", parseErr{n, err}
|
return "", parseErr{n, err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callTarget := className + "." + funcName
|
||||||
|
if className == "self" {
|
||||||
|
if this.currentClassName == "" {
|
||||||
|
return "", parseErr{n, fmt.Errorf("Made a self::Static method call while not in class context")}
|
||||||
|
}
|
||||||
|
// We're making a static call, and we renamed those to be top-level functions
|
||||||
|
callTarget = this.currentClassName + funcName
|
||||||
|
}
|
||||||
|
|
||||||
callParams, err := this.convertFuncCallArgsCommon(n.ArgumentList)
|
callParams, err := this.convertFuncCallArgsCommon(n.ArgumentList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", parseErr{n, err}
|
return "", parseErr{n, err}
|
||||||
}
|
}
|
||||||
|
|
||||||
return className + "." + funcName + callParams, nil // expr only, no semicolon/newline
|
return callTarget + callParams, nil // expr only, no semicolon/newline
|
||||||
|
|
||||||
case *expr.New:
|
case *expr.New:
|
||||||
// new foo(xx)
|
// new foo(xx)
|
||||||
@ -870,11 +879,23 @@ func (this *conversionState) resolveName(n node.Node) (string, error) {
|
|||||||
|
|
||||||
// Handle class lookups
|
// Handle class lookups
|
||||||
if strings.ToLower(paramType) == "parent" {
|
if strings.ToLower(paramType) == "parent" {
|
||||||
if this.currentClassParentName != "" {
|
if this.currentClassParentName == "" {
|
||||||
return `this.` + this.currentClassParentName, nil
|
|
||||||
} else {
|
|
||||||
return "", parseErr{n, fmt.Errorf("Lookup of 'parent' while not in an inherited child class context")}
|
return "", parseErr{n, fmt.Errorf("Lookup of 'parent' while not in an inherited child class context")}
|
||||||
}
|
}
|
||||||
|
return `this.` + this.currentClassParentName, nil
|
||||||
|
|
||||||
|
} else if strings.ToLower(paramType) == "self" {
|
||||||
|
// Let it through as-is
|
||||||
|
// return "", parseErr{n, fmt.Errorf("Lookup of 'self::' should have been resolved already")}
|
||||||
|
/*
|
||||||
|
if this.currentClassName == "" {
|
||||||
|
return "", parseErr{n, fmt.Errorf("Lookup of 'self' while not in class context")}
|
||||||
|
}
|
||||||
|
return `this`, nil
|
||||||
|
*/
|
||||||
|
} else if strings.ToLower(paramType) == "static" {
|
||||||
|
return "", parseErr{n, fmt.Errorf("'static::' is not yet supported")}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return paramType, nil
|
return paramType, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user