diff --git a/pkg/service/expr.go b/pkg/service/expr.go index 4e2ffde..52ac982 100644 --- a/pkg/service/expr.go +++ b/pkg/service/expr.go @@ -25,6 +25,8 @@ func handleExpr(expr ast.Expr) string { code += handleSelectorExpr(e) case *ast.StructType: code += handleStructType(e) + case *ast.ArrayType: + code += handleArray(e) } return code } diff --git a/pkg/service/features/variables.feature b/pkg/service/features/variables.feature index eac4991..afd844c 100644 --- a/pkg/service/features/variables.feature +++ b/pkg/service/features/variables.feature @@ -57,4 +57,18 @@ int a[]; bool b[]; int c[8]; int d[LENGTH]; -``` \ No newline at end of file +``` + + Сценарий: Кастомные типы + * Исходник: +``` +package test + +type Mera int +type GPIOS [GPIO_count]bool +``` + * Результат: +``` +typedef int Mera; +typedef bool GPIOS[GPIO_count]; +``` diff --git a/pkg/service/type.go b/pkg/service/type.go index d9eed96..6abb243 100644 --- a/pkg/service/type.go +++ b/pkg/service/type.go @@ -17,8 +17,31 @@ func handleTypeSpec(s *ast.TypeSpec) (code string) { return handleType(s) } -func handleType(s *ast.TypeSpec) string { - return "" +func handleType(s *ast.TypeSpec) (code string) { + code += "typedef " + code += handleExpr(s.Type) + code += " " + code += handleIdentExpr(s.Name) + code += optionallyAddArrayDetails(s) + code += ";" + + return +} + +func optionallyAddArrayDetails(s *ast.TypeSpec) (code string) { + v, ok := s.Type.(*ast.ArrayType) + if !ok { + return + } + + code += "[" + code += handleArrayLen(v) + code += "]" + return +} + +func handleArrayLen(a *ast.ArrayType) (code string) { + return handleExpr(a.Len) } func handleStructType(s *ast.StructType) (code string) {