View | Details | Raw Unified | Return to bug 332492 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/photran/internal/core/refactoring/Messages.java (+33 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    UIUC - Initial API and implementation
9
 *    UIUC - Initial API and implementation
10
 *    Rita Chow - Photran Modifications
11
 *    Nicola Hall - Photran Modifications
12
 *    Jerry Hsiao - Photran Modifications
13
 *    Mark Mozolewski - Photran Modifications
14
 *    Chamil Wijenayaka - Photran Modifications
10
 *******************************************************************************/
15
 *******************************************************************************/
11
package org.eclipse.photran.internal.core.refactoring;
16
package org.eclipse.photran.internal.core.refactoring;
12
17
Lines 356-364 Link Here
356
361
357
    public static String RemoveArithmeticIfRefactoring_Name;
362
    public static String RemoveArithmeticIfRefactoring_Name;
358
363
364
    public static String RemoveBranchToEndIfRefactoring_Name;
365
    
366
    public static String RemoveBranchToEndIfRefactoring_MissingGoToStatement;
367
    
368
    public static String RemoveBranchToEndIfRefactoring_GoToLabelDoesNotMatchAnyEndIfLabel;
369
    
370
    public static String RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf;
371
    
372
    public static String RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor;
373
    
374
    public static String RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct;
375
    
376
    public static String RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel;
377
    
359
    public static String RemoveComputedGoToRefactoring_Name;
378
    public static String RemoveComputedGoToRefactoring_Name;
360
379
361
    public static String RemoveComputedGoToRefactoring_PleaseSelectComputedGotoStmt;
380
    public static String RemoveComputedGoToRefactoring_PleaseSelectComputedGotoStmt;
381
    
382
    public static String RemovePauseStmtRefactoring_Name;
383
    
384
    public static String RemovePauseStmtRefactoring_SelectPauseStmt;
385
    
386
    public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_Name;
387
    
388
    public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectADoLoop;
389
    
390
    public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectAControlledDoLoop;
391
    
392
    public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableMissingDeclaration;
393
    
394
    public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableNotRealOrDouble;
362
395
363
    public static String RemoveUnusedVariablesRefactoring_CouldNotCompleteOperation;
396
    public static String RemoveUnusedVariablesRefactoring_CouldNotCompleteOperation;
364
397
(-)src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java (+557 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.core.refactoring;
16
17
import java.util.LinkedList;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22
import org.eclipse.photran.internal.core.analysis.binding.ScopingNode;
23
import org.eclipse.photran.internal.core.analysis.loops.ASTProperLoopConstructNode;
24
import org.eclipse.photran.internal.core.analysis.loops.ASTVisitorWithLoops;
25
import org.eclipse.photran.internal.core.analysis.loops.LoopReplacer;
26
import org.eclipse.photran.internal.core.parser.*;
27
import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring;
28
29
/**
30
 * Remove branching to END IF statement from outside its IF ... END IF block. Such branching should
31
 * be replaced with branching to CONTINUE statement that immediately follows the END IF statement.
32
 * If the END IF statement is followed by a CONTINUE statement then outside GOTO branches should
33
 * target the CONTINUE statement. If one does not exist the refactoring will insert one and target
34
 * it. GOTOs inside the selected IF block are not re-targeted.
35
 * 
36
 * User Selection Requirements: The labeled END IF that they want considered for the refactoring.
37
 * 
38
 * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka
39
 *         (wijenay2), Nicola Hall (nfhall2)
40
 */
41
public class RemoveBranchToEndIfRefactoring extends FortranEditorRefactoring
42
{
43
    private IASTNode selectedNode;
44
45
    private ASTEndIfStmtNode selectedEndIfNode;
46
47
    private ASTIfConstructNode selectedIfConstructNode;
48
49
    private LinkedList<ASTGotoStmtNode> gotoStatements;
50
51
    private LinkedList<ASTGotoStmtNode> selectedGotoStatements;
52
53
    private ASTContinueStmtNode continueAfterIfStmtNode;
54
55
    private LinkedList<ASTGotoStmtNode> selectedGotoStatementWithEndIfLabel;
56
57
    private LinkedList<ASTGotoStmtNode> gotoStatementWithEndIfLabel;
58
59
    /**
60
     * Provide GUI refactoring label.
61
     */
62
    @Override
63
    public String getName()
64
    {
65
        return Messages.RemoveBranchToEndIfRefactoring_Name;
66
    }
67
68
    /**
69
     * Preconditions that are checked before the refactoring is applied are: 1) END IF selected must
70
     * be labeled and part of an IF block. 2) GOTO from either inside the selected IF block or
71
     * outside the selected IF block must target the label of the END IF selected. 3) must be more
72
     * GOTOs than just in local selected END IF scope.
73
     * 
74
     */
75
    @Override
76
    protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
77
        throws PreconditionFailure
78
    {
79
        ensureProjectHasRefactoringEnabled(status);
80
81
        // Check if selected text is a portion within an END IF statement with label.
82
        setSelectedNodeAndEndIfNode();
83
        if ((selectedEndIfNode == null) || (selectedEndIfNode.getLabel() == null))
84
        {
85
            fail(Messages.RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor);
86
        }
87
88
        // Check if selected END IF is within an IF block.
89
        setSelectedIfConstructNode();
90
        if (selectedIfConstructNode == null)
91
        {
92
            fail(Messages.RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct);
93
        }
94
95
        // Check if selected scope contains a branch.
96
        setGotoStatements();
97
        if (gotoStatements.isEmpty())
98
        {
99
            fail(Messages.RemoveBranchToEndIfRefactoring_MissingGoToStatement);
100
        }
101
102
        // Check if contains a GOTO statement with selected END IF label.
103
        setGotoStatementsWithEndIfLabel();
104
        if (gotoStatementWithEndIfLabel.size() == 0)
105
        {
106
            fail(Messages.RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel);
107
        }
108
109
        // Check to see if there are branches outside of selected if block to selected END IF label.
110
        setSelectedGotoStatementsWithEndIfLabel();
111
        if (selectedGotoStatementWithEndIfLabel.size() == gotoStatementWithEndIfLabel.size())
112
        {
113
            fail(Messages.RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf);
114
        }
115
116
        setContinueAfterIfStmtNode();
117
    }
118
119
    /**
120
     * There are no final conditions.
121
     */
122
    @Override
123
    protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm)
124
        throws PreconditionFailure
125
    {
126
        // No final conditions
127
    }
128
129
    /**
130
     * Separate refactroing methods based on if there is a CONTINUE statement after the selected END
131
     * IF (if so target it) or if no CONTINUE statement exists after the END IF block (insert one
132
     * with unique label and have GOTO statements outside the IF block target it.).
133
     */
134
    @Override
135
    protected void doCreateChange(IProgressMonitor pm) throws CoreException,
136
        OperationCanceledException
137
    {
138
        setAstAndNodes();
139
140
        if (continueAfterIfStmtNode == null)
141
        {
142
            changeNoContinueAfterEndIf(); // User Story #2
143
144
        }
145
        else
146
        {
147
            changeGotoLabelToContinueLabel(); // User Story #1
148
        }
149
150
        // User Story 3 checked in doCheckInitialConditions
151
152
        this.addChangeFromModifiedAST(this.fileInEditor, pm);
153
        vpg.releaseAST(this.fileInEditor);
154
    }
155
156
    /**
157
     * Sets AST of selected file and nodes used for refactoring.
158
     * 
159
     * @param None.
160
     * 
161
     * @return None.
162
     */
163
    private void setAstAndNodes()
164
    {
165
        this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor);
166
167
        // Setup nodes used for refactoring
168
        setSelectedNodeAndEndIfNode();
169
        setSelectedIfConstructNode();
170
        setGotoStatements();
171
        setGotoStatementsWithEndIfLabel();
172
        setSelectedGotoStatementsWithEndIfLabel();
173
        setContinueAfterIfStmtNode();
174
    }
175
176
    /**
177
     * Set selected node and selected end if node used for refactoring.
178
     * 
179
     * @param None.
180
     * 
181
     * @return None.
182
     */
183
    private void setSelectedNodeAndEndIfNode()
184
    {
185
        selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor);
186
        selectedEndIfNode = (ASTEndIfStmtNode)findEnclosingNodeOfType(selectedNode,
187
            ASTEndIfStmtNode.class);
188
    }
189
190
    /**
191
     * Set selected if construct node used for refactoring.
192
     * 
193
     * @param None.
194
     * 
195
     * @return None.
196
     */
197
    private void setSelectedIfConstructNode()
198
    {
199
        selectedIfConstructNode = (ASTIfConstructNode)findEnclosingNodeOfType(selectedEndIfNode,
200
            ASTIfConstructNode.class);
201
    }
202
203
    /**
204
     * Set goto statements used for refactoring.
205
     * 
206
     * @param None.
207
     * 
208
     * @return None.
209
     */
210
    private void setGotoStatements()
211
    {
212
        gotoStatements = getGotoNodes(ScopingNode.getLocalScope(selectedEndIfNode));
213
    }
214
215
    /**
216
     * Set go to statements with end if label used for refactoring.
217
     * 
218
     * @param None.
219
     * 
220
     * @return None.
221
     */
222
    private void setGotoStatementsWithEndIfLabel()
223
    {
224
        gotoStatementWithEndIfLabel = findGotoForLabel(gotoStatements, selectedEndIfNode.getLabel()
225
            .getText());
226
    }
227
228
    /**
229
     * Set selected go to statements with end if label used for refactoring.
230
     * 
231
     * @param None.
232
     * 
233
     * @return None.
234
     */
235
    private void setSelectedGotoStatementsWithEndIfLabel()
236
    {
237
        selectedGotoStatements = getGotoNodes(selectedIfConstructNode);
238
        selectedGotoStatementWithEndIfLabel = findGotoForLabel(selectedGotoStatements,
239
            selectedEndIfNode.getLabel().getText());
240
    }
241
242
    /**
243
     * Set continue after if statement used for refactoring.
244
     * 
245
     * @param None.
246
     * 
247
     * @return None.
248
     */
249
    private void setContinueAfterIfStmtNode()
250
    {
251
        continueAfterIfStmtNode = continueAfterIfStmt(selectedIfConstructNode);
252
    }
253
254
    /**
255
     * Main refactoring code for condition when CONTINUE statement follows the END..IF that was
256
     * selected for refactoring. The logic will renumber/retarget any GOTO statements in the GOTO to
257
     * that of the CONINUE label. (Per FORTRAN language standard the CONTINUE statement must have a
258
     * label). If any GOTO statement inside the selected END..IF targets the END..IF selected for
259
     * the Refactoring then the label of the END..IF will not be removed and that inner GOTO will
260
     * still target it. If there are no inner GOTOs targeting the END..IF label then the END..IF
261
     * label will be removed as part of the refactoring.
262
     * 
263
     */
264
    private void changeGotoLabelToContinueLabel()
265
    {
266
        // Check all GOTO statements in the entire PROGRAM to see if they target the END..IF label
267
        // number selected during the Refactoring. If so then retarget/renumber them to the
268
        // CONTINUE block that follows. (Note: Inner GOTO statements that that target the END..IF
269
        // statement are not retargeted/renumbered.)
270
        for (ASTGotoStmtNode gotoNode : gotoStatementWithEndIfLabel)
271
        {
272
            // Do not re-target GOTO statements from within the selected END..IF for refactoring.
273
            if (!selectedGotoStatementWithEndIfLabel.contains(gotoNode))
274
            { // Goto targeted to our selected IF..ENDIF block
275
                gotoNode.getGotoLblRef().getLabel()
276
                    .setText(continueAfterIfStmtNode.getLabel().getText()); // Use existing
277
            }
278
        }
279
280
        // Label of selected END..IF for Refactoring is only removed after all other GOTOs have been
281
        // retargeted and if no inner GOTO statements target its label.
282
        if (selectedGotoStatementWithEndIfLabel.isEmpty())
283
        {
284
            selectedEndIfNode.setLabel(null);
285
            selectedEndIfNode.findFirstToken().setWhiteBefore(
286
                selectedIfConstructNode.findFirstToken().getWhiteBefore()); // reindenter alt.
287
        }
288
289
    }
290
291
    /**
292
     * Modify Fortran code to add a CONTINUE statement after labeled END IF then remove END IF label
293
     * only if there are no GOTO statements within the selected IF statement that target that END IF
294
     * statement.
295
     * 
296
     */
297
    private void changeNoContinueAfterEndIf()
298
    {
299
300
        // build the CONTINUE node
301
        if (continueAfterIfStmtNode != null) { return; }
302
303
        @SuppressWarnings("unchecked")
304
        ASTListNode<ASTNode> listNode = (ASTListNode<ASTNode>)selectedIfConstructNode.getParent();
305
306
        // build the CONTINUE statement program source code
307
        String programString = "program p\n" + selectedEndIfNode.getLabel().getText() + " CONTINUE" //$NON-NLS-1$ //$NON-NLS-2$
308
            + EOL + "end program"; //$NON-NLS-1$
309
        ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString);
310
        ASTContinueStmtNode continueStmt = (ASTContinueStmtNode)programNode.getBody().get(0);
311
312
        // insert into AST
313
        continueStmt.setParent(selectedIfConstructNode.getParent());
314
        listNode.insertAfter(selectedIfConstructNode, continueStmt);
315
316
        // clear label on END IF statement
317
        if (selectedGotoStatementWithEndIfLabel.size() == 0)
318
        {
319
            selectedEndIfNode.setLabel(null);
320
            // correct indentation
321
            selectedEndIfNode.findFirstToken().setWhiteBefore(
322
                selectedIfConstructNode.findFirstToken().getWhiteBefore());
323
        }
324
        else
325
        {
326
            // Grab all labels
327
            LinkedList<IActionStmt> actionStmts = getActionStmts(ScopingNode
328
                .getLocalScope(selectedEndIfNode));
329
330
            // Calculate unique label
331
            String label = getUniqueLabel(actionStmts);
332
333
            // Set continue label to new label
334
            continueStmt.getLabel().setText(label);
335
336
            // Set all goto statements to new label
337
            for (ASTGotoStmtNode node : gotoStatementWithEndIfLabel)
338
            {
339
                if (!selectedGotoStatementWithEndIfLabel.contains(node))
340
                {
341
                    node.getGotoLblRef().getLabel().setText(label);
342
                }
343
            }
344
        }
345
    }
346
347
    /**
348
     * Build a list of all GOTO node types from the starting node.
349
     * 
350
     * @param startNode Node to start the search.
351
     * 
352
     * @return LinkedList of GOTO nodes.
353
     */
354
    private LinkedList<ASTGotoStmtNode> getGotoNodes(IASTNode startNode)
355
    {
356
        if (startNode == null) { return null; }
357
358
        /*
359
         * Unable to find all goto statements when there are do loops in startNode, so need to
360
         * search in the do loops separately.
361
         */
362
        final LinkedList<ASTGotoStmtNode> gotoNodes = getGotoStmtsInAllProperLoopConstructs(startNode);
363
364
        startNode.accept(new ASTVisitor()
365
        {
366
            @Override
367
            public void visitASTGotoStmtNode(ASTGotoStmtNode node)
368
            {
369
                gotoNodes.add(node);
370
            }
371
        });
372
373
        return gotoNodes;
374
    }
375
376
    /**
377
     * Build a list of all proper-loop-construct node types from the starting node.
378
     * 
379
     * @param startNode Node to start the search.
380
     * @return LinkedList of proper-loop-construct nodes.
381
     */
382
    private LinkedList<ASTGotoStmtNode> getGotoStmtsInAllProperLoopConstructs(IASTNode startNode)
383
    {
384
        final LinkedList<ASTGotoStmtNode> gotoNodes = new LinkedList<ASTGotoStmtNode>();
385
        final LinkedList<ASTProperLoopConstructNode> loopNodes = getProperLoopConstructs(startNode);
386
387
        for (ASTProperLoopConstructNode loop : loopNodes)
388
        {
389
            for (IASTNode node : loop.getBody())
390
            {
391
                node.accept(new ASTVisitor()
392
                {
393
                    @Override
394
                    public void visitASTGotoStmtNode(ASTGotoStmtNode node)
395
                    {
396
                        gotoNodes.add(node);
397
                    }
398
                });
399
            }
400
        }
401
402
        return gotoNodes;
403
    }
404
405
    /**
406
     * Find GOTO node(s) based on matching label.
407
     * 
408
     * @param gotos List of GOTO statements to check for matching label.
409
     * @param label Label to match against.
410
     * @return List of GOTO nodes that target the specified label.
411
     */
412
    private LinkedList<ASTGotoStmtNode> findGotoForLabel(LinkedList<ASTGotoStmtNode> gotos,
413
        String label)
414
    {
415
        if (gotos == null) { return new LinkedList<ASTGotoStmtNode>(); }
416
417
        LinkedList<ASTGotoStmtNode> gotoWithLabel = new LinkedList<ASTGotoStmtNode>();
418
        for (ASTGotoStmtNode gotoNode : gotos)
419
        {
420
            if (gotoNode.getGotoLblRef().getLabel().getText().contentEquals(label))
421
            {
422
                gotoWithLabel.add(gotoNode);
423
            }
424
        }
425
426
        return gotoWithLabel;
427
    }
428
429
    /**
430
     * Check for CONTINUE statement after a if construct node
431
     * 
432
     * @param ifStmt If construct node.
433
     * @return continue statement node or null.
434
     */
435
    private static ASTContinueStmtNode continueAfterIfStmt(ASTIfConstructNode ifStmt)
436
    {
437
        if (ifStmt == null) { return null; }
438
439
        @SuppressWarnings("unchecked")
440
        ASTListNode<ASTNode> list = (ASTListNode<ASTNode>)ifStmt.getParent();
441
442
        for (int i = 0; i < list.size() - 1; i++)
443
        {
444
            if (list.get(i) != null)
445
            {
446
                if (list.get(i).equals(ifStmt))
447
                {
448
                    if (list.get(i + 1) instanceof ASTContinueStmtNode) { return (ASTContinueStmtNode)list
449
                        .get(i + 1); }
450
                }
451
            }
452
        }
453
454
        return null;
455
    }
456
457
    /**
458
     * Generate a unique label based on the labels passed in (unique in that find the largest and
459
     * add 10)
460
     * 
461
     * @param actionStmts List of statements that may be labeled to consider for a unique label.
462
     * @return Unique label value.
463
     */
464
    private String getUniqueLabel(LinkedList<IActionStmt> actionStmts)
465
    {
466
        int label = Integer.parseInt(selectedEndIfNode.getLabel().getText());
467
        for (IActionStmt stmt : actionStmts)
468
        {
469
            if (stmt.getLabel() != null)
470
            {
471
                int currentLabel = Integer.parseInt(stmt.getLabel().getText());
472
                if (currentLabel > label)
473
                {
474
                    label = currentLabel;
475
                }
476
            }
477
        }
478
        label += 10;
479
480
        return String.valueOf(label);
481
    }
482
483
    /**
484
     * Find Action statement nodes in the tree from the starting search node.
485
     * 
486
     * @param startNode Starting node from which to perform the search.
487
     * @return LinkedList of action statement nodes that are found.
488
     */
489
    private LinkedList<IActionStmt> getActionStmts(IASTNode startNode)
490
    {
491
        final LinkedList<IActionStmt> actionStmts = getActionStmtsInAllProperLoopConstructs();
492
        startNode.accept(new ASTVisitor()
493
        {
494
            @Override
495
            public void visitIActionStmt(IActionStmt node)
496
            {
497
                actionStmts.add(node);
498
            }
499
        });
500
501
        return actionStmts;
502
    }
503
504
    /**
505
     * Find Action statement nodes in entire file in editor.
506
     * 
507
     * @return LinkedList of action statement nodes found.
508
     */
509
    private LinkedList<IActionStmt> getActionStmtsInAllProperLoopConstructs()
510
    {
511
        final LinkedList<IActionStmt> actionStmts = new LinkedList<IActionStmt>();
512
        final LinkedList<ASTProperLoopConstructNode> loopNodes = getProperLoopConstructs(ScopingNode
513
            .getLocalScope(selectedEndIfNode));
514
515
        for (ASTProperLoopConstructNode loop : loopNodes)
516
        {
517
            for (IASTNode node : loop.getBody())
518
            {
519
                node.accept(new ASTVisitor()
520
                {
521
                    @Override
522
                    public void visitIActionStmt(IActionStmt node)
523
                    {
524
                        actionStmts.add(node);
525
                    }
526
                });
527
            }
528
        }
529
530
        return actionStmts;
531
    }
532
533
    /**
534
     * Find all proper loop constructs in the tree from the starting search node.
535
     * 
536
     * @param startNode Starting node from which to perform the search.
537
     * @return LinkedList of proper loop construct nodes found.
538
     */
539
    private LinkedList<ASTProperLoopConstructNode> getProperLoopConstructs(IASTNode startNode)
540
    {
541
        final LinkedList<ASTProperLoopConstructNode> loopNodes = new LinkedList<ASTProperLoopConstructNode>();
542
543
        // Change AST to represent DO-loops as ASTProperLoopConstructNodes
544
        LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot());
545
546
        startNode.accept(new ASTVisitorWithLoops()
547
        {
548
            @Override
549
            public void visitASTProperLoopConstructNode(ASTProperLoopConstructNode node)
550
            {
551
                loopNodes.add(node);
552
            }
553
        });
554
555
        return loopNodes;
556
    }
557
}
(-)src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java (+144 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.core.refactoring;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
21
import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring;
22
import org.eclipse.photran.internal.core.parser.*;
23
24
/**
25
 * This feature address the replacement of the PAUSE statement with a PRINT and READ statement.
26
 * Execution of a PAUSE statement may be different on different platforms. The refactoring assumes
27
 * the most basic functionality: it replaces the PAUSE statement with a PRINT statement that
28
 * displays the message of the PAUSE statement, immediately followed by a READ statement that waits
29
 * for any input from the user.
30
 * 
31
 * User Selection Requirements: The PAUSE statement to be replaced.
32
 * 
33
 * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka
34
 *         (wijenay2), Nicola Hall (nfhall2)
35
 */
36
public class RemovePauseStmtRefactoring extends FortranEditorRefactoring
37
{
38
    private IASTNode selectedNode = null;
39
40
    private ASTPauseStmtNode selectedPauseStmt = null;
41
42
    /**
43
     * Preconditions checks: Check if project has refactoring is enabled. Checks that the user
44
     * selects a PAUSE statement for refactoring. Failure to meet these conditions will result in a
45
     * fail-initial condition.
46
     */
47
    @Override
48
    protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
49
        throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
50
    {
51
        ensureProjectHasRefactoringEnabled(status);
52
53
        // Check if selected is a PAUSE statement
54
        setSelectedPauseStmt();
55
56
        if (selectedPauseStmt == null)
57
        {
58
            fail(Messages.RemovePauseStmtRefactoring_SelectPauseStmt);
59
        }
60
    }
61
62
    /**
63
     * FinalConditions no final checks required.
64
     */
65
    @Override
66
    protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm)
67
        throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
68
    {
69
    }
70
71
    /**
72
     * Performs main refactoring (delegated to other methods).
73
     */
74
    @Override
75
    protected void doCreateChange(IProgressMonitor pm) throws CoreException,
76
        OperationCanceledException
77
    {
78
        changePauseStmt();
79
80
        // Finalize.
81
        this.addChangeFromModifiedAST(this.fileInEditor, pm);
82
        vpg.releaseAST(this.fileInEditor);
83
    }
84
85
    /**
86
     * Provide GUI refactoring label.
87
     */
88
    @Override
89
    public String getName()
90
    {
91
        return Messages.RemovePauseStmtRefactoring_Name;
92
    }
93
94
    /**
95
     * Obtains the selected pause statement else sets the member field to null.
96
     */
97
    private void setSelectedPauseStmt()
98
    {
99
        selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor);
100
101
        selectedPauseStmt = (ASTPauseStmtNode)findEnclosingNodeOfType(selectedNode,
102
            ASTPauseStmtNode.class);
103
    }
104
105
    /**
106
     * Insert modified PRINT statement and build READ() AST node to insert in to the program after
107
     * the PRINT statement.
108
     */
109
    private void changePauseStmt()
110
    {
111
        // change to modify the transient AST.
112
        this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor);
113
114
        // check on pause statement performed in initial, should not have changed in final.
115
        setSelectedPauseStmt();
116
117
        String pauseMessage = "\'\'"; //$NON-NLS-1$;
118
119
        // Contents of the PRINT statement to maintain.
120
        if (null != selectedPauseStmt.getStringConst())
121
        {
122
            pauseMessage = selectedPauseStmt.getStringConst().getText();
123
        }
124
125
        // Build new AST node for modified PRINT statement and new READ statement.
126
        String indent = selectedPauseStmt.findFirstToken().getWhiteBefore();
127
        String programString = "program p" + EOL + //$NON-NLS-1$
128
            indent
129
            + "PRINT *, " + pauseMessage + selectedPauseStmt.findLastToken().getWhiteBefore() + EOL + //$NON-NLS-1$
130
            indent + "READ (*, *)" + EOL + //$NON-NLS-1$
131
            "end program"; //$NON-NLS-1$
132
133
        // Insert new AST node in place of selected PRINT statement.
134
        ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString);
135
        ASTPrintStmtNode printStmt = (ASTPrintStmtNode)programNode.getBody().get(0);
136
        ASTReadStmtNode readStmt = (ASTReadStmtNode)programNode.getBody().get(1);
137
138
        @SuppressWarnings("unchecked")
139
        ASTListNode<ASTNode> listNode = (ASTListNode<ASTNode>)selectedPauseStmt.getParent();
140
141
        selectedPauseStmt.replaceWith(printStmt);
142
        listNode.insertAfter(printStmt, readStmt);
143
    }
144
}
(-)src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java (+392 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.core.refactoring;
16
17
import java.util.LinkedList;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22
import org.eclipse.photran.internal.core.analysis.binding.ScopingNode;
23
import org.eclipse.photran.internal.core.analysis.loops.LoopReplacer;
24
import org.eclipse.photran.internal.core.parser.*;
25
import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring;
26
import org.eclipse.photran.internal.core.analysis.loops.ASTProperLoopConstructNode;
27
28
/**
29
 * Remove Real and Double Precision Loop Counter Refactoring:
30
 * 
31
 * This refactoring will take a controlled DO loop, i.e. on that specifies the starting and ending
32
 * values for the control loop index and transform it to an uncontrolled do loop where the same loop
33
 * index and values are manually inserted into to the loop. If a explicit step size is specified is
34
 * used, otherwise an implicit one is inserted. The refactoring checks the start/end values of the
35
 * loop control variable to determine if the loop control variable should increment or decrement.
36
 * 
37
 * User Selection Requirements: A controlled DO loop statement to be considered for refactoring.
38
 * 
39
 * @author Rita Chow (chow15), Nicola Hall (nfhall2), Jerry Hsiao (jhsiao2), Mark Mozolewski
40
 *         (mozolews), Chamil Wijenayaka (wijenay2)
41
 */
42
public class RemoveRealAndDoublePrecisionLoopCountersRefactoring extends FortranEditorRefactoring
43
{
44
45
    private IASTNode selectedNode = null;
46
47
    private ASTProperLoopConstructNode selectedDoLoopNode = null;
48
49
    private LinkedList<ASTTypeDeclarationStmtNode> typeDeclarationsInFile;
50
51
    private String doVarName;
52
53
    private boolean shouldReplaceWithDoWhileLoop = false;
54
55
    /**
56
     * Provide GUI refactoring label.
57
     */
58
    @Override
59
    public String getName()
60
    {
61
        return Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_Name;
62
    }
63
64
    /**
65
     * Set method for DO or DO WHILE refactoring selection variable.
66
     * 
67
     * @param value Set tracking variable for DO or DO WHILE refactoring selection.
68
     */
69
    public void setShouldReplaceWithDoWhileLoop(boolean value)
70
    {
71
        this.shouldReplaceWithDoWhileLoop = value;
72
    }
73
74
    /**
75
     * Precondition checks: Check if project has refactoring enabled.
76
     */
77
    @Override
78
    protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
79
        throws PreconditionFailure
80
    {
81
        ensureProjectHasRefactoringEnabled(status);
82
    }
83
84
    /**
85
     * The following initial conditions are checked (a failure of any will result in a
86
     * fail-initial): - A controlled DO loop must be selected by the user. - Loop control variables
87
     * of a controlled DO loop must be declared as type REAL or DOUBLE PRECISION only.
88
     */
89
    @Override
90
    protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm)
91
        throws PreconditionFailure
92
    {
93
        Boolean doVarNameIsRealOrDouble = false;
94
95
        this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor);
96
97
        // Change AST to represent DO-loops as ASTProperLoopConstructNodes
98
        LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot());
99
100
        // Identify selected DO loop.
101
        selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor);
102
        selectedDoLoopNode = (ASTProperLoopConstructNode)findEnclosingNodeOfType(selectedNode,
103
            ASTProperLoopConstructNode.class);
104
105
        // Check for invalid selection (DO statement not selected)
106
        if (selectedDoLoopNode == null)
107
        {
108
            fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectADoLoop);
109
        }
110
111
        // Check uncontrolled DO loop selected.
112
        if (selectedDoLoopNode.getLoopHeader().getLoopControl() == null)
113
        {
114
            fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectAControlledDoLoop);
115
        }
116
117
        // Find all REAL and DOUBLE declared variables.
118
        doVarName = selectedDoLoopNode.getLoopHeader().getLoopControl().getVariableName().getText()
119
            .toString();
120
        typeDeclarationsInFile = getTypeDeclarations(this.astOfFileInEditor.getRoot());
121
122
        if (typeDeclarationsInFile == null)
123
        {
124
            fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableMissingDeclaration);
125
        }
126
127
        // Search all type declarations of the PROGRAM to find DO loop control variable name and
128
        // REAL or DOUBLE variable type.
129
        for (ASTTypeDeclarationStmtNode typeDeclaration : typeDeclarationsInFile)
130
        {
131
132
            if (typeDeclaration.getTypeSpec().isReal() || typeDeclaration.getTypeSpec().isDouble())
133
            {
134
135
                // Search all variable names for this REAL/DOUBLE variable declaration.
136
                for (ASTEntityDeclNode entityDeclaration : typeDeclaration.getEntityDeclList())
137
                {
138
139
                    if (entityDeclaration.getObjectName().getObjectName().getText()
140
                        .equals(doVarName))
141
                    {
142
                        doVarNameIsRealOrDouble = true;
143
                        break;
144
                    }
145
                }
146
147
            }
148
        }
149
150
        if (!doVarNameIsRealOrDouble)
151
        {
152
            fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableNotRealOrDouble);
153
        }
154
    }
155
156
    /**
157
     * After initial conditions checks pass there is a proper controlled DO loop variable to
158
     * refactor. The refactoring consists of building a number of AST node elements and inserting
159
     * them in to the program to do the work that the controlled DO loop would have done. This
160
     * includes: 1) Initial loop control variable assignment (starting value). 2)
161
     * Increment/Decrement control variable by specified amount (implicit or explicit step size) 3)
162
     * Check inside DO loop to see if loop variable limit specified is exceeded.
163
     */
164
    @Override
165
    protected void doCreateChange(IProgressMonitor pm) throws CoreException,
166
        OperationCanceledException
167
    {
168
        String ifCheckLb = selectedDoLoopNode.getLoopHeader().getLoopControl().getLb().toString();
169
        String ifCheckUb = selectedDoLoopNode.getLoopHeader().getLoopControl().getUb().toString();
170
        String ifCheckVar = selectedDoLoopNode.getLoopHeader().getLoopControl().getVariableName()
171
            .getText().toString();
172
173
        // Implicit step size check.
174
        String ifCheckStep = null;
175
        if (selectedDoLoopNode.getLoopHeader().getLoopControl().getStep() != null)
176
        {
177
            ifCheckStep = selectedDoLoopNode.getLoopHeader().getLoopControl().getStep().toString();
178
        }
179
        else
180
        {
181
            ifCheckStep = " 1"; //$NON-NLS-1$
182
        }
183
184
        String ifCheckIncrDecr = ""; //$NON-NLS-1$
185
        String ifCheckStr = ""; //$NON-NLS-1$
186
187
        // Work with both as double type.
188
        double dLb = Double.valueOf(ifCheckLb.trim()).doubleValue();
189
        double dUb = Double.valueOf(ifCheckUb.trim()).doubleValue();
190
191
        // Check for > or < IF check.
192
        if (dLb < dUb)
193
        {
194
            if (shouldReplaceWithDoWhileLoop)
195
                ifCheckStr = ifCheckVar + " <=" + ifCheckUb; //$NON-NLS-1$
196
            else
197
                ifCheckStr = ifCheckVar + " >" + ifCheckUb; //$NON-NLS-1$
198
            ifCheckIncrDecr = " +"; //$NON-NLS-1$
199
        }
200
        else
201
        {
202
            if (shouldReplaceWithDoWhileLoop)
203
                ifCheckStr = ifCheckVar + " >=" + ifCheckUb; //$NON-NLS-1$
204
            else
205
                ifCheckStr = ifCheckVar + " <" + ifCheckUb; //$NON-NLS-1$
206
            ifCheckIncrDecr = " -"; //$NON-NLS-1$
207
        }
208
209
        // AST modification for refactoring.
210
        if (shouldReplaceWithDoWhileLoop)
211
        {
212
            insertNewDoWhileLoop(ifCheckLb, ifCheckVar, ifCheckStep, ifCheckIncrDecr, ifCheckStr);
213
        }
214
        else
215
        {
216
            insertNewDoLoop(ifCheckLb, ifCheckVar, ifCheckStep, ifCheckIncrDecr, ifCheckStr);
217
        }
218
219
        // Finalize
220
        this.addChangeFromModifiedAST(this.fileInEditor, pm);
221
        vpg.releaseAST(this.fileInEditor);
222
    }
223
224
    /**
225
     * With provided strings this method builds the new AST nodes for the initial variable
226
     * assignment, increment/decrement statement, and IF DO loop break statement. They are then
227
     * inserted in to the proper hierarchy of the program AST structure. (See main refactoring
228
     * comments at the top of the file for a list of steps performed.)
229
     * 
230
     * @param ifCheckLb Lower bound (starting value) of loop variable.
231
     * @param ifCheckVar Loop control variable name.
232
     * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared)
233
     * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction.
234
     * @param ifCheckStr The IF check condition to break the DO loop.
235
     */
236
    private void insertNewDoLoop(String ifCheckLb, String ifCheckVar, String ifCheckStep,
237
        String ifCheckIncrDecr, String ifCheckStr)
238
    {
239
        // Build initial value assignment node.
240
        insertInitialCounterAssignment(ifCheckVar, ifCheckLb);
241
242
        // Remove DO control
243
        int sizeOfLoopControlString = selectedDoLoopNode.getLoopHeader().getLoopControl()
244
            .toString().length();
245
        String replaceLoopControlStringWith = ""; //$NON-NLS-1$
246
        for (int i = 0; i < sizeOfLoopControlString; i++)
247
        {
248
            replaceLoopControlStringWith += " "; //$NON-NLS-1$
249
        }
250
        selectedDoLoopNode.getLoopHeader().setLoopControl(null);
251
        selectedDoLoopNode
252
            .getLoopHeader()
253
            .findLastToken()
254
            .setWhiteBefore(
255
                replaceLoopControlStringWith
256
                    + selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore());
257
258
        // Build increment assignment node.
259
        ASTAssignmentStmtNode incrDecrNode = insertCounterAssignment(ifCheckVar, ifCheckIncrDecr,
260
            ifCheckStep);
261
262
        // Build IF node for checking DO limits.
263
        IExecutionPartConstruct lastNodeInDoLoopBody = selectedDoLoopNode.getBody().get(
264
            selectedDoLoopNode.getBody().size() - 1);
265
        String initialIndent = ScopingNode.getLocalScope(selectedDoLoopNode).getBody()
266
            .findFirstToken().getWhiteBefore();
267
        String programString = ""; //$NON-NLS-1$
268
        programString = "program p\n" + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() //$NON-NLS-1$
269
            + "IF(" + ifCheckStr + ") THEN\n" //$NON-NLS-1$ //$NON-NLS-2$
270
            + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore()
271
            + initialIndent
272
            + "EXIT\n" //$NON-NLS-1$
273
            + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore()
274
            + "END IF" + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$
275
        ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString);
276
        ASTIfConstructNode ifNode = (ASTIfConstructNode)programNode.getBody().get(0);
277
278
        // Insert IF node into AST
279
        ifNode.setParent(selectedDoLoopNode.getParent());
280
        selectedDoLoopNode.getBody().insertAfter(incrDecrNode, ifNode);
281
    }
282
283
    /**
284
     * With provided strings this method builds the new AST nodes for the initial variable
285
     * assignment, increment/decrement statement, and DO WHILE loop check statement. They are then
286
     * inserted in to the proper hierarchy of the program AST structure. (See main refactoring
287
     * comments at the top of the file for a list of steps performed.)
288
     * 
289
     * @param ifCheckLb Lower bound (starting value) of loop variable.
290
     * @param ifCheckVar Loop control variable name.
291
     * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared)
292
     * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction.
293
     * @param ifCheckStr The IF check condition to break the DO loop.
294
     */
295
    @SuppressWarnings("nls")
296
    private void insertNewDoWhileLoop(String ifCheckLb, String ifCheckVar, String ifCheckStep,
297
        String ifCheckIncrDecr, String ifCheckStr)
298
    {
299
        // Build initial value assignment node.
300
        insertInitialCounterAssignment(ifCheckVar, ifCheckLb);
301
302
        // Build increment assignment node.
303
        insertCounterAssignment(ifCheckVar, ifCheckIncrDecr, ifCheckStep);
304
305
        // Change do loop to while do loop
306
        String programString = "";
307
        programString = "program p\n"
308
            + selectedDoLoopNode.getLoopHeader().findFirstToken().getWhiteBefore() + "DO WHILE ("
309
            + ifCheckStr + ")"
310
            + selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore() + EOL
311
            + "EXIT\nENDDO" + EOL + "end program";
312
313
        ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString);
314
        ASTDoConstructNode doConstructNode = (ASTDoConstructNode)programNode.getBody().get(0);
315
        selectedDoLoopNode.setLoopHeader(doConstructNode.getLabelDoStmt());
316
        selectedDoLoopNode.getLoopHeader().findLastToken()
317
            .setWhiteBefore(selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore());
318
    }
319
320
    /**
321
     * Creates an assignment statement node for the initial loop counter value assignment and
322
     * inserts it before the selected DO loop of the refactoring.
323
     * 
324
     * @param ifCheckVar Loop control variable name.
325
     * @param ifCheckLb Lower bound (starting value) of loop variable.
326
     */
327
    private void insertInitialCounterAssignment(String ifCheckVar, String ifCheckLb)
328
    {
329
        String programString = "program p\n" + selectedDoLoopNode.findFirstToken().getWhiteBefore() + ifCheckVar + //$NON-NLS-1$
330
            " =" + ifCheckLb + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$
331
        ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString);
332
        ASTAssignmentStmtNode initValNode = (ASTAssignmentStmtNode)programNode.getBody().get(0);
333
334
        // Insert initial value assignment node into AST
335
        initValNode.setParent(selectedDoLoopNode.getParent());
336
        @SuppressWarnings("unchecked")
337
        ASTListNode<ASTNode> doNode = (ASTListNode<ASTNode>)selectedDoLoopNode.getParent();
338
        doNode.insertBefore(selectedDoLoopNode, initValNode);
339
    }
340
341
    /**
342
     * Creates an assignment statement node for the loop counter variable assignment and inserts it
343
     * after the selected DO loop of the refactoring.
344
     * 
345
     * @param ifCheckVar Loop control variable name.
346
     * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction.
347
     * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared)
348
     */
349
    private ASTAssignmentStmtNode insertCounterAssignment(String ifCheckVar,
350
        String ifCheckIncrDecr, String ifCheckStep)
351
    {
352
        IExecutionPartConstruct lastNodeInDoLoopBody = selectedDoLoopNode.getBody().get(
353
            selectedDoLoopNode.getBody().size() - 1);
354
        String programString = ""; //$NON-NLS-1$
355
        programString = "program p\n" + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() + ifCheckVar + //$NON-NLS-1$
356
            " = " + ifCheckVar + ifCheckIncrDecr + ifCheckStep + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$
357
        ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString);
358
        ASTAssignmentStmtNode incrDecrNode = (ASTAssignmentStmtNode)programNode.getBody().get(0);
359
360
        // Insert increment/decrement assignment node into AST
361
        incrDecrNode.setParent(selectedDoLoopNode.getParent());
362
363
        selectedDoLoopNode.getBody().insertAfter(lastNodeInDoLoopBody, incrDecrNode);
364
365
        return incrDecrNode;
366
    }
367
368
    /**
369
     * Get all variable type declarations in the program.
370
     * 
371
     * @param startNode node to start search.
372
     * 
373
     * @return LinkedList of type declarations nodes.
374
     */
375
    private LinkedList<ASTTypeDeclarationStmtNode> getTypeDeclarations(IASTNode startNode)
376
    {
377
        if (startNode == null) { return null; }
378
379
        final LinkedList<ASTTypeDeclarationStmtNode> typeDeclarations = new LinkedList<ASTTypeDeclarationStmtNode>();
380
381
        startNode.accept(new ASTVisitor()
382
        {
383
            @Override
384
            public void visitASTTypeDeclarationStmtNode(ASTTypeDeclarationStmtNode node)
385
            {
386
                typeDeclarations.add(node);
387
            }
388
        });
389
390
        return typeDeclarations;
391
    }
392
}
(-)src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java (+26 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    UIUC - Initial API and implementation
9
 *    UIUC - Initial API and implementation
10
 *    Rita Chow - Photran Modifications
11
 *    Nicola Hall - Photran Modifications
12
 *    Jerry Hsiao - Photran Modifications
13
 *    Mark Mozolewski - Photran Modifications
14
 *    Chamil Wijenayaka - Photran Modifications
10
 *******************************************************************************/
15
 *******************************************************************************/
11
package org.eclipse.photran.internal.core.refactoring.infrastructure;
16
package org.eclipse.photran.internal.core.refactoring.infrastructure;
12
17
Lines 373-378 Link Here
373
        return null;
378
        return null;
374
    }
379
    }
375
380
381
    /**
382
     * Get node based on type.
383
     * 
384
     * @param startNode node to start search.
385
     * @param typeChecker instance type to search.
386
     * 
387
     * @return node if found else null.
388
     */
389
    protected IASTNode findEnclosingNodeOfType(IASTNode startNode, Class classType)
390
    {
391
        if(startNode == null) { return null; }
392
393
        IASTNode node = startNode;
394
        while ((node != null) && (node.getClass() != classType))
395
        {
396
             node = node.getParent();
397
        }
398
399
        return node;
400
    }
401
376
    protected static boolean nodeExactlyEnclosesRegion(IASTNode parent, Token firstToken, Token lastToken)
402
    protected static boolean nodeExactlyEnclosesRegion(IASTNode parent, Token firstToken, Token lastToken)
377
    {
403
    {
378
        return parent.findFirstToken() == firstToken && parent.findLastToken() == lastToken;
404
        return parent.findFirstToken() == firstToken && parent.findLastToken() == lastToken;
(-)refactoring-test-code/remove-branch-to-end-if/branch_from_Inside_and_outside_if_block/branch_from_Inside_and_outside_if_block.f90 (+29 lines)
Added Link Here
1
! More complicated PROGRAM to check that outer GOTOs
2
! are retargetted to existing CONTINUE statement
3
! but END IF label is not removed since inner GOTO
4
! targets it.
5
6
PROGRAM branch_from_inside_and_outside_if_block
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
          GOTO 50
17
30     END IF
18
40     CONTINUE
19
10 END IF
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
   IF (sum.ge.100) THEN
23
       PRINT *, 'sum:', sum
24
    ELSE
25
       sum = sum + sum
26
       GOTO 50
27
50 END IF	!<<<<< 27, 1, 27, 9, pass
28
60 CONTINUE
29
END PROGRAM branch_from_inside_and_outside_if_block
(-)refactoring-test-code/remove-branch-to-end-if/branch_from_Inside_and_outside_if_block/branch_from_Inside_and_outside_if_block.f90.result (+29 lines)
Added Link Here
1
! More complicated PROGRAM to check that outer GOTOs
2
! are retargetted to existing CONTINUE statement
3
! but END IF label is not removed since inner GOTO
4
! targets it.
5
6
PROGRAM branch_from_inside_and_outside_if_block
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
          GOTO 60
17
30     END IF
18
40     CONTINUE
19
10 END IF
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
   IF (sum.ge.100) THEN
23
       PRINT *, 'sum:', sum
24
    ELSE
25
       sum = sum + sum
26
       GOTO 50
27
50 END IF	!<<<<< 27, 1, 27, 9, pass
28
60 CONTINUE
29
END PROGRAM branch_from_inside_and_outside_if_block
(-)refactoring-test-code/remove-branch-to-end-if/branch_from_inside_and_outside_if_block_no_do_loop/branch_from_inside_and_outside_if_block_no_do_loop.f90 (+26 lines)
Added Link Here
1
! More complicated PROGRAM to check that outer GOTOs
2
! are retargetted a CONTINUE statement that is inserted
3
! but END IF label is not removed since inner GOTO
4
! targets it.
5
6
PROGRAM branch_from_inside_and_outside_if_block_no_do_loop
7
   INTEGER :: sum, i
8
   sum = 0
9
   IF (MOD(i,2).eq.0) THEN
10
      sum = sum + i
11
      IF (sum.ge.100) THEN
12
         GOTO 30
13
      ELSE
14
         sum = sum + sum
15
         GOTO 50
16
30    END IF
17
10 END IF
18
19
   PRINT *, 'sum:', sum
20
   IF (sum.ge.100) THEN
21
       PRINT *, 'sum:', sum
22
    ELSE
23
       sum = sum + sum
24
       GOTO 50
25
50 END IF	!<<<<< 25, 1, 25, 9, pass
26
END PROGRAM branch_from_inside_and_outside_if_block_no_do_loop
(-)refactoring-test-code/remove-branch-to-end-if/branch_from_inside_and_outside_if_block_no_do_loop/branch_from_inside_and_outside_if_block_no_do_loop.f90.result (+27 lines)
Added Link Here
1
! More complicated PROGRAM to check that outer GOTOs
2
! are retargetted a CONTINUE statement that is inserted
3
! but END IF label is not removed since inner GOTO
4
! targets it.
5
6
PROGRAM branch_from_inside_and_outside_if_block_no_do_loop
7
   INTEGER :: sum, i
8
   sum = 0
9
   IF (MOD(i,2).eq.0) THEN
10
      sum = sum + i
11
      IF (sum.ge.100) THEN
12
         GOTO 30
13
      ELSE
14
         sum = sum + sum
15
         GOTO 60
16
30    END IF
17
10 END IF
18
19
   PRINT *, 'sum:', sum
20
   IF (sum.ge.100) THEN
21
       PRINT *, 'sum:', sum
22
    ELSE
23
       sum = sum + sum
24
       GOTO 50
25
50 END IF	!<<<<< 25, 1, 25, 9, pass
26
60 CONTINUE
27
END PROGRAM branch_from_inside_and_outside_if_block_no_do_loop
(-)refactoring-test-code/remove-branch-to-end-if/branch_to_immediate_end_if_from_else/branch_to_immediate_end_if_from_else.f90 (+21 lines)
Added Link Here
1
! END IF selected that only has its own GOTO targetting
2
! it so no refactoring is performed by design and 
3
! user it told so.
4
5
PROGRAM branch_to_immediate_end_if_from_else
6
   INTEGER :: sum, i
7
   sum = 0
8
   DO 20, i = 1, 10
9
     IF (MOD(i,2).eq.0) THEN
10
       sum = sum + i
11
       IF (sum.ge.100) THEN
12
          GOTO 10
13
       ELSE
14
          sum = sum + sum
15
          GOTO 30
16
30     END IF	!<<<<< 16, 1, 16, 9, fail-initial
17
40     CONTINUE
18
10 END IF
19
20 CONTINUE
20
   PRINT *, 'sum:', sum
21
END PROGRAM branch_to_immediate_end_if_from_else
(-)refactoring-test-code/remove-branch-to-end-if/branch_to_immediate_end_if_from_else/branch_to_immediate_end_if_from_else.f90.result (+22 lines)
Added Link Here
1
! More complicated PROGRAM to check that outer GOTOs
2
! are retargeted a CONTINUE statement that is inserted
3
! but END IF label is not removed since inner GOTO
4
! targets it.
5
6
PROGRAM branch_to_immediate_end_if_from_else
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 10
14
       ELSE
15
          sum = sum + sum
16
          GOTO 30
17
30     END IF	!<<<<< 16, 1, 16, 9, fail-initial
18
40     CONTINUE
19
10 END IF
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
END PROGRAM branch_to_immediate_end_if_from_else
(-)refactoring-test-code/remove-branch-to-end-if/nested_If_block_branch_from_else/nested_If_block_branch_from_else.f90 (+22 lines)
Added Link Here
1
! With a DO statement enclosing nested IF blocks make sure
2
! existing CONTINUE statement is targeted for outer GOTOs
3
! and since no inner GOTO exists remove the label of 
4
! selected END IF (check reindentation as well).
5
6
PROGRAM nested_if_block_branch_from_else
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
          GOTO 10
17
30     END IF
18
40     CONTINUE
19
10 END IF                           !<<<<< 19, 1, 19, 9, fail-initial
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
END PROGRAM nested_if_block_branch_from_else
(-)refactoring-test-code/remove-branch-to-end-if/nested_If_block_branch_from_else/nested_If_block_branch_from_else.f90.result (+22 lines)
Added Link Here
1
! With a DO statement enclosing nested IF blocks make sure
2
! existing CONTINUE statement is targeted for outer GOTOs
3
! and since no inner GOTO exists remove the label of 
4
! selected END IF (check reindentation as well).
5
6
PROGRAM nested_if_block_branch_from_else
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
          GOTO 20
17
30     END IF
18
40     CONTINUE
19
     END IF                           !<<<<< 19, 1, 19, 9, fail-initial
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
END PROGRAM nested_if_block_branch_from_else
(-)refactoring-test-code/remove-branch-to-end-if/nested_if_block_basic/nested_if_block_basic.f90 (+21 lines)
Added Link Here
1
! Using a nested IF block check that GOTO of inner IF
2
! block is still considered an outer GOTO statement 
3
! so a CONTINUE statement is inserted and that GOTO
4
! (and other outer GOTOs) target the new CONTINUE statement
5
6
PROGRAM NestedIfBlockBasic
7
   INTEGER :: k, i
8
   READ(*,*) k
9
   IF (k.lt.10) THEN
10
     GOTO 20
11
   END IF
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100
15
     IF (i.lt.10) THEN
16
       GOTO 20
17
     END IF
18
     i = i - 10
19
20 END IF                       !<<<<< 19, 1, 19, 10, pass
20
   PRINT *, i
21
END PROGRAM NestedIfBlockBasic
(-)refactoring-test-code/remove-branch-to-end-if/nested_if_block_basic/nested_if_block_basic.f90.result (+22 lines)
Added Link Here
1
! Using a nested IF block check that GOTO of inner IF
2
! block is still considered an outer GOTO statement 
3
! so a CONTINUE statement is inserted and that GOTO
4
! (and other outer GOTOs) target the new CONTINUE statement
5
6
PROGRAM NestedIfBlockBasic
7
   INTEGER :: k, i
8
   READ(*,*) k
9
   IF (k.lt.10) THEN
10
     GOTO 30
11
   END IF
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100
15
     IF (i.lt.10) THEN
16
       GOTO 20
17
     END IF
18
     i = i - 10
19
20 END IF                       !<<<<< 19, 1, 19, 10, pass
20
30 CONTINUE
21
   PRINT *, i
22
END PROGRAM NestedIfBlockBasic
(-)refactoring-test-code/remove-branch-to-end-if/nested_if_block_branch_to_immediate_inner_end_if/nested_if_block_branch_to_immediate_inner_end_if.f90 (+21 lines)
Added Link Here
1
! Only GOTO targets the selected END IF for refactoring
2
! but since a refactoring would not make any changes
3
! by design we fail and warn the user that no change
4
! would occur.
5
6
PROGRAM nested_if_block_branch_to_immediate_inner_end_if
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
30     END IF		!<<<<< 16, 1, 16, 9, fail-initial
17
40     CONTINUE
18
10 END IF
19
20 CONTINUE
20
   PRINT *, 'sum:', sum
21
END PROGRAM nested_if_block_branch_to_immediate_inner_end_if
(-)refactoring-test-code/remove-branch-to-end-if/nested_if_block_branch_to_immediate_inner_end_if/nested_if_block_branch_to_immediate_inner_end_if.f90.result (+21 lines)
Added Link Here
1
! Only GOTO targets the selected END IF for refactoring
2
! but since a refactoring would not make any changes
3
! by design we fail and warn the user that no change
4
! would occur.
5
6
PROGRAM nested_if_block_branch_to_immediate_inner_end_if
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
30     END IF		!<<<<< 16, 1, 16, 9, fail-initial
17
40     CONTINUE
18
10 END IF
19
20 CONTINUE
20
   PRINT *, 'sum:', sum
21
END PROGRAM nested_if_block_branch_to_immediate_inner_end_if
(-)refactoring-test-code/remove-branch-to-end-if/nested_if_block_branch_to_immediate_outer_end_if/nested_if_block_branch_to_immediate_outer_end_if.f90 (+22 lines)
Added Link Here
1
! Only GOTO targets the selected END IF for refactoring
2
! but since a refactoring would not make any changes
3
! by design we fail and warn the user that no change
4
! would occur. (Other GOTOs target other labels.)
5
6
PROGRAM nested_if_block_branch_to_immediate_inner_end_ifsubroutine
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
30     END IF
17
40     CONTINUE
18
       GOTO 10
19
10 END IF                           !<<<<< 19, 1, 19, 9, fail-initial
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
END PROGRAM nested_if_block_branch_to_immediate_inner_end_ifsubroutine
(-)refactoring-test-code/remove-branch-to-end-if/nested_if_block_branch_to_immediate_outer_end_if/nested_if_block_branch_to_immediate_outer_end_if.f90.result (+22 lines)
Added Link Here
1
! Only GOTO targets the selected END IF for refactoring
2
! but since a refactoring would not make any changes
3
! by design we fail and warn the user that no change
4
! would occur. (Other GOTOs target other labels.)
5
6
PROGRAM nested_if_block_branch_to_immediate_inner_end_ifsubroutine
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       sum = sum + i
12
       IF (sum.ge.100) THEN
13
          GOTO 30
14
       ELSE
15
          sum = sum + sum
16
30     END IF
17
40     CONTINUE
18
       GOTO 10
19
10 END IF                           !<<<<< 19, 1, 19, 9, fail-initial
20
20 CONTINUE
21
   PRINT *, 'sum:', sum
22
END PROGRAM nested_if_block_branch_to_immediate_inner_end_ifsubroutine
(-)refactoring-test-code/remove-branch-to-end-if/test-branch_end_if_label/test-branch_end_if_label.f90 (+17 lines)
Added Link Here
1
! Outer GOTO targets selected END IF so insert
2
! a CONTINUE statement and retarget its label.
3
! Remove END IF label since no inner GOTO
4
! statement exists
5
6
PROGRAM test_branch_end_if_label
7
   INTEGER :: k, i
8
   READ(*,*) k
9
   IF (k.lt.10) THEN
10
     GOTO 20
11
   END IF
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100
15
20 END IF  !<<<<< 15, 4, 15, 9, pass
16
   PRINT *, i
17
END PROGRAM test_branch_end_if_label
(-)refactoring-test-code/remove-branch-to-end-if/test-branch_end_if_label/test-branch_end_if_label.f90.result (+18 lines)
Added Link Here
1
! Outer GOTO targets selected END IF so insert
2
! a CONTINUE statement and retarget its label.
3
! Remove END IF label since no inner GOTO
4
! statement exists
5
6
PROGRAM test_branch_end_if_label
7
   INTEGER :: k, i
8
   READ(*,*) k
9
   IF (k.lt.10) THEN
10
     GOTO 20
11
   END IF
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100
15
   END IF  !<<<<< 15, 4, 15, 9, pass
16
20 CONTINUE
17
   PRINT *, i
18
END PROGRAM test_branch_end_if_label
(-)refactoring-test-code/remove-branch-to-end-if/test-branch_to_immediate_end_if/test-branch_to_immediate_end_if.f90 (+16 lines)
Added Link Here
1
! GOTO statement is inner GOTO for selected END IF
2
! so no change is expected. By design we warn the
3
! user that no change will be made.
4
5
PROGRAM test_branch_to_immediate_end_if
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     GOTO 20
10
20 END IF	!<<<<< 10, 1, 10, 9, fail-initial
11
   i = k - 10
12
   IF (i.gt.100)  THEN
13
     i = i - 100  
14
   END IF
15
   PRINT *, i
16
END PROGRAM test_branch_to_immediate_end_if
(-)refactoring-test-code/remove-branch-to-end-if/test-branch_to_immediate_end_if/test-branch_to_immediate_end_if.f90.result (+16 lines)
Added Link Here
1
! GOTO statement is inner GOTO for selected END IF
2
! so no change is expected. By design we warn the
3
! user that no change will be made.
4
5
PROGRAM test_branch_to_immediate_end_if
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     GOTO 20
10
20 END IF	!<<<<< 10, 1, 10, 9, fail-initial
11
   i = k - 10
12
   IF (i.gt.100)  THEN
13
     i = i - 100  
14
   END IF
15
   PRINT *, i
16
END PROGRAM test_branch_to_immediate_end_if
(-)refactoring-test-code/remove-branch-to-end-if/test-branch_to_immediate_end_if_with_continue_after_end_if/test-branch_to_immediate_end_if_with_continue_after_end_if.f90 (+17 lines)
Added Link Here
1
! By design if no GOTOs target the END IF statement even
2
! if a labels CONTINUE exists no refactoring should take
3
! place and the user will be notified as such.
4
5
PROGRAM branch_to_immediate_end_if_with_continue_after_end_if
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     GOTO 20
10
20 END IF	!<<<<< 10, 1, 10, 9, fail-initial
11
30 CONTINUE
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100  
15
   END IF
16
   PRINT *, i
17
END PROGRAM branch_to_immediate_end_if_with_continue_after_end_if
(-)refactoring-test-code/remove-branch-to-end-if/test-branch_to_immediate_end_if_with_continue_after_end_if/test-branch_to_immediate_end_if_with_continue_after_end_if.f90.result (+17 lines)
Added Link Here
1
! By design if no GOTOs target the END IF statement even
2
! if a labels CONTINUE exists no refactoring should take
3
! place and the user will be notified as such.
4
5
PROGRAM branch_to_immediate_end_if_with_continue_after_end_if
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     GOTO 20
10
20 END IF	!<<<<< 10, 1, 10, 9, fail-initial
11
30 CONTINUE
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100  
15
   END IF
16
   PRINT *, i
17
END PROGRAM branch_to_immediate_end_if_with_continue_after_end_if
(-)refactoring-test-code/remove-branch-to-end-if/test-end_if_label_between_branch_to_end_if/test-end_if_label_between_branch_to_end_if.f90 (+17 lines)
Added Link Here
1
! When two labeled END IF blocks the outer GOTO that 
2
! targets the selected END IF block should be retargetted
3
! to a new CONTINUE statement and the original END IF label
4
! removed but other labeled END IF should remain.
5
6
PROGRAM test_end_if_label_between_branch_to_end_if
7
   INTEGER :: k, i
8
   READ(*,*) k
9
   IF (k.lt.10) THEN
10
     GOTO 30
11
20 END IF
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100  
15
30 END IF	!<<<<< 15, 1, 15, 9, pass
16
   PRINT *, i
17
END PROGRAM test_end_if_label_between_branch_to_end_if
(-)refactoring-test-code/remove-branch-to-end-if/test-end_if_label_between_branch_to_end_if/test-end_if_label_between_branch_to_end_if.f90.result (+18 lines)
Added Link Here
1
! When two labeled END IF blocks the outer GOTO that 
2
! targets the selected END IF block should be retargetted
3
! to a new CONTINUE statement and the original END IF label
4
! removed but other labeled END IF should remain.
5
6
PROGRAM test_end_if_label_between_branch_to_end_if
7
   INTEGER :: k, i
8
   READ(*,*) k
9
   IF (k.lt.10) THEN
10
     GOTO 30
11
20 END IF
12
   i = k - 10
13
   IF (i.gt.100)  THEN
14
     i = i - 100  
15
   END IF	!<<<<< 15, 1, 15, 9, pass
16
30 CONTINUE
17
   PRINT *, i
18
END PROGRAM test_end_if_label_between_branch_to_end_if
(-)refactoring-test-code/remove-branch-to-end-if/test-endif_continue_branch-1/test-endif_continue_branch-1.f90 (+20 lines)
Added Link Here
1
! With more DO and IF structures the outer GOTO
2
! statement should still be retargetted to the 
3
! existing CONTINUE statement and then remove the 
4
! label of the selected END IF statement.
5
6
PROGRAM test_endif_continue_branch_1
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       GOTO 10
12
     END IF
13
     sum = sum + i
14
     IF (sum.ge.100) THEN
15
       sum = sum + sum
16
       GOTO 30
17
10   END IF                         !<<<<< 17, 1, 17, 12, pass
18
20 CONTINUE
19
30 PRINT *, 'sum:', sum
20
END PROGRAM test_endif_continue_branch_1
(-)refactoring-test-code/remove-branch-to-end-if/test-endif_continue_branch-1/test-endif_continue_branch-1.f90.result (+20 lines)
Added Link Here
1
! With more DO and IF structures the outer GOTO
2
! statement should still be retargetted to the 
3
! existing CONTINUE statement and then remove the 
4
! label of the selected END IF statement.
5
6
PROGRAM test_endif_continue_branch_1
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       GOTO 20
12
     END IF
13
     sum = sum + i
14
     IF (sum.ge.100) THEN
15
       sum = sum + sum
16
       GOTO 30
17
     END IF                         !<<<<< 17, 1, 17, 12, pass
18
20 CONTINUE
19
30 PRINT *, 'sum:', sum
20
END PROGRAM test_endif_continue_branch_1
(-)refactoring-test-code/remove-branch-to-end-if/test-endif_duplicate_continue/test-endif_duplicate_continue.f90 (+20 lines)
Added Link Here
1
! With two CONTINUE statements (unique labels) the
2
! outter GOTO statement should be refactored to target
3
! the CONTINUE statement immediately following the
4
! selected END IF statement.
5
6
PROGRAM test_endif_duplicate_continue
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       GOTO 10
12
     END IF
13
     sum = sum + i
14
     IF (sum.ge.100) THEN
15
       sum = sum + sum
16
10   END IF                         !<<<<< 16, 1, 16, 12, pass
17
20 CONTINUE
18
30 CONTINUE
19
40 PRINT *, 'sum:', sum
20
END PROGRAM test_endif_duplicate_continue
(-)refactoring-test-code/remove-branch-to-end-if/test-endif_duplicate_continue/test-endif_duplicate_continue.f90.result (+20 lines)
Added Link Here
1
! With two CONTINUE statements (unique labels) the
2
! outter GOTO statement should be refactored to target
3
! the CONTINUE statement immediately following the
4
! selected END IF statement.
5
6
PROGRAM test_endif_duplicate_continue
7
   INTEGER :: sum, i
8
   sum = 0
9
   DO 20, i = 1, 10
10
     IF (MOD(i,2).eq.0) THEN
11
       GOTO 20
12
     END IF
13
     sum = sum + i
14
     IF (sum.ge.100) THEN
15
       sum = sum + sum
16
     END IF                         !<<<<< 16, 1, 16, 12, pass
17
20 CONTINUE
18
30 CONTINUE
19
40 PRINT *, 'sum:', sum
20
END PROGRAM test_endif_duplicate_continue
(-)refactoring-test-code/remove-branch-to-end-if/test-invalid_selection/test-invalid_selection.f90 (+16 lines)
Added Link Here
1
! Refactoring requires that a labeled END IF is selected.
2
! This test checks when user selects something else
3
! the refactoring should not proceed.
4
5
PROGRAM test_invalid_selection
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     PRINT *, k
10
20 END IF
11
   i = k - 10
12
   IF (i.gt.100)  THEN
13
     i = i - 100  
14
30 END IF
15
   PRINT *, i               !<<<<< 15, 4, 15, 14, fail-initial
16
END PROGRAM test_invalid_selection
(-)refactoring-test-code/remove-branch-to-end-if/test-invalid_selection/test-invalid_selection.f90.result (+16 lines)
Added Link Here
1
! Refactoring requires that a labeled END IF is selected.
2
! This test checks when user selects something else
3
! the refactoring should not proceed.
4
5
PROGRAM test_invalid_selection
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     PRINT *, k
10
20 END IF
11
   i = k - 10
12
   IF (i.gt.100)  THEN
13
     i = i - 100  
14
30 END IF
15
   PRINT *, i               !<<<<< 15, 4, 15, 14, fail-initial
16
END PROGRAM test_invalid_selection
(-)refactoring-test-code/remove-branch-to-end-if/test-nested_if_blocks/test-nested_if_blocks.f90 (+21 lines)
Added Link Here
1
! Even with more complicated nested IF and DO structure
2
! since any GOTO inside any statements of the selected
3
! END IF line are considered inner IFs then it should
4
! be retargetted to the following CONTINIUE statement
5
! and the original END IF label removed.
6
7
PROGRAM test_nested_if_blocks
8
   INTEGER :: sum, i
9
   sum = 0
10
   DO 20, i = 1, 10
11
     IF (MOD(i,2).eq.0) THEN
12
       sum = sum + i
13
       IF (sum.ge.100) THEN
14
          GOTO 10
15
       ELSE
16
          sum = sum + sum
17
       END IF
18
10 END IF                           !<<<<< 18, 1, 18, 10, fail-initial
19
20 CONTINUE
20
   PRINT *, 'sum:', sum
21
END PROGRAM test_nested_if_blocks
(-)refactoring-test-code/remove-branch-to-end-if/test-nested_if_blocks/test-nested_if_blocks.f90.result (+21 lines)
Added Link Here
1
! Even with more complicated nested IF and DO structure
2
! since any GOTO inside any statements of the selected
3
! END IF line are considered inner IFs then it should
4
! be retargetted to the following CONTINIUE statement
5
! and the original END IF label removed.
6
7
PROGRAM test_nested_if_blocks
8
   INTEGER :: sum, i
9
   sum = 0
10
   DO 20, i = 1, 10
11
     IF (MOD(i,2).eq.0) THEN
12
       sum = sum + i
13
       IF (sum.ge.100) THEN
14
          GOTO 10
15
       ELSE
16
          sum = sum + sum
17
       END IF
18
10 END IF                           !<<<<< 18, 1, 18, 10, fail-initial
19
20 CONTINUE
20
   PRINT *, 'sum:', sum
21
END PROGRAM test_nested_if_blocks
(-)refactoring-test-code/remove-branch-to-end-if/test-no_branch_to_end_if_label/test-no_branch_to_end_if_label.f90 (+16 lines)
Added Link Here
1
! Test if no GOTOs exist in PROGRAM then no change
2
! will occur from the refactoring so the user is 
3
! warned and the refactoring halted.
4
5
PROGRAM test_no_branch_to_end_if_label
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     PRINT *, k
10
20 END IF
11
   i = k - 10
12
   IF (i.gt.100)  THEN
13
     i = i - 100  
14
30 END IF	!<<<<< 14, 1, 14, 9, fail-initial
15
   PRINT *, i
16
END PROGRAM test_no_branch_to_end_if_label
(-)refactoring-test-code/remove-branch-to-end-if/test-no_branch_to_end_if_label/test-no_branch_to_end_if_label.f90.result (+16 lines)
Added Link Here
1
! Test if no GOTOs exist in PROGRAM then no change
2
! will occur from the refactoring so the user is 
3
! warned and the refactoring halted.
4
5
PROGRAM test_no_branch_to_end_if_label
6
   INTEGER :: k, i
7
   READ(*,*) k
8
   IF (k.lt.10) THEN
9
     PRINT *, k
10
20 END IF
11
   i = k - 10
12
   IF (i.gt.100)  THEN
13
     i = i - 100  
14
30 END IF	!<<<<< 14, 1, 14, 9, fail-initial
15
   PRINT *, i
16
END PROGRAM test_no_branch_to_end_if_label
(-)refactoring-test-code/remove-branch-to-end-if/test-numbered_statement_after_continue/test-numbered_statement_after_continue.f90 (+20 lines)
Added Link Here
1
! GOTO statement is an outer IF block so existing CONTINIUE
2
! statement is targetted and since no inner GOTOs remain
3
! END if label is removed. (more complicated DO/IF structure
4
! to make sure refactoring is unaffected by other program  
5
! structures.)
6
7
PROGRAM test_numbered_statement_after_continue
8
   INTEGER :: sum, i
9
   sum = 0
10
   DO 20, i = 1, 10
11
     IF (MOD(i,2).eq.0) THEN
12
       GOTO 10
13
     END IF
14
     sum = sum + i
15
     IF (sum.ge.100) THEN
16
       sum = sum + sum
17
10   END IF                     !<<<<< 17, 1, 17, 12, pass
18
20 CONTINUE
19
30 PRINT *, 'sum:', sum
20
END PROGRAM test_numbered_statement_after_continue
(-)refactoring-test-code/remove-branch-to-end-if/test-numbered_statement_after_continue/test-numbered_statement_after_continue.f90.result (+20 lines)
Added Link Here
1
! GOTO statement is an outer IF block so existing CONTINIUE
2
! statement is targetted and since no inner GOTOs remain
3
! END if label is removed. (more complicated DO/IF structure
4
! to make sure refactoring is unaffected by other program  
5
! structures.)
6
7
PROGRAM test_numbered_statement_after_continue
8
   INTEGER :: sum, i
9
   sum = 0
10
   DO 20, i = 1, 10
11
     IF (MOD(i,2).eq.0) THEN
12
       GOTO 20
13
     END IF
14
     sum = sum + i
15
     IF (sum.ge.100) THEN
16
       sum = sum + sum
17
     END IF                     !<<<<< 17, 1, 17, 12, pass
18
20 CONTINUE
19
30 PRINT *, 'sum:', sum
20
END PROGRAM test_numbered_statement_after_continue
(-)refactoring-test-code/remove-pause-stmt/pause_as_only_stmt/pause_as_only_stmt.f90 (+6 lines)
Added Link Here
1
! Checks for basic replacement of a PAUSE statement
2
! with PRINT and READ.
3
4
PROGRAM pause_as_only_stmt
5
   PAUSE 'mid job'	!<<<<< 5, 5, 5, 7, pass
6
END PROGRAM pause_as_only_stmt
(-)refactoring-test-code/remove-pause-stmt/pause_as_only_stmt/pause_as_only_stmt.f90.result (+7 lines)
Added Link Here
1
! Checks for basic replacement of a PAUSE statement
2
! with PRINT and READ.
3
4
PROGRAM pause_as_only_stmt
5
   PRINT *, 'mid job'	!<<<<< 5, 5, 5, 7, pass
6
   READ (*, *)
7
END PROGRAM pause_as_only_stmt
(-)refactoring-test-code/remove-pause-stmt/pause_in_subroutine/pause_in_subroutine.f90 (+18 lines)
Added Link Here
1
! Checks for basic replacement of a PAUSE statement
2
! with PRINT and READ while PAUSE statement is in
3
! unit other than PROGRAM, e.g. SUBROUTINE.
4
5
PROGRAM PauseInSubroutine
6
  INTEGER :: i
7
  DO i = 1, 100
8
    IF (i == 50) THEN
9
      CALL CALLPRINT
10
    END IF
11
  END DO
12
  PRINT *, 'i=', i
13
END PROGRAM PauseInSubroutine
14
15
16
SUBROUTINE CALLPRINT
17
   PAUSE 'mid job'              !<<<<< 17, 4, 17, 19, pass
18
END
(-)refactoring-test-code/remove-pause-stmt/pause_in_subroutine/pause_in_subroutine.f90.result (+19 lines)
Added Link Here
1
! Checks for basic replacement of a PAUSE statement
2
! with PRINT and READ while PAUSE statement is in
3
! unit other than PROGRAM, e.g. SUBROUTINE.
4
5
PROGRAM PauseInSubroutine
6
  INTEGER :: i
7
  DO i = 1, 100
8
    IF (i == 50) THEN
9
      CALL CALLPRINT
10
    END IF
11
  END DO
12
  PRINT *, 'i=', i
13
END PROGRAM PauseInSubroutine
14
15
16
SUBROUTINE CALLPRINT
17
   PRINT *, 'mid job'              !<<<<< 17, 4, 17, 19, pass
18
   READ (*, *)
19
END
(-)refactoring-test-code/remove-pause-stmt/pause_nested_in_if_and_do_loop/pause_nested_in_if_and_do_loop.f90 (+14 lines)
Added Link Here
1
! Checks for replacement of a PAUSE statement
2
! with PRINT and READ while PAUSE statement is in
3
! a nested DO/IF block to make sure there are no
4
! dependencies on surrounding code.
5
6
PROGRAM pause_nested_in_if_and_do_loop
7
  INTEGER :: i
8
  DO i = 1, 100
9
    IF (i == 50) THEN
10
      PAUSE 'mid job'	!<<<<< 10, 7, 10, 21, pass
11
    END IF
12
  END DO
13
  PRINT *, 'i=', i
14
END PROGRAM pause_nested_in_if_and_do_loop
(-)refactoring-test-code/remove-pause-stmt/pause_nested_in_if_and_do_loop/pause_nested_in_if_and_do_loop.f90.result (+15 lines)
Added Link Here
1
! Checks for replacement of a PAUSE statement
2
! with PRINT and READ while PAUSE statement is in
3
! a nested DO/IF block to make sure there are no
4
! dependencies on surrounding code.
5
6
PROGRAM pause_nested_in_if_and_do_loop
7
  INTEGER :: i
8
  DO i = 1, 100
9
    IF (i == 50) THEN
10
      PRINT *, 'mid job'	!<<<<< 10, 7, 10, 21, pass
11
      READ (*, *)
12
    END IF
13
  END DO
14
  PRINT *, 'i=', i
15
END PROGRAM pause_nested_in_if_and_do_loop
(-)refactoring-test-code/remove-pause-stmt/pause_no_message/pause_no_message.f90 (+13 lines)
Added Link Here
1
! Check when no PAUSE message provided that
2
! an empty string is inserted in the 
3
! final refactoring.
4
5
PROGRAM pause_no_message
6
  INTEGER :: i
7
  DO i = 1, 100
8
    IF (i == 50) THEN
9
      PAUSE	!<<<<< 9, 7, 9, 11, pass
10
    END IF
11
  END DO
12
  PRINT *, 'i=', i
13
END PROGRAM pause_no_message
(-)refactoring-test-code/remove-pause-stmt/pause_no_message/pause_no_message.f90.result (+14 lines)
Added Link Here
1
! Check when no PAUSE message provided that
2
! an empty string is inserted in the 
3
! final refactoring.
4
5
PROGRAM pause_no_message
6
  INTEGER :: i
7
  DO i = 1, 100
8
    IF (i == 50) THEN
9
      PRINT *, ''	!<<<<< 9, 7, 9, 11, pass
10
      READ (*, *)
11
    END IF
12
  END DO
13
  PRINT *, 'i=', i
14
END PROGRAM pause_no_message
(-)refactoring-test-code/remove-pause-stmt/pause_not_selected/pause_not_selected.f90 (+13 lines)
Added Link Here
1
! Refactoring requires that PAUSE statement be
2
! selected. Check that no refactoring occurs
3
! when PAUSE is not selected.
4
5
PROGRAM pause_not_selected
6
  INTEGER :: i
7
  DO i = 1, 100
8
    IF (i == 50) THEN
9
      PAUSE 'mid job'
10
    END IF
11
  END DO
12
  PRINT *, 'i=', i	!<<<<< 12, 3, 12, 5, fail-initial
13
END PROGRAM pause_not_selected
(-)refactoring-test-code/remove-pause-stmt/pause_not_selected/pause_not_selected.f90.result (+13 lines)
Added Link Here
1
! Refactoring requires that PAUSE statement be
2
! selected. Check that no refactoring occurs
3
! when PAUSE is not selected.
4
5
PROGRAM pause_not_selected
6
  INTEGER :: i
7
  DO i = 1, 100
8
    IF (i == 50) THEN
9
      PAUSE 'mid job'
10
    END IF
11
  END DO
12
  PRINT *, 'i=', i	!<<<<< 12, 3, 12, 5, fail-initial
13
END PROGRAM pause_not_selected
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/equal-lb-ub/equal-lb-ub.f90 (+11 lines)
Added Link Here
1
! When upper and lower bounds are the same value
2
! refactoring should proceed with same value used.
3
4
PROGRAM EqualLbUb
5
  REAL :: counter, sum
6
  sum = 0.0
7
  DO counter = 1.2, 1.2, 0.1        !<<<<< 7, 3, 7, 29, 0, pass
8
    sum = sum + counter
9
  END DO
10
  PRINT *, sum
11
END PROGRAM EqualLbUb
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/equal-lb-ub/equal-lb-ub.f90.result (+16 lines)
Added Link Here
1
! When upper and lower bounds are the same value
2
! refactoring should proceed with same value used.
3
4
PROGRAM EqualLbUb
5
  REAL :: counter, sum
6
  sum = 0.0
7
  counter = 1.2
8
  DO                                !<<<<< 7, 3, 7, 29, 0, pass
9
    sum = sum + counter
10
    counter = counter - 0.1
11
    IF(counter < 1.2) THEN
12
      EXIT
13
    END IF
14
  END DO
15
  PRINT *, sum
16
END PROGRAM EqualLbUb
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/integer-control-variable/integer-control-variable.f90 (+12 lines)
Added Link Here
1
! Loop control variable declared as an INTEGER.
2
! Refactoring explicitly requires a REAL or DOUBLE
3
! type to proceed.
4
5
PROGRAM IntegerControlVariable
6
  INTEGER :: counter, sum
7
  sum = 0
8
  DO counter = 1, 10, 1        !<<<<< 8, 3, 8, 24, 0, fail-final
9
    sum = sum + counter
10
  END DO
11
  PRINT *, sum
12
END PROGRAM IntegerControlVariable
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/integer-control-variable/integer-control-variable.f90.result (+12 lines)
Added Link Here
1
! Loop control variable declared as an INTEGER.
2
! Refactoring explicitly requires a REAL or DOUBLE
3
! type to proceed.
4
5
PROGRAM IntegerControlVariable
6
  INTEGER :: counter, sum
7
  sum = 0
8
  DO counter = 1, 10, 1        !<<<<< 8, 3, 8, 24, 0, fail-final
9
    sum = sum + counter
10
  END DO
11
  PRINT *, sum
12
END PROGRAM IntegerControlVariable
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement-do-while/nested-do-double-inner-decrement-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleInnerDecrementDoWhile
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    DO counterin = 1.8, 1.2, 0.1                    !<<<<< 12, 5, 12, 33, 1, pass
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoDoubleInnerDecrementDoWhile
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement-do-while/nested-do-double-inner-decrement-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleInnerDecrementDoWhile
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    counterin = 1.8
13
    DO WHILE (counterin >= 1.2)                    !<<<<< 12, 5, 12, 33, 1, pass
14
      sumin = sumin + counterin
15
      counterin = counterin - 0.1
16
    END DO
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoDoubleInnerDecrementDoWhile
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement-implicit-do-while/nested-do-double-inner-decrement-implicit-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleInnerDecrementImplicit
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    DO counterin = 1.8, 1.2                         !<<<<< 12, 5, 12, 33, 1, pass
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoDoubleInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement-implicit-do-while/nested-do-double-inner-decrement-implicit-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleInnerDecrementImplicit
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    counterin = 1.8
13
    DO WHILE (counterin >= 1.2)                         !<<<<< 12, 5, 12, 33, 1, pass
14
      sumin = sumin + counterin
15
      counterin = counterin - 1
16
    END DO
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoDoubleInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement-implicit/nested-do-double-inner-decrement-implicit.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - implicit step count.
4
5
PROGRAM NestedDoDoubleInnerDecrementImplicit
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    DO counterin = 1.8, 1.2                         !<<<<< 11, 5, 11, 33, 0, pass
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoDoubleInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement-implicit/nested-do-double-inner-decrement-implicit.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - implicit step count.
4
5
PROGRAM NestedDoDoubleInnerDecrementImplicit
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    counterin = 1.8
12
    DO                                              !<<<<< 11, 5, 11, 33, 0, pass
13
      sumin = sumin + counterin
14
      counterin = counterin - 1
15
      IF(counterin < 1.2) THEN
16
        EXIT
17
      END IF
18
    END DO
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoDoubleInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement/nested-do-double-inner-decrement.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - explicit step count.
4
5
PROGRAM NestedDoDoubleInnerDecrement
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    DO counterin = 1.8, 1.2, 0.1                    !<<<<< 11, 5, 11, 33, 0, pass
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoDoubleInnerDecrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-inner-decrement/nested-do-double-inner-decrement.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - DOUBLE data type
3
! and decrement behavior - explicit step count.
4
5
PROGRAM NestedDoDoubleInnerDecrement
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    counterin = 1.8
12
    DO                                              !<<<<< 11, 5, 11, 33, 0, pass
13
      sumin = sumin + counterin
14
      counterin = counterin - 0.1
15
      IF(counterin < 1.2) THEN
16
        EXIT
17
      END IF
18
    END DO
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoDoubleInnerDecrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment-do-while/nested-do-double-outer-increment-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleOuterIncrement
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1                    !<<<<< 10, 3, 10, 29, 1, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoDoubleOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment-do-while/nested-do-double-outer-increment-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleOuterIncrement
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  counter = 1.2
11
  DO WHILE (counter <= 1.8)                    !<<<<< 10, 3, 10, 29, 1, pass
12
    sum = sum + counter
13
    DO counterin = 1.2, 1.8, 0.1
14
      sumin = sumin + counterin
15
    END DO
16
    counter = counter + 0.1
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoDoubleOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment-implicit-do-while/nested-do-double-outer-increment-implicit-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleOuterIncrementImplicit
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8                         !<<<<< 10, 3, 10, 29, 1, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoDoubleOuterIncrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment-implicit-do-while/nested-do-double-outer-increment-implicit-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoDoubleOuterIncrementImplicit
7
  DOUBLE PRECISION :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  counter = 1.2
11
  DO WHILE (counter <= 1.8)                         !<<<<< 10, 3, 10, 29, 1, pass
12
    sum = sum + counter
13
    DO counterin = 1.2, 1.8, 0.1
14
      sumin = sumin + counterin
15
    END DO
16
    counter = counter + 1
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoDoubleOuterIncrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment-implicit/nested-do-double-outer-increment-implicit.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - implicit step count.
4
5
PROGRAM NestedDoDoubleOuterIncrementImplicit
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8                         !<<<<< 9, 3, 9, 29, 0, pass
10
    sum = sum + counter
11
    DO counterin = 1.2, 1.8, 0.1
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoDoubleOuterIncrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment-implicit/nested-do-double-outer-increment-implicit.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - implicit step count.
4
5
PROGRAM NestedDoDoubleOuterIncrementImplicit
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  counter = 1.2
10
  DO                                            !<<<<< 9, 3, 9, 29, 0, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
    counter = counter + 1
16
    IF(counter > 1.8) THEN
17
      EXIT
18
    END IF
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoDoubleOuterIncrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment/nested-do-double-outer-increment.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - explicit step count.
4
5
PROGRAM NestedDoDoubleOuterIncrement
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1                    !<<<<< 9, 3, 9, 29, 0, pass
10
    sum = sum + counter
11
    DO counterin = 1.2, 1.8, 0.1
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoDoubleOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-double-outer-increment/nested-do-double-outer-increment.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - DOUBLE data type
3
! and increment behavior - explicit step count.
4
5
PROGRAM NestedDoDoubleOuterIncrement
6
  DOUBLE PRECISION :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  counter = 1.2
10
  DO                                            !<<<<< 9, 3, 9, 29, 0, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
    counter = counter + 0.1
16
    IF(counter > 1.8) THEN
17
      EXIT
18
    END IF
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoDoubleOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement-do-while/nested-do-real-inner-decrement-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealInnerDecrement
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    DO counterin = 1.8, 1.2, 0.1                !<<<<< 12, 5, 12, 33, 1, pass
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoRealInnerDecrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement-do-while/nested-do-real-inner-decrement-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealInnerDecrement
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    counterin = 1.8
13
    DO WHILE (counterin >= 1.2)                !<<<<< 12, 5, 12, 33, 1, pass
14
      sumin = sumin + counterin
15
      counterin = counterin - 0.1
16
    END DO
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoRealInnerDecrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement-implicit-do-while/nested-do-real-inner-decrement-implicit-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealInnerDecrementImplicit
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    DO counterin = 1.8, 1.2                     !<<<<< 12, 5, 12, 33, 1, pass
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoRealInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement-implicit-do-while/nested-do-real-inner-decrement-implicit-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealInnerDecrementImplicit
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1
11
    sum = sum + counter
12
    counterin = 1.8
13
    DO WHILE (counterin >= 1.2)                     !<<<<< 12, 5, 12, 33, 1, pass
14
      sumin = sumin + counterin
15
      counterin = counterin - 1
16
    END DO
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoRealInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement-implicit/nested-do-real-inner-decrement-implicit.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
5
PROGRAM NestedDoRealInnerDecrementImplicit
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    DO counterin = 1.8, 1.2                     !<<<<< 11, 5, 11, 33, 0, pass
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoRealInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement-implicit/nested-do-real-inner-decrement-implicit.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
5
PROGRAM NestedDoRealInnerDecrementImplicit
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    counterin = 1.8
12
    DO                                          !<<<<< 11, 5, 11, 33, 0, pass
13
      sumin = sumin + counterin
14
      counterin = counterin - 1
15
      IF(counterin < 1.2) THEN
16
        EXIT
17
      END IF
18
    END DO
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoRealInnerDecrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement/nested-do-real-inner-decrement.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
5
PROGRAM NestedDoRealInnerDecrement
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    DO counterin = 1.8, 1.2, 0.1                !<<<<< 11, 5, 11, 33, 0, pass
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoRealInnerDecrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-inner-decrement/nested-do-real-inner-decrement.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select inner DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
5
PROGRAM NestedDoRealInnerDecrement
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1
10
    sum = sum + counter
11
    counterin = 1.8
12
    DO                                          !<<<<< 11, 5, 11, 33, 0, pass
13
      sumin = sumin + counterin
14
      counterin = counterin - 0.1
15
      IF(counterin < 1.2) THEN
16
        EXIT
17
      END IF
18
    END DO
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoRealInnerDecrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment-do-while/nested-do-real-outer-increment-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealOuterIncrement
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8, 0.1                    !<<<<< 10, 3, 10, 29, 1, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoRalOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment-do-while/nested-do-real-outer-increment-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealOuterIncrement
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  counter = 1.2
11
  DO WHILE (counter <= 1.8)                    !<<<<< 10, 3, 10, 29, 1, pass
12
    sum = sum + counter
13
    DO counterin = 1.2, 1.8, 0.1
14
      sumin = sumin + counterin
15
    END DO
16
    counter = counter + 0.1
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoRalOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment-implicit-do-while/nested-do-real-outer-increment-implicit-do-while.f90 (+17 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealOuterIncrementImplicitDoWhile
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  DO counter = 1.2, 1.8                         !<<<<< 10, 3, 10, 29, 1, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
  END DO
16
  PRINT *, sum
17
END PROGRAM NestedDoRealOuterIncrementImplicitDoWhile
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment-implicit-do-while/nested-do-real-outer-increment-implicit-do-while.f90.result (+19 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
! (This test selecting to replace with DO WHILE loop.)
5
6
PROGRAM NestedDoRealOuterIncrementImplicitDoWhile
7
  REAL :: counter, sum, counterin, sumin
8
  sum = 0.0
9
  sumin = 0.0
10
  counter = 1.2
11
  DO WHILE (counter <= 1.8)                         !<<<<< 10, 3, 10, 29, 1, pass
12
    sum = sum + counter
13
    DO counterin = 1.2, 1.8, 0.1
14
      sumin = sumin + counterin
15
    END DO
16
    counter = counter + 1
17
  END DO
18
  PRINT *, sum
19
END PROGRAM NestedDoRealOuterIncrementImplicitDoWhile
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment-implicit/nested-do-real-outer-increment-implicit.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
5
PROGRAM NestedDoRealOuterIncrementImplicit
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8                         !<<<<< 9, 3, 9, 29, 0, pass
10
    sum = sum + counter
11
    DO counterin = 1.2, 1.8, 0.1
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoRalOuterIncrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment-implicit/nested-do-real-outer-increment-implicit.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - implicit step count.
4
5
PROGRAM NestedDoRealOuterIncrementImplicit
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  counter = 1.2
10
  DO                                            !<<<<< 9, 3, 9, 29, 0, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
    counter = counter + 1
16
    IF(counter > 1.8) THEN
17
      EXIT
18
    END IF
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoRalOuterIncrementImplicit
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment/nested-do-real-outer-increment.f90 (+16 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
5
PROGRAM NestedDoRealOuterIncrement
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  DO counter = 1.2, 1.8, 0.1                    !<<<<< 9, 3, 9, 29, 0, pass
10
    sum = sum + counter
11
    DO counterin = 1.2, 1.8, 0.1
12
      sumin = sumin + counterin
13
    END DO
14
  END DO
15
  PRINT *, sum
16
END PROGRAM NestedDoRalOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/nested-do-real-outer-increment/nested-do-real-outer-increment.f90.result (+21 lines)
Added Link Here
1
! Check that nested DO loop doesn't affect refactoring
2
! behavior. Select outer DO loop - REAL data type
3
! and decrement behavior - explicit step count.
4
5
PROGRAM NestedDoRealOuterIncrement
6
  REAL :: counter, sum, counterin, sumin
7
  sum = 0.0
8
  sumin = 0.0
9
  counter = 1.2
10
  DO                                            !<<<<< 9, 3, 9, 29, 0, pass
11
    sum = sum + counter
12
    DO counterin = 1.2, 1.8, 0.1
13
      sumin = sumin + counterin
14
    END DO
15
    counter = counter + 0.1
16
    IF(counter > 1.8) THEN
17
      EXIT
18
    END IF
19
  END DO
20
  PRINT *, sum
21
END PROGRAM NestedDoRalOuterIncrement
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/test-invalid-selection/test-invalid-selection.f90 (+11 lines)
Added Link Here
1
! Controlled DO loop must be selected for refactoring.
2
! Test invalid selection that refactoring will no proceed.
3
4
PROGRAM TestInvalidSelection
5
  REAL :: counter, sum
6
  sum = 0.0
7
  DO counter = 1.2, 1.8, 0.1
8
    sum = sum + counter
9
  END DO
10
  PRINT *, sum                  !<<<<< 10,3,10,15, 0, fail-final
11
END PROGRAM TestInvalidSelection
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/test-invalid-selection/test-invalid-selection.result (+11 lines)
Added Link Here
1
! Controlled DO loop must be selected for refactoring.
2
! Test invalid selection that refactoring will no proceed.
3
4
PROGRAM TestInvalidSelection
5
  REAL :: counter, sum
6
  sum = 0.0
7
  DO counter = 1.2, 1.8, 0.1
8
    sum = sum + counter
9
  END DO
10
  PRINT *, sum                  !<<<<< 10,3,10,15, 0, fail-final
11
END PROGRAM TestInvalidSelection
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/uncontrolled-do-loop/uncontrolled-do-loop.f90 (+16 lines)
Added Link Here
1
! DO loop selected for refactoring must be a controlled
2
! DO loop otherwise refactoring will not proceed.
3
4
PROGRAM UncontrolledDoLoop
5
  REAL :: counter, sum
6
  sum = 0.0
7
  counter = 1.2
8
  DO                                !<<<<< 8,3,8,5, 0, fail-final
9
    sum = sum + counter
10
    counter = counter + 0.1
11
    IF (counter > 1.8) THEN
12
      EXIT
13
    END IF
14
  END DO
15
  PRINT *, sum
16
END PROGRAM UncontrolledDoLoop
(-)refactoring-test-code/remove-real-and-double-precision-loop-counters/uncontrolled-do-loop/uncontrolled-do-loop.result (+16 lines)
Added Link Here
1
! DO loop selected for refactoring must be a controlled
2
! DO loop otherwise refactoring will not proceed.
3
4
PROGRAM UncontrolledDoLoop
5
  REAL :: counter, sum
6
  sum = 0.0
7
  counter = 1.2
8
  DO                                !<<<<< 8,3,8,5, 0, fail-final
9
    sum = sum + counter
10
    counter = counter + 0.1
11
    IF (counter > 1.8) THEN
12
      EXIT
13
    END IF
14
  END DO
15
  PRINT *, sum
16
END PROGRAM UncontrolledDoLoop
(-)src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.tests.refactoring;
16
17
import junit.framework.Test;
18
19
import org.eclipse.photran.internal.core.refactoring.RemoveBranchToEndIfRefactoring;
20
import org.eclipse.photran.internal.tests.Activator;
21
import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers;
22
23
/**
24
 * Unit tests for the Remove Branch To End If Refactoring.
25
 * 
26
 * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka
27
 *         (wijenay2), Nicola Hall (nfhall2)
28
 */
29
public class RemoveBranchToEndIfTestSuite extends
30
    PhotranRefactoringTestSuiteFromMarkers<RemoveBranchToEndIfRefactoring>
31
{
32
    private static final String DIR = "refactoring-test-code/remove-branch-to-end-if";
33
34
    public static Test suite() throws Exception
35
    {
36
        return new RemoveBranchToEndIfTestSuite();
37
    }
38
39
    public RemoveBranchToEndIfTestSuite() throws Exception
40
    {
41
        super(Activator.getDefault(), "Running Remove Branch To End If Refactoring in", DIR,
42
            RemoveBranchToEndIfRefactoring.class);
43
    }
44
45
}
(-)src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.tests.refactoring;
16
17
import junit.framework.Test;
18
19
import org.eclipse.photran.internal.core.refactoring.RemovePauseStmtRefactoring;
20
import org.eclipse.photran.internal.tests.Activator;
21
import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers;
22
23
/**
24
 * Unit tests for the Remove Pause Statement Refactoring.
25
 * 
26
 * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka
27
 *         (wijenay2), Nicola Hall (nfhall2)
28
 */
29
public class RemovePauseStmtTestSuite extends
30
    PhotranRefactoringTestSuiteFromMarkers<RemovePauseStmtRefactoring>
31
{
32
    private static final String DIR = "refactoring-test-code/remove-pause-stmt";
33
34
    public static Test suite() throws Exception
35
    {
36
        return new RemovePauseStmtTestSuite();
37
    }
38
39
    public RemovePauseStmtTestSuite() throws Exception
40
    {
41
        super(Activator.getDefault(), "Running Remove Pause Stmt Refactoring in", DIR,
42
            RemovePauseStmtRefactoring.class);
43
    }
44
45
}
(-)src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.tests.refactoring;
16
17
import junit.framework.Test;
18
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.jface.text.TextSelection;
21
import org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring;
22
import org.eclipse.photran.internal.tests.Activator;
23
import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers;
24
25
/**
26
 * Unit tests for the Remove Branch To End If Refactoring.
27
 * 
28
 * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka
29
 *         (wijenay2), Nicola Hall (nfhall2)
30
 */
31
public class RemoveRealAndDoublePrecisionLoopCountersTestSuite extends
32
    PhotranRefactoringTestSuiteFromMarkers<RemoveRealAndDoublePrecisionLoopCountersRefactoring>
33
{
34
    private static final String DIR = "refactoring-test-code/remove-real-and-double-precision-loop-counters";
35
36
    public static Test suite() throws Exception
37
    {
38
        return new RemoveRealAndDoublePrecisionLoopCountersTestSuite();
39
    }
40
41
    public RemoveRealAndDoublePrecisionLoopCountersTestSuite() throws Exception
42
    {
43
        super(Activator.getDefault(),
44
            "Running Remove Real and Double Precision Loop Counters Refactoring in", DIR,
45
            RemoveRealAndDoublePrecisionLoopCountersRefactoring.class);
46
    }
47
48
    @Override
49
    protected boolean configureRefactoring(
50
        RemoveRealAndDoublePrecisionLoopCountersRefactoring refactoring, IFile file,
51
        TextSelection selection, String[] markerText)
52
    {
53
        boolean shouldSucceed = super
54
            .configureRefactoring(refactoring, file, selection, markerText);
55
56
        boolean shouldReplaceWithDoWhileLoop;
57
        if (markerText[4].equals("1"))
58
            shouldReplaceWithDoWhileLoop = true;
59
        else
60
            shouldReplaceWithDoWhileLoop = false;
61
        refactoring.setShouldReplaceWithDoWhileLoop(shouldReplaceWithDoWhileLoop);
62
63
        return shouldSucceed;
64
    }
65
}
(-)plugin.xml (+10 lines)
Lines 83-88 Link Here
83
         <editorRefactoring
83
         <editorRefactoring
84
         	class="org.eclipse.photran.internal.core.refactoring.RemoveComputedGoToRefactoring"
84
         	class="org.eclipse.photran.internal.core.refactoring.RemoveComputedGoToRefactoring"
85
         />
85
         />
86
         <editorRefactoring
87
         	class="org.eclipse.photran.internal.core.refactoring.RemoveBranchToEndIfRefactoring"
88
         />
89
         <editorRefactoring
90
            class="org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring"
91
            inputPage="org.eclipse.photran.internal.ui.refactoring.RemoveRealAndDoublePrecisionLoopCountersInputPage"
92
         />
93
         <editorRefactoring
94
         	class="org.eclipse.photran.internal.core.refactoring.RemovePauseStmtRefactoring"
95
         />
86
      </group>
96
      </group>
87
      <group><!-- Refactorings for performance/loop transformations -->
97
      <group><!-- Refactorings for performance/loop transformations -->
88
         <editorRefactoring
98
         <editorRefactoring
(-)src/org/eclipse/photran/internal/ui/refactoring/Messages.java (+16 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    UIUC - Initial API and implementation
9
 *    UIUC - Initial API and implementation
10
 *    Rita Chow - Photran Modifications
11
 *    Nicola Hall - Photran Modifications
12
 *    Jerry Hsiao - Photran Modifications
13
 *    Mark Mozolewski - Photran Modifications
14
 *    Chamil Wijenayaka - Photran Modifications
10
 *******************************************************************************/
15
 *******************************************************************************/
11
package org.eclipse.photran.internal.ui.refactoring;
16
package org.eclipse.photran.internal.ui.refactoring;
12
17
Lines 84-89 Link Here
84
    public static String RenameAction_MatchExternalSubprograms;
89
    public static String RenameAction_MatchExternalSubprograms;
85
90
86
    public static String RenameAction_RenameAtoB;
91
    public static String RenameAction_RenameAtoB;
92
    
93
    public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter;
94
95
    public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop;
96
    
97
    public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop;
98
    
99
    public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage;
100
    
101
    public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage;
102
    
87
    static
103
    static
88
    {
104
    {
89
        // initialize resource bundle
105
        // initialize resource bundle
(-)src/org/eclipse/photran/internal/ui/refactoring/RemoveRealAndDoublePrecisionLoopCountersInputPage.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Rita Chow - Initial Implementation
10
 *    Nicola Hall - Initial Implementation
11
 *    Jerry Hsiao - Initial Implementation
12
 *    Mark Mozolewski - Initial Implementation
13
 *    Chamil Wijenayaka - Initial Implementation
14
 *******************************************************************************/
15
package org.eclipse.photran.internal.ui.refactoring;
16
17
import org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring;
18
import org.eclipse.rephraserengine.ui.refactoring.CustomUserInputPage;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionListener;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Label;
26
27
/**
28
 * User input wizard page for the Change Keyword Case refactoring
29
 * 
30
 * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka
31
 *         (wijenay2), Nicola Hall (nfhall2)
32
 */
33
public class RemoveRealAndDoublePrecisionLoopCountersInputPage extends
34
    CustomUserInputPage<RemoveRealAndDoublePrecisionLoopCountersRefactoring>
35
{
36
    protected Button doWhileLoop;
37
38
    protected Button doLoop;
39
40
    @Override
41
    public void createControl(Composite parent)
42
    {
43
        Composite top = new Composite(parent, SWT.NONE);
44
        initializeDialogUnits(top);
45
        setControl(top);
46
47
        top.setLayout(new GridLayout(1, false));
48
49
        Composite group = top;
50
        Label instr = new Label(group, SWT.NONE);
51
        instr
52
            .setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter);
53
54
        doWhileLoop = new Button(group, SWT.RADIO);
55
        doWhileLoop
56
            .setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop);
57
        doWhileLoop.setSelection(true);
58
        doWhileLoop.addSelectionListener(new SelectionListener()
59
        {
60
            public void widgetDefaultSelected(SelectionEvent e)
61
            {
62
                widgetSelected(e);
63
            }
64
65
            public void widgetSelected(SelectionEvent e)
66
            {
67
                boolean isChecked = doLoop.getSelection();
68
                getRefactoring().setShouldReplaceWithDoWhileLoop(isChecked);
69
            }
70
        });
71
72
        doLoop = new Button(group, SWT.RADIO);
73
        doLoop
74
            .setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop);
75
76
        Label ok = new Label(group, SWT.NONE);
77
        ok.setText("\n" + Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage); //$NON-NLS-1$
78
        Label preview = new Label(group, SWT.NONE);
79
        preview
80
            .setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage);
81
    }
82
}
(-)src/org/eclipse/photran/internal/ui/refactoring/messages.properties (+5 lines)
Lines 31-33 Link Here
31
MoveFromModuleInputPage_selectDataMessage=Please select member data to move from module 
31
MoveFromModuleInputPage_selectDataMessage=Please select member data to move from module 
32
RenameAction_MatchExternalSubprograms=Match external subprograms with interfaces and external declarations
32
RenameAction_MatchExternalSubprograms=Match external subprograms with interfaces and external declarations
33
RenameAction_RenameAtoB=Rename {0} to
33
RenameAction_RenameAtoB=Rename {0} to
34
RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter=Replace real/double precision loop counter with:
35
RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop=DO Loop
36
RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop=DO WHILE Loop
37
RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage=Click OK to replace the real/double precision loop counter.
38
RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage=To see what the changes will be made, click Preview.

Return to bug 332492