comparison truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/LocationImpl.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.object/src/com/oracle/truffle/object/LocationImpl.java@e9cbe1618733
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.object;
24
25 import com.oracle.truffle.api.object.*;
26
27 public abstract class LocationImpl extends Location {
28
29 public interface EffectivelyFinalLocation<T extends Location> {
30 T toNonFinalLocation();
31 }
32
33 public interface TypedObjectLocation<T extends Location & ObjectLocation> extends ObjectLocation {
34 T toUntypedLocation();
35 }
36
37 public interface InternalLongLocation extends LongLocation {
38 void setLongInternal(DynamicObject store, long value);
39 }
40
41 public interface LocationVisitor {
42 void visitObjectField(int index, int count);
43
44 void visitObjectArray(int index, int count);
45
46 void visitPrimitiveField(int index, int count);
47
48 void visitPrimitiveArray(int index, int count);
49 }
50
51 @Override
52 public void set(DynamicObject store, Object value, Shape shape) throws IncompatibleLocationException, FinalLocationException {
53 setInternal(store, value);
54 }
55
56 @Override
57 protected final Object getInternal(DynamicObject store) {
58 throw new UnsupportedOperationException();
59 }
60
61 @Override
62 protected abstract void setInternal(DynamicObject store, Object value) throws IncompatibleLocationException;
63
64 @Override
65 public final boolean canSet(DynamicObject store, Object value) {
66 return canStore(value) && canStoreFinal(store, value);
67 }
68
69 @Override
70 public boolean canStore(Object value) {
71 return true;
72 }
73
74 @SuppressWarnings("unused")
75 protected boolean canStoreFinal(DynamicObject store, Object value) {
76 return true;
77 }
78
79 @Override
80 public boolean isFinal() {
81 return false;
82 }
83
84 @Override
85 public boolean isConstant() {
86 return false;
87 }
88
89 @Override
90 public int hashCode() {
91 final int prime = 31;
92 int result = 1;
93 result = prime * result + (isFinal() ? 1231 : 1237);
94 return result;
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) {
100 return true;
101 }
102 if (obj == null) {
103 return false;
104 }
105 if (getClass() != obj.getClass()) {
106 return false;
107 }
108 Location other = (Location) obj;
109 if (isFinal() != other.isFinal()) {
110 return false;
111 }
112 return true;
113 }
114
115 @Override
116 public String toString() {
117 String finalString = isFinal() ? "f" : "";
118 String typeString = this instanceof IntLocation ? "i" : (this instanceof DoubleLocation ? "d" : (this instanceof BooleanLocation ? "b"
119 : (this instanceof TypedLocation ? ((TypedLocation) this).getType().getSimpleName() : "o")));
120 return finalString + typeString + getWhereString();
121 }
122
123 protected String getWhereString() {
124 return "";
125 }
126
127 /**
128 * Get the number of object array elements this location requires.
129 */
130 public int objectArrayCount() {
131 return 0;
132 }
133
134 /**
135 * Get the number of in-object {@link Object} fields this location requires.
136 */
137 public int objectFieldCount() {
138 return 0;
139 }
140
141 /**
142 * Get the number of in-object primitive fields this location requires.
143 */
144 public int primitiveFieldCount() {
145 return 0;
146 }
147
148 /**
149 * Get the number of primitive array elements this location requires.
150 */
151 public int primitiveArrayCount() {
152 return 0;
153 }
154
155 /**
156 * Accept a visitor for location allocation for this and every nested location.
157 *
158 * @param locationVisitor visitor to be notified of every allocated slot in use by this location
159 */
160 public abstract void accept(LocationVisitor locationVisitor);
161
162 /**
163 * Boxed values need to be compared by value not by reference.
164 *
165 * The first parameter should be the one with the more precise type information.
166 *
167 * For sets to final locations, otherValue.equals(thisValue) seems more beneficial, since we
168 * usually know more about the value to be set.
169 */
170 public static boolean valueEquals(Object val1, Object val2) {
171 return val1 == val2 || (val1 != null && val1.equals(val2));
172 }
173 }