comparison graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/Property.java @ 18407:f439fdb137a3

Truffle: initial commit of object API
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 16:18:45 +0100
parents
children de8880bbf2e1
comparison
equal deleted inserted replaced
18406:194041c3fdab 18407:f439fdb137a3
1 /*
2 * Copyright (c) 2012, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.api.object;
26
27 /**
28 * Property objects represent the mapping between low-level stores and high-level data. The simplest
29 * Property could be nothing more than a map of one index to one property's value, but abstracting
30 * the interface allows for getter/setter methods, type-checked properties, and other such
31 * specialized and language-specific behavior. ECMAScript[8.6.1]
32 */
33 public abstract class Property {
34 protected Property() {
35 }
36
37 public static Property create(Object key, Location location, int flags) {
38 return Layout.getFactory().createProperty(key, location, flags);
39 }
40
41 /**
42 * Get property identifier.
43 */
44 public abstract Object getKey();
45
46 /**
47 * Get property flags.
48 */
49 public abstract int getFlags();
50
51 /**
52 * Change the property's location.
53 *
54 * @return a Property with the new location (or {@code this} if the location is unchanged).
55 */
56 public abstract Property relocate(Location newLocation);
57
58 /**
59 * Gets the value of this property of the object.
60 *
61 * @param store the store that this property resides in
62 * @param shape the current shape of the object, which must contain this location
63 * @see DynamicObject#get(Object, Object)
64 */
65 public abstract Object get(DynamicObject store, Shape shape);
66
67 /**
68 * Gets the value of this property of the object.
69 *
70 * @param store the store that this property resides in
71 * @param condition the result of a shape check or {@code false}
72 * @see DynamicObject#get(Object, Object)
73 * @see #get(DynamicObject, Shape)
74 */
75 public abstract Object get(DynamicObject store, boolean condition);
76
77 /**
78 * Assigns value to this property of the object.
79 *
80 * Throws an exception if the value cannot be assigned to the property's current location.
81 *
82 * @param store the store that this property resides in
83 * @param value the value to assign
84 * @param shape the current shape of the object or {@code null}
85 * @throws IncompatibleLocationException if the value is incompatible with the property location
86 * @throws FinalLocationException if the location is final and values differ
87 * @see DynamicObject#set(Object, Object)
88 */
89 public abstract void set(DynamicObject store, Object value, Shape shape) throws IncompatibleLocationException, FinalLocationException;
90
91 /**
92 * Assigns value to this property of the object.
93 *
94 * Automatically relocates the property if the value cannot be assigned to its current location.
95 *
96 * @param shape the current shape of the object or {@code null}
97 */
98 public abstract void setGeneric(DynamicObject store, Object value, Shape shape);
99
100 /**
101 * Like {@link #set(DynamicObject, Object, Shape)}, but throws an {@link IllegalStateException}
102 * instead.
103 */
104 public abstract void setSafe(DynamicObject store, Object value, Shape shape);
105
106 /**
107 * Like {@link #setSafe}, but ignores the finalness of the property. For internal use only.
108 *
109 * @param store the store that this property resides in
110 * @param value the value to assign
111 */
112 public abstract void setInternal(DynamicObject store, Object value);
113
114 /**
115 * Assigns value to this property of the object, changing the object's shape.
116 *
117 * Combines {@link DynamicObject#setShapeAndGrow(Shape, Shape)} and
118 * {@link #set(DynamicObject, Object, Shape)} to an atomic operation.
119 *
120 * @param store the store that this property resides in
121 * @param value the value to assign
122 * @param oldShape the shape before the transition
123 * @param newShape the shape after the transition
124 * @throws IncompatibleLocationException if the value is incompatible with the property location
125 */
126 public abstract void set(DynamicObject store, Object value, Shape oldShape, Shape newShape) throws IncompatibleLocationException;
127
128 /**
129 * Assigns value to this property of the object, changing the object's shape.
130 *
131 * Combines {@link DynamicObject#setShapeAndGrow(Shape, Shape)} and
132 * {@link #setGeneric(DynamicObject, Object, Shape)} to an atomic operation.
133 *
134 * @param store the store that this property resides in
135 * @param value the value to assign
136 * @param oldShape the shape before the transition
137 * @param newShape the shape after the transition
138 */
139 public abstract void setGeneric(DynamicObject store, Object value, Shape oldShape, Shape newShape);
140
141 /**
142 * Assigns value to this property of the object, changing the object's shape.
143 *
144 * Combines {@link DynamicObject#setShapeAndGrow(Shape, Shape)} and
145 * {@link #setSafe(DynamicObject, Object, Shape)} to an atomic operation.
146 *
147 * @param store the store that this property resides in
148 * @param value the value to assign
149 * @param oldShape the shape before the transition
150 * @param newShape the shape after the transition
151 */
152 public abstract void setSafe(DynamicObject store, Object value, Shape oldShape, Shape newShape);
153
154 /**
155 * Returns {@code true} if this property and some other property have the same key and flags.
156 */
157 public abstract boolean isSame(Property other);
158
159 /**
160 * Get the property location.
161 */
162 public abstract Location getLocation();
163
164 /**
165 * Is this property hidden from iteration.
166 *
167 * @see HiddenKey
168 */
169 public abstract boolean isHidden();
170
171 public abstract boolean isShadow();
172
173 /**
174 * Create a copy of the property with the given flags.
175 */
176 public abstract Property copyWithFlags(int newFlags);
177
178 public abstract Property copyWithRelocatable(boolean newRelocatable);
179 }