Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 22180:5e5b38579bda
remove FieldOffsetProvider
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Tue, 22 Sep 2015 14:56:59 +0200 |
parents | dc83cc1f94f2 |
children | 0d36601f233e |
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 java.io.OutputStream; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
28 import java.io.PrintStream; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
29 import java.io.PrintWriter; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
30 import java.io.StringWriter; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
31 import java.lang.annotation.Annotation; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
32 import java.lang.reflect.Array; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
33 import java.lang.reflect.Field; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
34 import java.util.ArrayList; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
35 import java.util.Arrays; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
36 import java.util.Collection; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
37 import java.util.Iterator; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
38 import java.util.List; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
39 import java.util.NoSuchElementException; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22080
diff
changeset
|
40 import java.util.Objects; |
22180
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
41 |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
42 import com.oracle.truffle.api.CompilerAsserts; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
43 import com.oracle.truffle.api.TruffleOptions; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
44 import com.oracle.truffle.api.instrument.Probe; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
45 import com.oracle.truffle.api.instrument.ProbeNode.WrapperNode; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
46 import com.oracle.truffle.api.instrument.StandardSyntaxTag; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
47 import com.oracle.truffle.api.instrument.SyntaxTag; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
48 import com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind; |
5e5b38579bda
remove FieldOffsetProvider
Andreas Woess <andreas.woess@oracle.com>
parents:
22157
diff
changeset
|
49 import com.oracle.truffle.api.source.SourceSection; |
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 |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16466
diff
changeset
|
56 static Iterator<Node> makeIterator(Node node) { |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
57 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
|
58 } |
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
|
59 |
17399
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
60 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
|
61 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
|
62 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
63 |
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
|
64 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
|
65 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
|
66 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
67 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
|
68 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
|
69 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
70 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
|
71 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
72 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
|
73 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
|
74 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
75 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
80 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
|
81 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
|
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 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
84 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
|
85 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
|
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 }); |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
88 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
89 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
90 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
|
91 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
|
92 } |
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 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
|
95 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
|
96 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
|
97 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
|
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 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
106 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
107 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
|
108 } |
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 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 } else { |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
117 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
|
118 } |
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 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
|
121 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
122 |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
123 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
|
124 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
|
125 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
126 } |
5787218bad91
Truffle: implemented recursive node iterator and node streams for the graal runtime.
Christian Humer <christian.humer@gmail.com>
parents:
17275
diff
changeset
|
127 |
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
|
128 @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
|
129 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
|
130 return (T) orig.deepCopy(); |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
131 } |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
132 |
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
133 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
|
134 CompilerAsserts.neverPartOfCompilation(); |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
135 final Node clone = orig.copy(); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
136 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
|
137 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
138 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
|
139 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
140 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
|
141 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
|
142 if (child != null) { |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 } |
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
|
147 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
148 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
|
149 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
|
150 if (children != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
151 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
|
152 for (int i = 0; i < children.length; i++) { |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
153 if (children[i] != null) { |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
154 Node clonedChild = ((Node) children[i]).deepCopy(); |
11809
c7769440afd8
improve NodeUtil.cloneNode.
Andreas Woess <andreas.woess@jku.at>
parents:
11649
diff
changeset
|
155 clonedChildren[i] = clonedChild; |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
156 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
|
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 } |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
159 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
|
160 } |
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 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 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
|
166 } |
cb4d5cc2b52b
Truffle: clone ConditionProfile and BranchProfile node fields
Andreas Woess <andreas.woess@jku.at>
parents:
18485
diff
changeset
|
167 } |
18750
8a758dce7d80
Truffle: added new deepCopy method to Node.
Christian Humer <christian.humer@gmail.com>
parents:
18510
diff
changeset
|
168 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
|
169 } |
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
|
170 |
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
|
171 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
|
172 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
|
173 List<Node> nodes = new ArrayList<>(); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
174 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
|
175 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
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 } |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
182 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
|
183 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
|
184 if (children != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
185 for (Object child : children) { |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
186 if (child != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
187 nodes.add((Node) child); |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
188 } |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
189 } |
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
|
190 } |
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 |
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
|
193 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
|
194 } |
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 |
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
|
196 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
|
197 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
|
198 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
|
199 } |
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
|
200 |
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
|
201 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
|
202 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
|
203 } |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
204 |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
205 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
|
206 CompilerAsserts.neverPartOfCompilation(); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
207 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
|
208 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 if (adopt) { |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
213 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
|
214 } |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
215 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
|
216 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
|
217 } |
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
|
218 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
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.getChildrenFields()) { |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
221 Object arrayObject = nodeField.getObject(parent); |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
222 if (arrayObject != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
223 Object[] array = (Object[]) arrayObject; |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
224 for (int i = 0; i < array.length; i++) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
225 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
|
226 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
|
227 if (adopt) { |
65e9fbb40e51
avoid publishing unadopted children in node replacement to fix potential race
Andreas Woess <andreas.woess@oracle.com>
parents:
21987
diff
changeset
|
228 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
|
229 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
230 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
|
231 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
|
232 } |
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
|
233 } |
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
|
234 } |
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
|
235 } |
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
|
236 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
|
237 } |
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
|
238 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
239 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
|
240 if (newValue == null) { |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
241 return true; |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
242 } |
18904
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
243 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
|
244 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
|
245 return true; |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
246 } else { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
247 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
|
248 return false; |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
249 } |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
250 } 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
|
251 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
|
252 return true; |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
253 } else { |
6ba170cb6f53
Truffle: channel all NodeUtil field accesses through NodeField class
Andreas Woess <andreas.woess@jku.at>
parents:
18751
diff
changeset
|
254 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
|
255 return false; |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
256 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
257 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
258 throw new IllegalArgumentException(); |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
259 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
260 |
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
|
261 /** |
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
|
262 * 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
|
263 * |
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
|
264 * @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
|
265 */ |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
266 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
|
267 assert child != null; |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
268 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
|
269 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
270 for (NodeFieldAccessor field : parentNodeClass.getChildFields()) { |
19012
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
271 if (field.getObject(parent) == child) { |
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
272 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
|
273 } |
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 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
276 for (NodeFieldAccessor field : parentNodeClass.getChildrenFields()) { |
19012
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 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
|
281 if (array[i] == child) { |
19012
f5b83e7b2b4c
Truffle: simplify NodeUtil.findChildField
Andreas Woess <andreas.woess@jku.at>
parents:
19010
diff
changeset
|
282 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
|
283 } |
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 } |
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
|
287 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
|
288 } |
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 |
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 /** |
19141
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
291 * 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
|
292 */ |
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
|
293 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
|
294 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
|
295 if (parent != null) { |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 default: |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
304 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
|
305 } |
67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19012
diff
changeset
|
306 } |
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
|
307 } |
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 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
|
309 } |
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
|
310 |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
311 /** |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
312 * 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
|
313 * |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
314 * @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
|
315 */ |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
316 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
|
317 CompilerAsserts.neverPartOfCompilation(); |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
318 Objects.requireNonNull(visitor); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
319 NodeClass parentNodeClass = parent.getNodeClass(); |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
320 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
321 for (NodeFieldAccessor field : parentNodeClass.getChildFields()) { |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
322 Object child = field.getObject(parent); |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
323 if (child != null) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
324 if (!visitor.visit((Node) child)) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
325 return false; |
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 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
328 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
329 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
330 for (NodeFieldAccessor field : parentNodeClass.getChildrenFields()) { |
19607
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
331 Object arrayObject = field.getObject(parent); |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
332 if (arrayObject != null) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
333 Object[] array = (Object[]) arrayObject; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
334 for (int i = 0; i < array.length; i++) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
335 Object child = array[i]; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
336 if (child != null) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
337 if (!visitor.visit((Node) child)) { |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
338 return false; |
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 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
341 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
342 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
343 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
344 |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
345 return true; |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
346 } |
73811d1b4cd0
Truffle: add NodeUtil.forEachChild
Andreas Woess <andreas.woess@oracle.com>
parents:
19141
diff
changeset
|
347 |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
348 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
|
349 NodeClass parentNodeClass = parent.getNodeClass(); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
350 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
351 for (NodeFieldAccessor field : parentNodeClass.getChildFields()) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
352 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
|
353 return false; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
354 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
355 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
356 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
357 for (NodeFieldAccessor field : parentNodeClass.getChildrenFields()) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
358 Object arrayObject = field.getObject(parent); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
359 if (arrayObject == null) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
360 continue; |
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 Object[] array = (Object[]) arrayObject; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
363 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
|
364 if (!visitChild((Node) array[i], visitor)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
365 return false; |
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 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
369 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
370 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
371 } |
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 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
|
374 if (child == null) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
375 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
376 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
377 if (!visitor.visit(child)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
378 return false; |
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 if (!forEachChildRecursive(child, visitor)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
381 return false; |
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 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
384 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
385 |
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
|
386 /** 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 } |
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
|
392 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
|
393 } |
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
|
394 |
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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 } |
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 |
11622
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
401 /** |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
402 * 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
|
403 * are less than n ancestors. |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
404 */ |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
405 public static Node getNthParent(Node node, int n) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
406 Node parent = node; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
407 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
408 for (int i = 0; i < n; i++) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
409 parent = parent.getParent(); |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
410 |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
411 if (parent == null) { |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
412 return null; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
413 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
414 } |
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 return parent; |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
417 } |
ccf047a30f18
Truffle: NodeUtil.getNthParent.
Chris Seaton <chris.seaton@oracle.com>
parents:
11279
diff
changeset
|
418 |
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
|
419 /** 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
|
420 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
|
421 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
|
422 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
|
423 } else { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 } |
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
|
428 } |
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
|
429 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
|
430 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
|
431 } |
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 } |
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 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
|
434 } |
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
|
435 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
436 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
|
437 Node parent = start.getParent(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
438 if (parent == null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
439 return null; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
440 } else if (clazz.isInstance(parent)) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
441 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
|
442 } else { |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
443 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
|
444 } |
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> 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
|
448 List<T> parents = new ArrayList<>(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
449 T parent = findParent(start, clazz); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
450 while (parent != null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
451 parents.add(parent); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
452 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
|
453 } |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
454 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
|
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 |
12666
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
457 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
|
458 List<Node> nodes = new ArrayList<>(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
459 Node current = child; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
460 while (current != null) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
461 nodes.add(current); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
462 if (current == parent) { |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
463 return nodes; |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
464 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
465 current = current.getParent(); |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
466 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
467 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
|
468 } |
d9c34e8337f4
Truffle: cleanup of NodeUtil#findParent; added NodeUtil#findAllParents
Christian Humer <christian.humer@gmail.com>
parents:
11950
diff
changeset
|
469 |
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
|
470 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
|
471 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
|
472 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
|
473 } |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
474 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
|
475 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
|
476 if (node != null) { |
45ed86c4d127
Truffle: change NodeUtil.findFirstNodeInstance to include root in potential matches
Andreas Woess <andreas.woess@oracle.com>
parents:
21469
diff
changeset
|
477 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
|
478 } |
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
|
479 } |
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
|
480 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
|
481 } |
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
|
482 |
16465
456abab80eb5
Truffle: remove obsolete NodeUtil.findNodeInstancesInFunction (functionally equivalent to findAllNodeInstances)
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
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 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
|
491 } |
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 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
|
494 } |
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 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
496 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
|
497 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
|
498 } |
e455fc531ec2
Truffle: Added API in NodeUtil to count nodes restricted to a Kind.
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
499 |
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
|
500 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
|
501 NodeCounter counter = new NodeCounter(filter); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
502 root.accept(counter); |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
503 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
|
504 } |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
505 |
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
|
506 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
|
507 |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
508 NodeCountFilter NO_FILTER = new NodeCountFilter() { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
509 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
510 public boolean isCounted(Node node) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
511 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
512 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
513 }; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
514 |
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
|
515 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
|
516 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
517 } |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
518 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
519 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
|
520 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
521 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
|
522 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
|
523 } |
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
|
524 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
525 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
|
526 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
|
527 } |
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
|
528 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
529 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
|
530 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
|
531 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
|
532 } |
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
|
533 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
|
534 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
|
535 } |
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
|
536 if (parent == null) { |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
537 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
|
538 } else { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
539 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
|
540 p.print(" = "); |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
541 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
|
542 } |
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 (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
|
545 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
|
546 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
547 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
|
548 } |
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 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
550 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
|
551 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
|
552 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
|
553 return out.toString(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
554 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
555 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
556 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
|
557 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
|
558 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
559 |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
560 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
|
561 printSourceAttributionTree(out, null, node, 1); |
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
562 } |
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20131
diff
changeset
|
563 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
564 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
|
565 if (node == null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
566 return; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
567 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
568 if (parent == null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
569 // 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
|
570 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
|
571 if (sourceSection != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
572 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
|
573 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
|
574 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
|
575 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
576 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
577 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
|
578 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
|
579 sb.append("| "); |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
580 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
581 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
582 if (parent != null) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
583 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
|
584 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
585 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
586 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
|
587 |
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
|
588 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
|
589 |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
590 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
|
591 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
|
592 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
593 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
|
594 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
|
595 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
596 p.flush(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
597 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
598 |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
599 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
|
600 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
|
601 for (NodeFieldAccessor field : fields) { |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
602 Object value = field.loadValue(parent); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
603 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
|
604 return field.getName(); |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
605 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
606 int index = 0; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
607 for (Object arrayNode : (Object[]) value) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
608 if (arrayNode == node) { |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
609 return field.getName() + "[" + index + "]"; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
610 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
611 index++; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
612 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
613 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
614 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
615 return defaultName; |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
616 } |
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
617 |
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
|
618 /** |
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
|
619 * 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
|
620 * 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
|
621 * <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
|
622 * <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
|
623 * {@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
|
624 * <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
|
625 * <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
|
626 * </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
|
627 */ |
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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 } |
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 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
|
641 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
|
642 } |
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 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
|
644 } |
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 |
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 /** |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
647 * 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
|
648 * 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
|
649 * |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
650 * @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
|
651 * @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
|
652 */ |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
653 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
|
654 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
|
655 } |
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
|
656 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
657 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
|
658 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
659 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
|
660 return out.toString(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
661 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
662 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
663 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
|
664 printTree(p, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
665 p.println(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
666 p.flush(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
667 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
668 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
669 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
|
670 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
|
671 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
|
672 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
|
673 } |
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
|
674 |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
675 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
|
676 |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
677 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
|
678 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
|
679 p.print("("); |
20130
8dc73c226c63
Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents:
20129
diff
changeset
|
680 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
|
681 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
|
682 childFields.add(field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
683 } 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
|
684 p.print(sep); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
685 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
|
686 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
687 p.print(field.getName()); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
688 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
689 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
|
690 } |
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
|
691 } |
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
|
692 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
|
693 |
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
|
694 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
|
695 p.print(" {"); |
20129
5b7db8941fd7
Truffle: make NodeClass and NodeField a top-level class.
Christian Humer <christian.humer@gmail.com>
parents:
19974
diff
changeset
|
696 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
|
697 printNewLine(p, level); |
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()); |
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
|
699 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
700 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
|
701 if (value == null) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
702 p.print(" = null "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
703 } 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
|
704 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
705 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
|
706 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
707 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
|
708 } |
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
|
709 } |
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 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
|
711 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
|
712 } |
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
|
713 } |
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
|
714 |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
715 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
|
716 String sep; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
717 Object[] children = (Object[]) value; |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
718 p.print(" = ["); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
719 sep = ""; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
720 for (Object child : children) { |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
721 p.print(sep); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
722 sep = ", "; |
17275
846c059e3ecf
Truffle: allow interface types in child fields
Andreas Woess <andreas.woess@jku.at>
parents:
16779
diff
changeset
|
723 printTree(p, (Node) child, level + 1); |
16548
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
724 } |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
725 p.print("]"); |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
726 } |
a3b0a2d61e62
extract method in NodeUtil
Christian Wirth <christian.wirth@oracle.com>
parents:
16513
diff
changeset
|
727 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
728 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
|
729 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
|
730 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
|
731 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
|
732 } |
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
|
733 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
734 |
10845
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
735 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
|
736 return node.getClass().getSimpleName(); |
e9248ebb1d79
Truffle: ignore null children in NodeUtil.findNodeChildren; refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
10793
diff
changeset
|
737 } |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
738 |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 } |
11848
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
744 if (section != null) { |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
745 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
|
746 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
|
747 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
|
748 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
|
749 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
|
750 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
|
751 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
|
752 return sb.toString(); |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
753 } |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
754 return ""; |
099af41815ea
Truffle: add NodeUtil.printSourceAttributionTree() for debugging
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11809
diff
changeset
|
755 } |
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
|
756 |
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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 } |
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
|
764 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
|
765 } |
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
|
766 } |
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 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
|
768 } |
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 |
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 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
|
771 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
|
772 } |
16464
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
773 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
774 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
|
775 if (TruffleOptions.TraceRewritesFilterFromCost != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
776 if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
777 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
778 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
779 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
780 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
781 if (TruffleOptions.TraceRewritesFilterToCost != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
782 if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
783 return; |
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 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
786 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
787 String filter = TruffleOptions.TraceRewritesFilterClass; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
788 Class<? extends Node> from = oldNode.getClass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
789 Class<? extends Node> to = newNode.getClass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
790 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
|
791 return; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
792 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
793 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
794 final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection(); |
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 PrintStream out = System.out; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
797 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
|
798 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
|
799 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
800 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
801 private static String formatNodeInfo(Node node) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
802 String cost = "?"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
803 switch (node.getCost()) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
804 case NONE: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
805 cost = "G"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
806 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
807 case MONOMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
808 cost = "M"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
809 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
810 case POLYMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
811 cost = "P"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
812 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
813 case MEGAMORPHIC: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
814 cost = "G"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
815 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
816 default: |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
817 cost = "?"; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
818 break; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
819 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
820 return cost + " " + node.getClass().getSimpleName(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
821 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
822 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
823 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
|
824 return node.getCost() == cost; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
825 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
826 |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
827 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
|
828 Class<?> currentFrom = from; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
829 while (currentFrom != null) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
830 if (currentFrom.getName().contains(filter)) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
831 return false; |
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 currentFrom = currentFrom.getSuperclass(); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
834 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
835 return true; |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16067
diff
changeset
|
836 } |
20131
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
837 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
838 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
|
839 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
840 public int count; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
841 private final NodeCountFilter filter; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
842 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
843 public NodeCounter(NodeCountFilter filter) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
844 this.filter = filter; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
845 } |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
846 |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
847 public boolean visit(Node node) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
848 if (filter.isCounted(node)) { |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
849 count++; |
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 return true; |
4b12d5355811
Truffle: do not use iterators for visitors.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
852 } |
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 } |
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
|
855 } |