Repository navigation
Expand file tree
/
Copy pathTypeDefinition.cpp
More file actions
99 lines (79 loc) · 2.23 KB
/
Copy pathTypeDefinition.cpp
File metadata and controls
99 lines (79 loc) · 2.23 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
#include "code_generator/TypeDefinition.hpp"
TypeDefinition::TypeDefinition(const String &name,
TypeRef declare)
: Type(declare)
, m_name(name)
{
}
TypeRef TypeDefinition::declare() const
{
return parent();
}
String TypeDefinition::name() const
{
return m_name;
}
bool BlockTypeDefinition::hasPosition(int pos, BlockTypeDefinition::Position check)
{
return (pos & check) == check;
}
int BlockTypeDefinition::indexToPosition(int idx, int count)
{
int position = 0;
if (idx == count - 1) {
position |= Position_End;
} else if (idx == 0) {
position |= Position_Start;
}
return position;
}
BlockTypeDefinition::BlockTypeDefinition(const String &name,
TypeRef declare,
const BlockTypeDefinition::CodesContainer &codeContainer)
: TypeDefinition(name, declare)
, m_codeContainer(codeContainer)
{
}
BlockTypeDefinition::~BlockTypeDefinition()
{
}
const BlockTypeDefinition::CodesContainer &BlockTypeDefinition::codeContainer() const
{
return m_codeContainer;
}
int BlockTypeDefinition::typeWrite(Dequque &leftSide, Dequque &rightSide)
{
leftSide.push_back("{$>\n");
for (size_t i = 0; i < m_codeContainer.size(); ++i) {
auto& field = m_codeContainer[i];
writeCode(field, indexToPosition(int(i), int(m_codeContainer.size())), leftSide, rightSide);
}
leftSide.push_back("}");
return 0;
}
void BlockTypeDefinition::addCode(CodeRef code)
{
m_codeContainer.push_back(code);
}
void BlockTypeDefinition::writeCode(CodeRef code, int position, Dequque &larea, Dequque &/*rarea*/)
{
bool isStart = hasPosition(position, Position_Start);
bool isEnd = hasPosition(position, Position_End);
String fieldStr = code->toString();
larea.push_back(fieldStr);
if (code->codeType() != Code::CodeType_Text && code->codeType() != Code::CodeType_Normal) {
larea.push_back(";");
}
if (isEnd) {
larea.push_back("$<");
}
larea.push_back("\n");
if (code->kind() == Code::Kind::CodeBlock) {
if (!isStart) {
larea.push_back("\n");
}
if (isEnd) {
larea.push_back("\n");
}
}
}