Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 185105 Details for
Bug 332492
Refactoring [427]: Remove Obsolete Language Features - CQ approved
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Remove Obsolete Language Features - Refactoring Enhancement (Patch)
RemoveObsoleteLanguageFeatures.txt (text/plain), 65.06 KB, created by
Mark Mozolewski
on 2010-12-14 00:17:20 EST
(
hide
)
Description:
Remove Obsolete Language Features - Refactoring Enhancement (Patch)
Filename:
MIME Type:
Creator:
Mark Mozolewski
Created:
2010-12-14 00:17:20 EST
Size:
65.06 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.photran.core.vpg >Index: src/org/eclipse/photran/internal/core/refactoring/Messages.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java,v >retrieving revision 1.15 >diff -u -r1.15 Messages.java >--- src/org/eclipse/photran/internal/core/refactoring/Messages.java 21 Sep 2010 18:32:41 -0000 1.15 >+++ src/org/eclipse/photran/internal/core/refactoring/Messages.java 14 Dec 2010 04:49:33 -0000 >@@ -7,6 +7,11 @@ > * > * Contributors: > * UIUC - Initial API and implementation >+ * Rita Chow - Photran Modifications >+ * Nicola Hall - Photran Modifications >+ * Jerry Hsiao - Photran Modifications >+ * Mark Mozolewski - Photran Modifications >+ * Chamil Wijenayaka - Photran Modifications > *******************************************************************************/ > package org.eclipse.photran.internal.core.refactoring; > >@@ -356,9 +361,37 @@ > > public static String RemoveArithmeticIfRefactoring_Name; > >+ public static String RemoveBranchToEndIfRefactoring_Name; >+ >+ public static String RemoveBranchToEndIfRefactoring_MissingGoToStatement; >+ >+ public static String RemoveBranchToEndIfRefactoring_GoToLabelDoesNotMatchAnyEndIfLabel; >+ >+ public static String RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf; >+ >+ public static String RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor; >+ >+ public static String RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct; >+ >+ public static String RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel; >+ > public static String RemoveComputedGoToRefactoring_Name; > > public static String RemoveComputedGoToRefactoring_PleaseSelectComputedGotoStmt; >+ >+ public static String RemovePauseStmtRefactoring_Name; >+ >+ public static String RemovePauseStmtRefactoring_SelectPauseStmt; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_Name; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectADoLoop; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectAControlledDoLoop; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableMissingDeclaration; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableNotRealOrDouble; > > public static String RemoveUnusedVariablesRefactoring_CouldNotCompleteOperation; > >Index: src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java >diff -N src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,564 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.core.refactoring; >+ >+import java.util.LinkedList; >+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.ScopingNode; >+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.parser.*; >+import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring; >+ >+/** >+ * Remove branching to END IF statement from outside its IF ... END IF block. Such branching should >+ * be replaced with branching to CONTINUE statement that immediately follows the END IF statement. >+ * If the END IF statement is followed by a CONTINUE statement then outside GOTO branches should >+ * target the CONTINUE statement. If one does not exist the refactoring will insert one and target >+ * it. GOTOs inside the selected IF block are not re-targeted. >+ * >+ * User Selection Requirements: The labeled END IF that they want considered for the refactoring. >+ * >+ * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka >+ * (wijenay2), Nicola Hall (nfhall2) >+ */ >+public class RemoveBranchToEndIfRefactoring extends FortranEditorRefactoring >+{ >+ private IASTNode selectedNode; >+ >+ private ASTEndIfStmtNode selectedEndIfNode; >+ >+ private ASTIfConstructNode selectedIfConstructNode; >+ >+ private LinkedList<ASTGotoStmtNode> gotoStatements; >+ >+ private LinkedList<ASTGotoStmtNode> selectedGotoStatements; >+ >+ private ASTContinueStmtNode continueAfterIfStmtNode; >+ >+ private LinkedList<ASTGotoStmtNode> selectedGotoStatementWithEndIfLabel; >+ >+ private LinkedList<ASTGotoStmtNode> gotoStatementWithEndIfLabel; >+ >+ /** >+ * Provide GUI refactoring label. >+ */ >+ @Override >+ public String getName() >+ { >+ return Messages.RemoveBranchToEndIfRefactoring_Name; >+ } >+ >+ /** >+ * Preconditions that are checked before the refactoring is applied are: 1) END IF selected must >+ * be labeled and part of an IF block. 2) GOTO from either inside the selected IF block or >+ * outside the selected IF block must target the label of the END IF selected. 3) must be more >+ * GOTOs than just in local selected END IF scope. >+ * >+ */ >+ @Override >+ protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws PreconditionFailure >+ { >+ ensureProjectHasRefactoringEnabled(status); >+ >+ // Check if selected text is a portion within an END IF statement with label. >+ setSelectedNodeAndEndIfNode(); >+ if ((selectedEndIfNode == null) || (selectedEndIfNode.getLabel() == null)) >+ { >+ System.out >+ .println(Messages.RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor); >+ fail(Messages.RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor); >+ } >+ >+ // Check if selected END IF is within an IF block. >+ setSelectedIfConstructNode(); >+ if (selectedIfConstructNode == null) >+ { >+ System.out.println(Messages.RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct); >+ fail(Messages.RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct); >+ } >+ >+ // Check if selected scope contains a branch. >+ setGotoStatements(); >+ if (gotoStatements.isEmpty()) >+ { >+ System.out.println(Messages.RemoveBranchToEndIfRefactoring_MissingGoToStatement); >+ fail(Messages.RemoveBranchToEndIfRefactoring_MissingGoToStatement); >+ } >+ >+ // Check if contains a GOTO statement with selected END IF label. >+ setGotoStatementsWithEndIfLabel(); >+ if (gotoStatementWithEndIfLabel.size() == 0) >+ { >+ System.out >+ .println(Messages.RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel); >+ fail(Messages.RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel); >+ } >+ >+ // Check to see if there are branches outside of selected if block to selected END IF label. >+ setSelectedGotoStatementsWithEndIfLabel(); >+ if (selectedGotoStatementWithEndIfLabel.size() == gotoStatementWithEndIfLabel.size()) >+ { >+ System.out.println(Messages.RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf); >+ fail(Messages.RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf); >+ } >+ >+ setContinueAfterIfStmtNode(); >+ } >+ >+ /** >+ * There are no final conditions. >+ */ >+ @Override >+ protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws PreconditionFailure >+ { >+ // No final conditions >+ } >+ >+ /** >+ * Separate refactroing methods based on if there is a CONTINUE statement after the selected END >+ * IF (if so target it) or if no CONTINUE statement exists after the END IF block (insert one >+ * with unique label and have GOTO statements outside the IF block target it.). >+ */ >+ @Override >+ protected void doCreateChange(IProgressMonitor pm) throws CoreException, >+ OperationCanceledException >+ { >+ setAstAndNodes(); >+ >+ if (continueAfterIfStmtNode == null) >+ { >+ changeNoContinueAfterEndIf(); // User Story #2 >+ >+ } >+ else >+ { >+ changeGotoLabelToContinueLabel(); // User Story #1 >+ } >+ >+ // User Story 3 checked in doCheckInitialConditions >+ >+ this.addChangeFromModifiedAST(this.fileInEditor, pm); >+ vpg.releaseAST(this.fileInEditor); >+ } >+ >+ /** >+ * Sets AST of selected file and nodes used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setAstAndNodes() >+ { >+ this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor); >+ >+ // Setup nodes used for refactoring >+ setSelectedNodeAndEndIfNode(); >+ setSelectedIfConstructNode(); >+ setGotoStatements(); >+ setGotoStatementsWithEndIfLabel(); >+ setSelectedGotoStatementsWithEndIfLabel(); >+ setContinueAfterIfStmtNode(); >+ } >+ >+ /** >+ * Set selected node and selected end if node used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setSelectedNodeAndEndIfNode() >+ { >+ selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor); >+ selectedEndIfNode = (ASTEndIfStmtNode)findEnclosingNodeOfType(selectedNode, >+ ASTEndIfStmtNode.class); >+ } >+ >+ /** >+ * Set selected if construct node used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setSelectedIfConstructNode() >+ { >+ selectedIfConstructNode = (ASTIfConstructNode)findEnclosingNodeOfType(selectedEndIfNode, >+ ASTIfConstructNode.class); >+ } >+ >+ /** >+ * Set goto statements used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setGotoStatements() >+ { >+ gotoStatements = getGotoNodes(ScopingNode.getLocalScope(selectedEndIfNode)); >+ } >+ >+ /** >+ * Set go to statements with end if label used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setGotoStatementsWithEndIfLabel() >+ { >+ gotoStatementWithEndIfLabel = findGotoForLabel(gotoStatements, selectedEndIfNode.getLabel() >+ .getText()); >+ } >+ >+ /** >+ * Set selected go to statements with end if label used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setSelectedGotoStatementsWithEndIfLabel() >+ { >+ selectedGotoStatements = getGotoNodes(selectedIfConstructNode); >+ selectedGotoStatementWithEndIfLabel = findGotoForLabel(selectedGotoStatements, >+ selectedEndIfNode.getLabel().getText()); >+ } >+ >+ /** >+ * Set continue after if statement used for refactoring. >+ * >+ * @param None. >+ * >+ * @return None. >+ */ >+ private void setContinueAfterIfStmtNode() >+ { >+ continueAfterIfStmtNode = continueAfterIfStmt(selectedIfConstructNode); >+ } >+ >+ /** >+ * Main refactoring code for condition when CONTINUE statement follows the END..IF that was >+ * selected for refactoring. The logic will renumber/retarget any GOTO statements in the GOTO to >+ * that of the CONINUE label. (Per FORTRAN language standard the CONTINUE statement must have a >+ * label). If any GOTO statement inside the selected END..IF targets the END..IF selected for >+ * the Refactoring then the label of the END..IF will not be removed and that inner GOTO will >+ * still target it. If there are no inner GOTOs targeting the END..IF label then the END..IF >+ * label will be removed as part of the refactoring. >+ * >+ */ >+ private void changeGotoLabelToContinueLabel() >+ { >+ // Check all GOTO statements in the entire PROGRAM to see if they target the END..IF label >+ // number selected during the Refactoring. If so then retarget/renumber them to the >+ // CONTINUE block that follows. (Note: Inner GOTO statements that that target the END..IF >+ // statement are not retargeted/renumbered.) >+ for (ASTGotoStmtNode gotoNode : gotoStatementWithEndIfLabel) >+ { >+ // Do not re-target GOTO statements from within the selected END..IF for refactoring. >+ if (!selectedGotoStatementWithEndIfLabel.contains(gotoNode)) >+ { // Goto targeted to our selected IF..ENDIF block >+ gotoNode.getGotoLblRef().getLabel() >+ .setText(continueAfterIfStmtNode.getLabel().getText()); // Use existing >+ } >+ } >+ >+ // Label of selected END..IF for Refactoring is only removed after all other GOTOs have been >+ // retargeted and if no inner GOTO statements target its label. >+ if (selectedGotoStatementWithEndIfLabel.isEmpty()) >+ { >+ selectedEndIfNode.setLabel(null); >+ selectedEndIfNode.findFirstToken().setWhiteBefore( >+ selectedIfConstructNode.findFirstToken().getWhiteBefore()); // reindenter alt. >+ } >+ >+ } >+ >+ /** >+ * Modify Fortran code to add a CONTINUE statement after labeled END IF then remove END IF label >+ * only if there are no GOTO statements within the selected IF statement that target that END IF >+ * statement. >+ * >+ */ >+ private void changeNoContinueAfterEndIf() >+ { >+ >+ // build the CONTINUE node >+ if (continueAfterIfStmtNode != null) { return; } >+ >+ @SuppressWarnings("unchecked") >+ ASTListNode<ASTNode> listNode = (ASTListNode<ASTNode>)selectedIfConstructNode.getParent(); >+ >+ // build the CONTINUE statement program source code >+ String programString = "program p\n" + selectedEndIfNode.getLabel().getText() + " CONTINUE" //$NON-NLS-1$ //$NON-NLS-2$ >+ + EOL + "end program"; //$NON-NLS-1$ >+ ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); >+ ASTContinueStmtNode continueStmt = (ASTContinueStmtNode)programNode.getBody().get(0); >+ >+ // insert into AST >+ continueStmt.setParent(selectedIfConstructNode.getParent()); >+ listNode.insertAfter(selectedIfConstructNode, continueStmt); >+ >+ // clear label on END IF statement >+ if (selectedGotoStatementWithEndIfLabel.size() == 0) >+ { >+ selectedEndIfNode.setLabel(null); >+ // correct indentation >+ selectedEndIfNode.findFirstToken().setWhiteBefore( >+ selectedIfConstructNode.findFirstToken().getWhiteBefore()); >+ } >+ else >+ { >+ // Grab all labels >+ LinkedList<IActionStmt> actionStmts = getActionStmts(ScopingNode >+ .getLocalScope(selectedEndIfNode)); >+ >+ // Calculate unique label >+ String label = getUniqueLabel(actionStmts); >+ >+ // Set continue label to new label >+ continueStmt.getLabel().setText(label); >+ >+ // Set all goto statements to new label >+ for (ASTGotoStmtNode node : gotoStatementWithEndIfLabel) >+ { >+ if (!selectedGotoStatementWithEndIfLabel.contains(node)) >+ { >+ node.getGotoLblRef().getLabel().setText(label); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Build a list of all GOTO node types from the starting node. >+ * >+ * @param startNode Node to start the search. >+ * >+ * @return LinkedList of GOTO nodes. >+ */ >+ private LinkedList<ASTGotoStmtNode> getGotoNodes(IASTNode startNode) >+ { >+ if (startNode == null) { return null; } >+ >+ /* >+ * Unable to find all goto statements when there are do loops in startNode, so need to >+ * search in the do loops separately. >+ */ >+ final LinkedList<ASTGotoStmtNode> gotoNodes = getGotoStmtsInAllProperLoopConstructs(startNode); >+ >+ startNode.accept(new ASTVisitor() >+ { >+ @Override >+ public void visitASTGotoStmtNode(ASTGotoStmtNode node) >+ { >+ gotoNodes.add(node); >+ } >+ }); >+ >+ return gotoNodes; >+ } >+ >+ /** >+ * Build a list of all proper-loop-construct node types from the starting node. >+ * >+ * @param startNode Node to start the search. >+ * @return LinkedList of proper-loop-construct nodes. >+ */ >+ private LinkedList<ASTGotoStmtNode> getGotoStmtsInAllProperLoopConstructs(IASTNode startNode) >+ { >+ final LinkedList<ASTGotoStmtNode> gotoNodes = new LinkedList<ASTGotoStmtNode>(); >+ final LinkedList<ASTProperLoopConstructNode> loopNodes = getProperLoopConstructs(startNode); >+ >+ for (ASTProperLoopConstructNode loop : loopNodes) >+ { >+ for (IASTNode node : loop.getBody()) >+ { >+ node.accept(new ASTVisitor() >+ { >+ @Override >+ public void visitASTGotoStmtNode(ASTGotoStmtNode node) >+ { >+ gotoNodes.add(node); >+ } >+ }); >+ } >+ } >+ >+ return gotoNodes; >+ } >+ >+ /** >+ * Find GOTO node(s) based on matching label. >+ * >+ * @param gotos List of GOTO statements to check for matching label. >+ * @param label Label to match against. >+ * @return List of GOTO nodes that target the specified label. >+ */ >+ private LinkedList<ASTGotoStmtNode> findGotoForLabel(LinkedList<ASTGotoStmtNode> gotos, >+ String label) >+ { >+ if (gotos == null) { return new LinkedList<ASTGotoStmtNode>(); } >+ >+ LinkedList<ASTGotoStmtNode> gotoWithLabel = new LinkedList<ASTGotoStmtNode>(); >+ for (ASTGotoStmtNode gotoNode : gotos) >+ { >+ if (gotoNode.getGotoLblRef().getLabel().getText().contentEquals(label)) >+ { >+ gotoWithLabel.add(gotoNode); >+ } >+ } >+ >+ return gotoWithLabel; >+ } >+ >+ /** >+ * Check for CONTINUE statement after a if construct node >+ * >+ * @param ifStmt If construct node. >+ * @return continue statement node or null. >+ */ >+ private static ASTContinueStmtNode continueAfterIfStmt(ASTIfConstructNode ifStmt) >+ { >+ if (ifStmt == null) { return null; } >+ >+ @SuppressWarnings("unchecked") >+ ASTListNode<ASTNode> list = (ASTListNode<ASTNode>)ifStmt.getParent(); >+ >+ for (int i = 0; i < list.size() - 1; i++) >+ { >+ if (list.get(i) != null) >+ { >+ if (list.get(i).equals(ifStmt)) >+ { >+ if (list.get(i + 1) instanceof ASTContinueStmtNode) { return (ASTContinueStmtNode)list >+ .get(i + 1); } >+ } >+ } >+ } >+ >+ return null; >+ } >+ >+ /** >+ * Generate a unique label based on the labels passed in (unique in that find the largest and >+ * add 10) >+ * >+ * @param actionStmts List of statements that may be labeled to consider for a unique label. >+ * @return Unique label value. >+ */ >+ private String getUniqueLabel(LinkedList<IActionStmt> actionStmts) >+ { >+ int label = Integer.parseInt(selectedEndIfNode.getLabel().getText()); >+ for (IActionStmt stmt : actionStmts) >+ { >+ if (stmt.getLabel() != null) >+ { >+ int currentLabel = Integer.parseInt(stmt.getLabel().getText()); >+ if (currentLabel > label) >+ { >+ label = currentLabel; >+ } >+ } >+ } >+ label += 10; >+ >+ return String.valueOf(label); >+ } >+ >+ /** >+ * Find Action statement nodes in the tree from the starting search node. >+ * >+ * @param startNode Starting node from which to perform the search. >+ * @return LinkedList of action statement nodes that are found. >+ */ >+ private LinkedList<IActionStmt> getActionStmts(IASTNode startNode) >+ { >+ final LinkedList<IActionStmt> actionStmts = getActionStmtsInAllProperLoopConstructs(); >+ startNode.accept(new ASTVisitor() >+ { >+ @Override >+ public void visitIActionStmt(IActionStmt node) >+ { >+ actionStmts.add(node); >+ } >+ }); >+ >+ return actionStmts; >+ } >+ >+ /** >+ * Find Action statement nodes in entire file in editor. >+ * >+ * @return LinkedList of action statement nodes found. >+ */ >+ private LinkedList<IActionStmt> getActionStmtsInAllProperLoopConstructs() >+ { >+ final LinkedList<IActionStmt> actionStmts = new LinkedList<IActionStmt>(); >+ final LinkedList<ASTProperLoopConstructNode> loopNodes = getProperLoopConstructs(ScopingNode >+ .getLocalScope(selectedEndIfNode)); >+ >+ for (ASTProperLoopConstructNode loop : loopNodes) >+ { >+ for (IASTNode node : loop.getBody()) >+ { >+ node.accept(new ASTVisitor() >+ { >+ @Override >+ public void visitIActionStmt(IActionStmt node) >+ { >+ actionStmts.add(node); >+ } >+ }); >+ } >+ } >+ >+ return actionStmts; >+ } >+ >+ /** >+ * Find all proper loop constructs in the tree from the starting search node. >+ * >+ * @param startNode Starting node from which to perform the search. >+ * @return LinkedList of proper loop construct nodes found. >+ */ >+ private LinkedList<ASTProperLoopConstructNode> getProperLoopConstructs(IASTNode startNode) >+ { >+ final LinkedList<ASTProperLoopConstructNode> loopNodes = new LinkedList<ASTProperLoopConstructNode>(); >+ >+ // Change AST to represent DO-loops as ASTProperLoopConstructNodes >+ LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot()); >+ >+ startNode.accept(new ASTVisitorWithLoops() >+ { >+ @Override >+ public void visitASTProperLoopConstructNode(ASTProperLoopConstructNode node) >+ { >+ loopNodes.add(node); >+ } >+ }); >+ >+ return loopNodes; >+ } >+} >Index: src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java >diff -N src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,145 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.core.refactoring; >+ >+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.refactoring.infrastructure.FortranEditorRefactoring; >+import org.eclipse.photran.internal.core.parser.*; >+ >+/** >+ * This feature address the replacement of the PAUSE statement with a PRINT and READ statement. >+ * Execution of a PAUSE statement may be different on different platforms. The refactoring assumes >+ * the most basic functionality: it replaces the PAUSE statement with a PRINT statement that >+ * displays the message of the PAUSE statement, immediately followed by a READ statement that waits >+ * for any input from the user. >+ * >+ * User Selection Requirements: The PAUSE statement to be replaced. >+ * >+ * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka >+ * (wijenay2), Nicola Hall (nfhall2) >+ */ >+public class RemovePauseStmtRefactoring extends FortranEditorRefactoring >+{ >+ private IASTNode selectedNode = null; >+ >+ private ASTPauseStmtNode selectedPauseStmt = null; >+ >+ /** >+ * Preconditions checks: Check if project has refactoring is enabled. >+ * Checks that the user selects a PAUSE statement for refactoring. Failure >+ * to meet these conditions will result in a fail-initial condition. >+ */ >+ @Override >+ protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure >+ { >+ ensureProjectHasRefactoringEnabled(status); >+ >+ // Check if selected is a PAUSE statement >+ setSelectedPauseStmt(); >+ >+ if (selectedPauseStmt == null) >+ { >+ System.out.println(Messages.RemovePauseStmtRefactoring_SelectPauseStmt); >+ fail(Messages.RemovePauseStmtRefactoring_SelectPauseStmt); >+ } >+ } >+ >+ /** >+ * FinalConditions no final checks required. >+ */ >+ @Override >+ protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure >+ { >+ } >+ >+ /** >+ * Performs main refactoring (delegated to other methods). >+ */ >+ @Override >+ protected void doCreateChange(IProgressMonitor pm) throws CoreException, >+ OperationCanceledException >+ { >+ changePauseStmt(); >+ >+ // Finalize. >+ this.addChangeFromModifiedAST(this.fileInEditor, pm); >+ vpg.releaseAST(this.fileInEditor); >+ } >+ >+ /** >+ * Provide GUI refactoring label. >+ */ >+ @Override >+ public String getName() >+ { >+ return Messages.RemovePauseStmtRefactoring_Name; >+ } >+ >+ /** >+ * Obtains the selected pause statement else sets the member field to null. >+ */ >+ private void setSelectedPauseStmt() >+ { >+ selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor); >+ >+ selectedPauseStmt = (ASTPauseStmtNode)findEnclosingNodeOfType(selectedNode, >+ ASTPauseStmtNode.class); >+ } >+ >+ /** >+ * Insert modified PRINT statement and build READ() AST node to insert in to the program after >+ * the PRINT statement. >+ */ >+ private void changePauseStmt() >+ { >+ // change to modify the transient AST. >+ this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor); >+ >+ // check on pause statement performed in initial, should not have changed in final. >+ setSelectedPauseStmt(); >+ >+ String pauseMessage = "\'\'"; //$NON-NLS-1$; >+ >+ // Contents of the PRINT statement to maintain. >+ if (null != selectedPauseStmt.getStringConst()) >+ { >+ pauseMessage = selectedPauseStmt.getStringConst().getText(); >+ } >+ >+ // Build new AST node for modified PRINT statement and new READ statement. >+ String indent = selectedPauseStmt.findFirstToken().getWhiteBefore(); >+ String programString = "program p" + EOL + //$NON-NLS-1$ >+ indent >+ + "PRINT *, " + pauseMessage + selectedPauseStmt.findLastToken().getWhiteBefore() + EOL + //$NON-NLS-1$ >+ indent + "READ (*, *)" + EOL + //$NON-NLS-1$ >+ "end program"; //$NON-NLS-1$ >+ >+ // Insert new AST node in place of selected PRINT statement. >+ ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); >+ ASTPrintStmtNode printStmt = (ASTPrintStmtNode)programNode.getBody().get(0); >+ ASTReadStmtNode readStmt = (ASTReadStmtNode)programNode.getBody().get(1); >+ >+ @SuppressWarnings("unchecked") >+ ASTListNode<ASTNode> listNode = (ASTListNode<ASTNode>)selectedPauseStmt.getParent(); >+ >+ selectedPauseStmt.replaceWith(printStmt); >+ listNode.insertAfter(printStmt, readStmt); >+ } >+} >Index: src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java >diff -N src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,392 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.core.refactoring; >+ >+import java.util.LinkedList; >+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.ScopingNode; >+import org.eclipse.photran.internal.core.analysis.loops.LoopReplacer; >+import org.eclipse.photran.internal.core.parser.*; >+import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring; >+import org.eclipse.photran.internal.core.analysis.loops.ASTProperLoopConstructNode; >+ >+/** >+ * Remove Real and Double Precision Loop Counter Refactoring: >+ * >+ * This refactoring will take a controlled DO loop, i.e. on that specifies the starting and ending >+ * values for the control loop index and transform it to an uncontrolled do loop where the same loop >+ * index and values are manually inserted into to the loop. If a explicit step size is specified is >+ * used, otherwise an implicit one is inserted. The refactoring checks the start/end values of the >+ * loop control variable to determine if the loop control variable should increment or decrement. >+ * >+ * User Selection Requirements: A controlled DO loop statement to be considered for refactoring. >+ * >+ * @author Rita Chow (chow15), Nicola Hall (nfhall2), Jerry Hsiao (jhsiao2), Mark Mozolewski >+ * (mozolews), Chamil Wijenayaka (wijenay2) >+ */ >+public class RemoveRealAndDoublePrecisionLoopCountersRefactoring extends FortranEditorRefactoring >+{ >+ >+ private IASTNode selectedNode = null; >+ >+ private ASTProperLoopConstructNode selectedDoLoopNode = null; >+ >+ private LinkedList<ASTTypeDeclarationStmtNode> typeDeclarationsInFile; >+ >+ private String doVarName; >+ >+ private boolean shouldReplaceWithDoWhileLoop = false; >+ >+ /** >+ * Provide GUI refactoring label. >+ */ >+ @Override >+ public String getName() >+ { >+ return Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_Name; >+ } >+ >+ /** >+ * Set method for DO or DO WHILE refactoring selection variable. >+ * >+ * @param value Set tracking variable for DO or DO WHILE refactoring selection. >+ */ >+ public void setShouldReplaceWithDoWhileLoop(boolean value) >+ { >+ this.shouldReplaceWithDoWhileLoop = value; >+ } >+ >+ /** >+ * Precondition checks: Check if project has refactoring enabled. >+ */ >+ @Override >+ protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws PreconditionFailure >+ { >+ ensureProjectHasRefactoringEnabled(status); >+ } >+ >+ /** >+ * The following initial conditions are checked (a failure of any will result in a >+ * fail-initial): - A controlled DO loop must be selected by the user. - Loop control variables >+ * of a controlled DO loop must be declared as type REAL or DOUBLE PRECISION only. >+ */ >+ @Override >+ protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws PreconditionFailure >+ { >+ Boolean doVarNameIsRealOrDouble = false; >+ >+ this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor); >+ >+ // Change AST to represent DO-loops as ASTProperLoopConstructNodes >+ LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot()); >+ >+ // Identify selected DO loop. >+ selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor); >+ selectedDoLoopNode = (ASTProperLoopConstructNode)findEnclosingNodeOfType(selectedNode, >+ ASTProperLoopConstructNode.class); >+ >+ // Check for invalid selection (DO statement not selected) >+ if (selectedDoLoopNode == null) >+ { >+ fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectADoLoop); >+ } >+ >+ // Check uncontrolled DO loop selected. >+ if (selectedDoLoopNode.getLoopHeader().getLoopControl() == null) >+ { >+ fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectAControlledDoLoop); >+ } >+ >+ // Find all REAL and DOUBLE declared variables. >+ doVarName = selectedDoLoopNode.getLoopHeader().getLoopControl().getVariableName().getText() >+ .toString(); >+ typeDeclarationsInFile = getTypeDeclarations(this.astOfFileInEditor.getRoot()); >+ >+ if (typeDeclarationsInFile == null) >+ { >+ fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableMissingDeclaration); >+ } >+ >+ // Search all type declarations of the PROGRAM to find DO loop control variable name and >+ // REAL or DOUBLE variable type. >+ for (ASTTypeDeclarationStmtNode typeDeclaration : typeDeclarationsInFile) >+ { >+ >+ if (typeDeclaration.getTypeSpec().isReal() || typeDeclaration.getTypeSpec().isDouble()) >+ { >+ >+ // Search all variable names for this REAL/DOUBLE variable declaration. >+ for (ASTEntityDeclNode entityDeclaration : typeDeclaration.getEntityDeclList()) >+ { >+ >+ if (entityDeclaration.getObjectName().getObjectName().getText() >+ .equals(doVarName)) >+ { >+ doVarNameIsRealOrDouble = true; >+ break; >+ } >+ } >+ >+ } >+ } >+ >+ if (!doVarNameIsRealOrDouble) >+ { >+ fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableNotRealOrDouble); >+ } >+ } >+ >+ /** >+ * After initial conditions checks pass there is a proper controlled DO loop variable to >+ * refactor. The refactoring consists of building a number of AST node elements and inserting >+ * them in to the program to do the work that the controlled DO loop would have done. This >+ * includes: 1) Initial loop control variable assignment (starting value). 2) >+ * Increment/Decrement control variable by specified amount (implicit or explicit step size) 3) >+ * Check inside DO loop to see if loop variable limit specified is exceeded. >+ */ >+ @Override >+ protected void doCreateChange(IProgressMonitor pm) throws CoreException, >+ OperationCanceledException >+ { >+ String ifCheckLb = selectedDoLoopNode.getLoopHeader().getLoopControl().getLb().toString(); >+ String ifCheckUb = selectedDoLoopNode.getLoopHeader().getLoopControl().getUb().toString(); >+ String ifCheckVar = selectedDoLoopNode.getLoopHeader().getLoopControl().getVariableName() >+ .getText().toString(); >+ >+ // Implicit step size check. >+ String ifCheckStep = null; >+ if (selectedDoLoopNode.getLoopHeader().getLoopControl().getStep() != null) >+ { >+ ifCheckStep = selectedDoLoopNode.getLoopHeader().getLoopControl().getStep().toString(); >+ } >+ else >+ { >+ ifCheckStep = " 1"; //$NON-NLS-1$ >+ } >+ >+ String ifCheckIncrDecr = ""; //$NON-NLS-1$ >+ String ifCheckStr = ""; //$NON-NLS-1$ >+ >+ // Work with both as double type. >+ double dLb = Double.valueOf(ifCheckLb.trim()).doubleValue(); >+ double dUb = Double.valueOf(ifCheckUb.trim()).doubleValue(); >+ >+ // Check for > or < IF check. >+ if (dLb < dUb) >+ { >+ if (shouldReplaceWithDoWhileLoop) >+ ifCheckStr = ifCheckVar + " <=" + ifCheckUb; //$NON-NLS-1$ >+ else >+ ifCheckStr = ifCheckVar + " >" + ifCheckUb; //$NON-NLS-1$ >+ ifCheckIncrDecr = " +"; //$NON-NLS-1$ >+ } >+ else >+ { >+ if (shouldReplaceWithDoWhileLoop) >+ ifCheckStr = ifCheckVar + " >=" + ifCheckUb; //$NON-NLS-1$ >+ else >+ ifCheckStr = ifCheckVar + " <" + ifCheckUb; //$NON-NLS-1$ >+ ifCheckIncrDecr = " -"; //$NON-NLS-1$ >+ } >+ >+ // AST modification for refactoring. >+ if (shouldReplaceWithDoWhileLoop) >+ { >+ insertNewDoWhileLoop(ifCheckLb, ifCheckVar, ifCheckStep, ifCheckIncrDecr, ifCheckStr); >+ } >+ else >+ { >+ insertNewDoLoop(ifCheckLb, ifCheckVar, ifCheckStep, ifCheckIncrDecr, ifCheckStr); >+ } >+ >+ // Finalize >+ this.addChangeFromModifiedAST(this.fileInEditor, pm); >+ vpg.releaseAST(this.fileInEditor); >+ } >+ >+ /** >+ * With provided strings this method builds the new AST nodes for the initial variable >+ * assignment, increment/decrement statement, and IF DO loop break statement. They are then >+ * inserted in to the proper hierarchy of the program AST structure. (See main refactoring >+ * comments at the top of the file for a list of steps performed.) >+ * >+ * @param ifCheckLb Lower bound (starting value) of loop variable. >+ * @param ifCheckVar Loop control variable name. >+ * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared) >+ * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction. >+ * @param ifCheckStr The IF check condition to break the DO loop. >+ */ >+ private void insertNewDoLoop(String ifCheckLb, String ifCheckVar, String ifCheckStep, >+ String ifCheckIncrDecr, String ifCheckStr) >+ { >+ // Build initial value assignment node. >+ insertInitialCounterAssignment(ifCheckVar, ifCheckLb); >+ >+ // Remove DO control >+ int sizeOfLoopControlString = selectedDoLoopNode.getLoopHeader().getLoopControl() >+ .toString().length(); >+ String replaceLoopControlStringWith = ""; //$NON-NLS-1$ >+ for (int i = 0; i < sizeOfLoopControlString; i++) >+ { >+ replaceLoopControlStringWith += " "; //$NON-NLS-1$ >+ } >+ selectedDoLoopNode.getLoopHeader().setLoopControl(null); >+ selectedDoLoopNode >+ .getLoopHeader() >+ .findLastToken() >+ .setWhiteBefore( >+ replaceLoopControlStringWith >+ + selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore()); >+ >+ // Build increment assignment node. >+ ASTAssignmentStmtNode incrDecrNode = insertCounterAssignment(ifCheckVar, ifCheckIncrDecr, >+ ifCheckStep); >+ >+ // Build IF node for checking DO limits. >+ IExecutionPartConstruct lastNodeInDoLoopBody = selectedDoLoopNode.getBody().get( >+ selectedDoLoopNode.getBody().size() - 1); >+ String initialIndent = ScopingNode.getLocalScope(selectedDoLoopNode).getBody() >+ .findFirstToken().getWhiteBefore(); >+ String programString = ""; //$NON-NLS-1$ >+ programString = "program p\n" + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() //$NON-NLS-1$ >+ + "IF(" + ifCheckStr + ") THEN\n" //$NON-NLS-1$ //$NON-NLS-2$ >+ + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() >+ + initialIndent >+ + "EXIT\n" //$NON-NLS-1$ >+ + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() >+ + "END IF" + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$ >+ ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); >+ ASTIfConstructNode ifNode = (ASTIfConstructNode)programNode.getBody().get(0); >+ >+ // Insert IF node into AST >+ ifNode.setParent(selectedDoLoopNode.getParent()); >+ selectedDoLoopNode.getBody().insertAfter(incrDecrNode, ifNode); >+ } >+ >+ /** >+ * With provided strings this method builds the new AST nodes for the initial variable >+ * assignment, increment/decrement statement, and DO WHILE loop check statement. They are then >+ * inserted in to the proper hierarchy of the program AST structure. (See main refactoring >+ * comments at the top of the file for a list of steps performed.) >+ * >+ * @param ifCheckLb Lower bound (starting value) of loop variable. >+ * @param ifCheckVar Loop control variable name. >+ * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared) >+ * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction. >+ * @param ifCheckStr The IF check condition to break the DO loop. >+ */ >+ @SuppressWarnings("nls") >+ private void insertNewDoWhileLoop(String ifCheckLb, String ifCheckVar, String ifCheckStep, >+ String ifCheckIncrDecr, String ifCheckStr) >+ { >+ // Build initial value assignment node. >+ insertInitialCounterAssignment(ifCheckVar, ifCheckLb); >+ >+ // Build increment assignment node. >+ insertCounterAssignment(ifCheckVar, ifCheckIncrDecr, ifCheckStep); >+ >+ // Change do loop to while do loop >+ String programString = ""; >+ programString = "program p\n" >+ + selectedDoLoopNode.getLoopHeader().findFirstToken().getWhiteBefore() + "DO WHILE (" >+ + ifCheckStr + ")" >+ + selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore() + EOL >+ + "EXIT\nENDDO" + EOL + "end program"; >+ >+ ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); >+ ASTDoConstructNode doConstructNode = (ASTDoConstructNode)programNode.getBody().get(0); >+ selectedDoLoopNode.setLoopHeader(doConstructNode.getLabelDoStmt()); >+ selectedDoLoopNode.getLoopHeader().findLastToken() >+ .setWhiteBefore(selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore()); >+ } >+ >+ /** >+ * Creates an assignment statement node for the initial loop counter value assignment and >+ * inserts it before the selected DO loop of the refactoring. >+ * >+ * @param ifCheckVar Loop control variable name. >+ * @param ifCheckLb Lower bound (starting value) of loop variable. >+ */ >+ private void insertInitialCounterAssignment(String ifCheckVar, String ifCheckLb) >+ { >+ String programString = "program p\n" + selectedDoLoopNode.findFirstToken().getWhiteBefore() + ifCheckVar + //$NON-NLS-1$ >+ " =" + ifCheckLb + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$ >+ ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); >+ ASTAssignmentStmtNode initValNode = (ASTAssignmentStmtNode)programNode.getBody().get(0); >+ >+ // Insert initial value assignment node into AST >+ initValNode.setParent(selectedDoLoopNode.getParent()); >+ @SuppressWarnings("unchecked") >+ ASTListNode<ASTNode> doNode = (ASTListNode<ASTNode>)selectedDoLoopNode.getParent(); >+ doNode.insertBefore(selectedDoLoopNode, initValNode); >+ } >+ >+ /** >+ * Creates an assignment statement node for the loop counter variable assignment and inserts it >+ * after the selected DO loop of the refactoring. >+ * >+ * @param ifCheckVar Loop control variable name. >+ * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction. >+ * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared) >+ */ >+ private ASTAssignmentStmtNode insertCounterAssignment(String ifCheckVar, >+ String ifCheckIncrDecr, String ifCheckStep) >+ { >+ IExecutionPartConstruct lastNodeInDoLoopBody = selectedDoLoopNode.getBody().get( >+ selectedDoLoopNode.getBody().size() - 1); >+ String programString = ""; //$NON-NLS-1$ >+ programString = "program p\n" + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() + ifCheckVar + //$NON-NLS-1$ >+ " = " + ifCheckVar + ifCheckIncrDecr + ifCheckStep + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$ >+ ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); >+ ASTAssignmentStmtNode incrDecrNode = (ASTAssignmentStmtNode)programNode.getBody().get(0); >+ >+ // Insert increment/decrement assignment node into AST >+ incrDecrNode.setParent(selectedDoLoopNode.getParent()); >+ >+ selectedDoLoopNode.getBody().insertAfter(lastNodeInDoLoopBody, incrDecrNode); >+ >+ return incrDecrNode; >+ } >+ >+ /** >+ * Get all variable type declarations in the program. >+ * >+ * @param startNode node to start search. >+ * >+ * @return LinkedList of type declarations nodes. >+ */ >+ private LinkedList<ASTTypeDeclarationStmtNode> getTypeDeclarations(IASTNode startNode) >+ { >+ if (startNode == null) { return null; } >+ >+ final LinkedList<ASTTypeDeclarationStmtNode> typeDeclarations = new LinkedList<ASTTypeDeclarationStmtNode>(); >+ >+ startNode.accept(new ASTVisitor() >+ { >+ @Override >+ public void visitASTTypeDeclarationStmtNode(ASTTypeDeclarationStmtNode node) >+ { >+ typeDeclarations.add(node); >+ } >+ }); >+ >+ return typeDeclarations; >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java,v >retrieving revision 1.11 >diff -u -r1.11 FortranResourceRefactoring.java >--- src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java 21 Sep 2010 15:08:23 -0000 1.11 >+++ src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java 14 Dec 2010 04:49:34 -0000 >@@ -7,6 +7,11 @@ > * > * Contributors: > * UIUC - Initial API and implementation >+ * Rita Chow - Photran Modifications >+ * Nicola Hall - Photran Modifications >+ * Jerry Hsiao - Photran Modifications >+ * Mark Mozolewski - Photran Modifications >+ * Chamil Wijenayaka - Photran Modifications > *******************************************************************************/ > package org.eclipse.photran.internal.core.refactoring.infrastructure; > >@@ -373,6 +378,27 @@ > return null; > } > >+ /** >+ * Get node based on type. >+ * >+ * @param startNode node to start search. >+ * @param typeChecker instance type to search. >+ * >+ * @return node if found else null. >+ */ >+ protected IASTNode findEnclosingNodeOfType(IASTNode startNode, Class classType) >+ { >+ if(startNode == null) { return null; } >+ >+ IASTNode node = startNode; >+ while ((node != null) && (node.getClass() != classType)) >+ { >+ node = node.getParent(); >+ } >+ >+ return node; >+ } >+ > protected static boolean nodeExactlyEnclosesRegion(IASTNode parent, Token firstToken, Token lastToken) > { > return parent.findFirstToken() == firstToken && parent.findLastToken() == lastToken; >#P org.eclipse.photran.core.vpg.tests >Index: src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java >diff -N src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.tests.refactoring; >+ >+import junit.framework.Test; >+ >+import org.eclipse.photran.internal.core.refactoring.RemoveBranchToEndIfRefactoring; >+import org.eclipse.photran.internal.tests.Activator; >+import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; >+ >+/** >+ * Unit tests for the Remove Branch To End If Refactoring. >+ * >+ * @author >+ */ >+public class RemoveBranchToEndIfTestSuite extends PhotranRefactoringTestSuiteFromMarkers<RemoveBranchToEndIfRefactoring> >+{ >+ private static final String DIR = "refactoring-test-code/remove-branch-to-end-if"; >+ >+ public static Test suite() throws Exception >+ { >+ return new RemoveBranchToEndIfTestSuite(); >+ } >+ >+ public RemoveBranchToEndIfTestSuite() throws Exception >+ { >+ super(Activator.getDefault(), >+ "Running Remove Branch To End If Refactoring in", >+ DIR, >+ RemoveBranchToEndIfRefactoring.class); >+ } >+ >+} >Index: src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java >diff -N src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.tests.refactoring; >+ >+import junit.framework.Test; >+ >+import org.eclipse.photran.internal.core.refactoring.RemovePauseStmtRefactoring; >+import org.eclipse.photran.internal.tests.Activator; >+import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; >+ >+/** >+ * Unit tests for the Remove Pause Statement Refractoring. >+ * >+ * @author >+ */ >+public class RemovePauseStmtTestSuite extends PhotranRefactoringTestSuiteFromMarkers<RemovePauseStmtRefactoring> >+{ >+ private static final String DIR = "refactoring-test-code/remove-pause-stmt"; >+ >+ public static Test suite() throws Exception >+ { >+ return new RemovePauseStmtTestSuite(); >+ } >+ >+ public RemovePauseStmtTestSuite() throws Exception >+ { >+ super(Activator.getDefault(), >+ "Running Remove Pause Stmt Refactoring in", >+ DIR, >+ RemovePauseStmtRefactoring.class); >+ } >+ >+} >Index: src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java >diff -N src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.tests.refactoring; >+ >+import junit.framework.Test; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.jface.text.TextSelection; >+import org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring; >+import org.eclipse.photran.internal.tests.Activator; >+import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; >+ >+/** >+ * Unit tests for the Remove Branch To End If Refactoring. >+ * >+ * @author >+ */ >+public class RemoveRealAndDoublePrecisionLoopCountersTestSuite extends PhotranRefactoringTestSuiteFromMarkers<RemoveRealAndDoublePrecisionLoopCountersRefactoring> >+{ >+ private static final String DIR = "refactoring-test-code/remove-real-and-double-precision-loop-counters"; >+ >+ public static Test suite() throws Exception >+ { >+ return new RemoveRealAndDoublePrecisionLoopCountersTestSuite(); >+ } >+ >+ public RemoveRealAndDoublePrecisionLoopCountersTestSuite() throws Exception >+ { >+ super(Activator.getDefault(), >+ "Running Remove Real and Double Precision Loop Counters Refactoring in", >+ DIR, >+ RemoveRealAndDoublePrecisionLoopCountersRefactoring.class); >+ } >+ >+ @Override >+ protected boolean configureRefactoring(RemoveRealAndDoublePrecisionLoopCountersRefactoring refactoring, >+ IFile file, >+ TextSelection selection, >+ String[] markerText) >+ { >+ boolean shouldSucceed = super.configureRefactoring(refactoring, file, selection, markerText); >+ >+ boolean shouldReplaceWithDoWhileLoop; >+ if(markerText[4].equals("1")) >+ shouldReplaceWithDoWhileLoop = true; >+ else >+ shouldReplaceWithDoWhileLoop = false; >+ refactoring.setShouldReplaceWithDoWhileLoop(shouldReplaceWithDoWhileLoop); >+ >+ return shouldSucceed; >+ } >+} >#P org.eclipse.photran.ui.vpg >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.ui.vpg/plugin.xml,v >retrieving revision 1.78 >diff -u -r1.78 plugin.xml >--- plugin.xml 16 Nov 2010 18:07:25 -0000 1.78 >+++ plugin.xml 14 Dec 2010 04:49:35 -0000 >@@ -83,6 +83,16 @@ > <editorRefactoring > class="org.eclipse.photran.internal.core.refactoring.RemoveComputedGoToRefactoring" > /> >+ <editorRefactoring >+ class="org.eclipse.photran.internal.core.refactoring.RemoveBranchToEndIfRefactoring" >+ /> >+ <editorRefactoring >+ class="org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring" >+ inputPage="org.eclipse.photran.internal.ui.refactoring.RemoveRealAndDoublePrecisionLoopCountersInputPage" >+ /> >+ <editorRefactoring >+ class="org.eclipse.photran.internal.core.refactoring.RemovePauseStmtRefactoring" >+ /> > </group> > <group><!-- Refactorings for performance/loop transformations --> > <editorRefactoring >Index: src/org/eclipse/photran/internal/ui/refactoring/Messages.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java,v >retrieving revision 1.3 >diff -u -r1.3 Messages.java >--- src/org/eclipse/photran/internal/ui/refactoring/Messages.java 21 Sep 2010 13:26:16 -0000 1.3 >+++ src/org/eclipse/photran/internal/ui/refactoring/Messages.java 14 Dec 2010 04:49:35 -0000 >@@ -7,6 +7,11 @@ > * > * Contributors: > * UIUC - Initial API and implementation >+ * Rita Chow - Photran Modifications >+ * Nicola Hall - Photran Modifications >+ * Jerry Hsiao - Photran Modifications >+ * Mark Mozolewski - Photran Modifications >+ * Chamil Wijenayaka - Photran Modifications > *******************************************************************************/ > package org.eclipse.photran.internal.ui.refactoring; > >@@ -84,6 +89,17 @@ > public static String RenameAction_MatchExternalSubprograms; > > public static String RenameAction_RenameAtoB; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage; >+ >+ public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage; >+ > static > { > // initialize resource bundle >Index: src/org/eclipse/photran/internal/ui/refactoring/RemoveRealAndDoublePrecisionLoopCountersInputPage.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/ui/refactoring/RemoveRealAndDoublePrecisionLoopCountersInputPage.java >diff -N src/org/eclipse/photran/internal/ui/refactoring/RemoveRealAndDoublePrecisionLoopCountersInputPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/ui/refactoring/RemoveRealAndDoublePrecisionLoopCountersInputPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,75 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka >+ * 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: >+ * Rita Chow - Initial Implementation >+ * Nicola Hall - Initial Implementation >+ * Jerry Hsiao - Initial Implementation >+ * Mark Mozolewski - Initial Implementation >+ * Chamil Wijenayaka - Initial Implementation >+ *******************************************************************************/ >+package org.eclipse.photran.internal.ui.refactoring; >+ >+import org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring; >+import org.eclipse.rephraserengine.ui.refactoring.CustomUserInputPage; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Label; >+ >+/** >+ * User input wizard page for the Change Keyword Case refactoring >+ * >+ * @author Kurt Hendle, Jeff Overbey >+ */ >+public class RemoveRealAndDoublePrecisionLoopCountersInputPage extends CustomUserInputPage<RemoveRealAndDoublePrecisionLoopCountersRefactoring> >+{ >+ protected Button doWhileLoop; >+ protected Button doLoop; >+ >+ @Override >+ public void createControl(Composite parent) >+ { >+ Composite top = new Composite(parent, SWT.NONE); >+ initializeDialogUnits(top); >+ setControl(top); >+ >+ top.setLayout(new GridLayout(1, false)); >+ >+ Composite group = top; >+ Label instr = new Label(group, SWT.NONE); >+ instr.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter); >+ >+ doWhileLoop = new Button(group, SWT.RADIO); >+ doWhileLoop.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop); >+ doWhileLoop.setSelection(true); >+ doWhileLoop.addSelectionListener(new SelectionListener() >+ { >+ public void widgetDefaultSelected(SelectionEvent e) >+ { >+ widgetSelected(e); >+ } >+ >+ public void widgetSelected(SelectionEvent e) >+ { >+ boolean isChecked = doLoop.getSelection(); >+ getRefactoring().setShouldReplaceWithDoWhileLoop(isChecked); >+ } >+ }); >+ >+ doLoop = new Button(group, SWT.RADIO); >+ doLoop.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop); >+ >+ Label ok = new Label(group, SWT.NONE); >+ ok.setText("\n" + Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage); //$NON-NLS-1$ >+ Label preview = new Label(group, SWT.NONE); >+ preview.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage); >+ } >+} >Index: src/org/eclipse/photran/internal/ui/refactoring/messages.properties >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties,v >retrieving revision 1.2 >diff -u -r1.2 messages.properties >--- src/org/eclipse/photran/internal/ui/refactoring/messages.properties 21 Sep 2010 13:26:16 -0000 1.2 >+++ src/org/eclipse/photran/internal/ui/refactoring/messages.properties 14 Dec 2010 04:49:36 -0000 >@@ -31,3 +31,8 @@ > MoveFromModuleInputPage_selectDataMessage=Please select member data to move from module > RenameAction_MatchExternalSubprograms=Match external subprograms with interfaces and external declarations > RenameAction_RenameAtoB=Rename {0} to >+RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter=Replace real/double precision loop counter with: >+RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop=DO Loop >+RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop=DO WHILE Loop >+RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage=Click OK to replace the real/double precision loop counter. >+RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage=To see what the changes will be made, click Preview.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 332492
:
185105
|
185107
|
185108