From dd7deadbbe9cc529feaf07e590782971031bd8a5 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 5 Nov 2016 02:52:12 +0330 Subject: now adds compound statements to elses too --- mutator.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mutator.cpp b/mutator.cpp index c1d00f9..3a022b4 100644 --- a/mutator.cpp +++ b/mutator.cpp @@ -291,9 +291,9 @@ public: const IfStmt *ElseIf = MR.Nodes.getNodeAs("mrifelse"); //const IfStmt *LastIf = MR.Nodes.getNodeAs("mrifelse"); - SourceLocation IFESL = ElseIf->getLocStart(); + SourceLocation IFESL = ElseIf->getElse()->getLocStart(); IFESL = Devi::SourceLocationHasMacro(IFESL, Rewrite, "start"); - SourceLocation IFESLE = ElseIf->getLocEnd(); + SourceLocation IFESLE = ElseIf->getElse()->getLocEnd(); IFESLE = Devi::SourceLocationHasMacro(IFESLE, Rewrite, "end"); SourceRange SR; SR.setBegin(IFESL); @@ -305,9 +305,9 @@ public: //std::cout << IFESLE.printToString(*MR.SourceManager) << "\n" << std::endl; -#if 0 - //Rewrite.InsertText(ElseIf->getThen()->getLocStart(), "{\n", "true", "true"); - Rewrite.InsertTextAfterToken(IFESL.getLocWithOffset(RangeSize + 1U), "else\n{/*intentionally left blank*/\n}\n"); +#if 1 + Rewrite.InsertText(IFESL, "{\n", "true", "true"); + Rewrite.InsertTextAfterToken(IFESL.getLocWithOffset(RangeSize), "\n}"); #endif } else @@ -378,7 +378,7 @@ public: Matcher.addMatcher(whileStmt(unless(hasDescendant(compoundStmt()))).bind("mrwhile"), &HandlerForWhile); - Matcher.addMatcher(ifStmt(allOf(hasElse(ifStmt()), unless(hasAncestor(ifStmt())), unless(hasDescendant(ifStmt(hasElse(unless(ifStmt()))))))).bind("mrifelse"), &HandlerForIfElse); + Matcher.addMatcher(ifStmt(allOf(hasElse(unless(ifStmt())), hasElse(unless(compoundStmt())))).bind("mrifelse"), &HandlerForIfElse); Matcher.addMatcher(ifStmt(unless(hasDescendant(compoundStmt()))).bind("mrif"), &HandlerForIfFixer); } -- cgit v1.2.3