Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Overbey2012-05-07 20:25:00 +0000
committerJeffrey Overbey2012-05-07 20:25:00 +0000
commit4c27eb1a61abb1e19c2278cc79a8cc19cff6f919 (patch)
treee8e0d3c9d7296dcf9fe4bfb2e819d5c015105b96
parentabbdc76bef6879c9f4b845975d53cd29ddee9346 (diff)
downloadorg.eclipse.photran-4c27eb1a61abb1e19c2278cc79a8cc19cff6f919.tar.gz
org.eclipse.photran-4c27eb1a61abb1e19c2278cc79a8cc19cff6f919.tar.xz
org.eclipse.photran-4c27eb1a61abb1e19c2278cc79a8cc19cff6f919.zip
Bug 345493 - [Refactoring] Change To Vector Notation
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f9012
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90.result10
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f903
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90.result3
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f9013
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90.result13
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f9012
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90.result12
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f9011
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90.result11
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-index-in-the-assignement-rh-epxr-test/test7.f9012
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f9014
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90.result14
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test6.f9014
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/ChangeToVectorNotationRefactoring.java293
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java6
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties4
-rw-r--r--org.eclipse.photran.ui.vpg/plugin.xml3
18 files changed, 459 insertions, 1 deletions
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90
new file mode 100644
index 00000000..9305dfc0
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90
@@ -0,0 +1,12 @@
+program test8!<<<<< 8,5,10,11,pass
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i,j,w
+
+
+ do i=1,N
+ v(i)=v(i)
+ end do
+
+end program test8
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90.result
new file mode 100644
index 00000000..4536ec26
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-change-a-simple-do-loop-test/test8.f90.result
@@ -0,0 +1,10 @@
+program test8!<<<<< 8,5,10,11,pass
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i,j,w
+
+
+ v(1:N)=v(1:N)
+
+end program test8
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90
new file mode 100644
index 00000000..93c76c08
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90
@@ -0,0 +1,3 @@
+program test1 !<<<<< 2,5,2,18,fail-initial
+ implicit none
+end program test1
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90.result
new file mode 100644
index 00000000..b4b01895
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-no-do-loop-selected-test/test1.f90.result
@@ -0,0 +1,3 @@
+program test1 !<<<<< 2,5,2,18,fail-initial
+ implicit none
+end program test1 \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90
new file mode 100644
index 00000000..bedc111e
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90
@@ -0,0 +1,13 @@
+program test2!<<<<< 9,5,11,13,fail-initial
+ implicit none
+
+ integer, parameter :: N=100000
+ real v(N)
+ integer i
+
+
+ do 10 i=1,N
+ v(i)=0
+10 continue
+
+end program test2
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90.result
new file mode 100644
index 00000000..80b1bbc7
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-old-style-do-loop-selected-test/test2.f90.result
@@ -0,0 +1,13 @@
+program test2!<<<<< 9,5,11,13,fail-initial
+ implicit none
+
+ integer, parameter :: N=100000
+ real v(N)
+ integer i
+
+
+ do 10 i=1,N
+ v(i)=0
+10 continue
+
+end program test2 \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90
new file mode 100644
index 00000000..9f82d56c
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90
@@ -0,0 +1,12 @@
+program text3!<<<<< 8,5,10,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i
+
+
+ do i=1,N
+ v(i)=i+1
+ end do
+
+end program text3
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90.result
new file mode 100644
index 00000000..24992e92
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test3.f90.result
@@ -0,0 +1,12 @@
+program text3!<<<<< 8,5,10,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i
+
+
+ do i=1,N
+ v(i)=i+1
+ end do
+
+end program text3 \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90
new file mode 100644
index 00000000..f16a543b
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90
@@ -0,0 +1,11 @@
+program test4!<<<<< 8,5,10,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i
+
+
+ do i=1,N
+ v(i)=v(i+1)
+ end do
+end program test4
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90.result
new file mode 100644
index 00000000..1f8bd8e1
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-subindex-dependencies-found-test/test4.f90.result
@@ -0,0 +1,11 @@
+program test4!<<<<< 8,5,10,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i
+
+
+ do i=1,N
+ v(i)=v(i+1)
+ end do
+end program test4 \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-index-in-the-assignement-rh-epxr-test/test7.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-index-in-the-assignement-rh-epxr-test/test7.f90
new file mode 100644
index 00000000..09d444a2
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-index-in-the-assignement-rh-epxr-test/test7.f90
@@ -0,0 +1,12 @@
+program test7!<<<<< 8,5,10,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N)
+ integer i,j,w
+
+
+ do i=1,N
+ v(i)=i
+ end do
+
+end program test7
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90
new file mode 100644
index 00000000..b089e66e
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90
@@ -0,0 +1,14 @@
+program test5!<<<<< 8,5,12,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N),w(N)
+ integer i
+ integer j
+
+ do i=1,N
+ v(i)=v(i)+1
+ w(i)=2
+ j=i
+ end do
+
+end program test5
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90.result
new file mode 100644
index 00000000..e2156538
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test5.f90.result
@@ -0,0 +1,14 @@
+program test5!<<<<< 8,5,12,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N),w(N)
+ integer i
+ integer j
+
+ do i=1,N
+ v(i)=v(i)+1
+ w(i)=2
+ j=i
+ end do
+
+end program test5 \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test6.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test6.f90
new file mode 100644
index 00000000..b3cb1232
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/change-to-vector-notation/should-fail-when-unproper-do-loop-is-selected-text/test6.f90
@@ -0,0 +1,14 @@
+program test6!<<<<< 8,5,13,11,fail-initial
+ implicit none
+ integer, parameter :: N=100000
+ real v(N),w(N)
+ integer i
+ integer j
+
+ do i=1,N
+ v(i)=v(i)+1
+ if (j>2) then
+ print *,"this can't be refactored "
+ end if
+ end do
+end program test6
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/ChangeToVectorNotationRefactoring.java b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/ChangeToVectorNotationRefactoring.java
new file mode 100644
index 00000000..d2e0e16f
--- /dev/null
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/ChangeToVectorNotationRefactoring.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mariano Mendez 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mariano Mendez - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.photran.internal.core.refactoring;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.photran.internal.core.analysis.binding.Definition;
+import org.eclipse.photran.internal.core.analysis.loops.ASTProperLoopConstructNode;
+import org.eclipse.photran.internal.core.analysis.loops.ASTVisitorWithLoops;
+import org.eclipse.photran.internal.core.analysis.loops.LoopReplacer;
+import org.eclipse.photran.internal.core.lexer.Terminal;
+import org.eclipse.photran.internal.core.lexer.Token;
+import org.eclipse.photran.internal.core.parser.ASTAssignmentStmtNode;
+import org.eclipse.photran.internal.core.parser.ASTBinaryExprNode;
+import org.eclipse.photran.internal.core.parser.ASTNameNode;
+import org.eclipse.photran.internal.core.parser.ASTNode;
+import org.eclipse.photran.internal.core.parser.ASTVarOrFnRefNode;
+import org.eclipse.photran.internal.core.parser.IASTListNode;
+import org.eclipse.photran.internal.core.parser.IASTNode;
+import org.eclipse.photran.internal.core.parser.IActionStmt;
+import org.eclipse.photran.internal.core.parser.IExecutableConstruct;
+import org.eclipse.photran.internal.core.parser.IExecutionPartConstruct;
+import org.eclipse.photran.internal.core.parser.IExpr;
+import org.eclipse.photran.internal.core.parser.IObsoleteActionStmt;
+import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring;
+import org.eclipse.photran.internal.core.reindenter.Reindenter;
+import org.eclipse.photran.internal.core.reindenter.Reindenter.Strategy;
+
+/**
+ * Change to Vector Form Refactoring: Change a loop that works only with an array
+ * into a vector notation statement.
+ *
+ * @author Mariano Mendez
+ */
+public class ChangeToVectorNotationRefactoring extends FortranEditorRefactoring
+{
+ private ASTProperLoopConstructNode DoLoopNode =null;
+ @Override
+ public String getName()
+ {
+ return "Change to Vector Notation"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
+ throws PreconditionFailure
+ {
+ ensureProjectHasRefactoringEnabled(status);
+ removeFixedFormFilesFrom(this.selectedFiles, status);
+ removeCpreprocessedFilesFrom(this.selectedFiles, status);
+ LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot());
+ ensureDoLoopHasBeenSelected();
+ checkIfCanBeChanged();
+ }
+
+ private void checkIfCanBeChanged()
+ throws PreconditionFailure
+ {
+ Token index = this.DoLoopNode.getIndexVariable();
+
+ DependencyFinderVisitor dependencyFinder= new DependencyFinderVisitor(index.getText());
+ VectorNotationVisitor changer= new VectorNotationVisitor(index.getText());
+
+ this.DoLoopNode.accept(dependencyFinder);
+ this.DoLoopNode.getBody().accept(changer);
+
+ if ((!changer.canBeChanged() || dependencyFinder.getHasDependencies() ) ) //
+ fail(Messages.ChangeToVectorNotation_CanNotBeChangedToVectorNotation);
+ }
+
+ private void ensureDoLoopHasBeenSelected()
+ throws PreconditionFailure
+ {
+ ASTNode oldNode = getNode(this.astOfFileInEditor, this.selectedRegionInEditor, ASTProperLoopConstructNode.class);
+ if (oldNode == null)
+ fail(Messages.ChangeToVectorNotation_PleaseSelectDoLoopNode);
+ else
+ {
+ if (!isOldStyleDoLoop((ASTProperLoopConstructNode)oldNode))
+ DoLoopNode = (ASTProperLoopConstructNode)oldNode;
+ else
+ fail(Messages.ChangeToVectorNotation_PleaseSelectNewStyleDoLoopNode);
+ }
+ }
+
+ private boolean isOldStyleDoLoop(ASTProperLoopConstructNode node)
+ {
+ return (node.getEndDoStmt()==null
+ && node.getLoopHeader().getLblRef()!=null);
+ }
+
+ @Override
+ protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm)
+ throws PreconditionFailure
+ {
+ // No final preconditions
+ }
+
+ @Override
+ protected void doCreateChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException
+ {
+ // Do something with
+ IASTNode newNode = getNewCode(this.DoLoopNode);
+ this.DoLoopNode.replaceWith(newNode.toString().trim()+"\n"); //$NON-NLS-1$
+ //this.DoLoopNode.removeFromTree();
+ Reindenter.reindent(this.DoLoopNode, this.astOfFileInEditor, Strategy.SHIFT_ENTIRE_BLOCK);
+ this.addChangeFromModifiedAST(this.fileInEditor, pm);
+ vpg.releaseAST(this.fileInEditor);
+ }
+
+
+
+ @SuppressWarnings("rawtypes")
+ private IASTNode getNewCode(ASTProperLoopConstructNode node)
+ {
+ IExpr lowerBound = this.DoLoopNode.getLowerBoundIExpr();
+ IExpr upperBound = this.DoLoopNode.getUpperBoundIExpr();
+ final String newIndex=(lowerBound.toString()+":"+upperBound.toString()); //$NON-NLS-1$
+ final String indexVariable = this.DoLoopNode.getIndexVariable().getText();
+
+ IASTListNode newBody = ((IASTListNode)(node.getBody().clone()));
+
+ newBody.accept(new ASTVisitorWithLoops()
+ {
+ @Override
+ public void visitToken(Token token)
+ {
+ if (token.getTerminal() == Terminal.T_IDENT && (token.getText()).equals(indexVariable))
+ {
+ String s2 = token.getText();
+ s2 = newIndex;
+ token.replaceWith(s2);
+ }
+ }
+
+ });
+ return newBody;
+ }
+
+
+
+
+ public class DependencyFinderVisitor extends ASTVisitorWithLoops
+ {
+ private boolean hasDependencies= false;
+ private String indexVarName;
+
+ public DependencyFinderVisitor(String indexVarName)
+ {
+ super();
+ this.indexVarName=indexVarName;
+ }
+
+ public boolean getHasDependencies()
+ {
+ return hasDependencies;
+ }
+ @Override
+ public void visitASTBinaryExprNode(ASTBinaryExprNode node)
+ {
+ IExpr lhsExpr; // in ASTBinaryExprNode
+ IExpr rhsExpr; // in ASTBinaryExprNode
+
+ lhsExpr=node.getLhsExpr();
+ rhsExpr=node.getRhsExpr();
+
+
+ checkExpr(lhsExpr);
+ checkExpr(rhsExpr);
+ traverseChildren(node);
+ }
+
+ private void checkExpr(IExpr Expr)
+ {
+ if (IsVariable(Expr))
+ {
+ ASTNameNode nameNode=((ASTVarOrFnRefNode)Expr).getName();
+ if (nameNode !=null)
+ {
+ if (this.indexVarName.equals(nameNode.getName().getText())) this.hasDependencies=true;
+ }
+ }
+
+ }
+
+ private boolean IsVariable(IExpr Expr)
+ {
+ return (Expr instanceof ASTVarOrFnRefNode );
+ }
+ }
+
+ public class VectorNotationVisitor extends ASTVisitorWithLoops
+ {
+ private boolean CanChangeVectorNotation=true;
+ private String indexVarName;
+
+ public VectorNotationVisitor(String indexVarName)
+ {
+ super();
+ this.indexVarName=indexVarName;
+ }
+
+ public boolean canBeChanged()
+ {
+ return CanChangeVectorNotation;
+ }
+
+ @Override public void visitIExecutionPartConstruct(IExecutionPartConstruct node)
+ {
+ if (! (node instanceof ASTAssignmentStmtNode ) )
+ this.CanChangeVectorNotation=false;
+ else CheckAsignmentNode((ASTAssignmentStmtNode)node);
+
+ }
+
+
+ private void CheckAsignmentNode(ASTAssignmentStmtNode node)
+ {
+ Token lhsVariable= node.getLhsVariable().getName();
+ IExpr rhs = node.getRhs();
+
+ if (! leftHandCanBeChanged(lhsVariable) ) this.CanChangeVectorNotation=false;
+ CheckRightHandExpr(rhs);
+ }
+
+ private void CheckRightHandExpr(IExpr rhs)
+ {
+ if (rhs instanceof ASTBinaryExprNode){
+ CheckRightHandExpr(((ASTBinaryExprNode)rhs).getLhsExpr());
+ CheckRightHandExpr(((ASTBinaryExprNode)rhs).getRhsExpr());
+ }
+
+ if (rhs instanceof ASTVarOrFnRefNode){
+ ASTNameNode nameNode=((ASTVarOrFnRefNode)rhs).getName();
+ if (nameNode!=null){
+ Token varName= nameNode.getName();
+ if ( varName!=null && varName.getText().toString().equals(this.indexVarName) )
+ this.CanChangeVectorNotation=false;
+ }
+ }
+ }
+
+ boolean leftHandCanBeChanged(Token lhsVariable)
+ {
+ if (lhsVariable.isIdentifier()) {
+
+ List<Definition> definitions = lhsVariable.resolveBinding();
+
+ if (!definitions.isEmpty() && definitions.size()==1)
+ {
+ Definition symbol = definitions.get(0);
+ if (!symbol.isArray()) return false; //if lhsVariable is not an array it can not be changed
+ }
+ else
+ return false;
+
+ }
+ else
+ return false ;
+
+ return true ;
+ }
+
+ @Override public void visitIExecutableConstruct(IExecutableConstruct node)
+ {
+ visitIExecutionPartConstruct(node);
+ }
+
+ @Override public void visitIActionStmt(IActionStmt node)
+ {
+ visitIExecutionPartConstruct(node);
+ }
+
+ @Override public void visitIObsoleteActionStmt(IObsoleteActionStmt node)
+ {
+ visitIExecutionPartConstruct(node);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java
index 6bb3305e..a98594b8 100644
--- a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java
@@ -81,6 +81,12 @@ public class Messages extends NLS
public static String AddSubroutineParameterRefactoring_selectSubroutineError;
+ public static String ChangeToVectorNotation_PleaseSelectDoLoopNode;
+
+ public static String ChangeToVectorNotation_PleaseSelectNewStyleDoLoopNode;
+
+ public static String ChangeToVectorNotation_CanNotBeChangedToVectorNotation;
+
public static String EncapsulateVariableRefactoring_CannotEncapsulateArrays;
public static String EncapsulateVariableRefactoring_CannotEncapsulatePARAMETER;
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties
index 377e5e9c..092b05d0 100644
--- a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties
@@ -233,7 +233,9 @@ SafeDeleteInternalSubprogramRefactoring_NotAnInternalSubprogram=Not an internal
SafeDeleteInternalSubprogramRefactoring_SubroutineMustHaveOnlyInternalReferences=Subroutine must only have internal references.
StandardizeStatementsRefactoring_Name=Standardize Statements
StandardizeStatementsRefactoring_SelectedFileCannotBeParsed=One of the selected files ({0}) cannot be parsed.
-IfConstructStatementConversionRefactoring_Name= Convert Between If Statement and If Construct
+ChangeToVectorNotation_PleaseSelectDoLoopNode=Please select a DO LOOP statement.
+ChangeToVectorNotation_PleaseSelectNewStyleDoLoopNode=Please select a new style DO LOOP statement ended with END DO statement.
+ChangeToVectorNotation_CanNotBeChangedToVectorNotation= Can not be changed to vector notation, subindex dependencies may be found or Do Loop can not be vectorized.IfConstructStatementConversionRefactoring_Name= Convert Between If Statement and If Construct
IfConstructStatementConversionRefactoring_SelectAValidIfStatement= Please select a valid IF statement or construct.
IfConstructStatementConversionRefactoring_InvalidNamedConstruct= Cannot refactor a named IF construct. Please select an unnamed IF construct.
IfConstructStatementConversionRefactoring_TooManyStatements= Selected IF construct contains too many statements and cannot be refactored to an IF statement.
diff --git a/org.eclipse.photran.ui.vpg/plugin.xml b/org.eclipse.photran.ui.vpg/plugin.xml
index dddb2ce5..e9076539 100644
--- a/org.eclipse.photran.ui.vpg/plugin.xml
+++ b/org.eclipse.photran.ui.vpg/plugin.xml
@@ -110,6 +110,9 @@
<editorRefactoring
command="org.eclipse.photran.ui.ReplaceDoLoopWithForallRefactoringCommand"
/>
+ <editorRefactoring
+ class="org.eclipse.photran.internal.core.refactoring.ChangeToVectorNotationRefactoring"
+ />
</submenu>
</group>
<group>

Back to the top