diff --git a/include/views/view_pattern.hpp b/include/views/view_pattern.hpp index 0a54c1916..09af47eed 100644 --- a/include/views/view_pattern.hpp +++ b/include/views/view_pattern.hpp @@ -34,8 +34,8 @@ namespace hex { void setHighlight(u64 offset, size_t size, std::string name, u32 color = 0); void parsePattern(char *buffer); - s32 highlightUsingDecls(std::vector &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDec, u64 offset); - s32 highlightStruct(std::vector &ast, lang::ASTNodeStruct* currStructNode, u64 offset); + s32 highlightUsingDecls(std::vector &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDec, u64 offset, std::string name); + s32 highlightStruct(std::vector &ast, lang::ASTNodeStruct* currStructNode, u64 offset, std::string name); }; } \ No newline at end of file diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 83bcdb379..587c838ec 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -125,7 +125,11 @@ namespace hex { for (auto &structNode : findNodes(lang::ASTNode::Type::Struct, ast)) if (varNode->getCustomVariableTypeName() == structNode->getName()) { for (u32 i = 0; i < varNode->getArraySize(); i++) { - if (size_t size = this->highlightStruct(ast, structNode, offset); size == -1) + std::string name = varNode->getVariableName(); + if (varNode->getArraySize() > 1) + name += "[" + std::to_string(varNode->getArraySize()) + "]"; + + if (size_t size = this->highlightStruct(ast, structNode, offset, name); size == -1) this->m_highlights.clear(); else offset += size; @@ -135,7 +139,11 @@ namespace hex { 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) + std::string name = varNode->getVariableName(); + if (varNode->getArraySize() > 1) + name += "[" + std::to_string(varNode->getArraySize()) + "]"; + + if (size_t size = this->highlightUsingDecls(ast, usingNode, varNode, offset, name); size == -1) this->m_highlights.clear(); else offset += size; @@ -149,21 +157,20 @@ namespace hex { for(auto &node : ast) delete node; } - s32 ViewPattern::highlightUsingDecls(std::vector &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDecl, u64 offset) { + s32 ViewPattern::highlightUsingDecls(std::vector &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDecl, u64 offset, std::string name) { u64 startOffset = offset; if (currTypeDeclNode->getAssignedType() != lang::Token::TypeToken::Type::CustomType) { size_t size = (static_cast(currTypeDeclNode->getAssignedType()) >> 4); - this->setHighlight(offset, size, currVarDecl->getVariableName()); + this->setHighlight(offset, size, name); offset += size; } else { bool foundType = false; for (auto &structNode : findNodes(lang::ASTNode::Type::Struct, ast)) if (structNode->getName() == currTypeDeclNode->getAssignedCustomTypeName()) { - size_t size = 0; for (size_t i = 0; i < currVarDecl->getArraySize(); i++) { - size = this->highlightStruct(ast, structNode, offset); + size_t size = this->highlightStruct(ast, structNode, offset, name); if (size == -1) return -1; @@ -177,9 +184,8 @@ namespace hex { for (auto &typeDeclNode : findNodes(lang::ASTNode::Type::TypeDecl, ast)) { if (typeDeclNode->getTypeName() == currTypeDeclNode->getAssignedCustomTypeName()) { - size_t size = 0; for (size_t i = 0; i < currVarDecl->getArraySize(); i++) { - size = this->highlightUsingDecls(ast, typeDeclNode, currVarDecl, offset); + size_t size = this->highlightUsingDecls(ast, typeDeclNode, currVarDecl, offset, name); if (size == -1) return -1; @@ -199,24 +205,32 @@ namespace hex { return offset - startOffset; } - s32 ViewPattern::highlightStruct(std::vector &ast, lang::ASTNodeStruct* currStructNode, u64 offset) { + s32 ViewPattern::highlightStruct(std::vector &ast, lang::ASTNodeStruct* currStructNode, u64 offset, std::string name) { u64 startOffset = offset; for (auto &node : currStructNode->getNodes()) { auto var = static_cast(node); if (var->getVariableType() != lang::Token::TypeToken::Type::CustomType) { - size_t size = (static_cast(var->getVariableType()) >> 4) * var->getArraySize(); + size_t size = (static_cast(var->getVariableType()) >> 4); + for (size_t i = 0; i < var->getArraySize(); i++) { + std::string memberName = name + "." + var->getVariableName(); + if (var->getArraySize() > 1) + memberName += "[" + std::to_string(i) + "]"; - this->setHighlight(offset, size, var->getVariableName()); - offset += size; + this->setHighlight(offset, size, memberName); + offset += size; + } } else { bool foundType = false; - for (auto &structNode : findNodes(lang::ASTNode::Type::Struct, ast)) + for (auto &structNode : findNodes(lang::ASTNode::Type::Struct, ast)) { if (structNode->getName() == var->getCustomVariableTypeName()) { - size_t size = 0; for (size_t i = 0; i < var->getArraySize(); i++) { - size = this->highlightStruct(ast, structNode, offset); + std::string memberName = name + "." + var->getVariableName(); + if (var->getArraySize() > 1) + memberName += "[" + std::to_string(i) + "]"; + + size_t size = this->highlightStruct(ast, structNode, offset, memberName); if (size == -1) return -1; @@ -227,12 +241,16 @@ namespace hex { foundType = true; break; } + } 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++) { - size = this->highlightUsingDecls(ast, typeDeclNode, var, offset); + std::string memberName = name + "." + var->getVariableName(); + if (var->getArraySize() > 1) + memberName += "[" + std::to_string(i) + "]"; + + size_t size = this->highlightUsingDecls(ast, typeDeclNode, var, offset, memberName); if (size == -1) return -1;