annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 14073:c5411233cdf8

Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
author Christian Humer <christian.humer@gmail.com>
date Wed, 05 Mar 2014 23:33:25 +0100
parents 989f58d6a0ca
children 5d1308c78ddc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /*
11535
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
2 * Copyright (c) 2012, 2013, 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: 10862
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: 10862
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: 10862
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
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
27 import java.io.*;
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
28 import java.lang.annotation.*;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.util.*;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
31 import com.oracle.truffle.api.*;
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
32 import com.oracle.truffle.api.nodes.NodeInfo.Kind;
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
33
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
34 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 * Abstract base class for all Truffle 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
36 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 public abstract class Node implements Cloneable {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 private Node parent;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
41 private SourceSection sourceSection;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
42
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
43 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 * Marks array fields that are children of this 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
45 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 @Retention(RetentionPolicy.RUNTIME)
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 @Target({ElementType.FIELD})
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 public @interface Children {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 * Marks fields that represent child nodes of this 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
53 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 @Retention(RetentionPolicy.RUNTIME)
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 @Target({ElementType.FIELD})
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 public @interface Child {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
59 protected Node() {
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
60 CompilerAsserts.neverPartOfCompilation();
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
61 }
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
62
11535
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
63 protected Node(SourceSection sourceSection) {
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
64 CompilerAsserts.neverPartOfCompilation();
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
65 this.sourceSection = sourceSection;
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
66 }
8f0fb0ade839 Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 11279
diff changeset
67
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
68 /**
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
69 * Assigns a link to a guest language source section to this node.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
70 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
71 * @param section the object representing a section in guest language source code
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
72 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
73 public final void assignSourceSection(SourceSection section) {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
74 if (sourceSection != null) {
11610
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
75 // Patch this test during the transition to constructor-based
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
76 // source attribution, which would otherwise trigger this
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
77 // exception. This method will eventually be deprecated.
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
78 if (getSourceSection() != section) {
11648
4ab1f371adc8 Do not assign new source section if replacing node already has source section assigned.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11610
diff changeset
79 throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section);
11610
5f532ea846fb applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents: 11535
diff changeset
80 }
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
81 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
82 this.sourceSection = section;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
83 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
84
13994
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
85 public Kind getKind() {
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
86 NodeInfo info = getClass().getAnnotation(NodeInfo.class);
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
87 if (info != null) {
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
88 return info.kind();
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
89 }
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
90 return Kind.SPECIALIZED;
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
91 }
989f58d6a0ca Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents: 13983
diff changeset
92
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
93 /**
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
94 * Clears any previously assigned guest language source code from this node.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
95 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
96 public final void clearSourceSection() {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
97 this.sourceSection = null;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
98 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
99
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
100 /**
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
101 * Retrieves the guest language source code section that is currently assigned to this node.
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
102 *
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
103 * @return the assigned source code section
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
104 */
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
105 public final SourceSection getSourceSection() {
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
106 return sourceSection;
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
107 }
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
108
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
109 /**
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
110 * Retrieves the guest language source code section that is currently assigned to this node.
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
111 *
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
112 * @return the assigned source code section
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
113 */
11818
793743715dc1 put Node.getEncapsulatedSourceSection() on slow path
Michael Haupt <michael.haupt@oracle.com>
parents: 11648
diff changeset
114 @CompilerDirectives.SlowPath
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
115 public final SourceSection getEncapsulatingSourceSection() {
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
116 if (sourceSection == null && getParent() != null) {
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
117 return getParent().getEncapsulatingSourceSection();
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
118 }
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
119 return sourceSection;
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
120 }
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
121
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
122 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
123 * Method that updates the link to the parent in the array of specified new child nodes to this
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
124 * node.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
125 *
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
126 * @param newChildren the array of new children whose parent should be updated
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 * @return the array of new children
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 protected final <T extends Node> T[] adoptChildren(T[] newChildren) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 if (newChildren != 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
131 for (T n : newChildren) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 adoptChild(n);
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 return newChildren;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 * Method that updates the link to the parent in the specified new child node to this node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
140 *
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
141 * @param newChild the new child whose parent should be updated
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 * @return the new child
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 protected final <T extends Node> T adoptChild(T newChild) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 if (newChild != null) {
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
146 if (newChild == this) {
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
147 throw new IllegalStateException("The parent of a node can never be the node itself.");
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
148 }
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
149 ((Node) newChild).parent = this;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
151 return newChild;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
153
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
154 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
155 * Returns properties of this node interesting for debugging and can be overwritten by
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
156 * subclasses to add their own custom properties.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
157 *
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
158 * @return the properties as a key/value hash map
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 public Map<String, Object> getDebugProperties() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 Map<String, Object> properties = new HashMap<>();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 return properties;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 * The current parent node of this node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
167 *
7267
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 * @return the parent 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
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 public final Node getParent() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171 return parent;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 /**
9256
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
175 * Replaces this node with another node. If there is a source section (see
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
176 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
177 *
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 * @param newNode the new node that is the replacement
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 * @param reason a description of the reason for the replacement
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 * @return the new 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
181 */
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
182 public final <T extends Node> T replace(T newNode, String reason) {
13915
d6b340b757a2 Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents: 13811
diff changeset
183 CompilerDirectives.transferToInterpreterAndInvalidate();
10481
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
184 if (this.getParent() == null) {
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
185 throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent.");
29e9a5d18c70 Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9782
diff changeset
186 }
11648
4ab1f371adc8 Do not assign new source section if replacing node already has source section assigned.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 11610
diff changeset
187 if (sourceSection != null && newNode.getSourceSection() == null) {
9256
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
188 // Pass on the source section to the new node.
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
189 newNode.assignSourceSection(sourceSection);
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
190 }
9782
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
191 onReplace(newNode, reason);
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
192 ((Node) newNode).parent = this.parent;
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
193 if (!NodeUtil.replaceChild(this.parent, this, newNode)) {
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
194 fixupTree();
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
195 }
13983
f46cab39a9a2 Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
196 reportReplace(this, newNode, reason);
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
197 return newNode;
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
198 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
200 /**
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
201 * Rewrite has failed; the tree is likely inconsistent, so fix any stale parent references.
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
202 *
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
203 * This is a rather expensive operation but rare to occur.
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
204 */
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
205 private void fixupTree() {
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
206 Node rootNode = getRootNode();
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
207 if (rootNode == null) {
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
208 throw new UnsupportedOperationException("Tree does not have a root node.");
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
209 }
12495
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
210 int fixCount = rootNode.fixupChildren();
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
211 assert fixCount != 0 : "sanity check failed: missing @Child[ren] or adoptChild?";
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
212 // if nothing had to be fixed, rewrite failed due to node not being a proper child.
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
213 }
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
214
12495
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
215 private int fixupChildren() {
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
216 int fixCount = 0;
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
217 for (Node child : getChildren()) {
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
218 if (child != null) {
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
219 if (child.parent != this) {
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
220 child.parent = this;
12495
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
221 fixCount++;
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
222 }
12495
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
223 fixCount += child.fixupChildren();
12494
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
224 }
57b8a41c0e18 Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents: 11951
diff changeset
225 }
12495
b7c8b843dc7b Truffle: add sanity check.
Andreas Woess <andreas.woess@jku.at>
parents: 12494
diff changeset
226 return fixCount;
9255
cdf10fb20022 Remove Node.replaceChild method from the public API. Node.replace remains as the only method in the API to modify the AST.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
227 }
cdf10fb20022 Remove Node.replaceChild method from the public API. Node.replace remains as the only method in the API to modify the AST.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9254
diff changeset
228
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
229 /**
9256
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
230 * Replaces this node with another node. If there is a source section (see
9640bb930327 Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9255
diff changeset
231 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
232 *
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
233 * @param newNode the new node that is the replacement
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 * @return the new 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
235 */
9254
4497235516df New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
236 public final <T extends Node> T replace(T newNode) {
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 return replace(newNode, "");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
239
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
240 /**
10846
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
241 * Checks if this node is properly adopted by a parent and can be replaced.
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
242 *
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
243 * @return {@code true} if it is safe to replace this node.
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
244 */
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
245 public final boolean isReplaceable() {
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
246 if (getParent() != null) {
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
247 for (Node sibling : getParent().getChildren()) {
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
248 if (sibling == this) {
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
249 return true;
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
250 }
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
251 }
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
252 }
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
253 return false;
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
254 }
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
255
13983
f46cab39a9a2 Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
256 private void reportReplace(Node oldNode, Node newNode, String reason) {
14073
c5411233cdf8 Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents: 13994
diff changeset
257 RootNode rootNode = getRootNode();
c5411233cdf8 Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents: 13994
diff changeset
258 if (rootNode != null) {
c5411233cdf8 Truffle: Now keeps track of all not just inlined call-sites called by CallNode. Deprecated some old API in NodeUtil.
Christian Humer <christian.humer@gmail.com>
parents: 13994
diff changeset
259 CallTarget target = rootNode.getCallTarget();
13983
f46cab39a9a2 Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
260 if (target instanceof ReplaceObserver) {
f46cab39a9a2 Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
261 ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason);
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
262 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
263 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
264 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
265
10846
e87d56a51047 Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents: 10843
diff changeset
266 /**
9782
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
267 * Intended to be implemented by subclasses of {@link Node} to receive a notification when the
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
268 * node is rewritten. This method is invoked before the actual replace has happened.
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
269 *
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
270 * @param newNode the replacement node
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
271 * @param reason the reason the replace supplied
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
272 */
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
273 protected void onReplace(Node newNode, String reason) {
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
274 if (TruffleOptions.TraceRewrites) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
275 traceRewrite(newNode, reason);
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
276 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
277 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
278
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
279 private void traceRewrite(Node newNode, String reason) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
280 Class<? extends Node> from = getClass();
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
281 Class<? extends Node> to = newNode.getClass();
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
282
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
283 if (TruffleOptions.TraceRewritesFilterFromKind != null) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
284 if (filterByKind(from, TruffleOptions.TraceRewritesFilterFromKind)) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
285 return;
10862
8c570011b86f Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10846
diff changeset
286 }
8c570011b86f Truffle: when a node is replaced, notify optimized call target and delay compilation.
Andreas Woess <andreas.woess@jku.at>
parents: 10846
diff changeset
287 }
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
288
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
289 if (TruffleOptions.TraceRewritesFilterToKind != null) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
290 if (filterByKind(to, TruffleOptions.TraceRewritesFilterToKind)) {
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
291 return;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
292 }
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
293 }
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
294
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
295 String filter = TruffleOptions.TraceRewritesFilterClass;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
296 if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
297 return;
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
298 }
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
299
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
300 PrintStream out = System.out;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
301 out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s.%n", this.toString(), formatNodeInfo(from), formatNodeInfo(to), reason);
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
302 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
303
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
304 private static String formatNodeInfo(Class<? extends Node> clazz) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
305 NodeInfo nodeInfo = clazz.getAnnotation(NodeInfo.class);
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
306 String kind = "?";
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
307 if (nodeInfo != null) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
308 switch (nodeInfo.kind()) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
309 case GENERIC:
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
310 kind = "G";
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
311 break;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
312 case SPECIALIZED:
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
313 kind = "S";
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
314 break;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
315 case UNINITIALIZED:
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
316 kind = "U";
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
317 break;
10592
99b58803d6d9 Truffle-DSL: API changes for new polymorphic caching feature.
Christian Humer <christian.humer@gmail.com>
parents: 10590
diff changeset
318 case POLYMORPHIC:
99b58803d6d9 Truffle-DSL: API changes for new polymorphic caching feature.
Christian Humer <christian.humer@gmail.com>
parents: 10590
diff changeset
319 kind = "P";
99b58803d6d9 Truffle-DSL: API changes for new polymorphic caching feature.
Christian Humer <christian.humer@gmail.com>
parents: 10590
diff changeset
320 break;
10590
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
321 default:
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
322 kind = "?";
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
323 break;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
324 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
325 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
326 return kind + " " + clazz.getSimpleName();
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
327 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
328
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
329 private static boolean filterByKind(Class<?> clazz, Kind kind) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
330 NodeInfo info = clazz.getAnnotation(NodeInfo.class);
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
331 if (info != null) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
332 return info.kind() != kind;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
333 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
334 return true;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
335 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
336
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
337 private static boolean filterByContainsClassName(Class<? extends Node> from, String filter) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
338 Class<?> currentFrom = from;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
339 while (currentFrom != null) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
340 if (currentFrom.getName().contains(filter)) {
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
341 return false;
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
342 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
343 currentFrom = currentFrom.getSuperclass();
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
344 }
6eb8d63cea34 Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents: 10481
diff changeset
345 return true;
9782
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
346 }
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
347
ba02d19dd3cc Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents: 9256
diff changeset
348 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
349 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
350 * child nodes.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
351 *
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
352 * @param nodeVisitor the visitor
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 public final void accept(NodeVisitor 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
355 if (nodeVisitor.visit(this)) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
356 for (Node child : this.getChildren()) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
357 if (child != 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
358 child.accept(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
359 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
360 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
361 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
362 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
364 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
365 * Iterator over the children of this node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
366 *
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
367 * @return the iterator
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
368 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
369 public final Iterable<Node> getChildren() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
370 final Node node = this;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371 return new Iterable<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
372
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
373 public Iterator<Node> iterator() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
374 return new NodeUtil.NodeIterator(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
375 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
376 };
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
377 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
378
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
379 /**
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
380 * Creates a shallow copy of this node.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
381 *
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
382 * @return the new copy
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
383 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
384 public Node copy() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
385 try {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 return (Node) super.clone();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
387 } catch (CloneNotSupportedException e) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 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
389 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
393 * This method must never be called. It enforces that {@link Object#clone} is not directly
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7267
diff changeset
394 * called by subclasses. Use the {@link #copy()} method instead.
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
395 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 @Override
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 @Deprecated
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 protected final Object clone() throws CloneNotSupportedException {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 throw new IllegalStateException("This method should never be called, use the copy method instead!");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
401
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402 /**
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
403 * Get the root node of the tree a node belongs to.
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
404 *
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
405 * @return the {@link RootNode} or {@code null} if there is none.
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
406 */
13983
f46cab39a9a2 Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents: 13915
diff changeset
407 public final RootNode getRootNode() {
12692
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
408 Node rootNode = this;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
409 while (rootNode.getParent() != null) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
410 assert !(rootNode instanceof RootNode) : "root node must not have a parent";
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
411 rootNode = rootNode.getParent();
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
412 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
413 if (rootNode instanceof RootNode) {
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
414 return (RootNode) rootNode;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
415 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
416 return null;
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
417 }
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
418
ffd4b6b4ae68 Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents: 12495
diff changeset
419 /**
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
420 * Converts this node to a textual representation useful for debugging.
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 */
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 @Override
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 public String toString() {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
424 StringBuilder sb = new StringBuilder(getClass().getSimpleName());
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 Map<String, Object> properties = getDebugProperties();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 boolean hasProperties = false;
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 for (Map.Entry<String, Object> entry : properties.entrySet()) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 sb.append(hasProperties ? "," : "<");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 hasProperties = 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
430 sb.append(entry.getKey()).append("=").append(entry.getValue());
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 if (hasProperties) {
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 sb.append(">");
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api 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 sb.append("@").append(Integer.toHexString(hashCode()));
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
436 return sb.toString();
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
437 }
a4b84ba6dc2e Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
438 }