Bug 335794 - Arthmetic If refactoring bug
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/remove-arithmetic-if-stmt/test5/bug335794.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/remove-arithmetic-if-stmt/test5/bug335794.f90
new file mode 100644
index 0000000..8277e40
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/remove-arithmetic-if-stmt/test5/bug335794.f90
@@ -0,0 +1,4 @@
+ if(ifcur-2)120,60,120 !<<<<< 1,1,pass
+ 60 if(4*ip2-ip4)80,80,120
+ 80 if(ifact(if+1)-2)120,100,120
+end
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/remove-arithmetic-if-stmt/test5/bug335794.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/remove-arithmetic-if-stmt/test5/bug335794.f90.result
new file mode 100644
index 0000000..08c83ce
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/remove-arithmetic-if-stmt/test5/bug335794.f90.result
@@ -0,0 +1,22 @@
+if(ifcur-2< 0) then !<<<<< 1,1,pass
+ goto 120
+else if(ifcur-2 == 0) then
+ goto 60
+else
+ goto 120
+end if
+60 if(4*ip2-ip4< 0) then
+ goto 80
+else if(4*ip2-ip4 == 0) then
+ goto 80
+else
+ goto 120
+end if
+80 if(ifact(if+1)-2< 0) then
+ goto 120
+else if(ifact(if+1)-2 == 0) then
+ goto 100
+else
+ goto 120
+end if
+end
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/RemoveArithmeticIfRefactoring.java b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/RemoveArithmeticIfRefactoring.java
index 486fb2c..bb9d330 100644
--- a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/RemoveArithmeticIfRefactoring.java
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/RemoveArithmeticIfRefactoring.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 University of Illinois at Urbana-Champaign and others.
+ * Copyright (c) 2010, 2011 University of Illinois at Urbana-Champaign and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.photran.internal.core.refactoring;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -30,6 +30,7 @@
* Refactoring to remove arithmetic if statements in Fortran files.
*
* @author Matthew Fotzler
+ * @author Jeff Overbey - Bug 335794
*/
public class RemoveArithmeticIfRefactoring extends FortranResourceRefactoring
{
@@ -72,7 +73,6 @@
if (ast == null) return;
List<ASTArithmeticIfStmtNode> nodesToReplace = findNodesToReplace(ast);
-
if (!nodesToReplace.isEmpty())
{
for (ASTArithmeticIfStmtNode node : nodesToReplace)
@@ -84,23 +84,15 @@
private List<ASTArithmeticIfStmtNode> findNodesToReplace(IFortranAST ast)
{
- ArithmeticIfRemovingVisitor replacer = new ArithmeticIfRemovingVisitor();
- ast.accept(replacer);
- return replacer.nodes;
- }
-
- private static final class ArithmeticIfRemovingVisitor extends GenericASTVisitor
- {
- private ArrayList<ASTArithmeticIfStmtNode> nodes = new ArrayList<ASTArithmeticIfStmtNode>();
-
- @Override
- public void visitASTNode(IASTNode node)
- {
- if (node instanceof ASTArithmeticIfStmtNode)
- nodes.add((ASTArithmeticIfStmtNode)node);
-
- traverseChildren(node);
- }
+ final List<ASTArithmeticIfStmtNode> result = new LinkedList<ASTArithmeticIfStmtNode>();
+ ast.accept(new GenericASTVisitor()
+ {
+ @Override public void visitASTArithmeticIfStmtNode(ASTArithmeticIfStmtNode node)
+ {
+ result.add(node);
+ }
+ });
+ return result;
}
private void replaceNode(ASTArithmeticIfStmtNode node, IFortranAST ast)
@@ -110,6 +102,8 @@
String third = node.getThird().getLabel().getText();
String conditionVariable = node.getExpr().toString();
String newNodeString = node.findFirstToken().getWhiteBefore();
+ if (node.getLabel() != null)
+ newNodeString += node.getLabel().getText() + " "; //$NON-NLS-1$
newNodeString +=
"if(" + conditionVariable + "< 0) then" + node.findLastToken().getWhiteBefore() + //$NON-NLS-1$ //$NON-NLS-2$
"\ngoto " + first + //$NON-NLS-1$