summaryrefslogtreecommitdiff
path: root/ZAPD/Declaration.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-10-01 22:19:47 -0300
committerGitHub <noreply@github.com>2021-10-01 21:19:47 -0400
commit6b06266eb8d35a7865aa1f942ecbe393e7cde740 (patch)
tree6b23ec1617f1ae76f49079ccc9c93c7f4d06eff3 /ZAPD/Declaration.cpp
parent26b00a2431a70ff190a2b22ee1faf77afa75a034 (diff)
Add `--static` flag (#193)
* remove static from every extracted asset * fix makefile * Move a bunch of code to Declaration * make static enablalble * fix texture static * clean up * minor fixes * Format * add small docs * fix * add table * add note in the readme * typo * maybe_unused * Add warning to ZSymbol * format * fix
Diffstat (limited to 'ZAPD/Declaration.cpp')
-rw-r--r--ZAPD/Declaration.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/ZAPD/Declaration.cpp b/ZAPD/Declaration.cpp
index dc4954e..230540e 100644
--- a/ZAPD/Declaration.cpp
+++ b/ZAPD/Declaration.cpp
@@ -1,5 +1,8 @@
#include "Declaration.h"
+#include "Globals.h"
+#include "Utils/StringHelper.h"
+
Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nText)
{
alignment = nAlignment;
@@ -54,3 +57,163 @@ Declaration::Declaration(std::string nIncludePath, size_t nSize, std::string nVa
varType = nVarType;
varName = nVarName;
}
+
+bool Declaration::IsStatic() const
+{
+ switch (staticConf)
+ {
+ case StaticConfig::Off:
+ return false;
+
+ case StaticConfig::Global:
+ return Globals::Instance->forceStatic;
+
+ case StaticConfig::On:
+ return true;
+ }
+
+ return false;
+}
+
+std::string Declaration::GetNormalDeclarationStr() const
+{
+ std::string output;
+
+ if (preText != "")
+ output += preText + "\n";
+
+ if (IsStatic())
+ {
+ output += "static ";
+ }
+
+ if (isArray)
+ {
+ if (arrayItemCntStr != "")
+ {
+ output += StringHelper::Sprintf("%s %s[%s];\n", varType.c_str(), varName.c_str(),
+ arrayItemCntStr.c_str());
+ }
+ else if (arrayItemCnt == 0)
+ {
+ output += StringHelper::Sprintf("%s %s[] = {\n", varType.c_str(), varName.c_str());
+ }
+ else
+ {
+ output += StringHelper::Sprintf("%s %s[%i] = {\n", varType.c_str(), varName.c_str(),
+ arrayItemCnt);
+ }
+
+ output += text + "\n";
+ }
+ else
+ {
+ output += StringHelper::Sprintf("%s %s = { ", varType.c_str(), varName.c_str());
+ output += text;
+ }
+
+ if (output.back() == '\n')
+ output += "};";
+ else
+ output += " };";
+
+ if (rightText != "")
+ output += " " + rightText + "";
+
+ output += "\n";
+
+ if (postText != "")
+ output += postText + "\n";
+
+ output += "\n";
+
+ return output;
+}
+
+std::string Declaration::GetExternalDeclarationStr() const
+{
+ std::string output;
+
+ if (preText != "")
+ output += preText + "\n";
+
+ if (IsStatic())
+ {
+ output += "static ";
+ }
+
+ if (arrayItemCntStr != "")
+ output +=
+ StringHelper::Sprintf("%s %s[%s] = {\n#include \"%s\"\n};", varType.c_str(),
+ varName.c_str(), arrayItemCntStr.c_str(), includePath.c_str());
+ else if (arrayItemCnt != 0)
+ output += StringHelper::Sprintf("%s %s[%i] = {\n#include \"%s\"\n};", varType.c_str(),
+ varName.c_str(), arrayItemCnt, includePath.c_str());
+ else
+ output += StringHelper::Sprintf("%s %s[] = {\n#include \"%s\"\n};", varType.c_str(),
+ varName.c_str(), includePath.c_str());
+
+ if (rightText != "")
+ output += " " + rightText + "";
+
+ output += "\n";
+
+ if (postText != "")
+ output += postText + "\n";
+
+ output += "\n";
+
+ return output;
+}
+
+std::string Declaration::GetExternStr() const
+{
+ if (IsStatic() || varType == "")
+ {
+ return "";
+ }
+
+ if (isArray)
+ {
+ if (arrayItemCntStr != "")
+ {
+ return StringHelper::Sprintf("extern %s %s[%s];\n", varType.c_str(), varName.c_str(),
+ arrayItemCntStr.c_str());
+ }
+ else if (arrayItemCnt != 0)
+ return StringHelper::Sprintf("extern %s %s[%i];\n", varType.c_str(), varName.c_str(),
+ arrayItemCnt);
+ else
+ return StringHelper::Sprintf("extern %s %s[];\n", varType.c_str(), varName.c_str());
+ }
+
+ return StringHelper::Sprintf("extern %s %s;\n", varType.c_str(), varName.c_str());
+}
+
+std::string Declaration::GetStaticForwardDeclarationStr() const
+{
+ if (!IsStatic() || isUnaccounted)
+ return "";
+
+ if (isArray)
+ {
+ if (arrayItemCntStr == "" && arrayItemCnt == 0)
+ {
+ // Forward declaring static arrays without specifying the size is not allowed.
+ return "";
+ }
+
+ if (arrayItemCntStr != "")
+ {
+ return StringHelper::Sprintf("static %s %s[%s];\n", varType.c_str(), varName.c_str(),
+ arrayItemCntStr.c_str());
+ }
+ else
+ {
+ return StringHelper::Sprintf("static %s %s[%i];\n", varType.c_str(), varName.c_str(),
+ arrayItemCnt);
+ }
+ }
+
+ return StringHelper::Sprintf("static %s %s;\n", varType.c_str(), varName.c_str());
+}