mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-12 07:48:16 -05:00
Add Tests for ZCG cpp
This commit is contained in:
43
src/ZoneCodeGeneratorLib.lua
Normal file
43
src/ZoneCodeGeneratorLib.lua
Normal file
@ -0,0 +1,43 @@
|
||||
ZoneCodeGeneratorLib = {}
|
||||
|
||||
function ZoneCodeGeneratorLib:include()
|
||||
if References:include(self:name()) then
|
||||
includedirs {
|
||||
path.join(ProjectFolder(), "ZoneCodeGeneratorLib")
|
||||
}
|
||||
end
|
||||
Utils:include()
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLib:link()
|
||||
if References:link(self:name()) then
|
||||
links(self:name())
|
||||
Utils:link()
|
||||
end
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLib:use()
|
||||
dependson(self:name())
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLib:name()
|
||||
return "ZoneCodeGeneratorLib"
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorLib:project()
|
||||
References:reset()
|
||||
local folder = ProjectFolder();
|
||||
|
||||
project(self:name())
|
||||
targetdir(TargetDirectoryLib)
|
||||
location "%{wks.location}/src/%{prj.name}"
|
||||
kind "StaticLib"
|
||||
language "C++"
|
||||
|
||||
files {
|
||||
path.join(folder, "ZoneCodeGeneratorLib/**.h"),
|
||||
path.join(folder, "ZoneCodeGeneratorLib/**.cpp")
|
||||
}
|
||||
|
||||
self:include()
|
||||
end
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
#include "Parsing/Impl/IncludingStreamProxy.h"
|
||||
#include "Parsing/Impl/ParserFilesystemStream.h"
|
||||
|
||||
@ -23,8 +23,14 @@ bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository) const
|
||||
return false;
|
||||
}
|
||||
|
||||
IncludingStreamProxy includeProxy(&stream);
|
||||
IParserLineStream* lineStream = &includeProxy;
|
||||
IParserLineStream* lineStream = &stream;
|
||||
|
||||
IncludingStreamProxy includeProxy(lineStream);
|
||||
lineStream = &includeProxy;
|
||||
|
||||
CommentRemovingStreamProxy commentProxy(lineStream);
|
||||
lineStream = &commentProxy;
|
||||
|
||||
|
||||
while(true)
|
||||
{
|
@ -0,0 +1,74 @@
|
||||
#include "CommentRemovingStreamProxy.h"
|
||||
|
||||
CommentRemovingStreamProxy::CommentRemovingStreamProxy(IParserLineStream* stream)
|
||||
: m_stream(stream),
|
||||
m_inside_multi_line_comment(false),
|
||||
m_next_line_is_comment(false)
|
||||
{
|
||||
}
|
||||
|
||||
ParserLine CommentRemovingStreamProxy::NextLine()
|
||||
{
|
||||
auto line = m_stream->NextLine();
|
||||
|
||||
if (m_next_line_is_comment)
|
||||
{
|
||||
m_next_line_is_comment = !line.m_line.empty() && line.m_line[line.m_line.size() - 1] == '\\';
|
||||
return ParserLine(line.m_filename, line.m_line_number, std::string());
|
||||
}
|
||||
|
||||
unsigned multiLineCommentStart = 0;
|
||||
for (auto i = 0u; i < line.m_line.size(); i++)
|
||||
{
|
||||
const auto c = line.m_line[i];
|
||||
|
||||
if (m_inside_multi_line_comment)
|
||||
{
|
||||
if (c == '*' && i + 1 < line.m_line.size() && line.m_line[i + 1] == '/')
|
||||
{
|
||||
line.m_line.erase(multiLineCommentStart, i + 2 - multiLineCommentStart);
|
||||
multiLineCommentStart = 0;
|
||||
m_inside_multi_line_comment = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(c == '/' && i + 1 < line.m_line.size())
|
||||
{
|
||||
const auto c1 = line.m_line[i + 1];
|
||||
|
||||
if (c1 == '*')
|
||||
{
|
||||
multiLineCommentStart = i;
|
||||
m_inside_multi_line_comment = true;
|
||||
}
|
||||
else if(c1 == '/')
|
||||
{
|
||||
m_next_line_is_comment = line.m_line[line.m_line.size() - 1] == '\\';
|
||||
line.m_line.erase(i);
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(m_inside_multi_line_comment)
|
||||
line.m_line.erase(multiLineCommentStart);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
bool CommentRemovingStreamProxy::IncludeFile(const std::string& filename)
|
||||
{
|
||||
return m_stream->IncludeFile(filename);
|
||||
}
|
||||
|
||||
bool CommentRemovingStreamProxy::IsOpen() const
|
||||
{
|
||||
return m_stream->IsOpen();
|
||||
}
|
||||
|
||||
bool CommentRemovingStreamProxy::Eof() const
|
||||
{
|
||||
return m_stream->Eof();
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
class CommentRemovingStreamProxy final : public IParserLineStream
|
||||
{
|
||||
IParserLineStream* const m_stream;
|
||||
bool m_inside_multi_line_comment;
|
||||
bool m_next_line_is_comment;
|
||||
|
||||
public:
|
||||
explicit CommentRemovingStreamProxy(IParserLineStream* stream);
|
||||
|
||||
ParserLine NextLine() override;
|
||||
bool IncludeFile(const std::string& filename) override;
|
||||
_NODISCARD bool IsOpen() const override;
|
||||
_NODISCARD bool Eof() const override;
|
||||
};
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
class IncludingStreamProxy final : public IParserLineStream
|
||||
@ -10,7 +9,7 @@ class IncludingStreamProxy final : public IParserLineStream
|
||||
static constexpr int INCLUDE_DIRECTIVE_LENGTH = std::char_traits<char>::length(INCLUDE_DIRECTIVE);
|
||||
static constexpr int INCLUDE_DIRECTIVE_MINIMUM_TOTAL_LENGTH = INCLUDE_DIRECTIVE_LENGTH + 1 + 2; // #=+1 ""=+2
|
||||
|
||||
IParserLineStream* m_stream;
|
||||
IParserLineStream* const m_stream;
|
||||
|
||||
_NODISCARD static bool FindIncludeDirective(const ParserLine& line, unsigned& includeDirectivePosition);
|
||||
_NODISCARD static bool ExtractIncludeFilename(const ParserLine& line, unsigned includeDirectivePosition, unsigned& filenameStartPosition, unsigned& filenameEndPosition);
|
@ -6,10 +6,13 @@ function ZoneCodeGeneratorNew:include()
|
||||
path.join(ProjectFolder(), "ZoneCodeGeneratorNew")
|
||||
}
|
||||
end
|
||||
Utils:include()
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorNew:link()
|
||||
|
||||
if References:link(self:name()) then
|
||||
links(self:name())
|
||||
end
|
||||
end
|
||||
|
||||
function ZoneCodeGeneratorNew:use()
|
||||
@ -25,7 +28,7 @@ function ZoneCodeGeneratorNew:project()
|
||||
local folder = ProjectFolder();
|
||||
|
||||
project(self:name())
|
||||
targetdir(TargetDirectoryLib)
|
||||
targetdir(TargetDirectoryBin)
|
||||
location "%{wks.location}/src/%{prj.name}"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
@ -34,9 +37,15 @@ function ZoneCodeGeneratorNew:project()
|
||||
path.join(folder, "ZoneCodeGeneratorNew/**.h"),
|
||||
path.join(folder, "ZoneCodeGeneratorNew/**.cpp")
|
||||
}
|
||||
vpaths {
|
||||
["*"] = {
|
||||
path.join(folder, "ZoneCodeGeneratorNew"),
|
||||
}
|
||||
}
|
||||
|
||||
self:include()
|
||||
Utils:include()
|
||||
ZoneCodeGeneratorLib:include()
|
||||
|
||||
Utils:link()
|
||||
ZoneCodeGeneratorLib:link()
|
||||
end
|
||||
|
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
class CommentRemovingStreamProxy final : IParserLineStream
|
||||
{
|
||||
public:
|
||||
std::string NextLine() override;
|
||||
bool IncludeFile(const std::string& filename) override;
|
||||
bool IsOpen() const override;
|
||||
_NODISCARD bool Eof() const override;
|
||||
};
|
Reference in New Issue
Block a user