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

Collapse All | Expand All

(-)src/org/eclipse/photran/internal/core/refactoring/MakeSaveExplicitRefactoring.java (+435 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Stephen Downs, Robert Samblanet, Kevin Schilling, Jon 
3
 * Woolwine, and Chad Zamzow
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    UIUC - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.photran.internal.core.refactoring;
13
14
import java.util.HashSet;
15
import java.util.Iterator;
16
import java.util.TreeSet;
17
18
import org.eclipse.core.internal.resources.SavedState;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
24
import org.eclipse.photran.core.IFortranAST;
25
import org.eclipse.photran.internal.core.analysis.binding.ScopingNode;
26
import org.eclipse.photran.internal.core.lexer.Terminal;
27
import org.eclipse.photran.internal.core.lexer.Token;
28
import org.eclipse.photran.internal.core.parser.ASTAssignmentStmtNode;
29
import org.eclipse.photran.internal.core.parser.ASTAttrSpecNode;
30
import org.eclipse.photran.internal.core.parser.ASTAttrSpecSeqNode;
31
import org.eclipse.photran.internal.core.parser.ASTDatalistNode;
32
import org.eclipse.photran.internal.core.parser.ASTDataStmtNode;
33
import org.eclipse.photran.internal.core.parser.ASTEntityDeclNode;
34
import org.eclipse.photran.internal.core.parser.ASTListNode;
35
import org.eclipse.photran.internal.core.parser.ASTSaveStmtNode;
36
import org.eclipse.photran.internal.core.parser.ASTSavedEntityNode;
37
import org.eclipse.photran.internal.core.parser.ASTSeparatedListNode;
38
import org.eclipse.photran.internal.core.parser.ASTTypeDeclarationStmtNode;
39
import org.eclipse.photran.internal.core.parser.ASTVariableNode;
40
import org.eclipse.photran.internal.core.parser.ASTVisitor;
41
import org.eclipse.photran.internal.core.parser.IASTListNode;
42
import org.eclipse.photran.internal.core.parser.IASTNode;
43
import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranResourceRefactoring;
44
import org.eclipse.photran.internal.core.refactoring.infrastructure.SourcePrinter;
45
import org.eclipse.photran.internal.core.reindenter.Reindenter;
46
47
/**
48
 * Makes all implicitly saved variables explicitly saved.
49
 * 
50
 * @author Stephen Downs
51
 * @author Robert Samblanet
52
 * @author Kevin Schilling
53
 * @author Jon Woolwine
54
 * @author Chad Zamzow
55
 */
56
@SuppressWarnings("all")
57
public class MakeSaveExplicitRefactoring extends FortranResourceRefactoring
58
{
59
    ///////////////////////////////////////////////////////////////////////////
60
    // Fields
61
    ///////////////////////////////////////////////////////////////////////////
62
63
    @Override
64
    public String getName()
65
    {
66
        return Messages.MakeSaveExplicitRefactoring_Name;
67
    }
68
    
69
    IFortranAST currAST = null;
70
71
    ///////////////////////////////////////////////////////////////////////////
72
    // Initial Preconditions
73
    ///////////////////////////////////////////////////////////////////////////
74
75
    /**
76
     * @see MoveSavedToCommonBlockRefactoring
77
     */
78
    @Override
79
    protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
80
    throws PreconditionFailure
81
    {
82
        ensureProjectHasRefactoringEnabled(status);
83
    }
84
85
    ///////////////////////////////////////////////////////////////////////////
86
    // Final Preconditions
87
    ///////////////////////////////////////////////////////////////////////////
88
89
    @Override
90
    protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) throws PreconditionFailure{
91
        try
92
        {
93
            for (IFile file : selectedFiles)
94
            {
95
                IFortranAST ast = vpg.acquirePermanentAST(file);
96
                if(ast == null)
97
                {
98
                    status.addError(Messages.bind(Messages.MakeSaveExplicitRefactoring_SelectedFileCannotBeParsed, file.getName()));
99
                }
100
                else
101
                {
102
                    currAST = ast;
103
                    makeChangesTo(file, ast, status, pm);
104
                    vpg.releaseAST(file);
105
                }
106
            }
107
        }
108
        finally
109
        {
110
            vpg.releaseAllASTs();
111
        }    
112
    }
113
114
    ///////////////////////////////////////////////////////////////////////////
115
    // Change
116
    ///////////////////////////////////////////////////////////////////////////
117
118
    @Override
119
    protected void doCreateChange(IProgressMonitor pm) throws CoreException, OperationCanceledException
120
    {
121
122
    }
123
    
124
    /**
125
     * Given an AST, makes the refactoring changes by calling the makeAllSaveAttributesExplicit function 
126
     * @param file
127
     * @param ast
128
     * @param status
129
     * @param pm
130
     * @throws PreconditionFailure
131
     */
132
    private void makeChangesTo(IFile file, IFortranAST ast, RefactoringStatus status, IProgressMonitor pm) throws PreconditionFailure
133
    {
134
        for (ScopingNode scope : ast.getRoot().getAllContainedScopes())
135
        {
136
            SavedVariableVisitor savedVariableVisitor = new SavedVariableVisitor();
137
            scope.accept(savedVariableVisitor);
138
            if(!savedVariableVisitor.hasGlobalSaveStmt() && !scope.isMainProgram())
139
            {
140
                HashSet<String> explicitlySavedVariables = savedVariableVisitor.getExplicitlySavedVariables();
141
                TreeSet<String> dataVariables = savedVariableVisitor.getDataBlockVariables();
142
                makeAllSaveAttributesExplicit(scope, explicitlySavedVariables, dataVariables);
143
            }
144
        }
145
        addChangeFromModifiedAST(file, pm);
146
    }
147
    
148
    /**
149
     * Makes all implicit saves explicit in the given scope
150
     * @param scope
151
     * @param explicitlySavedVariables
152
     * @param dataEntities
153
     * @throws PreconditionFailure
154
     */
155
    private void makeAllSaveAttributesExplicit(ScopingNode scope, HashSet<String> explicitlySavedVariables, TreeSet<String> dataEntities) 
156
    throws PreconditionFailure
157
    {
158
        if(scope.getBody() == null)
159
        {
160
            return;
161
        }
162
        
163
        for (IASTNode node : scope.getBody().getChildren())
164
        {
165
            if (node instanceof ASTTypeDeclarationStmtNode)
166
            {
167
                ASTTypeDeclarationStmtNode declarationNode = (ASTTypeDeclarationStmtNode)node;
168
                makeImplicitlySavedVariablesExplicitlySaved(scope, declarationNode, dataEntities, explicitlySavedVariables);
169
            }
170
        }
171
        
172
        //add all implicitly saved data block variables to a save statement
173
        for(String variable : dataEntities)
174
        {
175
            if(!explicitlySavedVariables.contains(variable.toLowerCase()))
176
            {
177
                addVariableToSaveStmt(scope, variable);
178
                explicitlySavedVariables.add(variable.toLowerCase());
179
            }
180
        }
181
    }
182
183
    /**
184
     * Helper function that adds SAVE to a type declaration
185
     * @param scope
186
     * @param typeDeclaration
187
     * @param dataEntities
188
     * @param savedEntities
189
     */
190
    private void makeImplicitlySavedVariablesExplicitlySaved(ScopingNode scope, ASTTypeDeclarationStmtNode typeDeclaration, TreeSet<String> dataEntities, HashSet<String> savedEntities)
191
    {
192
        IASTListNode<ASTEntityDeclNode> entityDeclList = typeDeclaration.getEntityDeclList();
193
        Iterator<ASTEntityDeclNode> declIterator = entityDeclList.iterator();
194
        boolean declContainsSavedAndUnsavedVariables = containsUnsavedAndSavedVariables(typeDeclaration, dataEntities);
195
        while(declIterator.hasNext())
196
        {
197
            ASTEntityDeclNode variableDeclaration = declIterator.next();
198
            if (isImplicitlySaved(scope, variableDeclaration, dataEntities) && 
199
                !savedEntities.contains(declarationVariableName(variableDeclaration).toLowerCase()))
200
            {
201
                if(!declContainsSavedAndUnsavedVariables)
202
                {
203
                    String declString = SourcePrinter.getSourceCodeFromASTNode(typeDeclaration);
204
                    ASTAttrSpecSeqNode attrSpecSeqNode = createSaveAttrSpecSeqNode(!declString.contains("::"));
205
    
206
                    // if there is no attrSpecSeq, create a new one and add it to the typeDeclaration
207
                    if( typeDeclaration.getAttrSpecSeq() == null )
208
                    {
209
                        IASTListNode<ASTAttrSpecSeqNode> attrSpecSeq = new ASTListNode<ASTAttrSpecSeqNode>( 1 );  
210
                        typeDeclaration.setAttrSpecSeq(attrSpecSeq);
211
                    }
212
    
213
                    // add Save attribute to attrSpecSeq
214
                    typeDeclaration.getAttrSpecSeq().add(attrSpecSeqNode);
215
                    
216
                    for(ASTEntityDeclNode decl : typeDeclaration.getEntityDeclList())
217
                    {
218
                        savedEntities.add(declarationVariableName(decl).toLowerCase());
219
                    }
220
                                        
221
                    return;
222
                }
223
                else
224
                {
225
                    String variableName = declarationVariableName(variableDeclaration);
226
                    savedEntities.add(variableName.toLowerCase());
227
                    addVariableToSaveStmt(scope, variableName);
228
                }
229
            }
230
        }
231
    }
232
233
    /**
234
     * Helper function that adds the given variable name to a global save statement in the given scope
235
     * @param scope
236
     * @param variableName
237
     */
238
    private void addVariableToSaveStmt(ScopingNode scope, String variableName)
239
    {
240
        ASTSavedEntityNode savedEntity = new ASTSavedEntityNode();
241
        Token savedEntityToken = new Token(Terminal.T_IDENT, variableName);
242
        savedEntity.setVariableName(savedEntityToken);
243
        for (IASTNode node : scope.getBody().getChildren())
244
        {
245
            if(node instanceof ASTSaveStmtNode)
246
            {
247
                IASTListNode<ASTSavedEntityNode> variableList = ((ASTSaveStmtNode)node).getVariableList();
248
                ASTSeparatedListNode<ASTSavedEntityNode> astSeparatedListNode = (ASTSeparatedListNode<ASTSavedEntityNode>)variableList;
249
                astSeparatedListNode.add(new Token(null, ", "), savedEntity);
250
                return;
251
            }
252
        }
253
        ASTSaveStmtNode newSaveStmt = (ASTSaveStmtNode)parseLiteralStatement("SAVE " + variableName);
254
        IASTListNode body = scope.getBody();
255
        body.add(0, newSaveStmt);
256
        Reindenter.reindent(newSaveStmt, currAST);
257
    }
258
259
    /**
260
     * Helper function that checks declaration lists to see if it contains both saved and unsaved variables
261
     * @param typeDeclaration
262
     * @param dataEntities
263
     * @return
264
     */
265
    private boolean containsUnsavedAndSavedVariables(ASTTypeDeclarationStmtNode typeDeclaration, TreeSet<String> dataEntities)
266
    {
267
        if(typeDeclaration.getEntityDeclList() == null) return false;
268
        boolean containsSaved = false, containsUnSaved = false;
269
        
270
        for(ASTEntityDeclNode decl : typeDeclaration.getEntityDeclList())
271
        {
272
            if (decl.getInitialization() == null
273
                && !dataEntities.contains(declarationVariableName(decl).toLowerCase()))
274
            {
275
                containsUnSaved = true;
276
            }
277
            else
278
            {
279
                containsSaved = true;
280
            }
281
        }
282
        return containsSaved && containsUnSaved;
283
    }
284
285
    /**
286
     * Helper function that extracts the declaration variable name from a declaration node
287
     * @param decl
288
     * @return
289
     */
290
    private String declarationVariableName(ASTEntityDeclNode decl)
291
    {
292
        return decl.getObjectName().getObjectName().getText();
293
    }
294
295
    /**
296
     * Helper function that checks to see if a given variable is implicitly saved
297
     * @param scope
298
     * @param variableDeclaration
299
     * @param dataEntities
300
     * @return
301
     */
302
    private boolean isImplicitlySaved(ScopingNode scope, ASTEntityDeclNode variableDeclaration, TreeSet<String> dataEntities)
303
    {
304
        return (variableDeclaration.getInitialization() != null ||
305
            dataEntities.contains(declarationVariableName(variableDeclaration).toLowerCase()));
306
    }
307
308
    /**
309
     * Creates a new AttrSpecSeqNode with SAVE attribute
310
     * @return new AttrSpecSeqNode with SAVE attribute
311
     */
312
    private ASTAttrSpecSeqNode createSaveAttrSpecSeqNode(boolean addDblColon)
313
    {
314
        ASTAttrSpecSeqNode attrSpecSeqNode = new ASTAttrSpecSeqNode();
315
        ASTAttrSpecNode attrSpecNode = new ASTAttrSpecNode();
316
        
317
        Token token;
318
        if(addDblColon)
319
        {
320
            token = new Token(null, ", SAVE ::" );
321
        }
322
        else 
323
        {
324
            token = new Token(null, ", SAVE" );
325
        }
326
            
327
        attrSpecNode.setIsSave( token );
328
        attrSpecSeqNode.setAttrSpec(attrSpecNode);
329
        return attrSpecSeqNode;
330
    }
331
    
332
    /**
333
     * Saved Variable Visitor class
334
     * 
335
     * Iterates through all nodes in a scope. While doing this, it checks three different cases:
336
     * 1) If the node is a save statement, it checks to see if it is a global save statement.
337
     * If it isn't, it adds all the saved variables to the explicitlySavedVariables list.
338
     * 2) If the node is a declaration, it checks to see if it has been explicitly saved. If it
339
     * has, it adds the variable to the explicitlySavedVariables list.
340
     * 3) If the node is a data statement, it adds all variables in the data block to the 
341
     * dataBlockVariables list.
342
     * 
343
     * @author ShinSheep
344
     */
345
    private class SavedVariableVisitor extends ASTVisitor
346
    {
347
        private boolean hasGlobalSaveStmt;
348
        private HashSet<String> explicitlySavedVariables;
349
        private TreeSet<String> dataBlockVariables;
350
        private ASTSaveStmtNode saveStmt;
351
        
352
        public TreeSet<String> getDataBlockVariables()
353
        {
354
            return dataBlockVariables;
355
        }
356
357
        public HashSet<String> getExplicitlySavedVariables()
358
        {
359
            return explicitlySavedVariables;
360
        }
361
362
        public boolean hasGlobalSaveStmt()
363
        {
364
            return hasGlobalSaveStmt;
365
        }
366
367
        public SavedVariableVisitor()
368
        {
369
            super();
370
            this.hasGlobalSaveStmt = false;
371
            explicitlySavedVariables = new HashSet<String>();
372
            dataBlockVariables = new TreeSet<String>();
373
            saveStmt = null;
374
        }
375
376
        @Override
377
        public void visitASTSaveStmtNode(ASTSaveStmtNode node)
378
        {
379
            this.saveStmt = node;
380
            if (node.getVariableList() == null)
381
            {
382
                hasGlobalSaveStmt = true;
383
            }
384
            else
385
            {
386
                for(ASTSavedEntityNode variable : node.getVariableList())
387
                {
388
                   explicitlySavedVariables.add(variable.getVariableName().getText().toLowerCase());
389
                }
390
            }
391
        }
392
        
393
        @Override
394
        public void visitASTTypeDeclarationStmtNode(ASTTypeDeclarationStmtNode node)
395
        {
396
            IASTListNode<ASTAttrSpecSeqNode> attrSpecSeq = node.getAttrSpecSeq();
397
            if(attrSpecSeq != null)
398
            {
399
                Iterator<ASTAttrSpecSeqNode> specIterator = attrSpecSeq.iterator();
400
                while(specIterator.hasNext())
401
                {
402
                    ASTAttrSpecSeqNode attrSpecSeqNode = specIterator.next();
403
                    ASTAttrSpecNode attrSpecNode = attrSpecSeqNode.getAttrSpec();
404
                    if(attrSpecNode != null && attrSpecNode.isSave())
405
                    {
406
                        for(ASTEntityDeclNode variable : node.getEntityDeclList())
407
                        {
408
                            explicitlySavedVariables.add(variable.getObjectName().getObjectName().getText().toLowerCase());
409
                        }
410
                    }
411
                }
412
            }
413
        }
414
        
415
        @Override
416
        public void visitASTDataStmtNode(ASTDataStmtNode node)
417
        {
418
            IASTListNode<ASTDatalistNode> dataList = ((ASTDataStmtNode)node).getDatalist();
419
            for (IASTNode dataEntity : dataList.getChildren())
420
            {
421
                ASTDatalistNode dataListNode = (ASTDatalistNode)dataEntity;
422
                for( IASTNode variableNameNode : dataListNode.getDataStmtSet().getDataStmtObjectList().getChildren())
423
                {
424
                    if(variableNameNode instanceof ASTVariableNode)
425
                    {
426
                        ASTVariableNode variableNode = (ASTVariableNode)variableNameNode;
427
                        String variableName = variableNode.getDataRef().get(0).getName().getText();
428
429
                        dataBlockVariables.add(variableName.toLowerCase());
430
                    }
431
                }
432
            }      
433
        }
434
    }
435
}
(-)src/org/eclipse/photran/internal/core/refactoring/Messages.java (+4 lines)
Lines 115-120 Link Here
115
    public static String ExtractProcedureRefactoring_ProcedureContainsLabels;
115
    public static String ExtractProcedureRefactoring_ProcedureContainsLabels;
116
116
117
    public static String ExtractProcedureRefactoring_StatementCannotBeExtracted;
117
    public static String ExtractProcedureRefactoring_StatementCannotBeExtracted;
118
    
119
    public static String MakeSaveExplicitRefactoring_Name;
120
    
121
    public static String MakeSaveExplicitRefactoring_SelectedFileCannotBeParsed;
118
122
119
    public static String MinOnlyListRefactoring_ModuleIsEmpty;
123
    public static String MinOnlyListRefactoring_ModuleIsEmpty;
120
124
(-)src/org/eclipse/photran/internal/core/refactoring/messages.properties (+2 lines)
Lines 120-125 Link Here
120
MakePrivateEntityPublicRefactoring_NoPrivateEntitySelected=No private entities selected.
120
MakePrivateEntityPublicRefactoring_NoPrivateEntitySelected=No private entities selected.
121
MakePrivateEntityPublicRefactoring_PublicEntitySelectedSelectPrivate=Public entity is selected. Please select a Private entity.
121
MakePrivateEntityPublicRefactoring_PublicEntitySelectedSelectPrivate=Public entity is selected. Please select a Private entity.
122
MakePrivateEntityPublicRefactoring_SelectPrivateEntityName=Please select a private entity name.
122
MakePrivateEntityPublicRefactoring_SelectPrivateEntityName=Please select a private entity name.
123
MakeSaveExplicitRefactoring_Name=Make Save Attributes Explicit
124
MakeSaveExplicitRefactoring_SelectedFileCannotBeParsed=One of the selected files ({0}) cannot be parsed.
123
MinOnlyListRefactoring_ModuleIsEmpty=Module contains no declared entities. No ONLY clause is necessary. Please remove the ONLY clause from the USE statement.
125
MinOnlyListRefactoring_ModuleIsEmpty=Module contains no declared entities. No ONLY clause is necessary. Please remove the ONLY clause from the USE statement.
124
MinOnlyListRefactoring_ModuleNodeNotFound=Module AST node could not be found.
126
MinOnlyListRefactoring_ModuleNodeNotFound=Module AST node could not be found.
125
MinOnlyListRefactoring_ModuleNotFoundWithName=No module with name {0}
127
MinOnlyListRefactoring_ModuleNotFoundWithName=No module with name {0}
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.1/make_save_1_1.f90 (+16 lines)
Added Link Here
1
! USER STORY 1, TEST 1
2
! Adds SAVE attribute to the initialized declaration statement for variable
3
! call_counter
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  INTEGER :: call_counter = 0
14
  call_counter = call_counter + 1
15
  PRINT *, 'called:', call_counter
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.1/make_save_1_1.f90.result (+16 lines)
Added Link Here
1
! USER STORY 1, TEST 1
2
! Adds SAVE attribute to the initialized declaration statement for variable
3
! call_counter
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  INTEGER, SAVE :: call_counter = 0
14
  call_counter = call_counter + 1
15
  PRINT *, 'called:', call_counter
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.2/make_save_1_2.f90 (+17 lines)
Added Link Here
1
! USER STORY 1, TEST 2
2
! Adds SAVE attribute to the initialized declaration statements for variables
3
! first_call_counter and second_call_counter
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER :: first_call_counter = 0
12
  INTEGER :: second_call_counter = 10
13
  first_call_counter = first_call_counter + 1
14
  second_call_counter = second_call_counter + 1
15
  PRINT *, 'called:', first_call_counter
16
  PRINT *, 'called:', second_call_counter
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.2/make_save_1_2.f90.result (+17 lines)
Added Link Here
1
! USER STORY 1, TEST 2
2
! Adds SAVE attribute to the initialized declaration statements for variables
3
! first_call_counter and second_call_counter
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, SAVE :: first_call_counter = 0
12
  INTEGER, SAVE :: second_call_counter = 10
13
  first_call_counter = first_call_counter + 1
14
  second_call_counter = second_call_counter + 1
15
  PRINT *, 'called:', first_call_counter
16
  PRINT *, 'called:', second_call_counter
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.3/make_save_1_3.f90 (+21 lines)
Added Link Here
1
! USER STORY 1, TEST 3
2
! Adds SAVE attribute to the initialized declaration statement for variable
3
! first_call_counter, but not to the non-initialized declaration statement for
4
! variable second_call_counter
5
6
! EXAMPLE FROM USER STORY
7
8
PROGRAM MyProgram !<<<<< 1, 1, pass
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  INTEGER :: first_call_counter = 0
15
  INTEGER :: second_call_counter
16
  second_call_counter = 10
17
  first_call_counter = first_call_counter + 1
18
  second_call_counter = second_call_counter + 1
19
  PRINT *, 'called:', first_call_counter
20
  PRINT *, 'called:', second_call_counter
21
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.3/make_save_1_3.f90.result (+21 lines)
Added Link Here
1
! USER STORY 1, TEST 3
2
! Adds SAVE attribute to the initialized declaration statement for variable
3
! first_call_counter, but not to the non-initialized declaration statement for
4
! variable second_call_counter
5
6
! EXAMPLE FROM USER STORY
7
8
PROGRAM MyProgram !<<<<< 1, 1, pass
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  INTEGER, SAVE :: first_call_counter = 0
15
  INTEGER :: second_call_counter
16
  second_call_counter = 10
17
  first_call_counter = first_call_counter + 1
18
  second_call_counter = second_call_counter + 1
19
  PRINT *, 'called:', first_call_counter
20
  PRINT *, 'called:', second_call_counter
21
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.4/make_save_1_4.f90 (+16 lines)
Added Link Here
1
! USER STORY 1, TEST 4
2
! Adds SAVE attribute to the initialized declaration statement for array
3
! myArray
4
5
PROGRAM MyProgram !<<<<< 11, 18, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, DIMENSION(3) :: myArray = (/ 1, 2, 3 /)
12
  myArray(1) = myArray(1) + 1
13
  myArray(2) = myArray(2) + 2
14
  myArray(3) = myArray(3) + 3
15
  PRINT *, 'myArray:', myArray(1), myArray(2), myArray(3)
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-1/test-1.4/make_save_1_4.f90.result (+16 lines)
Added Link Here
1
! USER STORY 1, TEST 4
2
! Adds SAVE attribute to the initialized declaration statement for array
3
! myArray
4
5
PROGRAM MyProgram !<<<<< 11, 18, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, DIMENSION(3), SAVE :: myArray = (/ 1, 2, 3 /)
12
  myArray(1) = myArray(1) + 1
13
  myArray(2) = myArray(2) + 2
14
  myArray(3) = myArray(3) + 3
15
  PRINT *, 'myArray:', myArray(1), myArray(2), myArray(3)
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-2/test-2.1/make_save_2_1.f90 (+20 lines)
Added Link Here
1
! USER STORY 2, TEST 1
2
! Does not add SAVE attribute to the initialized declaration statement for
3
! variable j due to the presence of the unspecified SAVE statement in the same
4
! subroutine
5
6
! EXAMPLE FROM USER STORY
7
8
PROGRAM MyProgram !<<<<< 1, 1, pass 
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  SAVE
15
  INTEGER :: i
16
  INTEGER :: j = 0
17
  i = i + 1
18
  j = j + 5
19
  PRINT *, 'i=', i, ', j=', j
20
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-2/test-2.1/make_save_2_1.f90.result (+20 lines)
Added Link Here
1
! USER STORY 2, TEST 1
2
! Does not add SAVE attribute to the initialized declaration statement for
3
! variable j due to the presence of the unspecified SAVE statement in the same
4
! subroutine
5
6
! EXAMPLE FROM USER STORY
7
8
PROGRAM MyProgram !<<<<< 1, 1, pass 
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  SAVE
15
  INTEGER :: i
16
  INTEGER :: j = 0
17
  i = i + 1
18
  j = j + 5
19
  PRINT *, 'i=', i, ', j=', j
20
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-2/test-2.2/make_save_2_2.f90 (+29 lines)
Added Link Here
1
! USER STORY 2, TEST 2
2
! Does not add SAVE attribute to the initialized declaration statement for
3
! variable j due to the presence of the unspecified SAVE statement in the same
4
! subroutine, but does add SAVE attribute to the initialized declaration
5
! statement for variable n with no SAVE statement in the same subroutine
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass 
8
  CALL MySubOne
9
  CALL MySubOne
10
  CALL MySubTwo
11
  CALL MySubTwo
12
END PROGRAM MyProgram
13
14
SUBROUTINE MySubOne
15
  SAVE
16
  INTEGER :: i
17
  INTEGER :: j = 0
18
  i = i + 1
19
  j = j + 5
20
  PRINT *, 'i=', i, ', j=', j
21
END SUBROUTINE MySub
22
23
SUBROUTINE MySubTwo
24
  INTEGER :: m
25
  INTEGER :: n = 0
26
  m = m + 1
27
  n = n + 5
28
  PRINT *, 'm=', m, ', n=', n
29
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-2/test-2.2/make_save_2_2.f90.result (+29 lines)
Added Link Here
1
! USER STORY 2, TEST 2
2
! Does not add SAVE attribute to the initialized declaration statement for
3
! variable j due to the presence of the unspecified SAVE statement in the same
4
! subroutine, but does add SAVE attribute to the initialized declaration
5
! statement for variable n with no SAVE statement in the same subroutine
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass 
8
  CALL MySubOne
9
  CALL MySubOne
10
  CALL MySubTwo
11
  CALL MySubTwo
12
END PROGRAM MyProgram
13
14
SUBROUTINE MySubOne
15
  SAVE
16
  INTEGER :: i
17
  INTEGER :: j = 0
18
  i = i + 1
19
  j = j + 5
20
  PRINT *, 'i=', i, ', j=', j
21
END SUBROUTINE MySub
22
23
SUBROUTINE MySubTwo
24
  INTEGER :: m
25
  INTEGER, SAVE :: n = 0
26
  m = m + 1
27
  n = n + 5
28
  PRINT *, 'm=', m, ', n=', n
29
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-2/test-2.3/make_save_2_3.f90 (+17 lines)
Added Link Here
1
! USER STORY 2, TEST 3
2
! Adds SAVE attribute to the initialized declaration statement for variable j
3
! with a SAVE statement for a different variable in the same subroutine
4
5
PROGRAM MyProgram !<<<<< 7, 9, pass 
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  SAVE i
12
  INTEGER :: i
13
  INTEGER :: j = 0
14
  i = i + 1
15
  j = j + 5
16
  PRINT *, 'i=', i, ', j=', j
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-2/test-2.3/make_save_2_3.f90.result (+17 lines)
Added Link Here
1
! USER STORY 2, TEST 3
2
! Adds SAVE attribute to the initialized declaration statement for variable j
3
! with a SAVE statement for a different variable in the same subroutine
4
5
PROGRAM MyProgram !<<<<< 7, 9, pass 
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  SAVE i
12
  INTEGER :: i
13
  INTEGER, SAVE :: j = 0
14
  i = i + 1
15
  j = j + 5
16
  PRINT *, 'i=', i, ', j=', j
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-3/test-3.1/make_save_3_1.f90 (+17 lines)
Added Link Here
1
! USER STORY 3, TEST 1
2
! Adds SAVE attribute to the declaration statement for variable sum initialized
3
! through a DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass 
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  INTEGER :: sum
14
  DATA sum /100/
15
  sum = sum + sum
16
  PRINT *, 'sum=', sum
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-3/test-3.1/make_save_3_1.f90.result (+17 lines)
Added Link Here
1
! USER STORY 3, TEST 1
2
! Adds SAVE attribute to the declaration statement for variable sum initialized
3
! through a DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass 
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  INTEGER, SAVE :: sum
14
  DATA sum /100/
15
  sum = sum + sum
16
  PRINT *, 'sum=', sum
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-3/test-3.2/make_save_3_2.f90 (+16 lines)
Added Link Here
1
! USER STORY 3, TEST 2
2
! Adds SAVE attribute to the declaration statement for array myArray
3
! initialized through a DATA statement
4
5
PROGRAM MyProgram !<<<<< 8,16, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, DIMENSION(2) :: myArray
12
  DATA myArray /100, 10/
13
  myArray(1) = myArray(1) + 1
14
  myArray(2) = myArray(2) + 1
15
  PRINT *, 'myArray(1)=', myArray(1), 'myArray(2)=', myArray(2)
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-3/test-3.2/make_save_3_2.f90.result (+16 lines)
Added Link Here
1
! USER STORY 3, TEST 2
2
! Adds SAVE attribute to the declaration statement for array myArray
3
! initialized through a DATA statement
4
5
PROGRAM MyProgram !<<<<< 8,16, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, DIMENSION(2), SAVE :: myArray
12
  DATA myArray /100, 10/
13
  myArray(1) = myArray(1) + 1
14
  myArray(2) = myArray(2) + 1
15
  PRINT *, 'myArray(1)=', myArray(1), 'myArray(2)=', myArray(2)
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.1/make_save_4_1.f90 (+17 lines)
Added Link Here
1
! USER STORY 4, TEST 1
2
! Adds SAVE attribute to the declaration statements for variables sumOne and
3
! sumTwo initialized through the same DATA statement
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass 
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER :: sumOne
12
  INTEGER :: sumTwo
13
  DATA sumOne /100/ sumTwo /10/
14
  sumOne = sumOne + sumOne
15
  sumTwo = sumTwo + sumTwo
16
  PRINT *, 'sumOne=', sumOne, 'sumTwo=', sumTwo
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.1/make_save_4_1.f90.result (+17 lines)
Added Link Here
1
! USER STORY 4, TEST 1
2
! Adds SAVE attribute to the declaration statements for variables sumOne and
3
! sumTwo initialized through the same DATA statement
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass 
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, SAVE :: sumOne
12
  INTEGER, SAVE :: sumTwo
13
  DATA sumOne /100/ sumTwo /10/
14
  sumOne = sumOne + sumOne
15
  sumTwo = sumTwo + sumTwo
16
  PRINT *, 'sumOne=', sumOne, 'sumTwo=', sumTwo
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.2/make_save_4_2.f90 (+23 lines)
Added Link Here
1
! USER STORY 4, TEST 2
2
! Adds SAVE attribute to the declaration statements for arrays myArray and
3
! myArray2 initialized through the same DATA statement
4
5
PROGRAM MyProgram !<<<<< 8,16, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, DIMENSION(2) :: myArray
12
  INTEGER, DIMENSION(2) :: myArray2
13
  DATA myArray /10, 20/  myArray2 /30, 40/
14
15
  myArray(1) = myArray(1) + 1
16
  myArray(2) = myArray(2) + 1
17
18
  myArray2(1) = myArray2(1) + 1
19
  myArray2(2) = myArray2(2) + 1
20
21
  PRINT *, 'myArray(1)=', myArray(1), 'myArray(2)=', myArray(2)
22
  PRINT *, 'myArray2(1)=', myArray2(1), 'myArray2(2)=', myArray2(2)
23
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.2/make_save_4_2.f90.result (+23 lines)
Added Link Here
1
! USER STORY 4, TEST 2
2
! Adds SAVE attribute to the declaration statements for arrays myArray and
3
! myArray2 initialized through the same DATA statement
4
5
PROGRAM MyProgram !<<<<< 8,16, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, DIMENSION(2), SAVE :: myArray
12
  INTEGER, DIMENSION(2), SAVE :: myArray2
13
  DATA myArray /10, 20/  myArray2 /30, 40/
14
15
  myArray(1) = myArray(1) + 1
16
  myArray(2) = myArray(2) + 1
17
18
  myArray2(1) = myArray2(1) + 1
19
  myArray2(2) = myArray2(2) + 1
20
21
  PRINT *, 'myArray(1)=', myArray(1), 'myArray(2)=', myArray(2)
22
  PRINT *, 'myArray2(1)=', myArray2(1), 'myArray2(2)=', myArray2(2)
23
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.3/make_save_4_3.f90 (+22 lines)
Added Link Here
1
! USER STORY 4, TEST 3
2
! Adds SAVE attribute to the declaration statements for variables i, j, and k
3
! initialized through the same DATA statement (alternate arrangement of DATA
4
! statement)
5
6
PROGRAM MyProgram !<<<<< 8,16, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  INTEGER :: i
13
  INTEGER :: j
14
  INTEGER :: k
15
  DATA i,j,k /10, 20, 35/
16
17
  i = i + 1
18
  j = j + 1
19
  k = k + 1
20
21
  PRINT *, 'i=', i, 'j=', j, 'k=', k
22
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.3/make_save_4_3.f90.result (+22 lines)
Added Link Here
1
! USER STORY 4, TEST 3
2
! Adds SAVE attribute to the declaration statements for variables i, j, and k
3
! initialized through the same DATA statement (alternate arrangement of DATA
4
! statement)
5
6
PROGRAM MyProgram !<<<<< 8,16, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  INTEGER, SAVE :: i
13
  INTEGER, SAVE :: j
14
  INTEGER, SAVE :: k
15
  DATA i,j,k /10, 20, 35/
16
17
  i = i + 1
18
  j = j + 1
19
  k = k + 1
20
21
  PRINT *, 'i=', i, 'j=', j, 'k=', k
22
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.4/make_save_4_4.f90 (+20 lines)
Added Link Here
1
! USER STORY 4, TEST 4
2
! Adds SAVE attribute to the declaration statements for variables sum1 and sum2
3
! initialized through the same DATA statement (alternate arrangement of DATA
4
! statement)
5
6
! EXAMPLE FROM USER STORY
7
8
PROGRAM MyProgram
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  INTEGER :: sum1, sum2
15
  DATA sum1, sum2 /100, 200/
16
  sum1 = sum1 + sum1
17
  sum2 = sum2 + sum2 !<<<<< 1,11, pass
18
  PRINT *, 'sum1=', sum1
19
  PRINT *, 'sum2=', sum2
20
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.4/make_save_4_4.f90.result (+20 lines)
Added Link Here
1
! USER STORY 4, TEST 4
2
! Adds SAVE attribute to the declaration statements for variables sum1 and sum2
3
! initialized through the same DATA statement (alternate arrangement of DATA
4
! statement)
5
6
! EXAMPLE FROM USER STORY
7
8
PROGRAM MyProgram
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  INTEGER, SAVE :: sum1, sum2
15
  DATA sum1, sum2 /100, 200/
16
  sum1 = sum1 + sum1
17
  sum2 = sum2 + sum2 !<<<<< 1,11, pass
18
  PRINT *, 'sum1=', sum1
19
  PRINT *, 'sum2=', sum2
20
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.5/make_save_4_5.f90 (+19 lines)
Added Link Here
1
! USER STORY 4, TEST 5
2
! Adds SAVE attribute to the declaration statements for variables sum1 and sum2
3
! initialized through the same DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
 !<<<<< 1,1, pass
12
SUBROUTINE MySub
13
  INTEGER :: sum1, sum2
14
  DATA sum1 /100/, sum2 /200/
15
  sum1 = sum1 + sum1
16
  sum2 = sum2 + sum2
17
  PRINT *, 'sum1=', sum1
18
  PRINT *, 'sum2=', sum2
19
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-4/test-4.5/make_save_4_5.f90.result (+19 lines)
Added Link Here
1
! USER STORY 4, TEST 5
2
! Adds SAVE attribute to the declaration statements for variables sum1 and sum2
3
! initialized through the same DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
 !<<<<< 1,1, pass
12
SUBROUTINE MySub
13
  INTEGER, SAVE :: sum1, sum2
14
  DATA sum1 /100/, sum2 /200/
15
  sum1 = sum1 + sum1
16
  sum2 = sum2 + sum2
17
  PRINT *, 'sum1=', sum1
18
  PRINT *, 'sum2=', sum2
19
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.1/make_save_5_1.f90 (+19 lines)
Added Link Here
1
! USER STORY 5, TEST 1
2
! Adds SAVE statement for variables sum1 and sum2 due to variables not 
3
! having declaration statements while being initialized by a DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  DATA sum1, sum2 /100, 200/
14
  sum1 = sum1 + sum1
15
  sum2 = sum2 + sum2
16
  PRINT *, 'sum1=', sum1
17
  PRINT *, 'sum2=', sum2
18
END SUBROUTINE MySub
19
!<<<<< 1,1, pass
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.1/make_save_5_1.f90.result (+20 lines)
Added Link Here
1
! USER STORY 5, TEST 1
2
! Adds SAVE statement for variables sum1 and sum2 due to variables not 
3
! having declaration statements while being initialized by a DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  SAVE sum1, sum2
14
  DATA sum1, sum2 /100, 200/
15
  sum1 = sum1 + sum1
16
  sum2 = sum2 + sum2
17
  PRINT *, 'sum1=', sum1
18
  PRINT *, 'sum2=', sum2
19
END SUBROUTINE MySub
20
!<<<<< 1,1, pass
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.2/make_save_5_2.f90 (+19 lines)
Added Link Here
1
! USER STORY 5, TEST 2
2
! Adds variable sum2 to a previously existing SAVE statement due to variable not
3
! having a declaration statement while being initialized by a DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram !<<<<< 1,1, pass
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  DATA sum1, sum2 /100, 200/
14
  SAVE sum1
15
  sum1 = sum1 + sum1
16
  sum2 = sum2 + sum2
17
  PRINT *, 'sum1=', sum1
18
  PRINT *, 'sum2=', sum2
19
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.2/make_save_5_2.f90.result (+19 lines)
Added Link Here
1
! USER STORY 5, TEST 2
2
! Adds variable sum2 to a previously existing SAVE statement due to variable not
3
! having a declaration statement while being initialized by a DATA statement
4
5
! EXAMPLE FROM USER STORY
6
7
PROGRAM MyProgram !<<<<< 1,1, pass
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  DATA sum1, sum2 /100, 200/
14
  SAVE sum1, sum2
15
  sum1 = sum1 + sum1
16
  sum2 = sum2 + sum2
17
  PRINT *, 'sum1=', sum1
18
  PRINT *, 'sum2=', sum2
19
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.3/make_save_5_3.f90 (+16 lines)
Added Link Here
1
! USER STORY 5, TEST 3
2
! Adds SAVE statement for variable i due to variable not having declaration
3
! statement while being initialized by a DATA statement (variable unused,
4
! otherwise), but does not add SAVE statement for variable j due to variable
5
! having neither a declaration statement nor a DATA statement for its
6
! initialization
7
8
PROGRAM MyProgram !<<<<< 1, 1, pass
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  DATA i /0/
15
  j = 0
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.3/make_save_5_3.f90.result (+17 lines)
Added Link Here
1
! USER STORY 5, TEST 3
2
! Adds SAVE statement for variable i due to variable not having declaration
3
! statement while being initialized by a DATA statement (variable unused,
4
! otherwise), but does not add SAVE statement for variable j due to variable
5
! having neither a declaration statement nor a DATA statement for its
6
! initialization
7
8
PROGRAM MyProgram !<<<<< 1, 1, pass
9
  CALL MySub
10
  CALL MySub
11
END PROGRAM MyProgram
12
13
SUBROUTINE MySub
14
  SAVE i
15
  DATA i /0/
16
  j = 0
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.4/make_save_5_4.f90 (+15 lines)
Added Link Here
1
! USER STORY 5, TEST 4
2
! Does not add variable i to existing SAVE statement due to variable names
3
! being case-insensitive, meaning that variable i is already explicitly saved
4
! due to the existing SAVE statement
5
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  SAVE I
14
  DATA i /0/
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-5/test-5.4/make_save_5_4.f90.result (+15 lines)
Added Link Here
1
! USER STORY 5, TEST 4
2
! Does not add variable i to existing SAVE statement due to variable names
3
! being case-insensitive, meaning that variable i is already explicitly saved
4
! due to the existing SAVE statement
5
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  CALL MySub
9
  CALL MySub
10
END PROGRAM MyProgram
11
12
SUBROUTINE MySub
13
  SAVE I
14
  DATA i /0/
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.1/make_save_6_1.f90 (+15 lines)
Added Link Here
1
! USER STORY 6, TEST 1
2
! Adds SAVE statement for variable call_counter due to variable being
3
! initialized in its declaration statement while sharing the same declaration
4
! statement with non-initialized variable other_var
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  INTEGER :: call_counter = 0, other_var
13
  call_counter = call_counter + 1
14
  PRINT *, 'called:', call_counter
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.1/make_save_6_1.f90.result (+16 lines)
Added Link Here
1
! USER STORY 6, TEST 1
2
! Adds SAVE statement for variable call_counter due to variable being
3
! initialized in its declaration statement while sharing the same declaration
4
! statement with non-initialized variable other_var
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  SAVE call_counter
13
  INTEGER :: call_counter = 0, other_var
14
  call_counter = call_counter + 1
15
  PRINT *, 'called:', call_counter
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.2/make_save_6_2.f90 (+17 lines)
Added Link Here
1
! USER STORY 6, TEST 2
2
! Adds variable call_counter to a previously existing SAVE statement due to
3
! variable being initialized in its declaration statement while sharing the
4
! same declaration statement with non-initialized variable other_var
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  SAVE third_var
13
  INTEGER :: call_counter = 0, other_var
14
  INTEGER :: third_var
15
  call_counter = call_counter + 1
16
  PRINT *, 'called:', call_counter
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.2/make_save_6_2.f90.result (+17 lines)
Added Link Here
1
! USER STORY 6, TEST 2
2
! Adds variable call_counter to a previously existing SAVE statement due to
3
! variable being initialized in its declaration statement while sharing the
4
! same declaration statement with non-initialized variable other_var
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  SAVE third_var, call_counter
13
  INTEGER :: call_counter = 0, other_var
14
  INTEGER :: third_var
15
  call_counter = call_counter + 1
16
  PRINT *, 'called:', call_counter
17
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.3/make_save_6_3.f90 (+18 lines)
Added Link Here
1
! USER STORY 6, TEST 3
2
! Adds SAVE attribute to the declaration statement for variables
3
! first_call_counter and second_call_counter since both variables are
4
! implicitly saved by some means
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  INTEGER :: first_call_counter = 0, second_call_counter
13
  DATA second_call_counter /10/
14
  first_call_counter = first_call_counter + 1
15
  second_call_counter = second_call_counter + 1
16
  PRINT *, 'called:', first_call_counter
17
  PRINT *, 'called:', second_call_counter
18
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.3/make_save_6_3.f90.result (+18 lines)
Added Link Here
1
! USER STORY 6, TEST 3
2
! Adds SAVE attribute to the declaration statement for variables
3
! first_call_counter and second_call_counter since both variables are
4
! implicitly saved by some means
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  INTEGER, SAVE :: first_call_counter = 0, second_call_counter
13
  DATA second_call_counter /10/
14
  first_call_counter = first_call_counter + 1
15
  second_call_counter = second_call_counter + 1
16
  PRINT *, 'called:', first_call_counter
17
  PRINT *, 'called:', second_call_counter
18
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.4/make_save_6_4.f90 (+18 lines)
Added Link Here
1
! USER STORY 6, TEST 4
2
! Adds SAVE statement for variables first_call_counter and second_call_counter
3
! since both variables are implicitly saved by some means while sharing the
4
! same declaration statement with a variable that is not implicitly saved
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  INTEGER :: first_call_counter = 0, second_call_counter, other_var
13
  DATA second_call_counter /10/
14
  first_call_counter = first_call_counter + 1
15
  second_call_counter = second_call_counter + 1
16
  PRINT *, 'called:', first_call_counter
17
  PRINT *, 'called:', second_call_counter
18
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.4/make_save_6_4.f90.result (+19 lines)
Added Link Here
1
! USER STORY 6, TEST 4
2
! Adds SAVE statement for variables first_call_counter and second_call_counter
3
! since both variables are implicitly saved by some means while sharing the
4
! same declaration statement with a variable that is not implicitly saved
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  SAVE first_call_counter, second_call_counter
13
  INTEGER :: first_call_counter = 0, second_call_counter, other_var
14
  DATA second_call_counter /10/
15
  first_call_counter = first_call_counter + 1
16
  second_call_counter = second_call_counter + 1
17
  PRINT *, 'called:', first_call_counter
18
  PRINT *, 'called:', second_call_counter
19
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.5/make_save_6_5.f90 (+16 lines)
Added Link Here
1
! USER STORY 6, TEST 5
2
! Adds variable call_counter to SAVE statement for variable other_var due to
3
! call_counter being initialized in its declaration statement while sharing the
4
! same declaration statement with explicitly-saved variable other_var
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  SAVE other_var
13
  INTEGER :: other_var, call_counter = 0
14
  call_counter = call_counter + 1
15
  PRINT *, 'called:', call_counter
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-6/test-6.5/make_save_6_5.f90.result (+16 lines)
Added Link Here
1
! USER STORY 6, TEST 5
2
! Adds variable call_counter to SAVE statement for variable other_var due to
3
! call_counter being initialized in its declaration statement while sharing the
4
! same declaration statement with explicitly-saved variable other_var
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  CALL MySub
8
  CALL MySub
9
END PROGRAM MyProgram
10
11
SUBROUTINE MySub
12
  SAVE other_var, call_counter
13
  INTEGER :: other_var, call_counter = 0
14
  call_counter = call_counter + 1
15
  PRINT *, 'called:', call_counter
16
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-7/test-7.1/make_save_7_1.f90 (+14 lines)
Added Link Here
1
! USER STORY 7, TEST 1
2
! Adds SAVE statement for variable call_counter due to variable being
3
! initialized in its declaration statement without :: operator
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER call_counter = 0
12
  call_counter = call_counter + 1
13
  PRINT *, 'called:', call_counter
14
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-7/test-7.1/make_save_7_1.f90.result (+14 lines)
Added Link Here
1
! USER STORY 7, TEST 1
2
! Adds SAVE statement for variable call_counter due to variable being
3
! initialized in its declaration statement without :: operator
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, SAVE :: call_counter = 0
12
  call_counter = call_counter + 1
13
  PRINT *, 'called:', call_counter
14
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-7/test-7.2/make_save_7_2.f90 (+15 lines)
Added Link Here
1
! USER STORY 7, TEST 1
2
! Adds SAVE statement for variable call_counter due to variable being
3
! implicitly saved in a data block
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER call_counter
12
  data call_counter /10/
13
  call_counter = call_counter + 1
14
  PRINT *, 'called:', call_counter
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-7/test-7.2/make_save_7_2.f90.result (+15 lines)
Added Link Here
1
! USER STORY 7, TEST 1
2
! Adds SAVE statement for variable call_counter due to variable being
3
! implicitly saved in a data block
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, SAVE :: call_counter
12
  data call_counter /10/
13
  call_counter = call_counter + 1
14
  PRINT *, 'called:', call_counter
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-7/test-7.3/make_save_7_3.f90 (+15 lines)
Added Link Here
1
! USER STORY 7, TEST 1
2
! Adds SAVE statement for variable call_counter and call_counter2  
3
! due to variables being implicitly saved 
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER call_counter = 10, call_counter2 = 20
12
  call_counter = call_counter + 1
13
  call_counter2 = call_counter2 + 2
14
  PRINT *, 'called:', call_counter, call_counter2
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-7/test-7.3/make_save_7_3.f90.result (+15 lines)
Added Link Here
1
! USER STORY 7, TEST 1
2
! Adds SAVE statement for variable call_counter and call_counter2  
3
! due to variables being implicitly saved 
4
5
PROGRAM MyProgram !<<<<< 1, 1, pass
6
  CALL MySub
7
  CALL MySub
8
END PROGRAM MyProgram
9
10
SUBROUTINE MySub
11
  INTEGER, SAVE :: call_counter = 10, call_counter2 = 20
12
  call_counter = call_counter + 1
13
  call_counter2 = call_counter2 + 2
14
  PRINT *, 'called:', call_counter, call_counter2
15
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-8/test-8.1/make_save_8_1.f90 (+20 lines)
Added Link Here
1
! USER STORY 8, TEST 1
2
! Adds SAVE attribute to the initialized declaration statement for variable j
3
! in subroutine MySub, but not to the initialized declaration statement for
4
! variable i in program MyProgram
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  INTEGER :: i = 0
8
  i = i + 1
9
  PRINT *, 'called:', i
10
  i = i + 1
11
  PRINT *, 'called:', i
12
  CALL MySub
13
  CALL MySub
14
END PROGRAM MyProgram
15
16
SUBROUTINE MySub
17
  INTEGER :: j = 10
18
  j = j + 1
19
  PRINT *, 'called:', j
20
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-8/test-8.1/make_save_8_1.f90.result (+20 lines)
Added Link Here
1
! USER STORY 8, TEST 1
2
! Adds SAVE attribute to the initialized declaration statement for variable j
3
! in subroutine MySub, but not to the initialized declaration statement for
4
! variable i in program MyProgram
5
6
PROGRAM MyProgram !<<<<< 1, 1, pass
7
  INTEGER :: i = 0
8
  i = i + 1
9
  PRINT *, 'called:', i
10
  i = i + 1
11
  PRINT *, 'called:', i
12
  CALL MySub
13
  CALL MySub
14
END PROGRAM MyProgram
15
16
SUBROUTINE MySub
17
  INTEGER, SAVE :: j = 10
18
  j = j + 1
19
  PRINT *, 'called:', j
20
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-8/test-8.2/make_save_8_2.f90 (+23 lines)
Added Link Here
1
! USER STORY 8, TEST 2
2
! Adds SAVE attribute to the declaration statement for variable j initialized
3
! through a DATA statement in subroutine MySub, but not to the declaration
4
! statement for variable i also initialized through a DATA statement in program
5
! MyProgram
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  INTEGER :: i
9
  DATA i /0/
10
  i = i + 1
11
  PRINT *, 'called:', i
12
  i = i + 1
13
  PRINT *, 'called:', i
14
  CALL MySub
15
  CALL MySub
16
END PROGRAM MyProgram
17
18
SUBROUTINE MySub
19
  INTEGER :: j
20
  DATA j /0/
21
  j = j + 1
22
  PRINT *, 'called:', j
23
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-8/test-8.2/make_save_8_2.f90.result (+23 lines)
Added Link Here
1
! USER STORY 8, TEST 2
2
! Adds SAVE attribute to the declaration statement for variable j initialized
3
! through a DATA statement in subroutine MySub, but not to the declaration
4
! statement for variable i also initialized through a DATA statement in program
5
! MyProgram
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  INTEGER :: i
9
  DATA i /0/
10
  i = i + 1
11
  PRINT *, 'called:', i
12
  i = i + 1
13
  PRINT *, 'called:', i
14
  CALL MySub
15
  CALL MySub
16
END PROGRAM MyProgram
17
18
SUBROUTINE MySub
19
  INTEGER, SAVE :: j
20
  DATA j /0/
21
  j = j + 1
22
  PRINT *, 'called:', j
23
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-8/test-8.3/make_save_8_3.f90 (+21 lines)
Added Link Here
1
! USER STORY 8, TEST 3
2
! Adds SAVE statement for variables j due to variable not having declaration
3
! statement while being initialized by a DATA statement in subroutine MySub,
4
! but doesn't add it for variables i due to variable not having declaration
5
! statement while being initialized by a DATA statement in program MyProgram
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  DATA i /0/
9
  i = i + 1
10
  PRINT *, 'called:', i
11
  i = i + 1
12
  PRINT *, 'called:', i
13
  CALL MySub
14
  CALL MySub
15
END PROGRAM MyProgram
16
17
SUBROUTINE MySub
18
  DATA j /0/
19
  j = j + 1
20
  PRINT *, 'called:', j
21
END SUBROUTINE MySub
(-)refactoring-test-code/make-save-explicit/user-story-8/test-8.3/make_save_8_3.f90.result (+22 lines)
Added Link Here
1
! USER STORY 8, TEST 3
2
! Adds SAVE statement for variables j due to variable not having declaration
3
! statement while being initialized by a DATA statement in subroutine MySub,
4
! but doesn't add it for variables i due to variable not having declaration
5
! statement while being initialized by a DATA statement in program MyProgram
6
7
PROGRAM MyProgram !<<<<< 1, 1, pass
8
  DATA i /0/
9
  i = i + 1
10
  PRINT *, 'called:', i
11
  i = i + 1
12
  PRINT *, 'called:', i
13
  CALL MySub
14
  CALL MySub
15
END PROGRAM MyProgram
16
17
SUBROUTINE MySub
18
  SAVE j
19
  DATA j /0/
20
  j = j + 1
21
  PRINT *, 'called:', j
22
END SUBROUTINE MySub
(-)src/org/eclipse/photran/internal/tests/refactoring/MakeSaveExplicitTestSuite.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Stephen Downs, Robert Samblanet, Kevin Schilling, Jon 
3
 * Woolwine, and Chad Zamzow
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    UIUC - Initial API and implementation
11
 *******************************************************************************/
12
13
package org.eclipse.photran.internal.tests.refactoring;
14
15
import junit.framework.Test;
16
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.jface.text.TextSelection;
19
import org.eclipse.photran.internal.core.refactoring.MakeSaveExplicitRefactoring;
20
import org.eclipse.photran.internal.tests.Activator;
21
import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers;
22
23
/**
24
 * Unit tests for the Make Save Explicit refactoring.
25
 *
26
 * @author Stephen Downs
27
 * @author Robert Samblanet
28
 * @author Kevin Schilling
29
 * @author Jon Woolwine
30
 * @author Chad Zamzow
31
 */
32
public class MakeSaveExplicitTestSuite
33
     extends PhotranRefactoringTestSuiteFromMarkers<MakeSaveExplicitRefactoring>
34
{
35
    private static final String DIR = "refactoring-test-code/make-save-explicit";
36
37
    public static Test suite() throws Exception
38
    {
39
        return new MakeSaveExplicitTestSuite();
40
    }
41
42
    public MakeSaveExplicitTestSuite() throws Exception
43
    {
44
        super(Activator.getDefault(),
45
              "Running Make Save Attribute Explicit refactoring in",
46
              DIR,
47
              MakeSaveExplicitRefactoring.class);
48
    }
49
50
    @Override
51
    protected boolean configureRefactoring(MakeSaveExplicitRefactoring refactoring,
52
                                           IFile file,
53
                                           TextSelection selection,
54
                                           String[] markerText)
55
    {
56
        boolean shouldSucceed = super.configureRefactoring(refactoring, file, selection, markerText);
57
58
        return shouldSucceed;
59
    }
60
}
(-)plugin.xml (+3 lines)
Lines 29-34 Link Here
29
             class="org.eclipse.photran.internal.core.refactoring.DataToParameterRefactoring"
29
             class="org.eclipse.photran.internal.core.refactoring.DataToParameterRefactoring"
30
         />
30
         />
31
         <resourceRefactoring
31
         <resourceRefactoring
32
             class="org.eclipse.photran.internal.core.refactoring.MakeSaveExplicitRefactoring"
33
         />
34
         <resourceRefactoring
32
             class="org.eclipse.photran.internal.core.refactoring.RemoveUnusedVariablesRefactoring"
35
             class="org.eclipse.photran.internal.core.refactoring.RemoveUnusedVariablesRefactoring"
33
         />
36
         />
34
         <resourceRefactoring
37
         <resourceRefactoring

Return to bug 332353