Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/InterfaceChildFieldTest.java @ 22241:14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
- Caused by lack of a "vm" known to the Accessor during most testing, making the Instrumenter unavailable, which is now required to create a CallTarget
- Modified the Instrumenter/Accessor with a static field that can be reflectively "poked" with a vm value for testing
- Create a pair of methods to globally enable/disable testing mode to modify that static field and restore it when tests complete.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 22 Sep 2015 20:31:19 -0700 |
parents | dc83cc1f94f2 |
children | 0d36601f233e |
rev | line source |
---|---|
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
1 /* |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
4 * |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
8 * |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
14 * |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
18 * |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
21 * questions. |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
22 */ |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
24 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
25 import com.oracle.truffle.api.CallTarget; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
26 import com.oracle.truffle.api.Truffle; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
27 import com.oracle.truffle.api.TruffleRuntime; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
28 import com.oracle.truffle.api.frame.VirtualFrame; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
29 import com.oracle.truffle.api.nodes.Node; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
30 import com.oracle.truffle.api.nodes.NodeInterface; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
31 import com.oracle.truffle.api.nodes.NodeUtil; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
32 import com.oracle.truffle.api.nodes.RootNode; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
33 import com.oracle.truffle.api.test.utilities.InstrumentationTestMode; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
34 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
35 import java.util.Iterator; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
36 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
37 import org.junit.After; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
38 import org.junit.Assert; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
39 import org.junit.Before; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22003
diff
changeset
|
40 import org.junit.Test; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
41 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
42 /** |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
43 * Test child fields declared with interface types instead of {@link Node} subclasses. |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
44 */ |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
45 public class InterfaceChildFieldTest { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
46 |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
47 @Before |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
48 public void before() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
49 InstrumentationTestMode.set(true); |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
50 } |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
51 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
52 @After |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
53 public void after() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
54 InstrumentationTestMode.set(false); |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
55 } |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
56 |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
57 @Test |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
58 public void testChild() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
59 TruffleRuntime runtime = Truffle.getRuntime(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
60 TestChildInterface leftChild = new TestLeafNode(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
61 TestChildInterface rightChild = new TestLeafNode(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
62 TestChildNode parent = new TestChildNode(leftChild, rightChild); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
63 TestRootNode rootNode = new TestRootNode(parent); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
64 CallTarget target = runtime.createCallTarget(rootNode); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
65 Iterator<Node> iterator = parent.getChildren().iterator(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
66 Assert.assertEquals(leftChild, iterator.next()); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
67 Assert.assertEquals(rightChild, iterator.next()); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
68 Assert.assertFalse(iterator.hasNext()); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
69 Object result = target.call(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
70 Assert.assertEquals(42, result); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
71 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
72 Assert.assertEquals(4, NodeUtil.countNodes(rootNode)); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
73 Assert.assertEquals(4, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode))); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
74 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
75 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
76 @Test |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
77 public void testChildren() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
78 TruffleRuntime runtime = Truffle.getRuntime(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
79 TestChildInterface[] children = new TestChildInterface[5]; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
80 for (int i = 0; i < children.length; i++) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
81 children[i] = new TestLeafNode(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
82 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
83 TestChildrenNode parent = new TestChildrenNode(children); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
84 TestRootNode rootNode = new TestRootNode(parent); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
85 CallTarget target = runtime.createCallTarget(rootNode); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
86 Iterator<Node> iterator = parent.getChildren().iterator(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
87 for (int i = 0; i < children.length; i++) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
88 Assert.assertEquals(children[i], iterator.next()); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
89 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
90 Assert.assertFalse(iterator.hasNext()); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
91 Object result = target.call(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
92 Assert.assertEquals(105, result); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
93 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
94 Assert.assertEquals(2 + children.length, NodeUtil.countNodes(rootNode)); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
95 Assert.assertEquals(2 + children.length, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode))); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
96 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
97 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
98 class TestRootNode extends RootNode { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
99 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
100 @Child private TestChildInterface child; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
101 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
102 public TestRootNode(TestChildInterface child) { |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
103 super(TestingLanguage.class, null, null); |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
104 this.child = child; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
105 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
106 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
107 @Override |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
108 public Object execute(VirtualFrame frame) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
109 return child.executeIntf(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
110 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
111 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
112 |
18332
65a160d9d259
Truffle: add NodeInterface and require that all child fields be of this type
Andreas Woess <andreas.woess@jku.at>
parents:
18163
diff
changeset
|
113 interface TestChildInterface extends NodeInterface { |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
17275
diff
changeset
|
114 int executeIntf(); |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
115 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
116 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
117 class TestLeafNode extends Node implements TestChildInterface { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
118 public TestLeafNode() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
119 super(null); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
120 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
121 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
122 public int executeIntf() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
123 return this.replace(new TestLeaf2Node()).executeIntf(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
124 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
125 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
126 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
127 class TestLeaf2Node extends Node implements TestChildInterface { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
128 public TestLeaf2Node() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
129 super(null); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
130 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
131 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
132 public int executeIntf() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
133 return 21; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
134 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
135 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
136 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
137 class TestChildNode extends Node implements TestChildInterface { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
138 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
139 @Child private TestChildInterface left; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
140 @Child private TestChildInterface right; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
141 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
142 public TestChildNode(TestChildInterface left, TestChildInterface right) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
143 super(null); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
144 this.left = left; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
145 this.right = right; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
146 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
147 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
148 @Override |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
149 public int executeIntf() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
150 return left.executeIntf() + right.executeIntf(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
151 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
152 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
153 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
154 class TestChildrenNode extends Node implements TestChildInterface { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
155 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
156 @Children private final TestChildInterface[] children; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
157 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
158 public TestChildrenNode(TestChildInterface[] children) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
159 super(null); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
160 this.children = children; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
161 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
162 |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
163 @Override |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
164 public int executeIntf() { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
165 int sum = 0; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
166 for (int i = 0; i < children.length; ++i) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
167 sum += children[i].executeIntf(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
168 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
169 return sum; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
170 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
171 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
diff
changeset
|
172 } |