diff options
Diffstat (limited to 'ZAPD/ZFile.cpp')
| -rw-r--r-- | ZAPD/ZFile.cpp | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index f209653..6e02ea4 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -39,13 +39,13 @@ ZFile::ZFile() rangeEnd = 0xFFFFFFFF; } -ZFile::ZFile(std::string nName) : ZFile() +ZFile::ZFile(const std::string& nName) : ZFile() { name = nName; } ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath, - std::string filename, const fs::path& nXmlFilePath, bool placeholderMode) + const std::string& filename, const fs::path& nXmlFilePath, bool placeholderMode) : ZFile() { xmlFilePath = nXmlFilePath; @@ -71,7 +71,7 @@ ZFile::~ZFile() } } -void ZFile::ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, +void ZFile::ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, const std::string& filename, [[maybe_unused]] bool placeholderMode) { if (filename == "") @@ -354,7 +354,8 @@ std::vector<ZResource*> ZFile::GetResourcesOfType(ZResourceType resType) } Declaration* ZFile::AddDeclaration(offset_t address, DeclarationAlignment alignment, size_t size, - std::string varType, std::string varName, std::string body) + const std::string& varType, const std::string& varName, + const std::string& body) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -377,8 +378,9 @@ Declaration* ZFile::AddDeclaration(offset_t address, DeclarationAlignment alignm } Declaration* ZFile::AddDeclarationArray(offset_t address, DeclarationAlignment alignment, - size_t size, std::string varType, std::string varName, - size_t arrayItemCnt, std::string body) + size_t size, const std::string& varType, + const std::string& varName, size_t arrayItemCnt, + const std::string& body) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -406,8 +408,9 @@ Declaration* ZFile::AddDeclarationArray(offset_t address, DeclarationAlignment a } Declaration* ZFile::AddDeclarationArray(offset_t address, DeclarationAlignment alignment, - size_t size, std::string varType, std::string varName, - std::string arrayItemCntStr, std::string body) + size_t size, const std::string& varType, + const std::string& varName, + const std::string& arrayItemCntStr, const std::string& body) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -449,7 +452,7 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address) return decl; } -Declaration* ZFile::AddDeclarationPlaceholder(offset_t address, std::string varName) +Declaration* ZFile::AddDeclarationPlaceholder(offset_t address, const std::string& varName) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -467,8 +470,9 @@ Declaration* ZFile::AddDeclarationPlaceholder(offset_t address, std::string varN return decl; } -Declaration* ZFile::AddDeclarationInclude(offset_t address, std::string includePath, size_t size, - std::string varType, std::string varName) +Declaration* ZFile::AddDeclarationInclude(offset_t address, const std::string& includePath, + size_t size, const std::string& varType, + const std::string& varName) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -489,9 +493,9 @@ Declaration* ZFile::AddDeclarationInclude(offset_t address, std::string includeP return decl; } -Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string includePath, - size_t size, std::string varType, - std::string varName, size_t arrayItemCnt) +Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& includePath, + size_t size, const std::string& varType, + const std::string& varName, size_t arrayItemCnt) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -541,7 +545,7 @@ std::string ZFile::GetDeclarationName(uint32_t address) const // message is just for testing } -std::string ZFile::GetDeclarationName(uint32_t address, std::string defaultResult) const +std::string ZFile::GetDeclarationName(uint32_t address, const std::string& defaultResult) const { Declaration* decl = GetDeclaration(address); if (decl != nullptr) @@ -604,7 +608,7 @@ bool ZFile::HasDeclaration(uint32_t address) void ZFile::GenerateSourceFiles(fs::path outputDir) { - std::string sourceOutput = ""; + std::string sourceOutput; sourceOutput += "#include \"ultra64.h\"\n"; sourceOutput += "#include \"z64.h\"\n"; @@ -766,7 +770,7 @@ void ZFile::RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc) std::string ZFile::ProcessDeclarations() { - std::string output = ""; + std::string output; if (declarations.size() == 0) return output; @@ -851,7 +855,7 @@ std::string ZFile::ProcessDeclarations() } else if (item.second->alignment == DeclarationAlignment::Align8) { - int32_t curPtr = lastAddr + declarations[lastAddr]->size; + size_t curPtr = lastAddr + declarations[lastAddr]->size; while (curPtr % 4 != 0) { @@ -864,7 +868,7 @@ std::string ZFile::ProcessDeclarations() { char buffer[2048]; - sprintf(buffer, "u32 %s_align%02X = 0;\n", name.c_str(), curPtr); + sprintf(buffer, "u32 %s_align%02zX = 0;\n", name.c_str(), curPtr); item.second->preText = buffer + item.second->preText; declarations[lastAddr]->size += 4; @@ -917,7 +921,7 @@ std::string ZFile::ProcessDeclarations() } } - uint32_t unaccountedAddress = lastAddr + lastSize; + size_t unaccountedAddress = lastAddr + lastSize; if (unaccountedAddress != currentAddress && lastAddr >= rangeStart && unaccountedAddress < rangeEnd) @@ -983,7 +987,7 @@ std::string ZFile::ProcessDeclarations() fprintf( stderr, "Warning in file: %s (%s)\n" - "\t A non-zero unaccounted block was found at address '0x%06X'.\n" + "\t A non-zero unaccounted block was found at address '0x%06zX'.\n" "\t Block size: '0x%X'.\n", xmlFilePath.c_str(), name.c_str(), unaccountedAddress, diff); } @@ -992,7 +996,7 @@ std::string ZFile::ProcessDeclarations() fprintf(stderr, "Warning in file: %s (%s)\n" "\t A big (size>=0x10) zero-only unaccounted block was found " - "at address '0x%06X'.\n" + "at address '0x%06zX'.\n" "\t Block size: '0x%X'.\n", xmlFilePath.c_str(), name.c_str(), unaccountedAddress, diff); } @@ -1024,7 +1028,7 @@ std::string ZFile::ProcessDeclarations() if (item.second->isExternal) { // HACK - std::string extType = ""; + std::string extType; if (item.second->varType == "Gfx") extType = "dlist"; @@ -1105,7 +1109,7 @@ void ZFile::ProcessDeclarationText(Declaration* decl) std::string ZFile::ProcessExterns() { - std::string output = ""; + std::string output; for (std::pair<uint32_t, Declaration*> item : declarations) { @@ -1124,12 +1128,12 @@ std::string ZFile::ProcessExterns() return output; } -std::string ZFile::ProcessTextureIntersections([[maybe_unused]] std::string prefix) +std::string ZFile::ProcessTextureIntersections([[maybe_unused]] const std::string& prefix) { if (texturesResources.empty()) return ""; - std::string defines = ""; + std::string defines; std::vector<std::pair<uint32_t, ZTexture*>> texturesSorted(texturesResources.begin(), texturesResources.end()); |
