Сценарий: Структура с вызовом метода другого объекта

Этот коммит содержится в:
Softonik 2024-02-11 22:25:36 +03:00 коммит произвёл Nobody
родитель b1694abd29
коммит 04c61b67a1
3 изменённых файлов: 33 добавлений и 5 удалений

Просмотреть файл

@ -109,9 +109,7 @@ func handleParenExpr(stmt *ast.ParenExpr) string {
return code
}
func handleSelectorExpr(expr ast.Expr) string {
s := expr.(*ast.SelectorExpr)
code := ""
func handleSelectorExpr(s *ast.SelectorExpr) (code string) {
switch x := s.X.(type) {
case *ast.Ident:
if isInMethod {
@ -125,12 +123,17 @@ func handleSelectorExpr(expr ast.Expr) string {
code += handleIdentExpr(x)
code += "."
}
case *ast.SelectorExpr:
code += "this"
code += "->"
code += handleIdentExpr(x.Sel)
code += "->"
}
code += handleIdentExpr(s.Sel)
if val, ok := mapping[code]; ok {
code = val
}
return code
return
}
func handleStarExpr(s *ast.StarExpr) (code string) {

Просмотреть файл

@ -131,6 +131,31 @@ this->doSomethingElse();
}
void device::doSomethingElse() {
}
```
Сценарий: Структура с вызовом метода другого объекта
* Исходник:
```
package test
type device struct {
remote Other
}
func (d *device) doSomething() {
d.remote.doSomethingElse()
}
```
* Результат:
```
class device {
public:
Other remote;
void doSomething();
};
void device::doSomething() {
this->remote->doSomethingElse();
}
```
Сценарий: Структура с вызовом методов со входящими и выходящими параметрами

Просмотреть файл

@ -87,7 +87,7 @@ func handleValueSpecValues(values []ast.Expr) string {
case *ast.BinaryExpr:
code += handleBinaryExpr(v)
case *ast.SelectorExpr:
code += handleSelectorExpr(value)
code += handleSelectorExpr(v)
case *ast.CallExpr:
code += handleCallExpr(v)
}