mirror of
https://github.com/zeldaret/mm.git
synced 2026-08-05 17:43:19 -04:00
b2747aa8b4
* git subrepo pull tools/asm-differ --force subrepo: subdir: "tools/asm-differ" merged: "d218cdf0" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "main" commit: "d218cdf0" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/graphovl --force subrepo: subdir: "tools/graphovl" merged: "f5fe93d7" upstream: origin: "https://github.com/AngheloAlf/graphovl.git" branch: "master" commit: "f5fe93d7" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "e7a8a48c" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e7a8a48c" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/graphovl --force subrepo: subdir: "tools/graphovl" merged: "d14ea084" upstream: origin: "https://github.com/AngheloAlf/graphovl.git" branch: "master" commit: "d14ea084" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "e243634e" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e243634e" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/decomp-permuter --force subrepo: subdir: "tools/decomp-permuter" merged: "d1294dfa0" upstream: origin: "https://github.com/simonlindholm/decomp-permuter.git" branch: "main" commit: "d1294dfa0" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/graphovl --force subrepo: subdir: "tools/graphovl" merged: "f5fe93d75" upstream: origin: "https://github.com/AngheloAlf/graphovl.git" branch: "master" commit: "f5fe93d75" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "d0cd6b397" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "d0cd6b397" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * add ExternalXMLFolder config * git subrepo pull --force tools/decomp-permuter subrepo: subdir: "tools/decomp-permuter" merged: "a20bac942" upstream: origin: "https://github.com/simonlindholm/decomp-permuter.git" branch: "main" commit: "a20bac942" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "4f7b8393e" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "4f7b8393e" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull --force tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "f30d43ace" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "main" commit: "f30d43ace" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Remove Segment="128"
223 lines
5.7 KiB
C++
223 lines
5.7 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 != "")
|
|
{
|
|
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());
|
|
}
|