-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRunner.cpp
More file actions
114 lines (83 loc) · 2.13 KB
/
Runner.cpp
File metadata and controls
114 lines (83 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef _RUNNER_
#define _RUNNER_
#include "Runner.h"
#include "direct.h"
#include "Objects.h"
#include "share.h"
#include "ElementData.h"
TElementRunner *erun;
extern PCodeGenTools cgt;
TElementRunner::TElementRunner() {
CG_LOG_BEGIN
tools = NULL;
}
TElementRunner::~TElementRunner() {
for(TCode *item : codeList)
delete item;
codeList.clear();
if(tools)
delete tools;
CG_LOG_END
}
int TElementRunner::Add(TCode *code) {
CG_LOG_BEGIN
codeList.push_back(code);
CG_LOG_RETURN(0)
}
TCode *TElementRunner::find(const char *unit) {
CG_LOG_BEGIN
ASSERT(unit, "unit is NULL")
for(TCode *item : codeList)
if (strcasecmp(item->name, unit) == 0)
CG_LOG_RETURN(item)
CG_LOG_RETURN(NULL)
}
int TElementRunner::init(id_element e) {
CG_LOG_BEGIN
if(cgt->elGetData(e))
CG_LOG_RETURN(0)
const char *name = cgt->elGetClassName(e);
TCode *code = find(name);
if (!code) {
code = new TCode();
cg_assert(code->parseUnit(e, name) == 0)
Add(code);
}
ElementData *data = new ElementData(code->root);
cgt->elSetData(e, data);
TArgs *args = new TArgs();
TValue::free(code->run(e, "init", args));
delete args;
CG_LOG_RETURN(0)
}
TValue* TElementRunner::run(id_element e, const char *entry, TArgs *args) {
CG_LOG_BEGIN
if(init(e))
CG_LOG_RETURN(NULL)
TCode *code = find(cgt->elGetClassName(e));
ASSERT(code, "runner not found")
TValue *ret = code->run(e, entry, args);
CG_LOG_RETURN(ret)
}
int TElementRunner::createTools(id_element e) {
CG_LOG_BEGIN
gvars = new TVarsList();
tools = new TCode();
cg_assert(tools->parseUnit(e, "Sys") == 0)
TSysObject *t = (TSysObject*)searchObject("sys");
t->root = tools->root;
TArgs *args = new TArgs();
args->add(new TValue(cgt->elGetClassName(e)));
TValue::free(tools->run(e, "create", args));
delete args;
CG_LOG_RETURN(0)
}
int TElementRunner::destroyTools(id_element e) {
CG_LOG_BEGIN
TArgs *args = new TArgs();
args->add(new TValue(cgt->elGetClassName(e)));
TValue::free(tools->run(e, "destroy", args));
delete args;
CG_LOG_RETURN(0)
}
#endif