From e77861f56760fe31e7c3ff8c7aa0ac1269c6740e Mon Sep 17 00:00:00 2001 From: Samidh Talsania Date: Wed, 19 Oct 2016 00:12:47 -0700 Subject: [PATCH] Fixed a few memory related bugs. Removed old style used compiler warning. --- configure.ac | 2 +- src/includes/BodyDef.h | 2 +- src/includes/Predicate.h | 2 +- src/src/MVSMParserGrammar.cpp | 41 ++++++++++++++++------------------- src/src/MVSMParserGrammar.y | 41 ++++++++++++++++------------------- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/configure.ac b/configure.ac index c2c93cc..430300a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ AC_INIT([LPMLN],1.0) AM_INIT_AUTOMAKE([subdir-objects]) CC=${CC-/usr/bin/g++-4.8} -CXXFLAGS="$CXXFLAGS -g -std=c++11 -Wall -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused" +CXXFLAGS="$CXXFLAGS -g -std=c++11 -Wall -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused" AC_SUBST([PROJECT_ROOT],`pwd`) AC_PROG_CXX([g++]) AC_PROG_CC diff --git a/src/includes/BodyDef.h b/src/includes/BodyDef.h index 9af42ee..2bbe061 100644 --- a/src/includes/BodyDef.h +++ b/src/includes/BodyDef.h @@ -41,7 +41,7 @@ class BodyDef } - std::string setString(std::string s){ + void setString(std::string s){ str = s; aggregateString = true; } diff --git a/src/includes/Predicate.h b/src/includes/Predicate.h index 631864d..628480a 100644 --- a/src/includes/Predicate.h +++ b/src/includes/Predicate.h @@ -94,7 +94,7 @@ class Predicate std::string getExtra(const std::set& variable); std::string getExtraConstants() const; - std::string setString(std::string s){ + void setString(std::string s){ aggregateString = s; isAggregate = true; } diff --git a/src/src/MVSMParserGrammar.cpp b/src/src/MVSMParserGrammar.cpp index 0ebcdba..b312501 100644 --- a/src/src/MVSMParserGrammar.cpp +++ b/src/src/MVSMParserGrammar.cpp @@ -1450,14 +1450,14 @@ static void yy_reduce( case 35: /* body ::= bodydef */ { yygotominor.yy49 = new Body; - yygotominor.yy49->addPredicate(yymsp[0].minor.yy43->getPredicate()); - yygotominor.yy49->appendStr(yymsp[0].minor.yy43->getPredicate(),false,false,false); + Predicate p = yymsp[0].minor.yy43->getPredicate(); + yygotominor.yy49->addPredicate(p); + yygotominor.yy49->appendStr(p,false,false,false); delete yymsp[0].minor.yy43; } break; case 36: /* bodydef ::= literal */ { - yygotominor.yy43 = yymsp[0].minor.yy43; } break; @@ -1608,18 +1608,14 @@ static void yy_reduce( break; case 46: /* literal ::= string EQUAL COUNT LPAREN aggregateCum RPAREN */ { - Predicate p; - - yygotominor.yy43 = new BodyDef; std::string s = (*yymsp[-5].minor.yy0).toString(); - // std::string s1 = (*S1).toString(); Util::toUpper(s); - // Util::toUpper(s1); - - std::string str = s + "= #count{" + yymsp[-1].minor.yy0->toString() + "}"; - p.setString(str); - + s = s + "= #count{" + yymsp[-1].minor.yy0->toString() + "}"; + Predicate p(yymsp[-5].minor.yy0->token); + p.setString(s); + yygotominor.yy43 = new BodyDef; yygotominor.yy43->addPredicate(p); + delete yymsp[-1].minor.yy0; } break; case 47: /* aggregate ::= string COLON literal */ @@ -1627,26 +1623,27 @@ static void yy_reduce( yygotominor.yy0 = new Token(*(yymsp[-2].minor.yy0->token)); std::string s1 = yygotominor.yy0->toString(); Util::toUpper(s1); - std::string str = s1 + ":" + yymsp[0].minor.yy43->toString(); - yygotominor.yy0->modifyToken(str); + s1 = s1 + ":" + yymsp[0].minor.yy43->toString(); + yygotominor.yy0->modifyToken(s1); + delete yymsp[0].minor.yy43; } break; case 48: /* aggregate ::= number COLON literal */ { yygotominor.yy0 = new Token(*(yymsp[-2].minor.yy0->token)); std::string s1 = yygotominor.yy0->toString(); - // Util::toUpper(s1); - std::string str = s1 + ":" + yymsp[0].minor.yy43->toString(); - yygotominor.yy0->modifyToken(str); + s1 = s1 + ":" + yymsp[0].minor.yy43->toString(); + yygotominor.yy0->modifyToken(s1); + delete yymsp[0].minor.yy43; } break; case 49: /* aggregate ::= string COMMA literal COLON literal */ { yygotominor.yy0 = new Token(*(yymsp[-4].minor.yy0->token)); - std::string s1 = (*yymsp[-4].minor.yy0).toString(); + std::string s1 = yygotominor.yy0->toString(); Util::toUpper(s1); - std::string str = s1 + "," + yymsp[-2].minor.yy43->toString() + ":" + yymsp[0].minor.yy43->toString(); - yygotominor.yy0->modifyToken(str); + s1 = s1 + "," + yymsp[-2].minor.yy43->toString() + ":" + yymsp[0].minor.yy43->toString(); + yygotominor.yy0->modifyToken(s1); } break; case 50: /* aggregate ::= number COMMA literal COLON literal */ @@ -1654,8 +1651,8 @@ static void yy_reduce( yygotominor.yy0 = new Token(*(yymsp[-4].minor.yy0->token)); std::string s1 = (*yymsp[-4].minor.yy0).toString(); // Util::toUpper(s1); - std::string str = s1 + "," + yymsp[-2].minor.yy43->toString()+ ":" + yymsp[0].minor.yy43->toString(); - yygotominor.yy0->modifyToken(str); + s1 = s1 + "," + yymsp[-2].minor.yy43->toString()+ ":" + yymsp[0].minor.yy43->toString(); + yygotominor.yy0->modifyToken(s1); } break; case 51: /* aggregateCum ::= aggregate */ diff --git a/src/src/MVSMParserGrammar.y b/src/src/MVSMParserGrammar.y index e3b3f0b..be19a2a 100644 --- a/src/src/MVSMParserGrammar.y +++ b/src/src/MVSMParserGrammar.y @@ -627,8 +627,9 @@ head(H) ::= bodydef(Bd).{ body(B) ::= bodydef(Bd).{ B = new Body; - B->addPredicate(Bd->getPredicate()); - B->appendStr(Bd->getPredicate(),false,false,false); + Predicate p = Bd->getPredicate(); + B->addPredicate(p); + B->appendStr(p,false,false,false); delete Bd; } @@ -636,7 +637,6 @@ body(B) ::= bodydef(Bd).{ // BodyDef without negation in front bodydef(B) ::= literal(L).{ - B = L; } @@ -787,18 +787,14 @@ literal(L) ::= variable(V).{ } literal(L) ::= string(S) EQUAL COUNT LPAREN aggregateCum(A) RPAREN.{ - Predicate p; - - L = new BodyDef; std::string s = (*S).toString(); - // std::string s1 = (*S1).toString(); Util::toUpper(s); - // Util::toUpper(s1); - - std::string str = s + "= #count{" + A->toString() + "}"; - p.setString(str); - + s = s + "= #count{" + A->toString() + "}"; + Predicate p(S->token); + p.setString(s); + L = new BodyDef; L->addPredicate(p); + delete A; } @@ -806,24 +802,25 @@ aggregate(A) ::= string(S1) COLON literal(L1).{ A = new Token(*(S1->token)); std::string s1 = A->toString(); Util::toUpper(s1); - std::string str = s1 + ":" + L1->toString(); - A->modifyToken(str); + s1 = s1 + ":" + L1->toString(); + A->modifyToken(s1); + delete L1; } aggregate(A) ::= number(S1) COLON literal(L1).{ A = new Token(*(S1->token)); std::string s1 = A->toString(); - // Util::toUpper(s1); - std::string str = s1 + ":" + L1->toString(); - A->modifyToken(str); + s1 = s1 + ":" + L1->toString(); + A->modifyToken(s1); + delete L1; } aggregate(A) ::= string(S1) COMMA literal(L2) COLON literal(L1).{ A = new Token(*(S1->token)); - std::string s1 = (*S1).toString(); + std::string s1 = A->toString(); Util::toUpper(s1); - std::string str = s1 + "," + L2->toString() + ":" + L1->toString(); - A->modifyToken(str); + s1 = s1 + "," + L2->toString() + ":" + L1->toString(); + A->modifyToken(s1); } @@ -831,8 +828,8 @@ aggregate(A) ::= number(S1) COMMA literal(L2) COLON literal(L1).{ A = new Token(*(S1->token)); std::string s1 = (*S1).toString(); // Util::toUpper(s1); - std::string str = s1 + "," + L2->toString()+ ":" + L1->toString(); - A->modifyToken(str); + s1 = s1 + "," + L2->toString()+ ":" + L1->toString(); + A->modifyToken(s1); } aggregateCum(A) ::= aggregate(A1).{