From 0bdc442bf055694eda6962073a475395cac36869 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 13 Nov 2020 11:15:34 +0100 Subject: [PATCH] Fixed pattern array highlighting offsets being wrong --- source/views/view_pattern.cpp | 57 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 45cfa88e3..83bcdb379 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -123,14 +123,25 @@ namespace hex { this->setHighlight(offset, (static_cast(varNode->getVariableType()) >> 4) * varNode->getArraySize(), varNode->getVariableName()); } else { for (auto &structNode : findNodes(lang::ASTNode::Type::Struct, ast)) - if (varNode->getCustomVariableTypeName() == structNode->getName()) - if (this->highlightStruct(ast, structNode, offset) == -1) - this->m_highlights.clear(); + if (varNode->getCustomVariableTypeName() == structNode->getName()) { + for (u32 i = 0; i < varNode->getArraySize(); i++) { + if (size_t size = this->highlightStruct(ast, structNode, offset); size == -1) + this->m_highlights.clear(); + else + offset += size; + } + } - for (auto &usingNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) - if (varNode->getCustomVariableTypeName() == usingNode->getTypeName()) - if (this->highlightUsingDecls(ast, usingNode, varNode, offset) == -1) - this->m_highlights.clear(); + for (auto &usingNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) { + if (varNode->getCustomVariableTypeName() == usingNode->getTypeName()) { + for (u32 i = 0; i < varNode->getArraySize(); i++) { + if (size_t size = this->highlightUsingDecls(ast, usingNode, varNode, offset); size == -1) + this->m_highlights.clear(); + else + offset += size; + } + } + } } } @@ -139,6 +150,8 @@ namespace hex { } s32 ViewPattern::highlightUsingDecls(std::vector &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDecl, u64 offset) { + u64 startOffset = offset; + if (currTypeDeclNode->getAssignedType() != lang::Token::TypeToken::Type::CustomType) { size_t size = (static_cast(currTypeDeclNode->getAssignedType()) >> 4); @@ -148,23 +161,42 @@ namespace hex { bool foundType = false; for (auto &structNode : findNodes(lang::ASTNode::Type::Struct, ast)) if (structNode->getName() == currTypeDeclNode->getAssignedCustomTypeName()) { - offset = this->highlightStruct(ast, structNode, offset); + size_t size = 0; + for (size_t i = 0; i < currVarDecl->getArraySize(); i++) { + size = this->highlightStruct(ast, structNode, offset); + + if (size == -1) + return -1; + + offset += size; + } + foundType = true; break; } - for (auto &typeDeclNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) + for (auto &typeDeclNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) { if (typeDeclNode->getTypeName() == currTypeDeclNode->getAssignedCustomTypeName()) { - offset = this->highlightUsingDecls(ast, typeDeclNode, currVarDecl, offset); + size_t size = 0; + for (size_t i = 0; i < currVarDecl->getArraySize(); i++) { + size = this->highlightUsingDecls(ast, typeDeclNode, currVarDecl, offset); + + if (size == -1) + return -1; + + offset += size; + } + foundType = true; break; } + } if (!foundType) return -1; } - return offset; + return offset - startOffset; } s32 ViewPattern::highlightStruct(std::vector &ast, lang::ASTNodeStruct* currStructNode, u64 offset) { @@ -196,7 +228,7 @@ namespace hex { break; } - for (auto &typeDeclNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) + for (auto &typeDeclNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) { if (typeDeclNode->getTypeName() == var->getCustomVariableTypeName()) { size_t size = 0; for (size_t i = 0; i < var->getArraySize(); i++) { @@ -211,6 +243,7 @@ namespace hex { foundType = true; break; } + } if (!foundType) return -1;