This commit is contained in:
2023-03-13 08:41:32 -07:00
parent 95d1ef476f
commit a3b4da498e
8 changed files with 221 additions and 212 deletions

View File

@@ -1,75 +1,75 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "CodeGen.hpp"
using namespace Dawn;
void CodeGen::line(
std::vector<std::string> *out,
std::string contents,
std::string tabs
) {
out->push_back(tabs + contents);
}
void CodeGen::lines(
std::vector<std::string> *out,
std::vector<std::string> lines,
std::string tabs
) {
auto itLine = lines.begin();
while(itLine != lines.end()) {
line(out, *itLine, tabs);
++itLine;
}
}
void CodeGen::classGen(
std::vector<std::string> *out,
struct ClassGenInfo info
) {
std::vector<std::string> buffer;
line(out, "#pragma once", "");
line(out, "", "");
if(info.includes.size() > 0) {
lines(out, info.includes, "");
line(out, "", "");
}
line(out, "namespace Dawn {", "");
line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " ");
if(info.protectedCode.size() > 0) {
line(out, "protected:", " ");
lines(out, info.protectedProperties, " ");
line(out, "", " ");
lines(out, info.protectedCode, " ");
}
if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) {
line(out, "public:", " ");
lines(out, info.publicProperties, " ");
line(out, "", " ");
line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " ");
lines(out, info.constructorCode, " ");
line(out, "}", " ");
if(info.publicCode.size() > 0) {
line(out, "", " ");
lines(out, info.publicCode, " ");
}
}
line(out, "};", " ");
line(out, "}", "");
}
void CodeGen::methodGen(
std::vector<std::string> *out,
struct MethodGenInfo info
) {
line(out, info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override" : "" ) + "{", "");
lines(out, info.body, " ");
line(out, "}", "");
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "CodeGen.hpp"
using namespace Dawn;
void CodeGen::line(
std::vector<std::string> *out,
std::string contents,
std::string tabs
) {
out->push_back(tabs + contents);
}
void CodeGen::lines(
std::vector<std::string> *out,
std::vector<std::string> lines,
std::string tabs
) {
auto itLine = lines.begin();
while(itLine != lines.end()) {
line(out, *itLine, tabs);
++itLine;
}
}
void CodeGen::classGen(
std::vector<std::string> *out,
struct ClassGenInfo info
) {
std::vector<std::string> buffer;
line(out, "#pragma once", "");
line(out, "", "");
if(info.includes.size() > 0) {
lines(out, info.includes, "");
line(out, "", "");
}
line(out, "namespace Dawn {", "");
line(out, "class " + info.clazz + (info.extend.size() == 0 ? "{" : " : public " + info.extend + " {" ), " ");
if(info.protectedCode.size() > 0) {
line(out, "protected:", " ");
lines(out, info.protectedProperties, " ");
line(out, "", " ");
lines(out, info.protectedCode, " ");
}
if(info.publicCode.size() > 0 || info.constructorArgs.size() > 0 || info.constructorCode.size() > 0) {
line(out, "public:", " ");
lines(out, info.publicProperties, " ");
line(out, "", " ");
line(out, info.clazz + "(" + info.constructorArgs + ")" + (info.extend.size() > 0 ? " : " + info.extend + "(" + info.extendArgs + ")" : "") + " {", " ");
lines(out, info.constructorCode, " ");
line(out, "}", " ");
if(info.publicCode.size() > 0) {
line(out, "", " ");
lines(out, info.publicCode, " ");
}
}
line(out, "};", " ");
line(out, "}", "");
}
void CodeGen::methodGen(
std::vector<std::string> *out,
struct MethodGenInfo info
) {
line(out, (info.isStatic ? "static " : "") + info.type + " " + info.name + "(" + info.args + ") " + ( info.isOverride ? "override " : "" ) + "{", "");
lines(out, info.body, " ");
line(out, "}", "");
}