diff --git a/README.md b/README.md index 341e6a7..f687a63 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,8 @@ The goal is to produce idiomatic, maintainable Go code as part of a one-off conv - [X] super - [X] Need to track current conversion state through into function generator, to select the concrete parent - [X] parent:: - - [ ] static, self + - [X] self:: + - [ ] static:: - [ ] Traits / `use` - [ ] Abstract methods [ ] Type inference diff --git a/node.go b/node.go index 0d44f33..65e4fb5 100644 --- a/node.go +++ b/node.go @@ -538,12 +538,21 @@ func (this *conversionState) convert(n_ node.Node) (string, error) { 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) if err != nil { 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: // new foo(xx) @@ -870,11 +879,23 @@ func (this *conversionState) resolveName(n node.Node) (string, error) { // Handle class lookups if strings.ToLower(paramType) == "parent" { - if this.currentClassParentName != "" { - return `this.` + this.currentClassParentName, nil - } else { + if this.currentClassParentName == "" { 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