diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-09-29 14:58:42 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-29 13:58:42 -0400 |
| commit | 2e7e4c33db92944019cfd8c806054f703629c122 (patch) | |
| tree | 77ad974baa8df0442b9bb165e143b5bffcfcf16d /ZAPD/ZFile.cpp | |
| parent | cac62bff64235ec4be71b79443afaa135d739a92 (diff) | |
Remove `DeclarationPadding` and `DeclarationAlignment::None` (#186)
* Nuke DeclarationPadding
* Remove DeclarationAlignment::None
* Fix AddDeclaration memory leaks
* Run formatter
* Remove extra AddDeclarationPlaceholder
* Revert "Remove extra AddDeclarationPlaceholder"
This reverts commit 7a5d6a19d80bb246e0a6c8fde009b2a00a84ef96.
Diffstat (limited to 'ZAPD/ZFile.cpp')
| -rw-r--r-- | ZAPD/ZFile.cpp | 147 |
1 files changed, 69 insertions, 78 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index 472d3a7..6a039a1 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -359,47 +359,55 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); - Declaration* decl = new Declaration(alignment, size, varType, varName, false, body); - declarations[address] = decl; + Declaration* decl = GetDeclaration(address); + if (decl == nullptr) + { + decl = new Declaration(alignment, size, varType, varName, false, body); + declarations[address] = decl; + } + else + { + decl->alignment = alignment; + decl->size = size; + decl->varType = varType; + decl->varName = varName; + decl->text = body; + } return decl; } -Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, size_t size, std::string varType, - std::string varName, std::string body) -{ - assert(GETSEGNUM(address) == 0); - AddDeclarationDebugChecks(address); - - declarations[address] = - new Declaration(alignment, padding, size, varType, varName, false, body); - return declarations[address]; -} - Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size, std::string varType, std::string varName, size_t arrayItemCnt, std::string body) { - return AddDeclarationArray(address, alignment, DeclarationPadding::None, size, varType, varName, - arrayItemCnt, body); -} - -Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - size_t size, std::string varType, std::string varName, - std::string arrayItemCntStr, std::string body) -{ assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); - declarations[address] = - new Declaration(alignment, size, varType, varName, true, arrayItemCntStr, body); - return declarations[address]; + Declaration* decl = GetDeclaration(address); + if (decl == nullptr) + { + decl = new Declaration(alignment, size, varType, varName, true, arrayItemCnt, body); + declarations[address] = decl; + } + else + { + if (decl->isPlaceholder) + decl->varName = varName; + decl->alignment = alignment; + decl->size = size; + decl->varType = varType; + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + if (body != "" && decl->text == "") + decl->text = body; + } + + return decl; } Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, size_t size, - std::string varType, std::string varName, - size_t arrayItemCnt, std::string body) + size_t size, std::string varType, std::string varName, + std::string arrayItemCntStr, std::string body) { assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); @@ -407,24 +415,19 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a Declaration* decl = GetDeclaration(address); if (decl == nullptr) { - decl = - new Declaration(alignment, padding, size, varType, varName, true, arrayItemCnt, body); + decl = new Declaration(alignment, size, varType, varName, true, arrayItemCntStr, body); declarations[address] = decl; } else { - if (decl->isPlaceholder) - decl->varName = varName; decl->alignment = alignment; - decl->padding = padding; decl->size = size; decl->varType = varType; + decl->varName = varName; decl->isArray = true; - decl->arrayItemCnt = arrayItemCnt; - if (body != "" && decl->text == "") - decl->text = body; + decl->arrayItemCntStr = arrayItemCntStr; + decl->text = body; } - return decl; } @@ -436,7 +439,7 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address) if (declarations.find(address) == declarations.end()) { - decl = new Declaration(DeclarationAlignment::None, 0, "", "", false, ""); + decl = new Declaration(DeclarationAlignment::Align4, 0, "", "", false, ""); decl->isPlaceholder = true; declarations[address] = decl; } @@ -454,7 +457,7 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, std::string varN if (declarations.find(address) == declarations.end()) { - decl = new Declaration(DeclarationAlignment::None, 0, "", varName, false, ""); + decl = new Declaration(DeclarationAlignment::Align4, 0, "", varName, false, ""); decl->isPlaceholder = true; declarations[address] = decl; } @@ -470,10 +473,20 @@ Declaration* ZFile::AddDeclarationInclude(uint32_t address, std::string includeP assert(GETSEGNUM(address) == 0); AddDeclarationDebugChecks(address); - if (declarations.find(address) == declarations.end()) - declarations[address] = new Declaration(includePath, size, varType, varName); - - return declarations[address]; + Declaration* decl = GetDeclaration(address); + if (decl == nullptr) + { + decl = new Declaration(includePath, size, varType, varName); + declarations[address] = decl; + } + else + { + decl->includePath = includePath; + decl->size = size; + decl->varType = varType; + decl->varName = varName; + } + return decl; } Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string includePath, @@ -488,20 +501,8 @@ Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string inc if (StringHelper::StartsWith(includePath, "assets/custom/")) includePath = "assets/" + StringHelper::Split(includePath, "assets/custom/")[1]; - auto declCheck = declarations.find(address); - - if (declCheck != declarations.end()) - { - declCheck->second->includePath = includePath; - declCheck->second->varType = varType; - declCheck->second->varName = varName; - declCheck->second->size = size; - declCheck->second->isArray = true; - declCheck->second->arrayItemCnt = arrayItemCnt; - - return declCheck->second; - } - else + Declaration* decl = GetDeclaration(address); + if (decl == nullptr) { Declaration* decl = new Declaration(includePath, size, varType, varName); @@ -509,8 +510,17 @@ Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string inc decl->arrayItemCnt = arrayItemCnt; declarations[address] = decl; - return declarations[address]; } + else + { + decl->includePath = includePath; + decl->varType = varType; + decl->varName = varName; + decl->size = size; + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + } + return decl; } void ZFile::AddDeclarationDebugChecks(uint32_t address) @@ -856,25 +866,6 @@ std::string ZFile::ProcessDeclarations() } } - if (item.second->padding == DeclarationPadding::Pad16) - { - int32_t curPtr = item.first + item.second->size; - - while (curPtr % 4 != 0) - { - item.second->size++; - curPtr++; - } - - while (curPtr % 16 != 0) - { - item.second->postText += StringHelper::Sprintf("static u32 pad%02X = 0;\n", curPtr); - - item.second->size += 4; - curPtr += 4; - } - } - lastAddr = item.first; } @@ -971,7 +962,7 @@ std::string ZFile::ProcessDeclarations() } Declaration* decl = AddDeclarationArray( - unaccountedAddress, DeclarationAlignment::None, diff, "static u8", + unaccountedAddress, DeclarationAlignment::Align4, diff, "static u8", StringHelper::Sprintf("%s_%06X", unaccountedPrefix.c_str(), unaccountedAddress), diff, src); |
