mirror of
https://github.com/zeldaret/oot.git
synced 2025-01-15 21:07:15 +00:00
9b67778a00
* git subrepo pull (merge) tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "945e6ca1a" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "50242eca9" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Fix extract_assets.py multithreading * Update binutils doc a bit * Remove * import, add multiprocessing option and way to pass arguments to ZAPD * Update format.sh to be more platform-independent * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "fd5a7f434" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "fd5a7f434" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Remove ; * Update formatting script to not just use 11 * Add Python requirements, move the Mac stuff in the README into its own doc * Fix readme link * Minor format thing * . * Move ZAPDArgs into its own function * Update readme and remove requirements.txt * Dragorn-inspired rewrite of processZAPDArgs * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "a0d3f7b68" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "a0d3f7b68" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Fix function definition * Building docs overhaul * Add Python packages to Mac and Cygwin * Heading number * format format.sh (!) * Replace "currently" * Remove Debian * git subrepo pull (merge) --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "0ba781304" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "0ba781304" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596"
224 lines
5.8 KiB
C++
224 lines
5.8 KiB
C++
#include "Declaration.h"
|
|
|
|
#include "Globals.h"
|
|
#include "Utils/StringHelper.h"
|
|
|
|
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
|
const std::string& nText)
|
|
{
|
|
address = nAddress;
|
|
alignment = nAlignment;
|
|
size = nSize;
|
|
text = nText;
|
|
}
|
|
|
|
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)
|
|
{
|
|
varType = nVarType;
|
|
varName = nVarName;
|
|
isArray = nIsArray;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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)
|
|
{
|
|
varType = nVarType;
|
|
varName = nVarName;
|
|
isArray = nIsArray;
|
|
arrayItemCntStr = nArrayItemCntStr;
|
|
}
|
|
|
|
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)
|
|
{
|
|
isExternal = nIsExternal;
|
|
}
|
|
|
|
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, "")
|
|
{
|
|
includePath = nIncludePath;
|
|
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 != "" && (IsStatic() || forceArrayCnt))
|
|
{
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
output += StringHelper::Sprintf("%s %s[] = {\n", varType.c_str(), varName.c_str());
|
|
}
|
|
|
|
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 != "" && (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);
|
|
else
|
|
output += StringHelper::Sprintf("%s %s[] = ", varType.c_str(), varName.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";
|
|
|
|
return output;
|
|
}
|
|
|
|
std::string Declaration::GetExternStr() const
|
|
{
|
|
if (IsStatic() || varType == "" || isUnaccounted)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
if (isArray)
|
|
{
|
|
if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt))
|
|
{
|
|
return StringHelper::Sprintf("extern %s %s[%s];\n", varType.c_str(), varName.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(),
|
|
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());
|
|
}
|