Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 22157:dc83cc1f94f2
Using fully qualified imports
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 11:33:22 +0200 |
parents | 65e9fbb40e51 |
children | 5e5b38579bda c896a8e70777 |
rev | line source |
---|---|
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
11279
494b818b527c
Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10845
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
494b818b527c
Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10845
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
494b818b527c
Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10845
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 * questions. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.nodes; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
27 import com.oracle.truffle.api.CompilerAsserts; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
28 import com.oracle.truffle.api.TruffleOptions; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
29 import com.oracle.truffle.api.instrument.Probe; |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
30 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
31 import com.oracle.truffle.api.instrument.StandardSyntaxTag; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
32 import com.oracle.truffle.api.instrument.SyntaxTag; |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
33 import com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
34 import com.oracle.truffle.api.source.SourceSection; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
35 import java.io.OutputStream; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
36 import java.io.PrintStream; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
37 import java.io.PrintWriter; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
38 import java.io.StringWriter; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
39 import java.lang.annotation.Annotation; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
40 import java.lang.reflect.Array; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
41 import java.lang.reflect.Field; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
42 import java.util.ArrayList; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
43 import java.util.Arrays; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
44 import java.util.Collection; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
45 import java.util.Iterator; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
46 import java.util.List; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
47 import java.util.NoSuchElementException; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
48 import java.util.Objects; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
49 import sun.misc.Unsafe; |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
50 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 * Utility class that manages the special access methods for node instances. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 */ |
11636
136eaa90ef41
Truffle: make NodeUtil class final and its unsafe field private.
Andreas Woess <andreas.woess@jku.at>
parents:
11622
diff
changeset
|
54 public final class NodeUtil { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
56 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
57 * Interface that allows the customization of field offsets used for {@link Unsafe} field |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
58 * accesses. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
59 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
60 public interface FieldOffsetProvider { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
61 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
62 long objectFieldOffset(Field field); |
15834
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
63 |
fc6f8d143c68
Introduce method to customize type size
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15093
diff
changeset
|
64 int getTypeSize(Class<?> clazz); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
65 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
66 |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
67 static Iterator<Node> makeIterator(Node node) { |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
68 return node.getNodeClass().makeIterator(node); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
70 |
17399
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
71 public static Iterator<Node> makeRecursiveIterator(Node node) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
72 return new RecursiveNodeIterator(node); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
73 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
74 |
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:
17399
diff
changeset
|
75 private static final class RecursiveNodeIterator implements Iterator<Node> { |
17399
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
76 private final List<Iterator<Node>> iteratorStack = new ArrayList<>(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
77 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
78 public RecursiveNodeIterator(final Node node) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
79 iteratorStack.add(new Iterator<Node>() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
80 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
81 private boolean visited; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
82 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
83 public void remove() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
84 throw new UnsupportedOperationException(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
85 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
86 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
87 public Node next() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
88 if (visited) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
89 throw new NoSuchElementException(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
90 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
91 visited = true; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
92 return node; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
93 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
94 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
95 public boolean hasNext() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
96 return !visited; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
97 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
98 }); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
99 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
100 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
101 public boolean hasNext() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
102 return peekIterator() != null; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
103 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
104 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
105 public Node next() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
106 Iterator<Node> iterator = peekIterator(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
107 if (iterator == null) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
108 throw new NoSuchElementException(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
109 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
110 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
111 Node node = iterator.next(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
112 if (node != null) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
113 Iterator<Node> childIterator = makeIterator(node); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
114 if (childIterator.hasNext()) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
115 iteratorStack.add(childIterator); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
116 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
117 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
118 return node; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
119 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
120 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
121 private Iterator<Node> peekIterator() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
122 int tos = iteratorStack.size() - 1; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
123 while (tos >= 0) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
124 Iterator<Node> iterable = iteratorStack.get(tos); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
125 if (iterable.hasNext()) { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
126 return iterable; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
127 } else { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
128 iteratorStack.remove(tos--); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
129 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
130 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
131 return null; |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
132 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
133 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
134 public void remove() { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
135 throw new UnsupportedOperationException(); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
136 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
137 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
138 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
139 @SuppressWarnings("unchecked") |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
140 public static <T extends Node> T cloneNode(T orig) { |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
141 return (T) orig.deepCopy(); |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
142 } |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
143 |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
144 static Node deepCopyImpl(Node orig) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21951
diff
changeset
|
145 CompilerAsserts.neverPartOfCompilation(); |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
146 final Node clone = orig.copy(); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
147 NodeClass nodeClass = clone.getNodeClass(); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
148 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
149 nodeClass.getParentField().putObject(clone, null); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
150 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
151 for (NodeFieldAccessor childField : nodeClass.getChildFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
152 Node child = (Node) childField.getObject(orig); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
153 if (child != null) { |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
154 Node clonedChild = child.deepCopy(); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
155 nodeClass.getParentField().putObject(clonedChild, clone); |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
156 childField.putObject(clone, clonedChild); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
157 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
158 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
159 for (NodeFieldAccessor childrenField : nodeClass.getChildrenFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
160 Object[] children = (Object[]) childrenField.getObject(orig); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
161 if (children != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
162 Object[] clonedChildren = (Object[]) Array.newInstance(children.getClass().getComponentType(), children.length); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
163 for (int i = 0; i < children.length; i++) { |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
164 if (children[i] != null) { |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
165 Node clonedChild = ((Node) children[i]).deepCopy(); |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
166 clonedChildren[i] = clonedChild; |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
167 nodeClass.getParentField().putObject(clonedChild, clone); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
168 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
169 } |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
170 childrenField.putObject(clone, clonedChildren); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
171 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
172 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
173 for (NodeFieldAccessor cloneableField : nodeClass.getCloneableFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
174 Object cloneable = cloneableField.getObject(clone); |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
175 if (cloneable != null && cloneable == cloneableField.getObject(orig)) { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
176 cloneableField.putObject(clone, ((NodeCloneable) cloneable).clone()); |
18510
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
18485
diff
changeset
|
177 } |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
18485
diff
changeset
|
178 } |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
179 return clone; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
180 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
181 |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
182 public static List<Node> findNodeChildren(Node node) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21951
diff
changeset
|
183 CompilerAsserts.neverPartOfCompilation(); |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
184 List<Node> nodes = new ArrayList<>(); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
185 NodeClass nodeClass = node.getNodeClass(); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
186 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
187 for (NodeFieldAccessor nodeField : nodeClass.getChildFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
188 Object child = nodeField.getObject(node); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
189 if (child != null) { |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
190 nodes.add((Node) child); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
191 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
192 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
193 for (NodeFieldAccessor nodeField : nodeClass.getChildrenFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
194 Object[] children = (Object[]) nodeField.getObject(node); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 if (children != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
196 for (Object child : children) { |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
197 if (child != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
198 nodes.add((Node) child); |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
199 } |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
200 } |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
201 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
202 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
203 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
204 return nodes; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
205 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
206 |
19758
f682b9e6ca07
Truffle: expose non-atomic replace API to Truffle DSL to avoid multiple RootNode lookups for multiple replaces in one atomic block.
Christian Humer <christian.humer@gmail.com>
parents:
19607
diff
changeset
|
207 public static <T extends Node> T nonAtomicReplace(Node oldNode, T newNode, CharSequence reason) { |
f682b9e6ca07
Truffle: expose non-atomic replace API to Truffle DSL to avoid multiple RootNode lookups for multiple replaces in one atomic block.
Christian Humer <christian.humer@gmail.com>
parents:
19607
diff
changeset
|
208 oldNode.replaceHelper(newNode, reason); |
f682b9e6ca07
Truffle: expose non-atomic replace API to Truffle DSL to avoid multiple RootNode lookups for multiple replaces in one atomic block.
Christian Humer <christian.humer@gmail.com>
parents:
19607
diff
changeset
|
209 return newNode; |
f682b9e6ca07
Truffle: expose non-atomic replace API to Truffle DSL to avoid multiple RootNode lookups for multiple replaces in one atomic block.
Christian Humer <christian.humer@gmail.com>
parents:
19607
diff
changeset
|
210 } |
f682b9e6ca07
Truffle: expose non-atomic replace API to Truffle DSL to avoid multiple RootNode lookups for multiple replaces in one atomic block.
Christian Humer <christian.humer@gmail.com>
parents:
19607
diff
changeset
|
211 |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
212 public static boolean replaceChild(Node parent, Node oldChild, Node newChild) { |
22080
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
213 return replaceChild(parent, oldChild, newChild, false); |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
214 } |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
215 |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
216 static boolean replaceChild(Node parent, Node oldChild, Node newChild, boolean adopt) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21951
diff
changeset
|
217 CompilerAsserts.neverPartOfCompilation(); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
218 NodeClass nodeClass = parent.getNodeClass(); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
219 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
220 for (NodeFieldAccessor nodeField : nodeClass.getChildFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
221 if (nodeField.getObject(parent) == oldChild) { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
222 assert assertAssignable(nodeField, newChild); |
22080
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
223 if (adopt) { |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
224 parent.adoptHelper(newChild); |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
225 } |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
226 nodeField.putObject(parent, newChild); |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
227 return true; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
228 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
229 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
230 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
231 for (NodeFieldAccessor nodeField : nodeClass.getChildrenFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
232 Object arrayObject = nodeField.getObject(parent); |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
233 if (arrayObject != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
234 Object[] array = (Object[]) arrayObject; |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
235 for (int i = 0; i < array.length; i++) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
236 if (array[i] == oldChild) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
237 assert assertAssignable(nodeField, newChild); |
22080
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
238 if (adopt) { |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
239 parent.adoptHelper(newChild); |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
240 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
241 array[i] = newChild; |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
242 return true; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
244 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
245 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
246 } |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
247 return false; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
248 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
249 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
250 private static boolean assertAssignable(NodeFieldAccessor field, Object newValue) { |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
251 if (newValue == null) { |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
252 return true; |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
253 } |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
254 if (field.getKind() == NodeFieldKind.CHILD) { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
255 if (field.getType().isAssignableFrom(newValue.getClass())) { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
256 return true; |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
257 } else { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
258 assert false : "Child class " + newValue.getClass().getName() + " is not assignable to field \"" + field.getName() + "\" of type " + field.getType().getName(); |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
259 return false; |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
260 } |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
261 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
262 if (field.getType().getComponentType().isAssignableFrom(newValue.getClass())) { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
263 return true; |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
264 } else { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
265 assert false : "Child class " + newValue.getClass().getName() + " is not assignable to field \"" + field.getName() + "\" of type " + field.getType().getName(); |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
266 return false; |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
267 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
268 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
269 throw new IllegalArgumentException(); |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
270 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
271 |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
272 /** |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
273 * Finds the field in a parent node, if any, that holds a specified child node. |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
274 * |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
275 * @return the field (possibly an array) holding the child, {@code null} if not found. |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
276 */ |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
277 public static NodeFieldAccessor findChildField(Node parent, Node child) { |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
278 assert child != null; |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
279 NodeClass parentNodeClass = parent.getNodeClass(); |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
280 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
281 for (NodeFieldAccessor field : parentNodeClass.getChildFields()) { |
19012
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
282 if (field.getObject(parent) == child) { |
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
283 return field; |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
284 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
285 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
286 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
287 for (NodeFieldAccessor field : parentNodeClass.getChildrenFields()) { |
19012
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
288 Object arrayObject = field.getObject(parent); |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
289 if (arrayObject != null) { |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
290 Object[] array = (Object[]) arrayObject; |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
291 for (int i = 0; i < array.length; i++) { |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
292 if (array[i] == child) { |
19012
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
293 return field; |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
294 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
295 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
296 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
297 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
298 return null; |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
299 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
300 |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
301 /** |
19141
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
302 * Determines whether a proposed child replacement would be safe: structurally and type. |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
303 */ |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
304 public static boolean isReplacementSafe(Node parent, Node oldChild, Node newChild) { |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
305 assert newChild != null; |
19141
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
306 if (parent != null) { |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
307 final NodeFieldAccessor field = findChildField(parent, oldChild); |
19141
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
308 if (field != null) { |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
309 switch (field.getKind()) { |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
310 case CHILD: |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
311 return field.getType().isAssignableFrom(newChild.getClass()); |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
312 case CHILDREN: |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
313 return field.getType().getComponentType().isAssignableFrom(newChild.getClass()); |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
314 default: |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
315 throw new IllegalStateException(); |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
316 } |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
317 } |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
318 } |
19141
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
319 return false; |
18984
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
320 } |
0f462015296f
Truffle: Additions to NodeUtil to support optional "safe" AST node replacement (and diagnostics when unsafe)
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18905
diff
changeset
|
321 |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
322 /** |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
323 * Executes a closure for every non-null child of the parent node. |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
324 * |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
325 * @return {@code true} if all children were visited, {@code false} otherwise |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
326 */ |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
327 public static boolean forEachChild(Node parent, NodeVisitor visitor) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21951
diff
changeset
|
328 CompilerAsserts.neverPartOfCompilation(); |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
329 Objects.requireNonNull(visitor); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
330 NodeClass parentNodeClass = parent.getNodeClass(); |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
331 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
332 for (NodeFieldAccessor field : parentNodeClass.getChildFields()) { |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
333 Object child = field.getObject(parent); |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
334 if (child != null) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
335 if (!visitor.visit((Node) child)) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
336 return false; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
337 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
338 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
339 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
340 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
341 for (NodeFieldAccessor field : parentNodeClass.getChildrenFields()) { |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
342 Object arrayObject = field.getObject(parent); |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
343 if (arrayObject != null) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
344 Object[] array = (Object[]) arrayObject; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
345 for (int i = 0; i < array.length; i++) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
346 Object child = array[i]; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
347 if (child != null) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
348 if (!visitor.visit((Node) child)) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
349 return false; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
350 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
351 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
352 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
353 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
354 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
355 |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
356 return true; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
357 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
358 |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
359 static boolean forEachChildRecursive(Node parent, NodeVisitor visitor) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
360 NodeClass parentNodeClass = parent.getNodeClass(); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
361 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
362 for (NodeFieldAccessor field : parentNodeClass.getChildFields()) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
363 if (!visitChild((Node) field.getObject(parent), visitor)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
364 return false; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
365 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
366 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
367 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
368 for (NodeFieldAccessor field : parentNodeClass.getChildrenFields()) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
369 Object arrayObject = field.getObject(parent); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
370 if (arrayObject == null) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
371 continue; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
372 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
373 Object[] array = (Object[]) arrayObject; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
374 for (int i = 0; i < array.length; i++) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
375 if (!visitChild((Node) array[i], visitor)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
376 return false; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
377 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
378 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
379 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
380 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
381 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
382 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
383 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
384 private static boolean visitChild(Node child, NodeVisitor visitor) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
385 if (child == null) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
386 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
387 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
388 if (!visitor.visit(child)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
389 return false; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
390 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
391 if (!forEachChildRecursive(child, visitor)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
392 return false; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
393 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
394 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
395 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
396 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
397 /** Returns all declared fields in the class hierarchy. */ |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
398 static Field[] getAllFields(Class<? extends Object> clazz) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
399 Field[] declaredFields = clazz.getDeclaredFields(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
400 if (clazz.getSuperclass() != null) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
401 return concat(getAllFields(clazz.getSuperclass()), declaredFields); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
402 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
403 return declaredFields; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
404 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
405 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
406 public static <T> T[] concat(T[] first, T[] second) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
407 T[] result = Arrays.copyOf(first, first.length + second.length); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
408 System.arraycopy(second, 0, result, first.length, second.length); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
409 return result; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
410 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
411 |
11622
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
412 /** |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
413 * Get the nth parent of a node, where the 0th parent is the node itself. Returns null if there |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
414 * are less than n ancestors. |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
415 */ |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
416 public static Node getNthParent(Node node, int n) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
417 Node parent = node; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
418 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
419 for (int i = 0; i < n; i++) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
420 parent = parent.getParent(); |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
421 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
422 if (parent == null) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
423 return null; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
424 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
425 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
426 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
427 return parent; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
428 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
429 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
430 /** find annotation in class/interface hierarchy. */ |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
431 public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
432 if (clazz.getAnnotation(annotationClass) != null) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
433 return clazz.getAnnotation(annotationClass); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
434 } else { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
435 for (Class<?> intf : clazz.getInterfaces()) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
436 if (intf.getAnnotation(annotationClass) != null) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
437 return intf.getAnnotation(annotationClass); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
438 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
439 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
440 if (clazz.getSuperclass() != null) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
441 return findAnnotation(clazz.getSuperclass(), annotationClass); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
442 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
443 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
444 return null; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
445 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
446 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
447 public static <T> T findParent(Node start, Class<T> clazz) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
448 Node parent = start.getParent(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
449 if (parent == null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
450 return null; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
451 } else if (clazz.isInstance(parent)) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
452 return clazz.cast(parent); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
453 } else { |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
454 return findParent(parent, clazz); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
455 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
456 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
457 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
458 public static <T> List<T> findAllParents(Node start, Class<T> clazz) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
459 List<T> parents = new ArrayList<>(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
460 T parent = findParent(start, clazz); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
461 while (parent != null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
462 parents.add(parent); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
463 parent = findParent((Node) parent, clazz); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
464 } |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
465 return parents; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
466 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
467 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
468 public static List<Node> collectNodes(Node parent, Node child) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
469 List<Node> nodes = new ArrayList<>(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
470 Node current = child; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
471 while (current != null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
472 nodes.add(current); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
473 if (current == parent) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
474 return nodes; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
475 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
476 current = current.getParent(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
477 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
478 throw new IllegalArgumentException("Node " + parent + " is not a parent of " + child + "."); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
479 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
480 |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
481 public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { |
21650
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
482 if (clazz.isInstance(root)) { |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
483 return clazz.cast(root); |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
484 } |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
485 for (Node child : root.getChildren()) { |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
486 T node = findFirstNodeInstance(child, clazz); |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
487 if (node != null) { |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
488 return node; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
489 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
490 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
491 return null; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
492 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
493 |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
494 public static <T> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
495 final List<T> nodeList = new ArrayList<>(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
496 root.accept(new NodeVisitor() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
497 public boolean visit(Node node) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
498 if (clazz.isInstance(node)) { |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
499 nodeList.add(clazz.cast(node)); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
500 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
501 return true; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
502 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
503 }); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
504 return nodeList; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
505 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
506 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
507 public static int countNodes(Node root) { |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
508 return countNodes(root, NodeCountFilter.NO_FILTER); |
13995
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
509 } |
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
510 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
511 public static int countNodes(Node root, NodeCountFilter filter) { |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
512 NodeCounter counter = new NodeCounter(filter); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
513 root.accept(counter); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
514 return counter.count; |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
515 } |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
516 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
517 public interface NodeCountFilter { |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
518 |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
519 NodeCountFilter NO_FILTER = new NodeCountFilter() { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
520 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
521 public boolean isCounted(Node node) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
522 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
523 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
524 }; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
525 |
14569
5e04917e6616
Truffle: renamed NodeFilter to NodeCountFilter and changed it to have inclusive implementation semantics.
Christian Humer <christian.humer@gmail.com>
parents:
14565
diff
changeset
|
526 boolean isCounted(Node node); |
14565
9c01fabfb167
Truffle: Removed deprecated API; Added NodeFilter to customize filter when counting nodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
527 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
528 } |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
529 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
530 public static String printCompactTreeToString(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
531 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
532 printCompactTree(new PrintWriter(out), null, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
533 return out.toString(); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
534 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
535 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
536 public static void printCompactTree(OutputStream out, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
537 printCompactTree(new PrintWriter(out), null, node, 1); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
538 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
539 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
540 private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
541 if (node == null) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
542 return; |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
543 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
544 for (int i = 0; i < level; i++) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
545 p.print(" "); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
546 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
547 if (parent == null) { |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
548 p.println(nodeName(node)); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
549 } else { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
550 p.print(getNodeFieldName(parent, node, "unknownField")); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
551 p.print(" = "); |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
552 p.println(nodeName(node)); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
553 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
554 |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
555 for (Node child : node.getChildren()) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
556 printCompactTree(p, node, child, level + 1); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
557 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
558 p.flush(); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
559 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
560 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
561 public static String printSourceAttributionTree(Node node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
562 StringWriter out = new StringWriter(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
563 printSourceAttributionTree(new PrintWriter(out), null, node, 1); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
564 return out.toString(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
565 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
566 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
567 public static void printSourceAttributionTree(OutputStream out, Node node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
568 printSourceAttributionTree(new PrintWriter(out), null, node, 1); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
569 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
570 |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
571 public static void printSourceAttributionTree(PrintWriter out, Node node) { |
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
572 printSourceAttributionTree(out, null, node, 1); |
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
573 } |
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
574 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
575 private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
576 if (node == null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
577 return; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
578 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
579 if (parent == null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
580 // Add some preliminary information before starting with the root node |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
581 final SourceSection sourceSection = node.getSourceSection(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
582 if (sourceSection != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
583 final String txt = sourceSection.getSource().getCode(); |
11907
873da100d113
Truffle: another minor tweak to NodeUtil.printSourceAttributionTree
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11850
diff
changeset
|
584 p.println("Full source len=(" + txt.length() + ") ___" + txt + "___"); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
585 p.println("AST source attribution:"); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
586 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
587 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
588 final StringBuilder sb = new StringBuilder(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
589 for (int i = 0; i < level; i++) { |
11850
e68922869732
Truffle: minor legibility improvement in NodeUtil.printSourceAttributionTree()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11848
diff
changeset
|
590 sb.append("| "); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
591 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
592 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
593 if (parent != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
594 sb.append(getNodeFieldName(parent, node, "")); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
595 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
596 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
597 sb.append(" (" + node.getClass().getSimpleName() + ") "); |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
598 |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
599 sb.append(printSyntaxTags(node)); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
600 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
601 sb.append(displaySourceAttribution(node)); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
602 p.println(sb.toString()); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
603 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
604 for (Node child : node.getChildren()) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
605 printSourceAttributionTree(p, node, child, level + 1); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
606 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
607 p.flush(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
608 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
609 |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
610 private static String getNodeFieldName(Node parent, Node node, String defaultName) { |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
611 NodeFieldAccessor[] fields = parent.getNodeClass().getFields(); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
612 for (NodeFieldAccessor field : fields) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
613 Object value = field.loadValue(parent); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
614 if (field.getKind() == NodeFieldKind.CHILD && value == node) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
615 return field.getName(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
616 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
617 int index = 0; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
618 for (Object arrayNode : (Object[]) value) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
619 if (arrayNode == node) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
620 return field.getName() + "[" + index + "]"; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
621 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
622 index++; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
623 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
624 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
625 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
626 return defaultName; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
627 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
628 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
629 /** |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
630 * Returns a string listing the {@linkplain SyntaxTag syntax tags}, if any, associated with a |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
631 * node: |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
632 * <ul> |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
633 * <li>"[{@linkplain StandardSyntaxTag#STATEMENT STATEMENT}, |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
634 * {@linkplain StandardSyntaxTag#ASSIGNMENT ASSIGNMENT}]" if tags have been applied;</li> |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
635 * <li>"[]" if the node supports tags, but none are present; and</li> |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
636 * <li>"" if the node does not support tags.</li> |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
637 * </ul> |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
638 */ |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
639 public static String printSyntaxTags(final Object node) { |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
640 if (node instanceof WrapperNode) { |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
641 final Probe probe = ((WrapperNode) node).getProbe(); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
642 final Collection<SyntaxTag> syntaxTags = probe.getSyntaxTags(); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
643 final StringBuilder sb = new StringBuilder(); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
644 String prefix = ""; |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
645 sb.append("["); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
646 for (SyntaxTag tag : syntaxTags) { |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
647 sb.append(prefix); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
648 prefix = ","; |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
649 sb.append(tag.toString()); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
650 } |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
651 sb.append("]"); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
652 return sb.toString(); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
653 } |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
654 return ""; |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
655 } |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
656 |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18332
diff
changeset
|
657 /** |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
658 * Prints a human readable form of a {@link Node} AST to the given {@link PrintStream}. This |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
659 * print method does not check for cycles in the node structure. |
15090
07e7aae05983
Truffle: context sensitive inlining cleanup
Christian Humer <christian.humer@gmail.com>
parents:
15089
diff
changeset
|
660 * |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
661 * @param out the stream to print to. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
662 * @param node the root node to write |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
663 */ |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
664 public static void printTree(OutputStream out, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
665 printTree(new PrintWriter(out), node); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
666 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
667 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
668 public static String printTreeToString(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
669 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
670 printTree(new PrintWriter(out), node); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
671 return out.toString(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
672 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
673 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
674 public static void printTree(PrintWriter p, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
675 printTree(p, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
676 p.println(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
677 p.flush(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
678 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
679 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
680 private static void printTree(PrintWriter p, Node node, int level) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
681 if (node == null) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
682 p.print("null"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
683 return; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
684 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
685 |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
686 p.print(nodeName(node)); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
687 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
688 ArrayList<NodeFieldAccessor> childFields = new ArrayList<>(); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
689 String sep = ""; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
690 p.print("("); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
691 for (NodeFieldAccessor field : NodeClass.get(node).getFields()) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
692 if (field.getKind() == NodeFieldKind.CHILD || field.getKind() == NodeFieldKind.CHILDREN) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
693 childFields.add(field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
694 } else if (field.getKind() == NodeFieldKind.DATA) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
695 p.print(sep); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
696 sep = ", "; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
697 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
698 p.print(field.getName()); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
699 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
700 p.print(field.loadValue(node)); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
701 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
702 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
703 p.print(")"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
704 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
705 if (childFields.size() != 0) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
706 p.print(" {"); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
707 for (NodeFieldAccessor field : childFields) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
708 printNewLine(p, level); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
709 p.print(field.getName()); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
710 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
711 Object value = field.loadValue(node); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
712 if (value == null) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
713 p.print(" = null "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
714 } else if (field.getKind() == NodeFieldKind.CHILD) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
715 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
716 printTree(p, (Node) value, level + 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
717 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
718 printChildren(p, level, value); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
719 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
720 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
721 printNewLine(p, level - 1); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
722 p.print("}"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
723 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
724 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
725 |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
726 private static void printChildren(PrintWriter p, int level, Object value) { |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
727 String sep; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
728 Object[] children = (Object[]) value; |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
729 p.print(" = ["); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
730 sep = ""; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
731 for (Object child : children) { |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
732 p.print(sep); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
733 sep = ", "; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
734 printTree(p, (Node) child, level + 1); |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
735 } |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
736 p.print("]"); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
737 } |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
738 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
739 private static void printNewLine(PrintWriter p, int level) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
740 p.println(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
741 for (int i = 0; i < level; i++) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
742 p.print(" "); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
743 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
744 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
745 |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
746 private static String nodeName(Node node) { |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
747 return node.getClass().getSimpleName(); |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
748 } |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
749 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
750 private static String displaySourceAttribution(Node node) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
751 final SourceSection section = node.getSourceSection(); |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21966
diff
changeset
|
752 if (section != null && section.getSource() == null) { |
16511
aee02665e505
Truffle: NodeUtil fix for displaying null SourceSections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
753 return "source: " + section.getShortDescription(); |
aee02665e505
Truffle: NodeUtil fix for displaying null SourceSections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
754 } |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
755 if (section != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
756 final String srcText = section.getCode(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
757 final StringBuilder sb = new StringBuilder(); |
16674
70f47dbbcabd
Truffle/SourceAttribution: NodeUtil.displaySourceAttribution() outut revised for legibility.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16581
diff
changeset
|
758 sb.append("source:"); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
759 sb.append(" (" + section.getCharIndex() + "," + (section.getCharEndIndex() - 1) + ")"); |
19010
3bf612703773
Truffle: print the line number in the source attribution tree.
Chris Seaton <chris.seaton@oracle.com>
parents:
18984
diff
changeset
|
760 sb.append(" line=" + section.getLineLocation().getLineNumber()); |
16674
70f47dbbcabd
Truffle/SourceAttribution: NodeUtil.displaySourceAttribution() outut revised for legibility.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16581
diff
changeset
|
761 sb.append(" len=" + srcText.length()); |
70f47dbbcabd
Truffle/SourceAttribution: NodeUtil.displaySourceAttribution() outut revised for legibility.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16581
diff
changeset
|
762 sb.append(" text=\"" + srcText + "\""); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
763 return sb.toString(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
764 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
765 return ""; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
766 } |
11950
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
767 |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
768 public static boolean verify(Node root) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
769 Iterable<Node> children = root.getChildren(); |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
770 for (Node child : children) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
771 if (child != null) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
772 if (child.getParent() != root) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
773 throw new AssertionError(toStringWithClass(child) + ": actual parent=" + toStringWithClass(child.getParent()) + " expected parent=" + toStringWithClass(root)); |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
774 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
775 verify(child); |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
776 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
777 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
778 return true; |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
779 } |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
780 |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
781 private static String toStringWithClass(Object obj) { |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
782 return obj == null ? "null" : obj + "(" + obj.getClass().getName() + ")"; |
be0a33a631fa
Truffle: fix node rewrite issue that can occur when a currently executing node is replaced in a recursive call.
Andreas Woess <andreas.woess@jku.at>
parents:
11907
diff
changeset
|
783 } |
16464
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
784 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
785 static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
786 if (TruffleOptions.TraceRewritesFilterFromCost != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
787 if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
788 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
789 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
790 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
791 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
792 if (TruffleOptions.TraceRewritesFilterToCost != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
793 if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
794 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
795 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
796 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
797 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
798 String filter = TruffleOptions.TraceRewritesFilterClass; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
799 Class<? extends Node> from = oldNode.getClass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
800 Class<? extends Node> to = newNode.getClass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
801 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
802 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
803 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
804 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
805 final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
806 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
807 PrintStream out = System.out; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
808 out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s%s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode), |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
809 reason != null && reason.length() > 0 ? reason : "unknown", reportedSourceSection != null ? " at " + reportedSourceSection.getShortDescription() : ""); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
810 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
811 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
812 private static String formatNodeInfo(Node node) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
813 String cost = "?"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
814 switch (node.getCost()) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
815 case NONE: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
816 cost = "G"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
817 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
818 case MONOMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
819 cost = "M"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
820 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
821 case POLYMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
822 cost = "P"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
823 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
824 case MEGAMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
825 cost = "G"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
826 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
827 default: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
828 cost = "?"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
829 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
830 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
831 return cost + " " + node.getClass().getSimpleName(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
832 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
833 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
834 private static boolean filterByKind(Node node, NodeCost cost) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
835 return node.getCost() == cost; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
836 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
837 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
838 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
839 Class<?> currentFrom = from; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
840 while (currentFrom != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
841 if (currentFrom.getName().contains(filter)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
842 return false; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
843 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
844 currentFrom = currentFrom.getSuperclass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
845 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
846 return true; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
847 } |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
848 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
849 private static final class NodeCounter implements NodeVisitor { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
850 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
851 public int count; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
852 private final NodeCountFilter filter; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
853 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
854 public NodeCounter(NodeCountFilter filter) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
855 this.filter = filter; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
856 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
857 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
858 public boolean visit(Node node) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
859 if (filter.isCounted(node)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
860 count++; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
861 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
862 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
863 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
864 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
865 } |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
866 } |