summaryrefslogtreecommitdiff
path: root/ZAPD/Declaration.cpp
diff options
context:
space:
mode:
authorNicholas Estelami <NEstelami@users.noreply.github.com>2023-05-04 22:36:23 -0400
committerGitHub <noreply@github.com>2023-05-04 22:36:23 -0400
commitecc25616ec90e14f3ddcf3c703b7a29d6ccf1f95 (patch)
treeb68d94985389201efa89938523bc536f7950a7dd /ZAPD/Declaration.cpp
parent0dbba745dfed52be5cab97257dbf56a2223dd874 (diff)
Cleaned up and Documented Declaration Class (#290)
Diffstat (limited to 'ZAPD/Declaration.cpp')
-rw-r--r--ZAPD/Declaration.cpp187
1 files changed, 92 insertions, 95 deletions
diff --git a/ZAPD/Declaration.cpp b/ZAPD/Declaration.cpp
index ef651db..1da29f4 100644
--- a/ZAPD/Declaration.cpp
+++ b/ZAPD/Declaration.cpp
@@ -4,69 +4,81 @@
#include "Utils/StringHelper.h"
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
- const std::string& nText)
+ const std::string& nBody)
{
address = nAddress;
alignment = nAlignment;
size = nSize;
- text = nText;
+ declBody = nBody;
}
-Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
- const std::string& nVarType, const std::string& nVarName, bool nIsArray,
- const std::string& nText)
- : Declaration(nAddress, nAlignment, nSize, nText)
+Declaration* Declaration::Create(offset_t declAddr, DeclarationAlignment declAlign, size_t declSize,
+ const std::string& declType, const std::string& declName, const std::string& declBody)
{
- varType = nVarType;
- varName = nVarName;
- isArray = nIsArray;
-}
+ Declaration* decl = new Declaration(declAddr, declAlign, declSize, declBody);
-Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
- const std::string& nVarType, const std::string& nVarName, bool nIsArray,
- size_t nArrayItemCnt, const std::string& nText)
- : Declaration(nAddress, nAlignment, nSize, nText)
-{
- varType = nVarType;
- varName = nVarName;
- isArray = nIsArray;
- arrayItemCnt = nArrayItemCnt;
+ decl->declType = declType;
+ decl->declName = declName;
+ decl->declBody = declBody;
+
+ return decl;
}
-Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
- const std::string& nVarType, const std::string& nVarName, bool nIsArray,
- const std::string& nArrayItemCntStr, const std::string& nText)
- : Declaration(nAddress, nAlignment, nSize, nText)
+Declaration* Declaration::CreateArray(offset_t declAddr, DeclarationAlignment declAlign,
+ size_t declSize, const std::string& declType, const std::string& declName,
+ const std::string& declBody, size_t declArrayItemCnt,
+ bool isDeclExternal)
{
- varType = nVarType;
- varName = nVarName;
- isArray = nIsArray;
- arrayItemCntStr = nArrayItemCntStr;
+ Declaration* decl = new Declaration(declAddr, declAlign, declSize, declBody);
+
+
+ decl->declName = declName;
+ decl->declType = declType;
+ decl->arrayItemCnt = declArrayItemCnt;
+ decl->isExternal = isDeclExternal;
+ decl->isArray = true;
+
+ return decl;
}
-Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
- const std::string& nVarType, const std::string& nVarName, bool nIsArray,
- size_t nArrayItemCnt, const std::string& nText, bool nIsExternal)
- : Declaration(nAddress, nAlignment, nSize, nVarType, nVarName, nIsArray, nArrayItemCnt, nText)
+Declaration* Declaration::CreateArray(offset_t declAddr, DeclarationAlignment declAlign,
+ size_t declSize, const std::string& declType, const std::string& declName,
+ const std::string& declBody, const std::string& declArrayItemCntStr,
+ bool isDeclExternal)
{
- isExternal = nIsExternal;
+ Declaration* decl = new Declaration(declAddr, declAlign, declSize, declBody);
+
+ decl->declName = declName;
+ decl->declType = declType;
+ decl->arrayItemCntStr = declArrayItemCntStr;
+ decl->isExternal = isDeclExternal;
+ decl->isArray = true;
+
+ return decl;
}
-Declaration::Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize,
- const std::string& nVarType, const std::string& nVarName)
- : Declaration(nAddress, DeclarationAlignment::Align4, nSize, "")
+Declaration* Declaration::CreateInclude(offset_t declAddr, const std::string& includePath, size_t declSize,
+ const std::string& declType, const std::string& declName,
+ const std::string& defines)
{
- includePath = nIncludePath;
- varType = nVarType;
- varName = nVarName;
+ Declaration* decl = new Declaration(declAddr, DeclarationAlignment::Align4, declSize, "");
+ decl->includePath = includePath;
+ decl->declType = declType;
+ decl->declName = declName;
+ decl->defines = defines;
+
+
+ return decl;
}
-Declaration::Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize,
- const std::string& nVarType, const std::string& nVarName,
- const std::string& nDefines)
- : Declaration(nAddress, nIncludePath, nSize, nVarType, nVarName)
+Declaration* Declaration::CreatePlaceholder(offset_t declAddr, const std::string& declName)
{
- defines = nDefines;
+ Declaration* decl =
+ new Declaration(declAddr, DeclarationAlignment::Align4, 0, "");
+ decl->declName = declName;
+ decl->isPlaceholder = true;
+
+ return decl;
}
bool Declaration::IsStatic() const
@@ -90,9 +102,6 @@ std::string Declaration::GetNormalDeclarationStr() const
{
std::string output;
- if (preText != "")
- output += preText + "\n";
-
if (IsStatic())
{
output += "static ";
@@ -100,27 +109,28 @@ std::string Declaration::GetNormalDeclarationStr() const
if (isArray)
{
- if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt))
+ bool includeArraySize = (IsStatic() || forceArrayCnt);
+
+ if (includeArraySize)
{
- output += StringHelper::Sprintf("%s %s[%s];\n", varType.c_str(), varName.c_str(),
- arrayItemCntStr.c_str());
- }
- else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt))
- {
- output += StringHelper::Sprintf("%s %s[%i] = {\n", varType.c_str(), varName.c_str(),
- arrayItemCnt);
+ if (arrayItemCntStr != "")
+ output += StringHelper::Sprintf("%s %s[%s];\n", declType.c_str(), declName.c_str(),
+ arrayItemCntStr.c_str());
+ else
+ output += StringHelper::Sprintf("%s %s[%i] = {\n", declType.c_str(), declName.c_str(),
+ arrayItemCnt);
}
else
{
- output += StringHelper::Sprintf("%s %s[] = {\n", varType.c_str(), varName.c_str());
+ output += StringHelper::Sprintf("%s %s[] = {\n", declType.c_str(), declName.c_str());
}
- output += text + "\n";
+ output += declBody + "\n";
}
else
{
- output += StringHelper::Sprintf("%s %s = { ", varType.c_str(), varName.c_str());
- output += text;
+ output += StringHelper::Sprintf("%s %s = { ", declType.c_str(), declName.c_str());
+ output += declBody;
}
if (output.back() == '\n')
@@ -128,14 +138,8 @@ std::string Declaration::GetNormalDeclarationStr() const
else
output += " };";
- if (rightText != "")
- output += " " + rightText + "";
-
output += "\n";
- if (postText != "")
- output += postText + "\n";
-
output += "\n";
return output;
@@ -145,41 +149,34 @@ std::string Declaration::GetExternalDeclarationStr() const
{
std::string output;
- if (preText != "")
- output += preText + "\n";
-
if (IsStatic())
- {
output += "static ";
- }
- if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt))
- output += StringHelper::Sprintf("%s %s[%s] = ", varType.c_str(), varName.c_str(),
- arrayItemCntStr.c_str());
- else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt))
- output +=
- StringHelper::Sprintf("%s %s[%i] = ", varType.c_str(), varName.c_str(), arrayItemCnt);
+ bool includeArraySize = (IsStatic() || forceArrayCnt);
+
+ if (includeArraySize)
+ {
+ if (arrayItemCntStr != "")
+ output += StringHelper::Sprintf("%s %s[%s] = ", declType.c_str(), declName.c_str(),
+ arrayItemCntStr.c_str());
+ else
+ output += StringHelper::Sprintf("%s %s[%i] = ", declType.c_str(), declName.c_str(),
+ arrayItemCnt);
+ }
else
- output += StringHelper::Sprintf("%s %s[] = ", varType.c_str(), varName.c_str());
+ {
+ output += StringHelper::Sprintf("%s %s[] = ", declType.c_str(), declName.c_str());
+ }
output += StringHelper::Sprintf("{\n#include \"%s\"\n};", includePath.c_str());
-
- if (rightText != "")
- output += " " + rightText + "";
-
- output += "\n";
-
- if (postText != "")
- output += postText + "\n";
-
- output += "\n";
+ output += "\n\n";
return output;
}
std::string Declaration::GetExternStr() const
{
- if (IsStatic() || varType == "" || isUnaccounted)
+ if (IsStatic() || declType == "" || isUnaccounted)
{
return "";
}
@@ -188,24 +185,24 @@ std::string Declaration::GetExternStr() const
{
if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt))
{
- return StringHelper::Sprintf("extern %s %s[%s];\n", varType.c_str(), varName.c_str(),
+ return StringHelper::Sprintf("extern %s %s[%s];\n", declType.c_str(), declName.c_str(),
arrayItemCntStr.c_str());
}
else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt))
{
- return StringHelper::Sprintf("extern %s %s[%i];\n", varType.c_str(), varName.c_str(),
+ return StringHelper::Sprintf("extern %s %s[%i];\n", declType.c_str(), declName.c_str(),
arrayItemCnt);
}
else
- return StringHelper::Sprintf("extern %s %s[];\n", varType.c_str(), varName.c_str());
+ return StringHelper::Sprintf("extern %s %s[];\n", declType.c_str(), declName.c_str());
}
- return StringHelper::Sprintf("extern %s %s;\n", varType.c_str(), varName.c_str());
+ return StringHelper::Sprintf("extern %s %s;\n", declType.c_str(), declName.c_str());
}
std::string Declaration::GetDefinesStr() const
{
- if (IsStatic() || (varType == ""))
+ if (IsStatic() || (declType == ""))
{
return "";
}
@@ -227,15 +224,15 @@ std::string Declaration::GetStaticForwardDeclarationStr() const
if (arrayItemCntStr != "")
{
- return StringHelper::Sprintf("static %s %s[%s];\n", varType.c_str(), varName.c_str(),
+ return StringHelper::Sprintf("static %s %s[%s];\n", declType.c_str(), declName.c_str(),
arrayItemCntStr.c_str());
}
else
{
- return StringHelper::Sprintf("static %s %s[%i];\n", varType.c_str(), varName.c_str(),
+ return StringHelper::Sprintf("static %s %s[%i];\n", declType.c_str(), declName.c_str(),
arrayItemCnt);
}
}
- return StringHelper::Sprintf("static %s %s;\n", varType.c_str(), varName.c_str());
+ return StringHelper::Sprintf("static %s %s;\n", declType.c_str(), declName.c_str());
}