diff --git a/pkg/service/class_abstract.go b/pkg/service/class_abstract.go index 04c6a92..c33e5ea 100644 --- a/pkg/service/class_abstract.go +++ b/pkg/service/class_abstract.go @@ -5,6 +5,10 @@ import ( "strings" ) +var ( + abstractClassDeclarations []Class +) + type abstractClass struct { name string Interface *ast.InterfaceType @@ -82,6 +86,12 @@ func addAbstractClassFromStructType(name string, it *ast.InterfaceType) Class { } func createAbstractClass(className string) *abstractClass { c := NewAbstractClass(className) - addClassDeclaration(c) + addAbstractClassDeclaration(c) return c } +func addAbstractClassDeclaration(c Class) { + dlock.Lock() + defer dlock.Unlock() + + abstractClassDeclarations = append(abstractClassDeclarations, c) +} diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 75c6679..e947668 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -352,6 +352,10 @@ dev1=NewDevice(); ``` package test +type Device interface { + Name() string +} + type Mera int const c1 = 4 @@ -360,4 +364,8 @@ const c1 = 4 ``` const int c1 = 4; typedef int Mera; +class Device { +public: + virtual std::string Name() = 0; +}; ``` diff --git a/pkg/service/service.go b/pkg/service/service.go index c24ddb6..ccbd72b 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -87,6 +87,8 @@ func (s *defaultService) Start() error { } constDeclarations = nil + typeDeclarations = nil + abstractClassDeclarations = nil classDeclarations = nil funcDeclarations = nil helpersForDeclarations = nil @@ -106,6 +108,8 @@ func (s *defaultService) Start() error { s.printIncludeHeaders() s.printConstDeclarations() + s.printTypeDeclarations() + s.printAbstractClassDeclarations() s.printClassDeclarations() s.printFunctionDeclarations() s.printGoHelperDeclarations() @@ -145,6 +149,32 @@ func (s *defaultService) printConstDeclarations() { } s.out.Write([]byte("\n")) } +func (s *defaultService) printTypeDeclarations() { + dlock.Lock() + defer dlock.Unlock() + + for _, c := range typeDeclarations { + d := c.String() + s.out.Write([]byte(d + "\n")) + if s.header != nil { + s.header.Write([]byte(d + "\n")) + } + } + s.out.Write([]byte("\n")) +} +func (s *defaultService) printAbstractClassDeclarations() { + dlock.Lock() + defer dlock.Unlock() + + for _, c := range abstractClassDeclarations { + d := c.String() + s.out.Write([]byte(d + "\n")) + if s.header != nil { + s.header.Write([]byte(d + "\n")) + } + } + s.out.Write([]byte("\n")) +} func (s *defaultService) printClassDeclarations() { dlock.Lock() defer dlock.Unlock() diff --git a/pkg/service/type.go b/pkg/service/type.go index 7b5d697..b856761 100644 --- a/pkg/service/type.go +++ b/pkg/service/type.go @@ -19,17 +19,6 @@ func handleTypeSpec(s *ast.TypeSpec) (code string) { return handleType(s) } -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 { diff --git a/pkg/service/types.go b/pkg/service/types.go new file mode 100644 index 0000000..4397d62 --- /dev/null +++ b/pkg/service/types.go @@ -0,0 +1,34 @@ +package service + +import "go/ast" + +var ( + typeDeclarations []*Type +) + +type Type struct { + s *ast.TypeSpec +} + +func NewType(s *ast.TypeSpec) *Type { + return &Type{s: s} +} + +func (c *Type) String() (code string) { + code += "typedef " + code += handleExpr(c.s.Type) + code += " " + code += handleIdentExpr(c.s.Name) + code += optionallyAddArrayDetails(c.s) + code += ";" + return +} + +func handleType(s *ast.TypeSpec) (code string) { + addType(s) + return +} +func addType(s *ast.TypeSpec) { + c := NewType(s) + typeDeclarations = append(typeDeclarations, c) +}