Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/Location.java @ 22182:21863e2a1d34
api.object: remove BaseLocation interface
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Tue, 22 Sep 2015 15:49:49 +0200 |
parents | dc83cc1f94f2 |
children | dd0b18eb8000 |
comparison
equal
deleted
inserted
replaced
22181:4eb6f179a326 | 22182:21863e2a1d34 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this | 7 * published by the Free Software Foundation. Oracle designates this |
31 * | 31 * |
32 * @see Shape | 32 * @see Shape |
33 * @see Property | 33 * @see Property |
34 * @see DynamicObject | 34 * @see DynamicObject |
35 */ | 35 */ |
36 public abstract class Location implements BaseLocation { | 36 public abstract class Location { |
37 protected static IncompatibleLocationException incompatibleLocation() throws IncompatibleLocationException { | 37 protected static IncompatibleLocationException incompatibleLocation() throws IncompatibleLocationException { |
38 CompilerDirectives.transferToInterpreterAndInvalidate(); | 38 CompilerDirectives.transferToInterpreterAndInvalidate(); |
39 throw new IncompatibleLocationException(); | 39 throw new IncompatibleLocationException(); |
40 } | 40 } |
41 | 41 |
42 protected static FinalLocationException finalLocation() throws FinalLocationException { | 42 protected static FinalLocationException finalLocation() throws FinalLocationException { |
43 CompilerDirectives.transferToInterpreterAndInvalidate(); | 43 CompilerDirectives.transferToInterpreterAndInvalidate(); |
44 throw new FinalLocationException(); | 44 throw new FinalLocationException(); |
45 } | 45 } |
46 | 46 |
47 /** | |
48 * Get object value as object at this location in store. | |
49 * | |
50 * @param shape the current shape of the object, which must contain this location | |
51 */ | |
47 public final Object get(DynamicObject store, Shape shape) { | 52 public final Object get(DynamicObject store, Shape shape) { |
48 return get(store, checkShape(store, shape)); | 53 return get(store, checkShape(store, shape)); |
49 } | 54 } |
50 | 55 |
56 /** | |
57 * Get object value as object at this location in store. For internal use only and subject to | |
58 * change, use {@link #get(DynamicObject, Shape)} instead. | |
59 * | |
60 * @param condition the result of a shape check or {@code false} | |
61 * @see #get(DynamicObject, Shape) | |
62 */ | |
51 public Object get(DynamicObject store, boolean condition) { | 63 public Object get(DynamicObject store, boolean condition) { |
52 return getInternal(store); | 64 return getInternal(store); |
53 } | 65 } |
54 | 66 |
67 /** | |
68 * Get object value as object at this location in store. | |
69 * | |
70 * @param shape the current shape of the object, which must contain this location | |
71 */ | |
72 public final Object get(DynamicObject store) { | |
73 return get(store, false); | |
74 } | |
75 | |
76 /** | |
77 * Set object value at this location in store. | |
78 * | |
79 * @param shape the current shape of the storage object | |
80 * @throws IncompatibleLocationException for storage type invalidations | |
81 * @throws FinalLocationException for effectively final fields | |
82 */ | |
55 public void set(DynamicObject store, Object value, Shape shape) throws IncompatibleLocationException, FinalLocationException { | 83 public void set(DynamicObject store, Object value, Shape shape) throws IncompatibleLocationException, FinalLocationException { |
56 setInternal(store, value); | 84 setInternal(store, value); |
57 } | 85 } |
58 | 86 |
87 /** | |
88 * Set object value at this location in store and update shape. | |
89 * | |
90 * @param oldShape the shape before the transition | |
91 * @param newShape new shape after the transition | |
92 * @throws IncompatibleLocationException if value is of non-assignable type | |
93 */ | |
59 public final void set(DynamicObject store, Object value, Shape oldShape, Shape newShape) throws IncompatibleLocationException { | 94 public final void set(DynamicObject store, Object value, Shape oldShape, Shape newShape) throws IncompatibleLocationException { |
60 if (canStore(value)) { | 95 if (canStore(value)) { |
61 store.setShapeAndGrow(oldShape, newShape); | 96 store.setShapeAndGrow(oldShape, newShape); |
62 try { | 97 try { |
63 setInternal(store, value); | 98 setInternal(store, value); |
67 } else { | 102 } else { |
68 throw incompatibleLocation(); | 103 throw incompatibleLocation(); |
69 } | 104 } |
70 } | 105 } |
71 | 106 |
107 /** | |
108 * Set object value at this location in store. | |
109 * | |
110 * @throws IncompatibleLocationException for storage type invalidations | |
111 * @throws FinalLocationException for effectively final fields | |
112 */ | |
72 public final void set(DynamicObject store, Object value) throws IncompatibleLocationException, FinalLocationException { | 113 public final void set(DynamicObject store, Object value) throws IncompatibleLocationException, FinalLocationException { |
73 set(store, value, null); | 114 set(store, value, null); |
74 } | 115 } |
75 | 116 |
76 protected abstract Object getInternal(DynamicObject store); | 117 protected abstract Object getInternal(DynamicObject store); |
129 * Abstract to force overriding. | 170 * Abstract to force overriding. |
130 */ | 171 */ |
131 @Override | 172 @Override |
132 public abstract boolean equals(Object obj); | 173 public abstract boolean equals(Object obj); |
133 | 174 |
175 /** | |
176 * Equivalent to {@link Shape#check(DynamicObject)}. | |
177 */ | |
134 protected static boolean checkShape(DynamicObject store, Shape shape) { | 178 protected static boolean checkShape(DynamicObject store, Shape shape) { |
135 return store.getShape() == shape; | 179 return store.getShape() == shape; |
136 } | 180 } |
137 } | 181 } |