Указатели в параметрах интерфейсов и классов

Этот коммит содержится в:
Softonik 2024-02-12 07:07:36 +03:00 коммит произвёл Nobody
родитель 94ea4afaf4
коммит d340d11c77
3 изменённых файлов: 22 добавлений и 6 удалений

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

@ -63,11 +63,15 @@ func handleAbstractFuncDeclParams(t *ast.FuncType) (code string) {
}
values := make([]string, 0)
for _, field := range t.Params.List {
t := ""
switch ft := field.Type.(type) {
case *ast.Ident:
t := handleIdentExpr(ft)
values = append(values, t)
t = handleIdentExpr(ft)
case *ast.StarExpr:
t = handleStarExpr(ft)
t += "*"
}
values = append(values, t)
}
code += strings.Join(values, ",")
return

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

@ -35,6 +35,7 @@ package test
type Device interface {
Name() string
String() string
Some(*Thing) string
Add(int)
Add2(int,float64)
}
@ -45,6 +46,7 @@ class Device {
public:
virtual std::string Name() = 0;
virtual std::string String() = 0;
virtual std::string Some(Thing*) = 0;
virtual void Add(int) = 0;
virtual void Add2(int,double) = 0;
};
@ -145,7 +147,7 @@ type device struct {
a int
}
func (d *device) doSomething() {
func (d *device) doSomething(a *int) {
}
```
* Результат:
@ -153,9 +155,9 @@ func (d *device) doSomething() {
class device {
public:
int a;
void doSomething();
void doSomething(int* a);
};
void device::doSomething() {
void device::doSomething(int* a) {
}
```

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

@ -132,12 +132,22 @@ func handleFuncDeclParams(t *ast.FuncType) string {
values := make([]string, 0)
for _, field := range t.Params.List {
ftype := ""
star := false
switch ft := field.Type.(type) {
case *ast.Ident:
ftype = handleIdentExpr(ft)
case *ast.StarExpr:
ftype = handleStarExpr(ft)
star = true
}
for _, names := range field.Names {
values = append(values, ftype+" "+names.Name)
n := ftype
if star {
n += "*"
}
n += " "
n += names.Name
values = append(values, n)
}
}
code += strings.Join(values, ",")