Skip to content

Commit 89927ae

Browse files
Yurii.BlokYurii.Blok
authored andcommitted
Implemented generation of arrays and optional fields
1 parent 99b89ba commit 89927ae

File tree

9 files changed

+876
-176
lines changed

9 files changed

+876
-176
lines changed

Binaries/ibc_x64

12.7 KB
Binary file not shown.

Compiler/Compiler.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<SDLCheck>true</SDLCheck>
121121
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122122
<ConformanceMode>true</ConformanceMode>
123+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
123124
</ClCompile>
124125
<Link>
125126
<SubSystem>Console</SubSystem>
@@ -138,6 +139,7 @@
138139
<SDLCheck>true</SDLCheck>
139140
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
140141
<ConformanceMode>true</ConformanceMode>
142+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
141143
</ClCompile>
142144
<Link>
143145
<SubSystem>Console</SubSystem>
@@ -154,6 +156,7 @@
154156
</ItemGroup>
155157
<ItemGroup>
156158
<ClCompile Include="inbcompiler.cpp" />
159+
<ClCompile Include="inbcpp.cpp" />
157160
<ClCompile Include="main.cpp" />
158161
<ClCompile Include="stdafx.cpp">
159162
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

Compiler/inbcompiler.cpp

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,6 @@ void splitIbs(const std::string &source, std::list<std::string> &splitted)
4040
splitted.emplace_back(std::move(buffer));
4141
}
4242

43-
enum class kw
44-
{
45-
Namespace,
46-
Enum,
47-
Struct,
48-
Optional,
49-
Int8,
50-
Uint8,
51-
Int16,
52-
Uint16,
53-
Int32,
54-
Uint32,
55-
Int64,
56-
Uint64,
57-
Float32,
58-
Float64,
59-
Bytes,
60-
};
61-
static const std::map<std::string, kw> keywords =
62-
{
63-
{ "namespace", kw::Namespace },
64-
{ "enum" , kw::Enum },
65-
{ "struct" , kw::Struct },
66-
{ "optional" , kw::Optional },
67-
{ "int8" , kw::Int8 },
68-
{ "uint8" , kw::Uint8 },
69-
{ "int16" , kw::Int16 },
70-
{ "uint16" , kw::Uint16 },
71-
{ "int32" , kw::Int32 },
72-
{ "uint32" , kw::Uint32 },
73-
{ "int64" , kw::Int64 },
74-
{ "uint64" , kw::Uint64 },
75-
{ "float32" , kw::Float32 },
76-
{ "float64" , kw::Float64 },
77-
{ "bytes" , kw::Bytes }
78-
};
79-
static const std::string tokenOpenScope("{");
80-
static const std::string tokenCloseScope("}");
81-
static const std::string tokenArray("[]");
82-
static const std::string tokenEquals("=");
83-
static const std::string tokenColon(":");
84-
static const std::string tokenOptional("optional");
8543

8644
INBCompiler::INBCompiler()
8745
{}
@@ -294,7 +252,9 @@ void INBCompiler::parseStruct(tokens_it &it)
294252
if (*it != tokenOpenScope) // <{>
295253
return;
296254
next(it); // ++<{>
297-
auto &fieldsList = m_structs[structName];
255+
auto &fieldsList = m_structs[structName].first;
256+
auto &optionalCount = m_structs[structName].second;
257+
optionalCount = 0;
298258
bool isExpectType = false;
299259
while (*it != tokenCloseScope)
300260
{
@@ -305,6 +265,9 @@ void INBCompiler::parseStruct(tokens_it &it)
305265
if (fieldsList.empty())
306266
return;
307267
fieldsList.back().second.isArray = true;
268+
if (!fieldsList.back().second.isOptional)
269+
optionalCount++;
270+
fieldsList.back().second.isOptional = true;
308271
if (!next(it))
309272
return;
310273
}
@@ -314,6 +277,8 @@ void INBCompiler::parseStruct(tokens_it &it)
314277
return;
315278
if (fieldsList.empty())
316279
return;
280+
if (!fieldsList.back().second.isOptional)
281+
optionalCount++;
317282
fieldsList.back().second.isOptional = true;
318283
if (!next(it))
319284
return;
@@ -327,6 +292,13 @@ void INBCompiler::parseStruct(tokens_it &it)
327292
if (fieldsList.empty())
328293
return;
329294
fieldsList.back().second.type = std::move(*it);
295+
if (fieldsList.back().second.type == tokenBytes)
296+
{
297+
fieldsList.back().second.isArray = true;
298+
if (!fieldsList.back().second.isOptional)
299+
optionalCount++;
300+
fieldsList.back().second.isOptional = true;
301+
}
330302
if (!next(it))
331303
return;
332304
isExpectType = false;

Compiler/inbcompiler.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,50 @@ enum class Language
88
{
99
CPP
1010
};
11+
enum class kw
12+
{
13+
Namespace,
14+
Enum,
15+
Struct,
16+
Optional,
17+
Int8,
18+
Uint8,
19+
Int16,
20+
Uint16,
21+
Int32,
22+
Uint32,
23+
Int64,
24+
Uint64,
25+
Float32,
26+
Float64,
27+
Bytes,
28+
};
29+
static const std::map<std::string, kw> keywords =
30+
{
31+
{ "namespace", kw::Namespace },
32+
{ "enum" , kw::Enum },
33+
{ "struct" , kw::Struct },
34+
{ "optional" , kw::Optional },
35+
{ "int8" , kw::Int8 },
36+
{ "uint8" , kw::Uint8 },
37+
{ "int16" , kw::Int16 },
38+
{ "uint16" , kw::Uint16 },
39+
{ "int32" , kw::Int32 },
40+
{ "uint32" , kw::Uint32 },
41+
{ "int64" , kw::Int64 },
42+
{ "uint64" , kw::Uint64 },
43+
{ "float32" , kw::Float32 },
44+
{ "float64" , kw::Float64 },
45+
{ "bytes" , kw::Bytes }
46+
};
47+
static const std::string tokenOpenScope("{");
48+
static const std::string tokenCloseScope("}");
49+
static const std::string tokenArray("[]");
50+
static const std::string tokenEquals("=");
51+
static const std::string tokenColon(":");
52+
static const std::string tokenOptional("optional");
53+
static const std::string tokenBytes("bytes");
54+
1155

1256
class INBCompiler
1357
{
@@ -42,7 +86,9 @@ class INBCompiler
4286
bool isOptional = false;
4387
bool isArray = false;
4488
};
45-
using StructDescr = std::list<std::pair<std::string, StructFieldType>>;
89+
using StructDescr = std::pair<std::list<std::pair<std::string,
90+
StructFieldType>>,
91+
uint32_t>;
4692
std::map<std::string, StructDescr> m_structs;
4793

4894
bool m_detailed = false;

0 commit comments

Comments
 (0)