Сценарий: Последовательность блоков: абстрактные и обычные классы - в своей последовательности
Реализация методов - отдельно
Этот коммит содержится в:
родитель
88229f2bd5
коммит
6113b6be28
4 изменённых файлов: 61 добавлений и 45 удалений
|
@ -7,6 +7,7 @@ import (
|
|||
type Class interface {
|
||||
Name() string
|
||||
String() string
|
||||
MethodsString() string
|
||||
AddMethod(*ast.FuncDecl)
|
||||
}
|
||||
|
||||
|
@ -33,9 +34,13 @@ func (c *class) Name() string {
|
|||
|
||||
func (c *class) String() (code string) {
|
||||
code += c.classDefinitionToString()
|
||||
return
|
||||
}
|
||||
func (c *class) MethodsString() (code string) {
|
||||
code += c.methodImplementationsToString()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *class) classDefinitionToString() (code string) {
|
||||
code = "class " + c.name + " {"
|
||||
code += "public:\n"
|
||||
|
|
|
@ -5,10 +5,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
abstractClassDeclarations []Class
|
||||
)
|
||||
|
||||
type abstractClass struct {
|
||||
name string
|
||||
Interface *ast.InterfaceType
|
||||
|
@ -26,6 +22,10 @@ func (c *abstractClass) String() (code string) {
|
|||
code += c.abstractClassDefinitionToString()
|
||||
return
|
||||
}
|
||||
func (c *abstractClass) MethodsString() (code string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *abstractClass) abstractClassDefinitionToString() (code string) {
|
||||
code = "class " + c.name + " {"
|
||||
code += "public:\n"
|
||||
|
@ -93,5 +93,5 @@ func addAbstractClassDeclaration(c Class) {
|
|||
dlock.Lock()
|
||||
defer dlock.Unlock()
|
||||
|
||||
abstractClassDeclarations = append(abstractClassDeclarations, c)
|
||||
classDeclarations = append(classDeclarations, c)
|
||||
}
|
||||
|
|
|
@ -302,11 +302,14 @@ func main() {
|
|||
```
|
||||
* Результат:
|
||||
```
|
||||
void main();
|
||||
class device {
|
||||
public:
|
||||
};
|
||||
|
||||
void main();
|
||||
|
||||
device *dev1,*dev2;
|
||||
|
||||
void main() {
|
||||
dev1=new device();
|
||||
}
|
||||
|
@ -333,12 +336,15 @@ func main() {
|
|||
```
|
||||
* Результат:
|
||||
```
|
||||
Device* NewDevice();
|
||||
void main();
|
||||
class Device {
|
||||
public:
|
||||
};
|
||||
|
||||
Device* NewDevice();
|
||||
void main();
|
||||
|
||||
Device *dev1,*dev2;
|
||||
|
||||
Device* NewDevice() {
|
||||
return new Device();
|
||||
}
|
||||
|
@ -347,7 +353,12 @@ dev1=NewDevice();
|
|||
}
|
||||
```
|
||||
|
||||
Сценарий: Последовательность блоков: инклюды, константы, типы, абстрактные классы, классы, переменные, определения функций, функции
|
||||
Сценарий: Последовательность блоков:
|
||||
инклюды, константы, типы,
|
||||
абстрактные классы/классы,
|
||||
определения функций,
|
||||
переменные,
|
||||
методы классов, функции
|
||||
* Исходник:
|
||||
```
|
||||
package test
|
||||
|
@ -378,23 +389,24 @@ const int c1 = 4;
|
|||
|
||||
typedef int Mera;
|
||||
|
||||
void someFunc();
|
||||
|
||||
class device {
|
||||
public:
|
||||
void doSomething();
|
||||
};
|
||||
class Device {
|
||||
public:
|
||||
virtual std::string Name() = 0;
|
||||
};
|
||||
|
||||
class device {
|
||||
public:
|
||||
void doSomething();
|
||||
};
|
||||
void device::doSomething() {
|
||||
}
|
||||
|
||||
void someFunc();
|
||||
|
||||
int a = 1;
|
||||
int b = 1;
|
||||
|
||||
void device::doSomething() {
|
||||
}
|
||||
|
||||
void someFunc() {
|
||||
}
|
||||
```
|
||||
|
|
|
@ -89,7 +89,6 @@ func (s *defaultService) Start() error {
|
|||
includeDeclarations = nil
|
||||
constDeclarations = nil
|
||||
typeDeclarations = nil
|
||||
abstractClassDeclarations = nil
|
||||
classDeclarations = nil
|
||||
variableDeclarations = nil
|
||||
funcDeclarations = nil
|
||||
|
@ -112,10 +111,10 @@ func (s *defaultService) Start() error {
|
|||
s.printIncludes()
|
||||
s.printConstDeclarations()
|
||||
s.printTypeDeclarations()
|
||||
s.printFunctionDeclarations()
|
||||
s.printAbstractClassDeclarations()
|
||||
s.printClassDeclarations()
|
||||
s.printFunctionDeclarations()
|
||||
s.printVariableDeclarations()
|
||||
s.printMethodImplementations()
|
||||
s.printGoHelperDeclarations()
|
||||
|
||||
// Print the ordered result.
|
||||
|
@ -179,31 +178,6 @@ func (s *defaultService) printTypeDeclarations() {
|
|||
}
|
||||
s.out.Write([]byte("\n"))
|
||||
}
|
||||
func (s *defaultService) printFunctionDeclarations() {
|
||||
dlock.Lock()
|
||||
defer dlock.Unlock()
|
||||
|
||||
for _, f := range funcDeclarations {
|
||||
s.out.Write([]byte(f + "\n"))
|
||||
if s.header != nil {
|
||||
s.header.Write([]byte(f + "\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()
|
||||
|
@ -217,6 +191,18 @@ func (s *defaultService) printClassDeclarations() {
|
|||
}
|
||||
s.out.Write([]byte("\n"))
|
||||
}
|
||||
func (s *defaultService) printFunctionDeclarations() {
|
||||
dlock.Lock()
|
||||
defer dlock.Unlock()
|
||||
|
||||
for _, f := range funcDeclarations {
|
||||
s.out.Write([]byte(f + "\n"))
|
||||
if s.header != nil {
|
||||
s.header.Write([]byte(f + "\n"))
|
||||
}
|
||||
}
|
||||
s.out.Write([]byte("\n"))
|
||||
}
|
||||
func (s *defaultService) printVariableDeclarations() {
|
||||
dlock.Lock()
|
||||
defer dlock.Unlock()
|
||||
|
@ -230,6 +216,19 @@ func (s *defaultService) printVariableDeclarations() {
|
|||
}
|
||||
s.out.Write([]byte("\n"))
|
||||
}
|
||||
func (s *defaultService) printMethodImplementations() {
|
||||
dlock.Lock()
|
||||
defer dlock.Unlock()
|
||||
|
||||
for _, c := range classDeclarations {
|
||||
d := c.MethodsString()
|
||||
s.out.Write([]byte(d + "\n"))
|
||||
if s.header != nil {
|
||||
s.header.Write([]byte(d + "\n"))
|
||||
}
|
||||
}
|
||||
s.out.Write([]byte("\n"))
|
||||
}
|
||||
func (s *defaultService) printGoHelperDeclarations() {
|
||||
dlock.Lock()
|
||||
defer dlock.Unlock()
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче