Skip to content

Commit

Permalink
Implemented generation of arrays and optional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurii.Blok authored and Yurii.Blok committed Mar 30, 2018
1 parent 99b89ba commit 89927ae
Show file tree
Hide file tree
Showing 9 changed files with 876 additions and 176 deletions.
Binary file modified Binaries/ibc_x64
Binary file not shown.
3 changes: 3 additions & 0 deletions Compiler/Compiler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -138,6 +139,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -154,6 +156,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="inbcompiler.cpp" />
<ClCompile Include="inbcpp.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand Down
58 changes: 15 additions & 43 deletions Compiler/inbcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,6 @@ void splitIbs(const std::string &source, std::list<std::string> &splitted)
splitted.emplace_back(std::move(buffer));
}

enum class kw
{
Namespace,
Enum,
Struct,
Optional,
Int8,
Uint8,
Int16,
Uint16,
Int32,
Uint32,
Int64,
Uint64,
Float32,
Float64,
Bytes,
};
static const std::map<std::string, kw> keywords =
{
{ "namespace", kw::Namespace },
{ "enum" , kw::Enum },
{ "struct" , kw::Struct },
{ "optional" , kw::Optional },
{ "int8" , kw::Int8 },
{ "uint8" , kw::Uint8 },
{ "int16" , kw::Int16 },
{ "uint16" , kw::Uint16 },
{ "int32" , kw::Int32 },
{ "uint32" , kw::Uint32 },
{ "int64" , kw::Int64 },
{ "uint64" , kw::Uint64 },
{ "float32" , kw::Float32 },
{ "float64" , kw::Float64 },
{ "bytes" , kw::Bytes }
};
static const std::string tokenOpenScope("{");
static const std::string tokenCloseScope("}");
static const std::string tokenArray("[]");
static const std::string tokenEquals("=");
static const std::string tokenColon(":");
static const std::string tokenOptional("optional");

INBCompiler::INBCompiler()
{}
Expand Down Expand Up @@ -294,7 +252,9 @@ void INBCompiler::parseStruct(tokens_it &it)
if (*it != tokenOpenScope) // <{>
return;
next(it); // ++<{>
auto &fieldsList = m_structs[structName];
auto &fieldsList = m_structs[structName].first;
auto &optionalCount = m_structs[structName].second;
optionalCount = 0;
bool isExpectType = false;
while (*it != tokenCloseScope)
{
Expand All @@ -305,6 +265,9 @@ void INBCompiler::parseStruct(tokens_it &it)
if (fieldsList.empty())
return;
fieldsList.back().second.isArray = true;
if (!fieldsList.back().second.isOptional)
optionalCount++;
fieldsList.back().second.isOptional = true;
if (!next(it))
return;
}
Expand All @@ -314,6 +277,8 @@ void INBCompiler::parseStruct(tokens_it &it)
return;
if (fieldsList.empty())
return;
if (!fieldsList.back().second.isOptional)
optionalCount++;
fieldsList.back().second.isOptional = true;
if (!next(it))
return;
Expand All @@ -327,6 +292,13 @@ void INBCompiler::parseStruct(tokens_it &it)
if (fieldsList.empty())
return;
fieldsList.back().second.type = std::move(*it);
if (fieldsList.back().second.type == tokenBytes)
{
fieldsList.back().second.isArray = true;
if (!fieldsList.back().second.isOptional)
optionalCount++;
fieldsList.back().second.isOptional = true;
}
if (!next(it))
return;
isExpectType = false;
Expand Down
48 changes: 47 additions & 1 deletion Compiler/inbcompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,50 @@ enum class Language
{
CPP
};
enum class kw
{
Namespace,
Enum,
Struct,
Optional,
Int8,
Uint8,
Int16,
Uint16,
Int32,
Uint32,
Int64,
Uint64,
Float32,
Float64,
Bytes,
};
static const std::map<std::string, kw> keywords =
{
{ "namespace", kw::Namespace },
{ "enum" , kw::Enum },
{ "struct" , kw::Struct },
{ "optional" , kw::Optional },
{ "int8" , kw::Int8 },
{ "uint8" , kw::Uint8 },
{ "int16" , kw::Int16 },
{ "uint16" , kw::Uint16 },
{ "int32" , kw::Int32 },
{ "uint32" , kw::Uint32 },
{ "int64" , kw::Int64 },
{ "uint64" , kw::Uint64 },
{ "float32" , kw::Float32 },
{ "float64" , kw::Float64 },
{ "bytes" , kw::Bytes }
};
static const std::string tokenOpenScope("{");
static const std::string tokenCloseScope("}");
static const std::string tokenArray("[]");
static const std::string tokenEquals("=");
static const std::string tokenColon(":");
static const std::string tokenOptional("optional");
static const std::string tokenBytes("bytes");


class INBCompiler
{
Expand Down Expand Up @@ -42,7 +86,9 @@ class INBCompiler
bool isOptional = false;
bool isArray = false;
};
using StructDescr = std::list<std::pair<std::string, StructFieldType>>;
using StructDescr = std::pair<std::list<std::pair<std::string,
StructFieldType>>,
uint32_t>;
std::map<std::string, StructDescr> m_structs;

bool m_detailed = false;
Expand Down
Loading

0 comments on commit 89927ae

Please sign in to comment.