patterns: Fixed more memory leaks
This commit is contained in:
parent
0a29f25330
commit
a4b4360df6
@ -118,11 +118,15 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseMultiplicativeExpression() {
|
||||
auto node = this->parseUnaryExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(oneOf(OPERATOR_STAR, OPERATOR_SLASH, OPERATOR_PERCENT))) {
|
||||
auto op = getValue<Token::Operator>(-1);
|
||||
node = new ASTNodeNumericExpression(node, this->parseUnaryExpression(), op);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -130,11 +134,15 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseAdditiveExpression() {
|
||||
auto node = this->parseMultiplicativeExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(variant(OPERATOR_PLUS, OPERATOR_MINUS))) {
|
||||
auto op = getValue<Token::Operator>(-1);
|
||||
node = new ASTNodeNumericExpression(node, this->parseMultiplicativeExpression(), op);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -142,11 +150,15 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseShiftExpression() {
|
||||
auto node = this->parseAdditiveExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(variant(OPERATOR_SHIFTLEFT, OPERATOR_SHIFTRIGHT))) {
|
||||
auto op = getValue<Token::Operator>(-1);
|
||||
node = new ASTNodeNumericExpression(node, this->parseAdditiveExpression(), op);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -154,11 +166,15 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseRelationExpression() {
|
||||
auto node = this->parseShiftExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BOOLGREATERTHAN) || sequence(OPERATOR_BOOLLESSTHAN) || sequence(OPERATOR_BOOLGREATERTHANOREQUALS) || sequence(OPERATOR_BOOLLESSTHANOREQUALS))) {
|
||||
auto op = getValue<Token::Operator>(-1);
|
||||
node = new ASTNodeNumericExpression(node, this->parseShiftExpression(), op);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -166,11 +182,15 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseEqualityExpression() {
|
||||
auto node = this->parseRelationExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BOOLEQUALS) || sequence(OPERATOR_BOOLNOTEQUALS))) {
|
||||
auto op = getValue<Token::Operator>(-1);
|
||||
node = new ASTNodeNumericExpression(node, this->parseRelationExpression(), op);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -178,10 +198,14 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseBinaryAndExpression() {
|
||||
auto node = this->parseEqualityExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BITAND))) {
|
||||
node = new ASTNodeNumericExpression(node, this->parseEqualityExpression(), Token::Operator::BitAnd);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -189,10 +213,14 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseBinaryXorExpression() {
|
||||
auto node = this->parseBinaryAndExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BITXOR))) {
|
||||
node = new ASTNodeNumericExpression(node, this->parseBinaryAndExpression(), Token::Operator::BitXor);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -200,10 +228,14 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseBinaryOrExpression() {
|
||||
auto node = this->parseBinaryXorExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BITOR))) {
|
||||
node = new ASTNodeNumericExpression(node, this->parseBinaryXorExpression(), Token::Operator::BitOr);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -211,10 +243,14 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseBooleanAnd() {
|
||||
auto node = this->parseBinaryOrExpression();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BOOLAND))) {
|
||||
node = new ASTNodeNumericExpression(node, this->parseBinaryOrExpression(), Token::Operator::BitOr);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -222,10 +258,14 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseBooleanXor() {
|
||||
auto node = this->parseBooleanAnd();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BOOLXOR))) {
|
||||
node = new ASTNodeNumericExpression(node, this->parseBooleanAnd(), Token::Operator::BitOr);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -233,10 +273,14 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseBooleanOr() {
|
||||
auto node = this->parseBooleanXor();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_BOOLOR))) {
|
||||
node = new ASTNodeNumericExpression(node, this->parseBooleanXor(), Token::Operator::BitOr);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -244,6 +288,8 @@ namespace hex::lang {
|
||||
ASTNode* Parser::parseTernaryConditional() {
|
||||
auto node = this->parseBooleanOr();
|
||||
|
||||
ScopeExit nodeCleanup([&]{ delete node; });
|
||||
|
||||
while (MATCHES(sequence(OPERATOR_TERNARYCONDITIONAL))) {
|
||||
auto second = this->parseBooleanOr();
|
||||
|
||||
@ -254,6 +300,8 @@ namespace hex::lang {
|
||||
node = new ASTNodeTernaryExpression(node, second, third, Token::Operator::TernaryConditional);
|
||||
}
|
||||
|
||||
nodeCleanup.release();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user