summaryrefslogtreecommitdiff
path: root/ZAPD/Declaration.cpp
diff options
context:
space:
mode:
authorbriaguya <70942617+briaguya-ai@users.noreply.github.com>2023-10-18 00:09:24 -0400
committerbriaguya <70942617+briaguya-ai@users.noreply.github.com>2023-10-18 00:09:24 -0400
commit3f878d401fdcff6e7f898524f3bcf5cf4c2b2532 (patch)
tree2f0a7e29ec2dd17d0cbe70e8ee52c96f88608bfa /ZAPD/Declaration.cpp
parente9f4fc638ed904cc0dcdac24ea7708c9a220a702 (diff)
parent094e797349c86d0baef4a624962f4287aefdfef2 (diff)
Merge branch 'JackMaster' into mergeJackOntoSquash
Conflicts: ZAPD/Declaration.h ZAPD/Globals.cpp ZAPD/Globals.h ZAPD/Main.cpp ZAPD/OtherStructs/SkinLimbStructs.cpp ZAPD/OtherStructs/SkinLimbStructs.h ZAPD/ZAnimation.cpp ZAPD/ZCollision.cpp ZAPD/ZCollision.h ZAPD/ZDisplayList.cpp ZAPD/ZFile.cpp ZAPD/ZLimb.cpp ZAPD/ZLimb.h ZAPD/ZPath.cpp ZAPD/ZResource.h ZAPD/ZRoom/Commands/SetCsCamera.cpp ZAPD/ZRoom/Commands/SetCutsceneEntryList.cpp ZAPD/ZRoom/Commands/SetCutscenes.cpp ZAPD/ZRoom/Commands/SetCutscenes.h ZAPD/ZRoom/Commands/SetEntranceList.cpp ZAPD/ZRoom/Commands/SetLightingSettings.cpp ZAPD/ZRoom/Commands/SetMesh.cpp ZAPD/ZRoom/Commands/SetMinimapList.cpp ZAPD/ZTexture.cpp ZAPDUtils/Makefile ZAPDUtils/Utils/BitConverter.h ZAPDUtils/Utils/Directory.h ZAPDUtils/Utils/File.h ZAPDUtils/Utils/Path.h ZAPDUtils/Utils/StringHelper.h ZAPDUtils/ZAPDUtils.vcxproj
Diffstat (limited to 'ZAPD/Declaration.cpp')
-rw-r--r--ZAPD/Declaration.cpp186
1 files changed, 99 insertions, 87 deletions
diff --git a/ZAPD/Declaration.cpp b/ZAPD/Declaration.cpp
index 3f0c0ad..e4f91d8 100644
--- a/ZAPD/Declaration.cpp
+++ b/ZAPD/Declaration.cpp
@@ -5,61 +5,79 @@
#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);
+
+ 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,
- size_t nArrayItemCnt, 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;
- arrayItemCnt = nArrayItemCnt;
+ 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,
- 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,
+ const std::string& declArrayItemCntStr, 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->arrayItemCntStr = declArrayItemCntStr;
+ 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::CreateInclude(offset_t declAddr, const std::string& includePath,
+ size_t declSize, const std::string& declType,
+ const std::string& declName, const std::string& defines)
{
- isExternal = nIsExternal;
+ 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)
- : Declaration(nAddress, DeclarationAlignment::Align4, nSize, "")
+Declaration* Declaration::CreatePlaceholder(offset_t declAddr, const std::string& declName)
{
- includePath = nIncludePath;
- varType = nVarType;
- varName = nVarName;
+ Declaration* decl = new Declaration(declAddr, DeclarationAlignment::Align4, 0, "");
+ decl->declName = declName;
+ decl->isPlaceholder = true;
+
+ return decl;
}
Declaration::~Declaration()
@@ -89,9 +107,6 @@ std::string Declaration::GetNormalDeclarationStr() const
{
std::string output;
- if (preText != "")
- output += preText + "\n";
-
if (IsStatic())
{
output += "static ";
@@ -99,27 +114,28 @@ std::string Declaration::GetNormalDeclarationStr() const
if (isArray)
{
- if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt))
- {
- output += StringHelper::Sprintf("%s %s[%s];\n", varType.c_str(), varName.c_str(),
- arrayItemCntStr.c_str());
- }
- else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt))
+ bool includeArraySize = (IsStatic() || forceArrayCnt);
+
+ if (includeArraySize)
{
- 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')
@@ -127,14 +143,8 @@ std::string Declaration::GetNormalDeclarationStr() const
else
output += " };";
- if (rightText != "")
- output += " " + rightText + "";
-
output += "\n";
- if (postText != "")
- output += postText + "\n";
-
output += "\n";
return output;
@@ -144,41 +154,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 "";
}
@@ -192,19 +195,28 @@ 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() || (declType == ""))
+ {
+ return "";
+ }
+ return StringHelper::Sprintf("%s", defines.c_str());
}
std::string Declaration::GetStaticForwardDeclarationStr() const
@@ -222,15 +234,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());
}