Сценарий: Структура с объявлением переменных-указателей
Этот коммит содержится в:
родитель
56fe611154
коммит
11825a08c4
5 изменённых файлов: 52 добавлений и 8 удалений
|
@ -6,6 +6,9 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
classDeclarations []*Class
|
classDeclarations []*Class
|
||||||
|
|
||||||
|
isInMethod = false
|
||||||
|
currentReceiverName = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
type Class struct {
|
type Class struct {
|
||||||
|
@ -63,11 +66,6 @@ func (c *Class) methodImplementationsToString() (code string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
isInMethod = false
|
|
||||||
currentReceiverName = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Class) methodImplementationToString(m *ast.FuncDecl) (code string) {
|
func (c *Class) methodImplementationToString(m *ast.FuncDecl) (code string) {
|
||||||
code += "void "
|
code += "void "
|
||||||
code += c.Name + "::"
|
code += c.Name + "::"
|
||||||
|
|
|
@ -105,3 +105,11 @@ func handleSelectorExpr(expr ast.Expr) string {
|
||||||
}
|
}
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleStarExpr(s *ast.StarExpr) (code string) {
|
||||||
|
switch x := s.X.(type) {
|
||||||
|
case *ast.Ident:
|
||||||
|
code += handleIdentExpr(x)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -196,3 +196,21 @@ this->x=dev2->x;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Сценарий: Структура с объявлением переменных-указателей
|
||||||
|
* Исходник:
|
||||||
|
```
|
||||||
|
package test
|
||||||
|
|
||||||
|
var (
|
||||||
|
dev1, dev2 *device
|
||||||
|
)
|
||||||
|
|
||||||
|
type device struct {}
|
||||||
|
```
|
||||||
|
* Результат:
|
||||||
|
```
|
||||||
|
class device {
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
device *dev1,*dev2;
|
||||||
|
```
|
|
@ -4,6 +4,10 @@ import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
isPointerType = false
|
||||||
|
)
|
||||||
|
|
||||||
func handleTypeSpec(spec ast.Spec) (code string) {
|
func handleTypeSpec(spec ast.Spec) (code string) {
|
||||||
s := spec.(*ast.TypeSpec)
|
s := spec.(*ast.TypeSpec)
|
||||||
handleClass(s)
|
handleClass(s)
|
||||||
|
|
|
@ -9,7 +9,14 @@ func handleValueSpec(spec ast.Spec) string {
|
||||||
code := ""
|
code := ""
|
||||||
code += handleValueSpecType(s.Type)
|
code += handleValueSpecType(s.Type)
|
||||||
code += " "
|
code += " "
|
||||||
|
|
||||||
|
_, ok := s.Type.(*ast.StarExpr)
|
||||||
|
if ok {
|
||||||
|
isPointerType = true
|
||||||
|
}
|
||||||
code += handleValueSpecNames(s.Names)
|
code += handleValueSpecNames(s.Names)
|
||||||
|
isPointerType = false
|
||||||
|
|
||||||
if s.Values != nil {
|
if s.Values != nil {
|
||||||
code += " = "
|
code += " = "
|
||||||
code += handleValueSpecValues(s.Values)
|
code += handleValueSpecValues(s.Values)
|
||||||
|
@ -17,12 +24,19 @@ func handleValueSpec(spec ast.Spec) string {
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleValueSpecNames(names []*ast.Ident) string {
|
func handleValueSpecNames(names []*ast.Ident) (code string) {
|
||||||
code := ""
|
nado_zapyatuyu := false
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
code += handleIdentExpr(name)
|
if nado_zapyatuyu {
|
||||||
|
code += ","
|
||||||
}
|
}
|
||||||
return code
|
if isPointerType {
|
||||||
|
code += "*"
|
||||||
|
}
|
||||||
|
code += handleIdentExpr(name)
|
||||||
|
nado_zapyatuyu = true
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleValueSpecType(expr ast.Expr) string {
|
func handleValueSpecType(expr ast.Expr) string {
|
||||||
|
@ -32,6 +46,8 @@ func handleValueSpecType(expr ast.Expr) string {
|
||||||
code += handleSelectorExpr(t)
|
code += handleSelectorExpr(t)
|
||||||
case *ast.Ident:
|
case *ast.Ident:
|
||||||
code += handleIdentExpr(t)
|
code += handleIdentExpr(t)
|
||||||
|
case *ast.StarExpr:
|
||||||
|
code += handleStarExpr(t)
|
||||||
}
|
}
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче