annotate truffle/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/Layout.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 494bfe8a25ff
children 567d324c306c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22151
diff changeset
27 import com.oracle.truffle.api.nodes.NodeUtil.FieldOffsetProvider;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22151
diff changeset
28 import com.oracle.truffle.api.object.Shape.Allocator;
22150
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
29 import java.util.EnumSet;
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
30 import java.util.ServiceLoader;
18407
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
31
22092
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
32 /**
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
33 * Describes layout and behavior of a {@link DynamicObject} subclass and is used to create shapes.
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
34 *
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
35 * An object may change its shape but only to shapes of the same layout.
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
36 */
18407
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
37 public abstract class Layout {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
38 public static final EnumSet<ImplicitCast> NONE = EnumSet.noneOf(ImplicitCast.class);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
39 public static final EnumSet<ImplicitCast> INT_TO_DOUBLE = EnumSet.of(ImplicitCast.IntToDouble);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
40 public static final EnumSet<ImplicitCast> INT_TO_LONG = EnumSet.of(ImplicitCast.IntToLong);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
41
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
42 public static final String OPTION_PREFIX = "truffle.object.";
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
43
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
44 private static final LayoutFactory LAYOUT_FACTORY = loadLayoutFactory();
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
45
22092
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
46 /**
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
47 * Specifies the allowed implicit casts between primitive types without losing type information.
1a1aa12ab310 add some missing javadoc
Andreas Woess <andreas.woess@oracle.com>
parents: 21951
diff changeset
48 */
18407
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
49 public enum ImplicitCast {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
50 IntToDouble,
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
51 IntToLong,
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
52 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
53
22150
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
54 /**
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
55 * Create a new {@link LayoutBuilder}.
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
56 */
22151
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
57 public static Builder newLayout() {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
58 return new Builder();
22150
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
59 }
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
60
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
61 /**
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
62 * Equivalent to {@code Layout.newLayout().build()}.
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
63 */
18407
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
64 public static Layout createLayout() {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
65 return createLayout(NONE);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
66 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
67
22150
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
68 /**
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
69 * Equivalent to
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
70 * {@code Layout.newLayout().setAllowedImplicitCasts(allowedImplicitCasts).build()}.
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
71 */
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
72 @Deprecated
18407
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
73 public static Layout createLayout(EnumSet<ImplicitCast> allowedImplicitCasts) {
22150
ac6dadffdf32 add Layout.newLayout() as replacement for `new LayoutBuilder()`
Andreas Woess <andreas.woess@oracle.com>
parents: 22092
diff changeset
74 return newLayout().setAllowedImplicitCasts(allowedImplicitCasts).build();
18407
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
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
77 public abstract DynamicObject newInstance(Shape shape);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
78
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
79 public abstract Class<? extends DynamicObject> getType();
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
80
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
81 public abstract Shape createShape(ObjectType operations);
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 public abstract Shape createShape(ObjectType operations, Object sharedData);
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 public abstract Shape createShape(ObjectType operations, Object sharedData, int id);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
86
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
87 /**
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
88 * Create an allocator for static property creation. Reserves all array extension slots.
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
89 */
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
90 public abstract Allocator createAllocator();
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 protected static LayoutFactory getFactory() {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
93 return LAYOUT_FACTORY;
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
94 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
95
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
96 private static LayoutFactory loadLayoutFactory() {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
97 LayoutFactory bestLayoutFactory = null;
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 String layoutFactoryImplClassName = System.getProperty(OPTION_PREFIX + "LayoutFactory");
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
100 if (layoutFactoryImplClassName != null) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
101 Class<?> clazz;
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
102 try {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
103 clazz = Class.forName(layoutFactoryImplClassName);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
104 } catch (ClassNotFoundException e) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
105 throw new RuntimeException(e);
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
106 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
107 try {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
108 bestLayoutFactory = (LayoutFactory) clazz.newInstance();
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
109 } catch (InstantiationException | IllegalAccessException e) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
110 throw new AssertionError(e);
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 } else {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
113 ServiceLoader<LayoutFactory> serviceLoader = ServiceLoader.load(LayoutFactory.class, Layout.class.getClassLoader());
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
114 for (LayoutFactory currentLayoutFactory : serviceLoader) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
115 if (bestLayoutFactory == null) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
116 bestLayoutFactory = currentLayoutFactory;
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
117 } else if (currentLayoutFactory.getPriority() >= bestLayoutFactory.getPriority()) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
118 assert currentLayoutFactory.getPriority() != bestLayoutFactory.getPriority();
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
119 bestLayoutFactory = currentLayoutFactory;
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
120 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
121 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
122 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
123
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
124 if (bestLayoutFactory == null) {
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
125 throw new AssertionError("LayoutFactory not found");
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
126 }
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
127 return bestLayoutFactory;
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
128 }
22151
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
129
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
130 /**
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
131 * Layout builder.
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
132 *
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
133 * @see Layout
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
134 */
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
135 public static final class Builder {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
136 private EnumSet<ImplicitCast> allowedImplicitCasts;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
137 private FieldOffsetProvider fieldOffsetProvider;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
138
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
139 /**
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
140 * Create a new layout builder.
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
141 */
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
142 private Builder() {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
143 this.allowedImplicitCasts = Layout.NONE;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
144 this.fieldOffsetProvider = null;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
145 }
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
146
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
147 /**
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
148 * Build {@link Layout} from the configuration in this builder.
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
149 */
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
150 public Layout build() {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
151 return Layout.getFactory().createLayout(this);
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
152 }
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
153
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
154 /**
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
155 * Set the allowed implicit casts in this layout.
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
156 *
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
157 * @see Layout.ImplicitCast
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
158 */
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
159 public Builder setAllowedImplicitCasts(EnumSet<ImplicitCast> allowedImplicitCasts) {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
160 this.allowedImplicitCasts = allowedImplicitCasts;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
161 return this;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
162 }
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
163
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
164 /**
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
165 * Set a custom field offset provider for this layout.
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
166 */
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
167 public Builder setFieldOffsetProvider(FieldOffsetProvider fieldOffsetProvider) {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
168 this.fieldOffsetProvider = fieldOffsetProvider;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
169 return this;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
170 }
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
171
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
172 public EnumSet<ImplicitCast> getAllowedImplicitCasts() {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
173 return allowedImplicitCasts;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
174 }
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
175
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
176 public FieldOffsetProvider getFieldOffsetProvider() {
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
177 return fieldOffsetProvider;
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
178 }
494bfe8a25ff move LayoutBuilder to Layout.Builder
Andreas Woess <andreas.woess@oracle.com>
parents: 22150
diff changeset
179 }
18407
f439fdb137a3 Truffle: initial commit of object API
Andreas Woess <andreas.woess@jku.at>
parents:
diff changeset
180 }