Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java @ 20907:06b0a2fb20a1
Truffle/Tools: the coverage tool will now ignore counts for any sources holding the tag CoverageTracker.Tags.NO_COVERAGE.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Mon, 13 Apr 2015 11:05:58 -0700 |
parents | 723142fed324 |
children | 5f3dda39d205 |
rev | line source |
---|---|
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1 /* |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
4 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
10 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
15 * accompanied this code). |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
16 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
20 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
23 * questions. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
24 */ |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.object; |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
26 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
18747
6db7923af642
OM: DynamicObject extends TruffleObject, add default implementation
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
18407
diff
changeset
|
28 import com.oracle.truffle.api.interop.*; |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
29 |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
30 public abstract class DynamicObject implements TypedObject, TruffleObject { |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
31 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
32 * Get the object's current shape. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
33 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
34 public abstract Shape getShape(); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
35 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
36 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
37 * Get property value. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
38 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
39 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
40 * @param defaultValue return value if property is not found |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 * @return property value or defaultValue if object has no such property |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
43 public abstract Object get(Object key, Object defaultValue); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 * Set value of existing property. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
47 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
48 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
49 * @param value value to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
50 * @return {@code true} if successful or {@code false} if property not found |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
51 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
52 public abstract boolean set(Object key, Object value); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
53 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
54 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
55 * Define new property or redefine existing property. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
56 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
57 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
58 * @param value value to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
59 * @param flags flags to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
60 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
61 public abstract void define(Object key, Object value, int flags); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
62 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
63 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
64 * Define new property with a static location or change existing property. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
65 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
66 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
67 * @param value value to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
68 * @param flags flags to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
69 * @param locationFactory factory function that creates a location for a given shape and value |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
70 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
71 public abstract void define(Object key, Object value, int flags, LocationFactory locationFactory); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
72 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 * Change property flags. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 * @param newFlags flags to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 * @return {@code true} if successful or {@code false} if property not found |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
80 public abstract boolean changeFlags(Object key, int newFlags); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
81 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
82 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
83 * Change property flags. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
84 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
85 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
86 * @param flagsUpdateFunction function updating old flags to new flags |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
87 * @return {@code true} if successful or {@code false} if property not found |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
88 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
89 public abstract boolean changeFlags(Object key, FlagsFunction flagsUpdateFunction); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
90 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
91 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
92 * Delete property. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
93 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
94 * @param key property identifier |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
95 * @return {@code true} if successful or {@code false} if property not found |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
96 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
97 public abstract boolean delete(Object key); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
98 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
99 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
100 * Returns the number of properties in this object. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
101 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
102 public abstract int size(); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
103 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
104 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
105 * Returns {@code true} if this object contains no properties. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
106 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
107 public abstract boolean isEmpty(); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
108 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
109 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
110 * Set object shape and grow storage if necessary. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
111 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
112 * @param oldShape the object's current shape (must equal {@link #getShape()}) |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
113 * @param newShape the new shape to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
114 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
115 public abstract void setShapeAndGrow(Shape oldShape, Shape newShape); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
116 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
117 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
118 * Set object shape and resize storage if necessary. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
119 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
120 * @param oldShape the object's current shape (must equal {@link #getShape()}) |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
121 * @param newShape the new shape to be set |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
122 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
123 public abstract void setShapeAndResize(Shape oldShape, Shape newShape); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
124 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
125 /** |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
126 * Ensure object shape is up-to-date. |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
127 * |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
128 * @return {@code true} if shape has changed |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
129 */ |
19336
723142fed324
Change DynamicObject from an interface to an abstract class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18747
diff
changeset
|
130 public abstract boolean updateShape(); |
18407
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
131 |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
132 public interface FlagsFunction { |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
133 int apply(int t); |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
134 } |
f439fdb137a3
Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
135 } |