Initial import
[jpf-core.git] / src / main / gov / nasa / jpf / jvm / bytecode / LongReturn.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18 package gov.nasa.jpf.jvm.bytecode;
19
20 import gov.nasa.jpf.vm.StackFrame;
21 import gov.nasa.jpf.vm.ThreadInfo;
22
23 import java.util.Iterator;
24
25 /**
26  * common base for DRETURN and LRETURN
27  */
28 public abstract class LongReturn extends JVMReturnInstruction {
29
30   protected long ret;
31   
32   @Override
33   public int getReturnTypeSize() {
34     return 2;
35   }
36   
37   @Override
38   protected Object getReturnedOperandAttr (StackFrame frame) {
39     return frame.getLongOperandAttr();
40   }
41   
42   @Override
43   protected void getAndSaveReturnValue (StackFrame frame) {
44     ret = frame.popLong();
45   }
46
47   @Override
48   protected void pushReturnValue (StackFrame frame) {
49     frame.pushLong(ret);
50   }
51
52   //--- attribute accessors 
53   
54   @Override
55   public boolean hasReturnAttr (ThreadInfo ti){
56     StackFrame frame = ti.getTopFrame();
57     return frame.hasLongOperandAttr();
58   }
59   @Override
60   public boolean hasReturnAttr (ThreadInfo ti, Class<?> type){
61     StackFrame frame = ti.getTopFrame();
62     return frame.hasLongOperandAttr(type);
63   }
64   
65   /**
66    * this returns all of them - use either if you know there will be only
67    * one attribute at a time, or check/process result with ObjectList
68    * 
69    * obviously, this only makes sense from an instructionExecuted(), since
70    * the value is pushed during the enter(). Use ObjectList to access values
71    */
72   @Override
73   public Object getReturnAttr (ThreadInfo ti){
74     StackFrame frame = ti.getTopFrame();
75     return frame.getLongOperandAttr();
76   }
77   
78   /**
79    * this replaces all of them - use only if you know 
80    *  - there will be only one attribute at a time
81    *  - you obtained the value you set by a previous getXAttr()
82    *  - you constructed a multi value list with ObjectList.createList()
83    * 
84    * we don't clone since pushing a return value already changed the caller frame
85    */
86   @Override
87   public void setReturnAttr (ThreadInfo ti, Object a){
88     StackFrame frame = ti.getModifiableTopFrame();
89     frame.setLongOperandAttr(a);
90   }
91
92   /**
93    * this only returns the first attr of this type, there can be more
94    * if you don't use client private types or the provided type is too general
95    */
96   @Override
97   public <T> T getReturnAttr (ThreadInfo ti, Class<T> type){
98     StackFrame frame = ti.getTopFrame();
99     return frame.getLongOperandAttr(type);
100   }
101   @Override
102   public <T> T getNextReturnAttr (ThreadInfo ti, Class<T> type, Object prev){
103     StackFrame frame = ti.getTopFrame();
104     return frame.getNextLongOperandAttr(type, prev);
105   }
106   @Override
107   public Iterator returnAttrIterator (ThreadInfo ti){
108     StackFrame frame = ti.getTopFrame();
109     return frame.longOperandAttrIterator();
110   }
111   @Override
112   public <T> Iterator<T> returnAttrIterator (ThreadInfo ti, Class<T> type){
113     StackFrame frame = ti.getTopFrame();
114     return frame.longOperandAttrIterator(type);
115   }
116   
117   @Override
118   public void addReturnAttr (ThreadInfo ti, Object attr){
119     StackFrame frame = ti.getModifiableTopFrame();
120     frame.addLongOperandAttr(attr);
121   }
122
123
124 }