patterns: Fix unions causing crashes on cleanup
This commit is contained in:
parent
4b40546750
commit
f29febdc86
@ -858,6 +858,7 @@ namespace hex::lang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setMembers(const std::vector<PatternData*> & members) {
|
void setMembers(const std::vector<PatternData*> & members) {
|
||||||
|
this->m_members.clear();
|
||||||
for (auto &member : members) {
|
for (auto &member : members) {
|
||||||
if (member == nullptr) continue;
|
if (member == nullptr) continue;
|
||||||
|
|
||||||
|
@ -771,8 +771,8 @@ namespace hex::lang {
|
|||||||
auto startOffset = this->m_currOffset;
|
auto startOffset = this->m_currOffset;
|
||||||
for (auto &member : node->getMembers()) {
|
for (auto &member : node->getMembers()) {
|
||||||
this->evaluateMember(member, memberPatterns, true);
|
this->evaluateMember(member, memberPatterns, true);
|
||||||
structPattern->setMembers(memberPatterns);
|
|
||||||
}
|
}
|
||||||
|
structPattern->setMembers(memberPatterns);
|
||||||
structPattern->setSize(this->m_currOffset - startOffset);
|
structPattern->setSize(this->m_currOffset - startOffset);
|
||||||
|
|
||||||
this->m_currRecursionDepth--;
|
this->m_currRecursionDepth--;
|
||||||
@ -801,8 +801,8 @@ namespace hex::lang {
|
|||||||
|
|
||||||
for (auto &member : node->getMembers()) {
|
for (auto &member : node->getMembers()) {
|
||||||
this->evaluateMember(member, memberPatterns, false);
|
this->evaluateMember(member, memberPatterns, false);
|
||||||
unionPattern->setMembers(memberPatterns);
|
|
||||||
}
|
}
|
||||||
|
unionPattern->setMembers(memberPatterns);
|
||||||
|
|
||||||
this->m_currRecursionDepth--;
|
this->m_currRecursionDepth--;
|
||||||
|
|
||||||
|
@ -667,19 +667,15 @@ namespace hex::lang {
|
|||||||
variables.push_back(new ASTNodeVariableDecl(getValue<std::string>(-1), type->clone()));
|
variables.push_back(new ASTNodeVariableDecl(getValue<std::string>(-1), type->clone()));
|
||||||
} while (MATCHES(sequence(SEPARATOR_COMMA, IDENTIFIER)));
|
} while (MATCHES(sequence(SEPARATOR_COMMA, IDENTIFIER)));
|
||||||
|
|
||||||
delete type;
|
|
||||||
|
|
||||||
variableCleanup.release();
|
variableCleanup.release();
|
||||||
|
|
||||||
return new ASTNodeMultiVariableDecl(variables);
|
return new ASTNodeMultiVariableDecl(variables);
|
||||||
} else
|
} else
|
||||||
return new ASTNodeVariableDecl(getValue<std::string>(-1), type);
|
return new ASTNodeVariableDecl(getValue<std::string>(-1), type->clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parseType) Identifier[(parseMathematicalExpression)]
|
// (parseType) Identifier[(parseMathematicalExpression)]
|
||||||
ASTNode* Parser::parseMemberArrayVariable(ASTNodeTypeDecl *type) {
|
ASTNode* Parser::parseMemberArrayVariable(ASTNodeTypeDecl *type) {
|
||||||
if (type == nullptr) throwParseError("invalid type used in variable declaration", -1);
|
|
||||||
|
|
||||||
auto name = getValue<std::string>(-2);
|
auto name = getValue<std::string>(-2);
|
||||||
|
|
||||||
ASTNode *size = nullptr;
|
ASTNode *size = nullptr;
|
||||||
@ -697,7 +693,7 @@ namespace hex::lang {
|
|||||||
|
|
||||||
sizeCleanup.release();
|
sizeCleanup.release();
|
||||||
|
|
||||||
return new ASTNodeArrayVariableDecl(name, type, size);
|
return new ASTNodeArrayVariableDecl(name, type->clone(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (parseType) *Identifier : (parseType)
|
// (parseType) *Identifier : (parseType)
|
||||||
@ -713,7 +709,7 @@ namespace hex::lang {
|
|||||||
throwParseError("invalid type used for pointer size", -1);
|
throwParseError("invalid type used for pointer size", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ASTNodePointerVariableDecl(name, type, sizeType);
|
return new ASTNodePointerVariableDecl(name, type->clone(), sizeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [(parsePadding)|(parseMemberVariable)|(parseMemberArrayVariable)|(parseMemberPointerVariable)]
|
// [(parsePadding)|(parseMemberVariable)|(parseMemberArrayVariable)|(parseMemberPointerVariable)]
|
||||||
@ -725,6 +721,7 @@ namespace hex::lang {
|
|||||||
// Some kind of variable definition
|
// Some kind of variable definition
|
||||||
|
|
||||||
auto type = parseType();
|
auto type = parseType();
|
||||||
|
ON_SCOPE_EXIT { delete type; };
|
||||||
|
|
||||||
if (MATCHES(sequence(IDENTIFIER, SEPARATOR_SQUAREBRACKETOPEN)) && sequence<Not>(SEPARATOR_SQUAREBRACKETOPEN))
|
if (MATCHES(sequence(IDENTIFIER, SEPARATOR_SQUAREBRACKETOPEN)) && sequence<Not>(SEPARATOR_SQUAREBRACKETOPEN))
|
||||||
member = parseMemberArrayVariable(type);
|
member = parseMemberArrayVariable(type);
|
||||||
@ -759,9 +756,6 @@ namespace hex::lang {
|
|||||||
const auto &typeName = getValue<std::string>(-2);
|
const auto &typeName = getValue<std::string>(-2);
|
||||||
auto structGuard = SCOPE_GUARD { delete structNode; };
|
auto structGuard = SCOPE_GUARD { delete structNode; };
|
||||||
|
|
||||||
if (this->m_types.contains(typeName))
|
|
||||||
throwParseError(hex::format("redefinition of type '{}'", typeName));
|
|
||||||
|
|
||||||
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
||||||
structNode->addMember(parseMember());
|
structNode->addMember(parseMember());
|
||||||
}
|
}
|
||||||
@ -777,9 +771,6 @@ namespace hex::lang {
|
|||||||
const auto &typeName = getValue<std::string>(-2);
|
const auto &typeName = getValue<std::string>(-2);
|
||||||
auto unionGuard = SCOPE_GUARD { delete unionNode; };
|
auto unionGuard = SCOPE_GUARD { delete unionNode; };
|
||||||
|
|
||||||
if (this->m_types.contains(typeName))
|
|
||||||
throwParseError(hex::format("redefinition of type '{}'", typeName));
|
|
||||||
|
|
||||||
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
||||||
unionNode->addMember(parseMember());
|
unionNode->addMember(parseMember());
|
||||||
}
|
}
|
||||||
@ -799,9 +790,6 @@ namespace hex::lang {
|
|||||||
const auto enumNode = new ASTNodeEnum(underlyingType);
|
const auto enumNode = new ASTNodeEnum(underlyingType);
|
||||||
auto enumGuard = SCOPE_GUARD { delete enumNode; };
|
auto enumGuard = SCOPE_GUARD { delete enumNode; };
|
||||||
|
|
||||||
if (this->m_types.contains(typeName))
|
|
||||||
throwParseError(hex::format("redefinition of type '{}'", typeName));
|
|
||||||
|
|
||||||
if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN)))
|
if (!MATCHES(sequence(SEPARATOR_CURLYBRACKETOPEN)))
|
||||||
throwParseError("expected '{' after enum definition", -1);
|
throwParseError("expected '{' after enum definition", -1);
|
||||||
|
|
||||||
@ -849,9 +837,6 @@ namespace hex::lang {
|
|||||||
const auto bitfieldNode = new ASTNodeBitfield();
|
const auto bitfieldNode = new ASTNodeBitfield();
|
||||||
auto enumGuard = SCOPE_GUARD { delete bitfieldNode; };
|
auto enumGuard = SCOPE_GUARD { delete bitfieldNode; };
|
||||||
|
|
||||||
if (this->m_types.contains(typeName))
|
|
||||||
throwParseError(hex::format("redefinition of type '{}'", typeName));
|
|
||||||
|
|
||||||
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) {
|
||||||
if (MATCHES(sequence(IDENTIFIER, OPERATOR_INHERIT))) {
|
if (MATCHES(sequence(IDENTIFIER, OPERATOR_INHERIT))) {
|
||||||
auto name = getValue<std::string>(-2);
|
auto name = getValue<std::string>(-2);
|
||||||
@ -1024,6 +1009,9 @@ namespace hex::lang {
|
|||||||
if (auto typeDecl = dynamic_cast<ASTNodeTypeDecl*>(statement); typeDecl != nullptr) {
|
if (auto typeDecl = dynamic_cast<ASTNodeTypeDecl*>(statement); typeDecl != nullptr) {
|
||||||
auto typeName = getNamespacePrefixedName(typeDecl->getName().data());
|
auto typeName = getNamespacePrefixedName(typeDecl->getName().data());
|
||||||
|
|
||||||
|
if (this->m_types.contains(typeName))
|
||||||
|
throwParseError(hex::format("redefinition of type '{}'", typeName));
|
||||||
|
|
||||||
typeDecl->setName(typeName);
|
typeDecl->setName(typeName);
|
||||||
this->m_types.insert({ typeName, typeDecl });
|
this->m_types.insert({ typeName, typeDecl });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user