From 198da78c98b7826de19e4c8b01c79645506b4ebe Mon Sep 17 00:00:00 2001 From: Nathan Burles Date: Mon, 1 Aug 2016 16:32:51 +0100 Subject: [PATCH] Compare contents in SemanticContext::*::operator== --- .../Cpp/runtime/src/atn/SemanticContext.cpp | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/runtime/Cpp/runtime/src/atn/SemanticContext.cpp b/runtime/Cpp/runtime/src/atn/SemanticContext.cpp index ebca6c9cf..bc4648720 100755 --- a/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +++ b/runtime/Cpp/runtime/src/atn/SemanticContext.cpp @@ -65,14 +65,10 @@ size_t SemanticContext::Predicate::hashCode() const { } bool SemanticContext::Predicate::operator == (const SemanticContext &other) const { - const Predicate *p = dynamic_cast(&other); - if (p == nullptr) - return false; - - if (this == p) { + if (this == &other) return true; - } + const Predicate *p = dynamic_cast(&other); if (p == nullptr) return false; @@ -116,14 +112,13 @@ size_t SemanticContext::PrecedencePredicate::hashCode() const { } bool SemanticContext::PrecedencePredicate::operator == (const SemanticContext &other) const { + if (this == &other) + return true; + const PrecedencePredicate *predicate = dynamic_cast(&other); if (predicate == nullptr) return false; - if (this == predicate) { - return true; - } - return precedence == predicate->precedence; } @@ -172,15 +167,21 @@ std::vector> SemanticContext::AND::getOperands() const { } bool SemanticContext::AND::operator == (const SemanticContext &other) const { + if (this == &other) + return true; + const AND *context = dynamic_cast(&other); if (context == nullptr) return false; - if (this == context) { + if (opnds == context->opnds) return true; - } - return opnds == context->opnds; + for (auto opndIt = opnds.begin(), otherIt = context->opnds.begin(); opndIt < opnds.end(), otherIt < context->opnds.end(); ++opndIt, ++otherIt) { + if (*opndIt != *otherIt) + return false; + } + return true; } size_t SemanticContext::AND::hashCode() const { @@ -275,15 +276,21 @@ std::vector> SemanticContext::OR::getOperands() const { } bool SemanticContext::OR::operator == (const SemanticContext &other) const { + if (this == &other) + return true; + const OR *context = dynamic_cast(&other); if (context == nullptr) return false; - if (this == context) { + if (opnds == context->opnds) return true; - } - return opnds == context->opnds; + for (auto opndIt = opnds.begin(), otherIt = context->opnds.begin(); opndIt < opnds.end(), otherIt < context->opnds.end(); ++opndIt, ++otherIt ) { + if (*opndIt != *otherIt) + return false; + } + return true; } size_t SemanticContext::OR::hashCode() const {