Adding ParameterizedTypeImpl to getGenericSuperclass method.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / ReferenceArrayFields.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.vm;
19
20 import gov.nasa.jpf.util.HashData;
21 import gov.nasa.jpf.util.IntVector;
22 import gov.nasa.jpf.util.PrintUtils;
23
24 import java.io.PrintStream;
25
26 /**
27  * element values for reference array objects
28  * (references are stored as int's)
29  */
30 public class ReferenceArrayFields extends ArrayFields {
31
32   int[] values; // the references
33
34   public ReferenceArrayFields (int length) {
35     values = new int[length];
36
37     /** not required for MJIEnv.NULL = 0
38     for (int i=0; i<length; i++) {
39       values[i] = MJIEnv.NULL;
40     }
41     **/
42   }
43
44   @Override
45   public int[] asReferenceArray() {
46     return values;
47   }
48   
49   @Override
50   public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
51     ReferenceArrayFields a = (ReferenceArrayFields) src;
52     System.arraycopy(a.values, srcPos, values, dstPos, len);
53   }
54
55   @Override
56   protected void printValue(PrintStream ps, int idx){
57     PrintUtils.printReference(ps, values[idx]);
58   }
59   
60   @Override
61   public Object getValues(){
62     return values;
63   }
64
65   @Override
66   public int arrayLength() {
67     return values.length;
68   }
69
70   @Override
71   public boolean isReferenceArray() {
72     return true;
73   }
74
75   @Override
76   public int getHeapSize() {
77     return values.length * 4;
78   }
79
80   @Override
81   public void appendTo (IntVector v) {
82     v.append(values);
83   }
84
85   @Override
86   public ReferenceArrayFields clone(){
87     ReferenceArrayFields f = (ReferenceArrayFields)cloneFields();
88     f.values = values.clone();
89     return f;
90   }
91
92
93   @Override
94   public boolean equals(Object o) {
95     if (o instanceof ReferenceArrayFields) {
96       ReferenceArrayFields other = (ReferenceArrayFields)o;
97
98       int[] v = values;
99       int[] vOther = other.values;
100       if (v.length != vOther.length) {
101         return false;
102       }
103
104       for (int i=0; i<v.length; i++) {
105         if (v[i] != vOther[i]) {
106           return false;
107         }
108       }
109
110       return compareAttrs(other);
111
112     } else {
113       return false;
114     }
115   }
116
117   @Override
118   public void setReferenceValue(int pos, int newValue) {
119     values[pos] = newValue;
120   }
121
122   @Override
123   public int getReferenceValue(int pos) {
124     return values[pos];
125   }
126
127   @Override
128   public void hash (HashData hd) {
129     int[] v = values;
130     for (int i=0; i < v.length; i++) {
131       hd.add(v[i]);
132     }
133   }
134
135
136 }