Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeBaseFactory.java @ 18788:714f4931b02c
Truffle-DSL: inline specialized node into gen node if single specializable.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 06 Jan 2015 00:43:09 +0100 |
parents | c0fb70634640 |
children | 4ce856e65728 |
rev | line source |
---|---|
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.generator; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.dsl.processor.java.ElementUtils.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static javax.lang.model.element.Modifier.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import java.util.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import javax.lang.model.element.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import javax.lang.model.type.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import javax.lang.model.util.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.nodes.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.dsl.processor.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 import com.oracle.truffle.dsl.processor.java.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 import com.oracle.truffle.dsl.processor.java.model.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 import com.oracle.truffle.dsl.processor.model.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 import com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 import com.oracle.truffle.dsl.processor.parser.*; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 import com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
45 class NodeBaseFactory { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 private static final String THIS_NODE_LOCAL_VAR_NAME = "thisNode"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 static final String EXECUTE_CHAINED = "executeChained0"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 private static final String SPECIALIZE = "specialize0"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 private static final String DSLSHARE_REWRITE = "rewrite"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 private static final String DSLSHARE_FIND_ROOT = "findRoot"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 private static final String DSLSHARE_REWRITE_TO_POLYMORHPIC = "rewriteToPolymorphic"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 static final String EXECUTE_UNINITIALIZED = "executeUninitialized0"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 private static final String REWRITE = "rewrite0"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 private static final String CREATE_INFO = "createInfo0"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 static final String CONTAINS_FALLBACK = "containsFallback"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 static final String EMPTY_CLASS_ARRAY = "EMPTY_CLASS_ARRAY"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 static final String METADATA_FIELD_NAME = "METADATA"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
63 protected final ProcessorContext context; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
64 protected final NodeData node; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
65 protected final SpecializationData specialization; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
66 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
67 public NodeBaseFactory(ProcessorContext context, NodeData node, SpecializationData specialization) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
68 this.context = context; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
69 this.node = node; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
70 this.specialization = specialization; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
71 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
72 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
73 public CodeTypeElement create() { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
74 CodeTypeElement clazz = GeneratorUtils.createClass(node, null, modifiers(PRIVATE, ABSTRACT), baseClassName(node), node.getNodeType()); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
75 clazz.getImplements().add(context.getTruffleTypes().getDslNode()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
76 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
77 for (NodeChildData child : node.getChildren()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
78 clazz.add(createChildField(child)); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
79 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
80 if (child.getAccessElement() != null && child.getAccessElement().getModifiers().contains(Modifier.ABSTRACT)) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
81 ExecutableElement getter = (ExecutableElement) child.getAccessElement(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
82 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), getter); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
83 method.getModifiers().remove(Modifier.ABSTRACT); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
84 CodeTreeBuilder builder = method.createBuilder(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
85 builder.startReturn().string("this.").string(child.getName()).end(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
86 clazz.add(method); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
87 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
88 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
89 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
90 for (NodeFieldData field : node.getFields()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
91 if (!field.isGenerated()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
92 continue; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
93 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
94 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
95 clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), field.getType(), field.getName())); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
96 if (field.getGetter() != null && field.getGetter().getModifiers().contains(Modifier.ABSTRACT)) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
97 CodeExecutableElement method = CodeExecutableElement.clone(context.getEnvironment(), field.getGetter()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
98 method.getModifiers().remove(Modifier.ABSTRACT); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
99 method.createBuilder().startReturn().string("this.").string(field.getName()).end(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
100 clazz.add(method); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
101 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
102 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
103 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
104 for (String assumption : node.getAssumptions()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
105 clazz.add(createAssumptionField(assumption)); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
106 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
107 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
108 createConstructors(clazz); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
109 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
110 SpecializationGroup rootGroup = createSpecializationGroups(node); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
111 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
112 if (node.needsRewrites(context)) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
113 if (node.isPolymorphic(context)) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
114 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
115 CodeVariableElement var = new CodeVariableElement(modifiers(PROTECTED), clazz.asType(), "next0"); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
116 var.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getTruffleTypes().getChildAnnotation())); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
117 clazz.add(var); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
118 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
119 CodeExecutableElement genericCachedExecute = createCachedExecute(node.getPolymorphicSpecialization()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
120 clazz.add(genericCachedExecute); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
121 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
122 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
123 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
124 for (CodeExecutableElement method : createImplicitChildrenAccessors()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
125 clazz.add(method); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
126 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
127 clazz.add(createInfoMessage()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
128 clazz.add(createMonomorphicRewrite()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
129 clazz.add(createCreateSpecializationMethod(rootGroup)); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
130 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
131 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
132 clazz.add(createAdoptChildren0()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
133 clazz.add(createGetMetadata0(true)); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
134 clazz.add(createUpdateTypes0()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
135 clazz.add(createGetNext()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
136 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
137 return clazz; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
138 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
139 |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 public static List<ExecutableElement> findUserConstructors(TypeMirror nodeType) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 List<ExecutableElement> constructors = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 for (ExecutableElement constructor : ElementFilter.constructorsIn(ElementUtils.fromTypeMirror(nodeType).getEnclosedElements())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 if (constructor.getModifiers().contains(PRIVATE)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 if (isCopyConstructor(constructor)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 constructors.add(constructor); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 if (constructors.isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 constructors.add(new CodeExecutableElement(null, ElementUtils.getSimpleName(nodeType))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
154 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
155 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
156 return constructors; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
159 public static boolean isCopyConstructor(ExecutableElement element) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 if (element.getParameters().size() != 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
162 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 VariableElement var = element.getParameters().get(0); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 TypeElement enclosingType = ElementUtils.findNearestEnclosingType(var); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 if (ElementUtils.typeEquals(var.asType(), enclosingType.asType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
167 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 List<TypeElement> types = ElementUtils.getDirectSuperTypes(enclosingType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
169 for (TypeElement type : types) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
170 if (!(type instanceof CodeTypeElement)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
171 // no copy constructors which are not generated types |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
172 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
173 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
174 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
175 if (ElementUtils.typeEquals(var.asType(), type.asType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
176 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
177 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
178 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
179 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
182 public SpecializationData getSpecialization() { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
183 return specialization; |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
184 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
185 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
186 private Element createGetNext() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
187 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), context.getType(Node.class), "getNext0"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
188 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
189 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
190 if (node.isPolymorphic(context)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
191 builder.startReturn().string("next0").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
192 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
193 builder.returnNull(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
194 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
195 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
196 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
197 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
198 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
199 protected final CodeExecutableElement createUpdateTypes0() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
200 ArrayType classArray = new ArrayCodeTypeMirror(context.getType(Class.class)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
201 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getType(void.class), "updateTypes0"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
202 method.getParameters().add(new CodeVariableElement(classArray, "types")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
203 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
204 if (getSpecialization().isPolymorphic()) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
205 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
206 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
207 int index = 0; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
208 for (NodeExecutionData execution : getSpecialization().getNode().getChildExecutions()) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
209 String fieldName = polymorphicTypeName(execution); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
210 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
211 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 builder.string(fieldName).string(" = ").string("types[").string(String.valueOf(index)).string("]"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
213 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
214 index++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
215 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
216 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
217 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
218 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
219 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
220 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
221 protected final CodeExecutableElement createGetMetadata0(boolean empty) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
222 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getDslMetadata(), "getMetadata0"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
223 if (empty) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
224 method.createBuilder().startReturn().staticReference(context.getTruffleTypes().getDslMetadata(), "NONE").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
225 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
226 method.createBuilder().startReturn().string(METADATA_FIELD_NAME).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
227 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
228 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
229 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
230 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
231 private CodeExecutableElement createAdoptChildren0() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
232 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), context.getType(void.class), "adoptChildren0"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
233 method.getParameters().add(new CodeVariableElement(context.getTruffleTypes().getNode(), "other")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
234 method.getParameters().add(new CodeVariableElement(context.getTruffleTypes().getNode(), "newNext")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
235 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
236 List<NodeExecutionData> executions = node.getChildExecutions(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
237 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
238 if (executions.size() > 0) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
239 builder.startIf().string("other == null").end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
240 for (NodeExecutionData execution : executions) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
241 builder.startStatement().tree(createAccessChild(execution, "this")).string(" = null").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
242 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
243 builder.end().startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
244 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
245 String access; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
246 if (executions.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
247 builder.declaration(baseClassName(node), "otherCast", builder.create().cast(baseClassName(node)).string("other")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
248 access = "otherCast"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
249 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
250 assert executions.size() == 1; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
251 access = "((" + baseClassName(node) + ") other)"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
252 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
253 for (NodeExecutionData execution : executions) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
254 builder.startStatement().tree(createAccessChild(execution, "this")).string(" = ").tree(createAccessChild(execution, access)).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
255 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
256 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
257 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
259 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
260 if (getSpecialization().getNode().isPolymorphic(context)) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
261 builder.startIf().string("newNext == null").end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
262 builder.statement("this.next0 = null"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
263 builder.end().startElseBlock(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
264 builder.statement("this.next0 = (" + baseClassName(getSpecialization().getNode()) + ") newNext"); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
265 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
266 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
267 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
268 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
269 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
270 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
271 private List<CodeExecutableElement> createImplicitChildrenAccessors() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
272 List<Set<TypeData>> prototype = Collections.nCopies(node.getGenericSpecialization().getParameters().size(), null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
273 List<Set<TypeData>> expectTypes = new ArrayList<>(prototype); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
274 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
275 for (ExecutableTypeData executableType : node.getExecutableTypes()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
276 for (int i = 0; i < executableType.getEvaluatedCount(); i++) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
277 Parameter parameter = executableType.getSignatureParameter(i); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
278 if (i >= expectTypes.size()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
279 break; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
280 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
281 Set<TypeData> types = expectTypes.get(i); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
282 if (types == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
283 types = new TreeSet<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
284 expectTypes.set(i, types); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
285 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
286 types.add(parameter.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
287 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
288 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
289 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
290 List<CodeExecutableElement> methods = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
291 List<Set<TypeData>> visitedList = new ArrayList<>(prototype); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
292 for (SpecializationData spec : node.getSpecializations()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
293 int signatureIndex = -1; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
294 for (Parameter param : spec.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
295 if (!param.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
296 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
297 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
298 signatureIndex++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
299 Set<TypeData> visitedTypeData = visitedList.get(signatureIndex); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
300 if (visitedTypeData == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
301 visitedTypeData = new TreeSet<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
302 visitedList.set(signatureIndex, visitedTypeData); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
303 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
304 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
305 if (visitedTypeData.contains(param.getTypeSystemType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
306 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
307 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
308 visitedTypeData.add(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
309 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
310 Set<TypeData> expect = expectTypes.get(signatureIndex); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
311 if (expect == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
312 expect = Collections.emptySet(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
313 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
314 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
315 methods.addAll(createExecuteChilds(param, expect)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
316 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
317 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
318 return methods; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
319 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
320 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
321 private CodeTree truffleBooleanOption(CodeTreeBuilder parent, String name) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
322 CodeTreeBuilder builder = parent.create(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
323 builder.staticReference(context.getTruffleTypes().getTruffleOptions(), name); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
324 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
325 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
326 |
18766
a720bf2e2f43
Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
327 private void addInternalValueParameters(CodeExecutableElement executableMethod, TemplateMethod method, boolean forceFrame, boolean disableFrame, boolean evaluated) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
328 if (forceFrame && !disableFrame && method.getSpecification().findParameterSpec("frame") != null) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
329 executableMethod.addParameter(new CodeVariableElement(context.getTruffleTypes().getFrame(), "frameValue")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
330 } |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
331 for (Parameter parameter : method.getParameters()) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
332 ParameterSpec spec = parameter.getSpecification(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
333 if ((disableFrame || forceFrame) && spec.getName().equals("frame")) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
334 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
335 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
336 if (spec.isLocal()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
337 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
338 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
339 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
340 String name = valueName(parameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
341 if (evaluated && spec.isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
342 name = valueNameEvaluated(parameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
343 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
344 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
345 executableMethod.addParameter(new CodeVariableElement(parameter.getType(), name)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
346 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
347 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
348 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
349 private Element createInfoMessage() { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
350 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, STATIC), context.getType(String.class), CREATE_INFO); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
351 method.addParameter(new CodeVariableElement(context.getType(String.class), "message")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
352 addInternalValueParameters(method, node.getGenericSpecialization(), false, false, false); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
353 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
354 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
355 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
356 builder.startIf().tree(truffleBooleanOption(builder, TruffleTypes.OPTION_DETAILED_REWRITE_REASONS)).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
357 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
358 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
359 builder.startStatement().string("StringBuilder builder = new StringBuilder(message)").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
360 builder.startStatement().startCall("builder", "append").doubleQuote(" (").end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
361 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
362 String sep = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
363 for (Parameter parameter : node.getGenericSpecialization().getSignatureParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
364 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
365 builder.string("builder"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
366 if (sep != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
367 builder.startCall(".append").doubleQuote(sep).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
368 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
369 builder.startCall(".append").doubleQuote(parameter.getLocalName()).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
370 builder.startCall(".append").doubleQuote(" = ").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
371 builder.startCall(".append").string(parameter.getLocalName()).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
372 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
373 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
374 if (!ElementUtils.isPrimitive(parameter.getType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
375 builder.startIf().string(parameter.getLocalName() + " != null").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
376 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
377 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
378 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
379 if (ElementUtils.isPrimitive(parameter.getType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
380 builder.startCall("builder.append").doubleQuote(" (" + ElementUtils.getSimpleName(parameter.getType()) + ")").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
381 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
382 builder.startCall("builder.append").doubleQuote(" (").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
383 builder.startCall(".append").string(parameter.getLocalName() + ".getClass().getSimpleName()").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
384 builder.startCall(".append").doubleQuote(")").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
385 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
386 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
387 if (!ElementUtils.isPrimitive(parameter.getType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
388 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
389 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
390 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
391 sep = ", "; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
392 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
393 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
394 builder.startStatement().startCall("builder", "append").doubleQuote(")").end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
395 builder.startReturn().string("builder.toString()").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
396 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
397 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
398 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
399 builder.startReturn().string("message").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
400 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
401 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
402 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
403 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
404 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
405 private CodeExecutableElement createCachedExecute(SpecializationData polymorph) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
406 CodeExecutableElement cachedExecute = new CodeExecutableElement(modifiers(PROTECTED, ABSTRACT), polymorph.getReturnType().getType(), EXECUTE_CHAINED); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
407 addInternalValueParameters(cachedExecute, polymorph, true, false, false); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
408 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
409 ExecutableTypeData sourceExecutableType = node.findExecutableType(polymorph.getReturnType().getTypeSystemType(), 0); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
410 boolean sourceThrowsUnexpected = sourceExecutableType != null && sourceExecutableType.hasUnexpectedValue(context); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
411 if (sourceThrowsUnexpected && sourceExecutableType.getType().equals(node.getGenericSpecialization().getReturnType().getTypeSystemType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
412 sourceThrowsUnexpected = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
413 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
414 if (sourceThrowsUnexpected) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
415 cachedExecute.getThrownTypes().add(context.getType(UnexpectedResultException.class)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
416 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
417 return cachedExecute; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
418 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
419 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
420 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
421 private void createConstructors(CodeTypeElement clazz) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
422 List<ExecutableElement> constructors = findUserConstructors(node.getNodeType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
423 ExecutableElement sourceSectionConstructor = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
424 if (constructors.isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
425 clazz.add(createUserConstructor(clazz, null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
426 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
427 for (ExecutableElement constructor : constructors) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
428 clazz.add(createUserConstructor(clazz, constructor)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
429 if (NodeParser.isSourceSectionConstructor(context, constructor)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
430 sourceSectionConstructor = constructor; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
431 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
432 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
433 } |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
434 if (node.needsRewrites(context)) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
435 ExecutableElement copyConstructor = findCopyConstructor(node.getNodeType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
436 clazz.add(createCopyConstructor(clazz, copyConstructor, sourceSectionConstructor)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
437 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
438 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
439 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
440 private CodeExecutableElement createUserConstructor(CodeTypeElement type, ExecutableElement superConstructor) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
441 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
442 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
443 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
444 if (superConstructor != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
445 for (VariableElement param : superConstructor.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
446 method.getParameters().add(CodeVariableElement.clone(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
447 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
448 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
449 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
450 if (superConstructor != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
451 builder.startStatement().startSuperCall(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
452 for (VariableElement param : superConstructor.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
453 builder.string(param.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
454 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
455 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
456 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
457 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
458 for (VariableElement var : type.getFields()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
459 if (var.getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
460 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
461 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
462 NodeChildData child = node.findChild(var.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
463 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
464 if (child != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
465 method.getParameters().add(new CodeVariableElement(child.getOriginalType(), child.getName())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
466 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
467 method.getParameters().add(new CodeVariableElement(var.asType(), var.getSimpleName().toString())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
468 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
469 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
470 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
471 String fieldName = var.getSimpleName().toString(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
472 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
473 CodeTree init = createStaticCast(builder, child, fieldName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
474 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
475 builder.string("this.").string(fieldName).string(" = ").tree(init); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
476 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
477 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
478 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
479 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
480 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
481 private CodeTree createStaticCast(CodeTreeBuilder parent, NodeChildData child, String fieldName) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
482 NodeData parentNode = getSpecialization().getNode(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
483 if (child != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
484 CreateCastData createCast = parentNode.findCast(child.getName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
485 if (createCast != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
486 return createTemplateMethodCall(parent, null, parentNode.getGenericSpecialization(), createCast, null, fieldName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
487 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
488 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
489 return CodeTreeBuilder.singleString(fieldName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
490 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
491 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
492 private CodeExecutableElement createCopyConstructor(CodeTypeElement type, ExecutableElement superConstructor, ExecutableElement sourceSectionConstructor) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
493 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
494 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
495 method.getParameters().add(new CodeVariableElement(type.asType(), "copy")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
496 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
497 if (superConstructor != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
498 builder.startStatement().startSuperCall().string("copy").end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
499 } else if (sourceSectionConstructor != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
500 builder.startStatement().startSuperCall().string("copy.getSourceSection()").end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
501 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
502 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
503 for (VariableElement var : type.getFields()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
504 if (var.getModifiers().contains(STATIC) || !var.getModifiers().contains(FINAL)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
505 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
506 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
507 final String varName = var.getSimpleName().toString(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
508 final TypeMirror varType = var.asType(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
509 if (ElementUtils.isAssignable(varType, context.getTruffleTypes().getNodeArray())) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
510 CodeTree size = builder.create().string("copy.", varName, ".length").build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
511 builder.startStatement().string("this.").string(varName).string(" = ").startNewArray((ArrayType) varType, size).end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
512 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
513 builder.startStatement().string("this.", varName, " = copy.", varName).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
514 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
515 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
516 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
517 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
518 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
519 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
520 private CodeVariableElement createAssumptionField(String assumption) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
521 CodeVariableElement var = new CodeVariableElement(context.getTruffleTypes().getAssumption(), assumption); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
522 var.getModifiers().add(Modifier.FINAL); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
523 return var; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
524 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
525 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
526 private CodeVariableElement createChildField(NodeChildData child) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
527 TypeMirror type = child.getNodeType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
528 CodeVariableElement var = new CodeVariableElement(type, child.getName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
529 var.getModifiers().add(Modifier.PROTECTED); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
530 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
531 DeclaredType annotationType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
532 if (child.getCardinality() == Cardinality.MANY) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
533 var.getModifiers().add(Modifier.FINAL); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
534 annotationType = context.getTruffleTypes().getChildrenAnnotation(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
535 } else { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
536 annotationType = context.getTruffleTypes().getChildAnnotation(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
537 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
538 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
539 var.getAnnotationMirrors().add(new CodeAnnotationMirror(annotationType)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
540 return var; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
541 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
542 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
543 private static SpecializationGroup createSpecializationGroups(final NodeData node) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
544 List<SpecializationData> specializations = node.getSpecializations(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
545 List<SpecializationData> filteredSpecializations = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
546 for (SpecializationData current : specializations) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
547 if (current.isUninitialized() || current.isPolymorphic() || !current.isReachable()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
548 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
549 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
550 filteredSpecializations.add(current); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
551 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
552 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
553 return SpecializationGroup.create(filteredSpecializations); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
554 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
555 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
556 protected final CodeExecutableElement createExecuteUninitialized() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
557 SpecializationData generic = node.getGenericSpecialization(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
558 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), generic.getReturnType().getType(), EXECUTE_UNINITIALIZED); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
559 addInternalValueParameters(method, generic, true, false, false); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
560 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
561 |
18776
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18775
diff
changeset
|
562 boolean needsFrame = node.isFrameUsedByAnyGuard(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
563 CodeTreeBuilder createSpecializationCall = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
564 createSpecializationCall.startCall(SPECIALIZE); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
565 addInternalValueParameterNames(createSpecializationCall, generic, generic, null, needsFrame, !needsFrame, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
566 createSpecializationCall.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
567 builder.declaration(baseClassName(node), "newNode", createSpecializationCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
568 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
569 if (generic.isReachable()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
570 builder.startIf().string("newNode == null").end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
571 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
572 builder.startIf().startStaticCall(context.getTruffleTypes().getCompilerDirectives(), "inInterpreter").end().end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
573 builder.statement("containsFallback = true"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
574 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
575 builder.tree(createGenericInvoke(builder, generic, generic)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
576 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
577 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
578 builder.tree(createDeoptimize(builder)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
579 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
580 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
581 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
582 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
583 builder.startStaticCall(context.getTruffleTypes().getDslShare(), "rewriteUninitialized").string("this").string("newNode").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
584 builder.string(".").startCall(EXECUTE_CHAINED); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
585 addInternalValueParameterNames(builder, generic, generic, null, true, false, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
586 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
587 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
588 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
589 if (generic.isReachable()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
590 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
591 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
592 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
593 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
594 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
595 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
596 private static CodeTree createInfoCall(CodeTreeBuilder parent, SpecializationData specialization, String reason) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
597 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
598 builder.startCall(CREATE_INFO).string(reason); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
599 addInternalValueParameterNames(builder, specialization, specialization, null, false, false, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
600 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
601 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
602 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
603 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
604 private CodeExecutableElement createMonomorphicRewrite() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
605 SpecializationData generic = node.getGenericSpecialization(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
606 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), generic.getReturnType().getType(), REWRITE); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
607 addInternalValueParameters(method, generic, true, false, false); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
608 method.addParameter(new CodeVariableElement(context.getType(String.class), "reason")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
609 |
18776
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18775
diff
changeset
|
610 boolean needsFrame = node.isFrameUsedByAnyGuard(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
611 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
612 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
613 builder.startStatement().startStaticCall(context.getTruffleTypes().getCompilerAsserts(), "neverPartOfCompilation").end().end(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
614 String baseClassName = baseClassName(getSpecialization().getNode()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
615 CodeTreeBuilder createSpecializationCall = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
616 createSpecializationCall.startCall(SPECIALIZE); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
617 addInternalValueParameterNames(createSpecializationCall, generic, generic, null, needsFrame, !needsFrame, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
618 createSpecializationCall.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
619 builder.declaration(baseClassName, "newNode", createSpecializationCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
620 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
621 builder.startIf().string("newNode == null").end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
622 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
623 String uninitializedName = nodeSpecializationClassName(node.getUninitializedSpecialization()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
624 builder.string("newNode = ").startNew(uninitializedName).string("this").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
625 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
626 if (node.isFallbackReachable()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
627 builder.startStatement().string("((", uninitializedName, ") newNode).containsFallback = true").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
628 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
629 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
630 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
631 builder.startStatement(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
632 builder.type(context.getType(String.class)).string(" message = ").tree(createInfoCall(builder, generic, "reason")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
633 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
634 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
635 builder.declaration(baseClassName, "returnNode", |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
636 builder.create().startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_REWRITE).string("this").string("newNode").string("message").end().build()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
637 builder.startIf().string("returnNode == null").end().startBlock(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
638 builder.tree(createRewritePolymorphic(builder, "this")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
639 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
640 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
641 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
642 builder.startCall("returnNode", EXECUTE_CHAINED); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
643 addInternalValueParameterNames(builder, node.getGenericSpecialization(), node.getGenericSpecialization(), null, true, false, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
644 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
645 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
646 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
647 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
648 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
649 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
650 private CodeTree createRewritePolymorphic(CodeTreeBuilder parent, String currentNode) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
651 String polyClassName = nodePolymorphicClassName(node); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
652 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
653 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
654 builder.startStatement().string("returnNode = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
655 builder.startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_REWRITE_TO_POLYMORHPIC); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
656 builder.string("this"); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
657 builder.tree(builder.create().startNew(nodeSpecializationClassName(node.getUninitializedSpecialization())).string(currentNode).end().build()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
658 builder.tree(builder.create().startNew(polyClassName).string(currentNode).end().build()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
659 builder.startGroup().cast(baseClassName(node)).startCall("copy").end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
660 builder.string("newNode"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
661 builder.string("message"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
662 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
663 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
664 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
665 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
666 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
667 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
668 private CodeExecutableElement createCreateSpecializationMethod(SpecializationGroup group) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
669 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), new GeneratedTypeMirror(ElementUtils.getPackageName(node.getTemplateType()), baseClassName(node)), |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
670 SPECIALIZE); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
671 |
18776
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18775
diff
changeset
|
672 final boolean needsFrame = node.isFrameUsedByAnyGuard(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
673 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
674 if (!needsFrame) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
675 method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getTruffleTypes().getTruffleBoundary())); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
676 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
677 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
678 addInternalValueParameters(method, node.getGenericSpecialization(), needsFrame, !needsFrame, false); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
679 final CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
680 builder.tree(createExecuteTree(builder, node.getGenericSpecialization(), group, new CodeBlock<SpecializationData>() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
681 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
682 public CodeTree create(CodeTreeBuilder b, SpecializationData current) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
683 return createCreateSpecializationMethodBody0(builder, current, needsFrame); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
684 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
685 }, null, false, true, false, true)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
686 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
687 emitUnreachableSpecializations(builder, node); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
688 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
689 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
690 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
691 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
692 private CodeTree createCreateSpecializationMethodBody0(CodeTreeBuilder parent, SpecializationData current, boolean useDeoptimize) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
693 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
694 if (current.isFallback()) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
695 builder.startReturn().nullLiteral().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
696 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
697 String className = nodeSpecializationClassName(current); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
698 if (!current.getExcludedBy().isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
699 builder.startIf().string("!").startStaticCall(context.getTruffleTypes().getDslShare(), "isExcluded"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
700 builder.string("this").string(nodeSpecializationClassName(current), ".", METADATA_FIELD_NAME).end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
701 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
702 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
703 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
704 if (current.getNode().getGenericSpecialization().isReachable() && useDeoptimize) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
705 builder.tree(createDeoptimize(builder)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
706 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
707 builder.startReturn(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
708 builder.cast(baseClassName(getSpecialization().getNode())); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
709 builder.startGroup().startCall(className, NodeFactoryFactory.FACTORY_METHOD_NAME).string("this"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
710 for (Parameter param : current.getSignatureParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
711 NodeChildData child = param.getSpecification().getExecution().getChild(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
712 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
713 if (types.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
714 builder.string(implicitTypeName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
715 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
716 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
717 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
718 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
719 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
720 if (!current.getExcludedBy().isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
721 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
722 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
723 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
724 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
725 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
726 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
727 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
728 private static void emitUnreachableSpecializations(final CodeTreeBuilder builder, NodeData node) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
729 for (SpecializationData current : node.getSpecializations()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
730 if (current.isReachable()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
731 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
732 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
733 builder.string("// unreachable ").string(current.getId()).newLine(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
734 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
735 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
736 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
737 protected CodeTree createExecuteTree(CodeTreeBuilder outerParent, final SpecializationData source, final SpecializationGroup group, final CodeBlock<SpecializationData> guardedblock, |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
738 final CodeTree elseBlock, boolean forceElse, final boolean emitAssumptions, final boolean typedCasts, final boolean castForGuardsOnly) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
739 return guard(outerParent, source, group, new CodeBlock<Integer>() { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
740 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
741 public CodeTree create(CodeTreeBuilder parent, Integer ifCount) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
742 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
743 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
744 if (group.getSpecialization() != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
745 builder.tree(guardedblock.create(builder, group.getSpecialization())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
746 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
747 assert group.getChildren().isEmpty() : "missed a specialization"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
748 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
749 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
750 for (SpecializationGroup childGroup : group.getChildren()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
751 builder.tree(createExecuteTree(builder, source, childGroup, guardedblock, null, false, emitAssumptions, typedCasts, castForGuardsOnly)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
752 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
753 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
754 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
755 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
756 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
757 }, elseBlock, forceElse, emitAssumptions, typedCasts, castForGuardsOnly); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
758 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
759 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
760 private CodeTree guard(CodeTreeBuilder parent, SpecializationData source, SpecializationGroup group, CodeBlock<Integer> bodyBlock, CodeTree elseBlock, boolean forceElse, boolean emitAssumptions, |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
761 boolean typedCasts, boolean castForGuardsOnly) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
762 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
763 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
764 int ifCount = emitGuards(builder, source, group, emitAssumptions, typedCasts, castForGuardsOnly); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
765 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
766 if (isReachableGroup(group, ifCount)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
767 builder.tree(bodyBlock.create(builder, ifCount)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
768 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
769 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
770 builder.end(ifCount); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
771 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
772 if (elseBlock != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
773 if (ifCount > 0 || forceElse) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
774 builder.tree(elseBlock); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
775 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
776 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
777 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
778 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
779 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
780 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
781 private static boolean isReachableGroup(SpecializationGroup group, int ifCount) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
782 if (ifCount != 0) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
783 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
784 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
785 SpecializationGroup previous = group.getPreviousGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
786 if (previous == null || previous.findElseConnectableGuards().isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
787 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
788 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
789 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
790 /* |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
791 * Hacky else case. In this case the specialization is not reachable due to previous else |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
792 * branch. This is only true if the minimum state is not checked. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
793 */ |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
794 if (previous.getGuards().size() == 1 && previous.getTypeGuards().isEmpty() && previous.getAssumptions().isEmpty() && |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
795 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
796 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
797 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
798 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
799 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
800 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
801 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
802 private int emitGuards(CodeTreeBuilder builder, SpecializationData source, SpecializationGroup group, boolean emitAssumptions, boolean typedCasts, boolean castForGuardsOnly) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
803 CodeTreeBuilder guardsBuilder = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
804 CodeTreeBuilder castBuilder = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
805 CodeTreeBuilder guardsCastBuilder = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
806 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
807 String guardsAnd = ""; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
808 String guardsCastAnd = ""; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
809 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
810 if (emitAssumptions) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
811 for (String assumption : group.getAssumptions()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
812 guardsBuilder.string(guardsAnd); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
813 guardsBuilder.string("this"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
814 guardsBuilder.string(".").string(assumption).string(".isValid()"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
815 guardsAnd = " && "; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
816 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
817 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
818 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
819 for (TypeGuard typeGuard : group.getTypeGuards()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
820 Parameter valueParam = source.getSignatureParameter(typeGuard.getSignatureIndex()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
821 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
822 if (valueParam == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
823 /* |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
824 * If used inside a execute evaluated method then the value param may not exist. In |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
825 * that case we assume that the value is executed generic or of the current |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
826 * specialization. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
827 */ |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
828 if (group.getSpecialization() != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
829 valueParam = group.getSpecialization().getSignatureParameter(typeGuard.getSignatureIndex()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
830 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
831 valueParam = node.getGenericSpecialization().getSignatureParameter(typeGuard.getSignatureIndex()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
832 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
833 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
834 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
835 NodeExecutionData execution = valueParam.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
836 CodeTree implicitGuard = createTypeGuard(guardsBuilder, execution, valueParam, typeGuard.getType(), typedCasts); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
837 if (implicitGuard != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
838 guardsBuilder.string(guardsAnd); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
839 guardsBuilder.tree(implicitGuard); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
840 guardsAnd = " && "; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
841 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
842 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
843 CodeTree implicitGetType = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
844 if (castForGuardsOnly) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
845 implicitGetType = createGetImplicitType(builder, execution, valueParam, typeGuard.getType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
846 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
847 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
848 boolean performCast = true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
849 if (castForGuardsOnly) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
850 // if cast for guards we just cast if the type guard is used inside a guard. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
851 performCast = group.isTypeGuardUsedInAnyGuardBelow(context, source, typeGuard); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
852 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
853 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
854 if (performCast) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
855 CodeTree cast = createCast(castBuilder, execution, valueParam, typeGuard.getType(), typedCasts); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
856 if (cast != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
857 castBuilder.tree(cast); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
858 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
859 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
860 if (implicitGetType != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
861 castBuilder.tree(implicitGetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
862 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
863 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
864 List<GuardExpression> elseGuards = group.findElseConnectableGuards(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
865 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
866 for (GuardExpression guard : group.getGuards()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
867 if (elseGuards.contains(guard)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
868 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
869 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
870 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
871 if (needsTypeGuard(source, group, guard)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
872 guardsCastBuilder.tree(createMethodGuard(builder, guardsCastAnd, source, guard)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
873 guardsCastAnd = " && "; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
874 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
875 guardsBuilder.tree(createMethodGuard(builder, guardsAnd, source, guard)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
876 guardsAnd = " && "; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
877 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
878 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
879 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
880 int ifCount = startGuardIf(builder, guardsBuilder.build(), 0, elseGuards); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
881 builder.tree(castBuilder.build()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
882 ifCount = startGuardIf(builder, guardsCastBuilder.build(), ifCount, elseGuards); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
883 return ifCount; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
884 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
885 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
886 private static int startGuardIf(CodeTreeBuilder builder, CodeTree condition, int ifCount, List<GuardExpression> elseGuard) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
887 int newIfCount = ifCount; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
888 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
889 if (!condition.isEmpty()) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
890 if (ifCount == 0 && !elseGuard.isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
891 builder.startElseIf(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
892 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
893 builder.startIf(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
894 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
895 builder.tree(condition); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
896 builder.end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
897 newIfCount++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
898 } else if (ifCount == 0 && !elseGuard.isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
899 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
900 newIfCount++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
901 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
902 return newIfCount; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
903 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
904 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
905 private static boolean needsTypeGuard(SpecializationData source, SpecializationGroup group, GuardExpression guard) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
906 for (Parameter parameter : guard.getResolvedGuard().getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
907 if (!parameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
908 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
909 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
910 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
911 int signatureIndex = source.getNode().getChildExecutions().indexOf(parameter.getSpecification().getExecution()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
912 if (signatureIndex == -1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
913 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
914 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
915 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
916 TypeGuard typeGuard = group.findTypeGuard(signatureIndex); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
917 if (typeGuard != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
918 TypeData requiredType = typeGuard.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
919 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
920 Parameter sourceParameter = source.findParameter(parameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
921 if (sourceParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
922 sourceParameter = source.getNode().getGenericSpecialization().findParameter(parameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
923 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
924 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
925 if (ElementUtils.needsCastTo(sourceParameter.getType(), requiredType.getPrimitiveType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
926 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
927 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
928 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
929 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
930 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
931 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
932 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
933 private CodeTree createTypeGuard(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType, boolean typedCasts) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
934 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
935 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
936 TypeData sourceType = source.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
937 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
938 if (!sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
939 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
940 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
941 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
942 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
943 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
944 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
945 Parameter shortCircuit = source.getPreviousParameter(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
946 assert shortCircuit != null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
947 builder.string("("); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
948 builder.string("!").string(valueName(shortCircuit)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
949 builder.string(" || "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
950 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
951 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
952 List<TypeData> types = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
953 if (types.size() > 1) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
954 String castTypeName = null; |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
955 if (typedCasts) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
956 castTypeName = implicitTypeName(source); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
957 } |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
958 CodeTree check; |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
959 if (castTypeName == null) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
960 check = TypeSystemCodeGenerator.implicitCheck(targetType, CodeTreeBuilder.singleString(valueName(source)), null); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
961 } else { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
962 check = TypeSystemCodeGenerator.implicitCheck(targetType, CodeTreeBuilder.singleString(valueName(source)), castTypeName); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
963 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
964 builder.tree(check); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
965 } else { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
966 builder.tree(TypeSystemCodeGenerator.check(targetType, CodeTreeBuilder.singleString(valueName(source)))); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
967 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
968 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
969 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
970 builder.string(")"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
971 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
972 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
973 builder.end(); // group |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
974 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
975 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
976 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
977 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
978 // TODO merge redundancies with #createTypeGuard |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
979 private CodeTree createCast(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType, boolean typedCasts) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
980 TypeData sourceType = source.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
981 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
982 if (!sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
983 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
984 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
985 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
986 CodeTree condition = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
987 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
988 Parameter shortCircuit = source.getPreviousParameter(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
989 assert shortCircuit != null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
990 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
991 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
992 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
993 CodeTree cast; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
994 List<TypeData> types = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
995 if (types.size() > 1) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
996 String castTypeName = null; |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
997 if (typedCasts) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
998 castTypeName = implicitTypeName(source); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
999 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1000 cast = TypeSystemCodeGenerator.implicitCast(targetType, CodeTreeBuilder.singleString(valueName(source)), castTypeName); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1001 } else { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1002 cast = TypeSystemCodeGenerator.cast(targetType, valueName(source)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1003 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1004 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1005 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1006 builder.tree(createLazyAssignment(parent, castValueName(source), targetType.getPrimitiveType(), condition, cast)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1007 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1008 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1009 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1010 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1011 private CodeTree createGetImplicitType(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1012 CodeTree condition = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1013 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1014 Parameter shortCircuit = source.getPreviousParameter(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1015 assert shortCircuit != null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1016 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1017 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1018 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1019 CodeTreeBuilder builder = parent.create(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1020 List<TypeData> types = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1021 if (types.size() > 1) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1022 CodeTree castType = TypeSystemCodeGenerator.implicitType(targetType, CodeTreeBuilder.singleString(valueName(source))); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1023 builder.tree(createLazyAssignment(builder, implicitTypeName(source), context.getType(Class.class), condition, castType)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1024 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1025 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1026 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1027 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1028 private static CodeTree createMethodGuard(CodeTreeBuilder parent, String prefix, SpecializationData source, GuardExpression guard) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1029 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1030 builder.string(prefix); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1031 if (guard.isNegated()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1032 builder.string("!"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1033 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1034 builder.tree(createTemplateMethodCall(builder, null, source, guard.getResolvedGuard(), null)); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1035 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1036 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1037 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1038 protected CodeTree createGenericInvoke(CodeTreeBuilder parent, SpecializationData source, SpecializationData current) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1039 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1040 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1041 if (current.getMethod() == null) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1042 emitEncounteredSynthetic(builder, getSpecialization().getNode(), current); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1043 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1044 builder.startReturn().tree(createTemplateMethodCall(builder, null, source, current, null)).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1045 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1046 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1047 return encloseThrowsWithFallThrough(parent, current, builder.build()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1048 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1049 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1050 private CodeTree encloseThrowsWithFallThrough(CodeTreeBuilder parent, SpecializationData current, CodeTree tree) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1051 if (current.getExceptions().isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1052 return tree; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1053 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1054 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1055 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1056 builder.startTryBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1057 builder.tree(tree); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1058 for (SpecializationThrowsData exception : current.getExceptions()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1059 builder.end().startCatchBlock(exception.getJavaClass(), "rewriteEx"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1060 builder.tree(createDeoptimize(builder)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1061 builder.tree(createCallRewriteMonomorphic(builder, false, current.getNode().getGenericSpecialization().getReturnType().getTypeSystemType(), null, |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1062 "Thrown " + ElementUtils.getSimpleName(exception.getJavaClass()))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1063 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1064 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1065 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1066 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1067 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1068 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1069 protected CodeTree createCastingExecute(CodeTreeBuilder parent, ExecutableTypeData executable, ExecutableTypeData castExecutable) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1070 TypeData type = executable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1071 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1072 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1073 TypeData primaryType = castExecutable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1074 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1075 boolean needsTry = castExecutable.hasUnexpectedValue(context); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1076 boolean returnVoid = type.isVoid(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1077 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1078 List<Parameter> executeParameters = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1079 for (Parameter sourceParameter : executable.getSignatureParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1080 Parameter targetParameter = castExecutable.findParameter(sourceParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1081 if (targetParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1082 executeParameters.add(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1083 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1084 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1085 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1086 // execute names are enforced no cast |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1087 String[] executeParameterNames = new String[executeParameters.size()]; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1088 for (int i = 0; i < executeParameterNames.length; i++) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1089 executeParameterNames[i] = valueName(executeParameters.get(i)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1090 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1091 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1092 builder.tree(createExecuteChildren(builder, executable, specialization, executeParameters, null)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1093 boolean hasUnexpected = executable.hasUnexpectedValue(context); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1094 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1095 CodeTree primaryExecuteCall = createTemplateMethodCall(builder, null, executable, castExecutable, null, executeParameterNames); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1096 if (needsTry) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1097 if (!returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1098 builder.declaration(primaryType.getPrimitiveType(), "value"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1099 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1100 builder.startTryBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1101 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1102 if (returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1103 builder.statement(primaryExecuteCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1104 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1105 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1106 builder.string("value = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1107 builder.tree(primaryExecuteCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1108 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1109 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1110 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1111 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1112 if (returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1113 builder.string("// ignore").newLine(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1114 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1115 builder.startReturn(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1116 builder.tree(createExpectExecutableType(specialization.getNode().getTypeSystem().getGenericTypeData(), hasUnexpected, executable.getType(), |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1117 CodeTreeBuilder.singleString("ex.getResult()"))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1118 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1119 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1120 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1121 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1122 if (!returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1123 builder.startReturn(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1124 builder.tree(createExpectExecutableType(castExecutable.getReturnType().getTypeSystemType(), hasUnexpected, executable.getType(), CodeTreeBuilder.singleString("value"))); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1125 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1126 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1127 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1128 if (returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1129 builder.statement(primaryExecuteCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1130 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1131 builder.startReturn(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1132 builder.tree(createExpectExecutableType(castExecutable.getReturnType().getTypeSystemType(), hasUnexpected, executable.getType(), primaryExecuteCall)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1133 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1134 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1135 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1136 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1137 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1138 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1139 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1140 private static CodeTree createExpectExecutableType(TypeData sourceType, boolean hasUnexpected, TypeData exepctedType, CodeTree value) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1141 return createCastType(sourceType, exepctedType, hasUnexpected, value); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1142 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1143 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1144 protected CodeTree createExecuteChildren(CodeTreeBuilder parent, ExecutableTypeData sourceExecutable, SpecializationData currentSpecialization, List<Parameter> targetParameters, |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1145 Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1146 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1147 for (Parameter targetParameter : targetParameters) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1148 if (!targetParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1149 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1150 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1151 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1152 CodeTree executionExpressions = createExecuteChild(builder, execution, sourceExecutable, targetParameter, unexpectedParameter); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1153 CodeTree unexpectedTree = createCatchUnexpectedTree(builder, executionExpressions, currentSpecialization, sourceExecutable, targetParameter, execution.isShortCircuit(), |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1154 unexpectedParameter); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1155 CodeTree shortCircuitTree = createShortCircuitTree(builder, unexpectedTree, currentSpecialization, targetParameter, unexpectedParameter); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1156 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1157 if (shortCircuitTree == executionExpressions) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1158 if (containsNewLine(executionExpressions)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1159 builder.declaration(targetParameter.getType(), valueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1160 builder.tree(shortCircuitTree); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1161 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1162 builder.startStatement().type(targetParameter.getType()).string(" ").tree(shortCircuitTree).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1163 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1164 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1165 builder.tree(shortCircuitTree); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1166 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1167 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1168 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1169 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1170 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1171 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1172 private ExecutableTypeData resolveExecutableType(NodeExecutionData execution, TypeData type) { |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18766
diff
changeset
|
1173 ExecutableTypeData targetExecutable = execution.getChild().findExecutableType(type); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1174 if (targetExecutable == null) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1175 targetExecutable = execution.getChild().findAnyGenericExecutableType(context); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1176 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1177 return targetExecutable; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1178 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1179 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1180 private CodeTree createExecuteChild(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData sourceExecutable, Parameter targetParameter, Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1181 if (specialization.isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1182 List<TypeData> possiblePolymorphicTypes = lookupPolymorphicTargetTypes(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1183 if (possiblePolymorphicTypes.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1184 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1185 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1186 boolean elseIf = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1187 for (TypeData possiblePolymoprhicType : possiblePolymorphicTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1188 if (possiblePolymoprhicType.isGeneric()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1189 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1190 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1191 elseIf = builder.startIf(elseIf); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1192 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1193 Parameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1194 TypeData sourceType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1195 builder.string(polymorphicTypeName(targetParameter.getSpecification().getExecution())).string(" == ").typeLiteral(possiblePolymoprhicType.getPrimitiveType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1196 builder.end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1197 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1198 builder.tree(createExecuteChildExpression(parent, execution, sourceType, new Parameter(targetParameter, possiblePolymoprhicType), unexpectedParameter, null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1199 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1200 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1201 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1202 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1203 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1204 builder.startStatement().tree(createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter)).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1205 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1206 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1207 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1208 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1209 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1210 return createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1211 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1212 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1213 protected static final List<Parameter> getImplicitTypeParameters(SpecializationData model) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1214 List<Parameter> parameter = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1215 for (Parameter param : model.getSignatureParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1216 NodeChildData child = param.getSpecification().getExecution().getChild(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1217 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1218 if (types.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1219 parameter.add(param); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1220 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1221 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1222 return parameter; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1223 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1224 |
18766
a720bf2e2f43
Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
1225 private List<TypeData> lookupPolymorphicTargetTypes(Parameter param) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1226 Set<TypeData> possiblePolymorphicTypes = new HashSet<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1227 for (SpecializationData otherSpecialization : specialization.getNode().getSpecializations()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1228 if (!otherSpecialization.isSpecialized()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1229 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1230 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1231 Parameter otherParameter = otherSpecialization.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1232 if (otherParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1233 possiblePolymorphicTypes.add(otherParameter.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1234 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1235 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1236 List<TypeData> types = new ArrayList<>(possiblePolymorphicTypes); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1237 Collections.sort(types); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1238 return types; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1239 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1240 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1241 private CodeTree createExecuteChildImplicit(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData sourceExecutable, Parameter param, Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1242 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1243 Parameter sourceParameter = sourceExecutable.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1244 String childExecuteName = createExecuteChildMethodName(param, sourceParameter != null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1245 if (childExecuteName != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1246 builder.string(valueName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1247 builder.string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1248 builder.startCall(childExecuteName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1249 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1250 for (Parameter parameters : sourceExecutable.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1251 if (parameters.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1252 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1253 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1254 builder.string(parameters.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1255 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1256 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1257 if (sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1258 builder.string(valueNameEvaluated(sourceParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1259 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1260 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1261 builder.string(implicitTypeName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1262 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1263 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1264 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1265 List<TypeData> sourceTypes = execution.getChild().getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1266 TypeData expectType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1267 if (sourceTypes.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1268 builder.tree(createExecuteChildImplicitExpressions(parent, param, expectType)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1269 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1270 builder.tree(createExecuteChildExpression(parent, execution, expectType, param, unexpectedParameter, null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1271 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1272 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1273 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1274 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1275 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1276 private static String createExecuteChildMethodName(Parameter param, boolean expect) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1277 NodeExecutionData execution = param.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1278 NodeChildData child = execution.getChild(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1279 if (child.getExecuteWith().size() > 0) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1280 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1281 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1282 List<TypeData> sourceTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1283 if (sourceTypes.size() <= 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1284 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1285 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1286 String prefix = expect ? "expect" : "execute"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1287 String suffix = execution.getIndex() > -1 ? String.valueOf(execution.getIndex()) : ""; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1288 return prefix + ElementUtils.firstLetterUpperCase(child.getName()) + ElementUtils.firstLetterUpperCase(ElementUtils.getTypeId(param.getType())) + suffix; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1289 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1290 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1291 private List<CodeExecutableElement> createExecuteChilds(Parameter param, Set<TypeData> expectTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1292 CodeExecutableElement executeMethod = createExecuteChild(param, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1293 if (executeMethod == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1294 return Collections.emptyList(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1295 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1296 List<CodeExecutableElement> childs = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1297 childs.add(executeMethod); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1298 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1299 for (TypeData expectType : expectTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1300 CodeExecutableElement method = createExecuteChild(param, expectType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1301 if (method != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1302 childs.add(method); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1303 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1304 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1305 return childs; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1306 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1307 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1308 private CodeExecutableElement createExecuteChild(Parameter param, TypeData expectType) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1309 String childExecuteName = createExecuteChildMethodName(param, expectType != null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1310 if (childExecuteName == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1311 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1312 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1313 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1314 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, expectType != null ? STATIC : FINAL), param.getType(), childExecuteName); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1315 method.getThrownTypes().add(context.getTruffleTypes().getUnexpectedValueException()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1316 method.addParameter(new CodeVariableElement(context.getTruffleTypes().getFrame(), "frameValue")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1317 if (expectType != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1318 method.addParameter(new CodeVariableElement(expectType.getPrimitiveType(), valueNameEvaluated(param))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1319 } |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1320 method.addParameter(new CodeVariableElement(context.getType(Class.class), implicitTypeName(param))); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1321 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1322 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1323 builder.declaration(param.getType(), valueName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1324 builder.tree(createExecuteChildImplicitExpressions(builder, param, expectType)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1325 builder.startReturn().string(valueName(param)).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1326 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1327 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1328 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1329 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1330 private CodeTree createExecuteChildImplicitExpressions(CodeTreeBuilder parent, Parameter targetParameter, TypeData expectType) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1331 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1332 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1333 List<TypeData> sourceTypes = node.getTypeSystem().lookupSourceTypes(targetParameter.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1334 boolean elseIf = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1335 int index = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1336 for (TypeData sourceType : sourceTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1337 if (index < sourceTypes.size() - 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1338 elseIf = builder.startIf(elseIf); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1339 builder.string(implicitTypeName(targetParameter)).string(" == ").typeLiteral(sourceType.getPrimitiveType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1340 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1341 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1342 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1343 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1344 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1345 |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18766
diff
changeset
|
1346 ExecutableTypeData implictExecutableTypeData = execution.getChild().findExecutableType(sourceType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1347 if (implictExecutableTypeData == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1348 /* |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1349 * For children with executeWith.size() > 0 an executable type may not exist so use |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1350 * the generic executable type which is guaranteed to exist. An expect call is |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1351 * inserted automatically by #createExecuteExpression. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1352 */ |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18766
diff
changeset
|
1353 implictExecutableTypeData = execution.getChild().getNodeData().findAnyGenericExecutableType(context, execution.getChild().getExecuteWith().size()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1354 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1355 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1356 ImplicitCastData cast = execution.getChild().getNodeData().getTypeSystem().lookupCast(sourceType, targetParameter.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1357 CodeTree execute = createExecuteChildExpression(builder, execution, expectType, targetParameter, null, cast); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1358 builder.statement(execute); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1359 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1360 index++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1361 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1362 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1363 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1364 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1365 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeExecutionData execution, TypeData sourceParameterType, Parameter targetParameter, Parameter unexpectedParameter, |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1366 ImplicitCastData cast) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1367 // assignments: targetType <- castTargetType <- castSourceType <- sourceType |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1368 TypeData sourceType = sourceParameterType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1369 TypeData targetType = targetParameter.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1370 TypeData castSourceType = targetType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1371 TypeData castTargetType = targetType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1372 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1373 if (cast != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1374 castSourceType = cast.getSourceType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1375 castTargetType = cast.getTargetType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1376 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1377 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1378 CodeTree expression; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1379 if (sourceType == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1380 ExecutableTypeData targetExecutable = resolveExecutableType(execution, castSourceType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1381 expression = createExecuteChildExpression(parent, execution, targetExecutable, unexpectedParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1382 sourceType = targetExecutable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1383 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1384 expression = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1385 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1386 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1387 // target = expectTargetType(implicitCast(expectCastSourceType(source))) |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1388 expression = createExpectType(sourceType, castSourceType, expression); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1389 expression = createImplicitCast(cast, expression); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1390 expression = createExpectType(castTargetType, targetType, expression); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1391 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1392 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1393 builder.string(valueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1394 builder.string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1395 builder.tree(expression); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1396 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1397 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1398 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1399 private static CodeTree createImplicitCast(ImplicitCastData cast, CodeTree expression) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1400 if (cast == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1401 return expression; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1402 } |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1403 return TypeSystemCodeGenerator.invokeImplicitCast(cast, expression); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1404 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1405 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1406 private boolean containsNewLine(CodeTree tree) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1407 if (tree.getCodeKind() == CodeTreeKind.NEW_LINE) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1408 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1409 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1410 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1411 List<CodeTree> enclosing = tree.getEnclosedElements(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1412 if (enclosing != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1413 for (CodeTree codeTree : enclosing) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1414 if (containsNewLine(codeTree)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1415 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1416 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1417 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1418 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1419 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1420 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1421 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1422 private boolean hasUnexpected(Parameter sourceParameter, Parameter targetParameter, Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1423 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1424 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1425 if (getSpecialization().isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1426 // check for other polymorphic types |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1427 List<TypeData> polymorphicTargetTypes = lookupPolymorphicTargetTypes(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1428 if (polymorphicTargetTypes.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1429 for (TypeData polymorphicTargetType : polymorphicTargetTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1430 if (hasUnexpectedType(execution, sourceParameter, polymorphicTargetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1431 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1432 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1433 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1434 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1435 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1436 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1437 if (hasUnexpectedType(execution, sourceParameter, targetParameter.getTypeSystemType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1438 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1439 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1440 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1441 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1442 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1443 private boolean hasUnexpectedType(NodeExecutionData execution, Parameter sourceParameter, TypeData targetType) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1444 List<TypeData> implicitSourceTypes = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1445 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1446 for (TypeData implicitSourceType : implicitSourceTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1447 TypeData sourceType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1448 ExecutableTypeData targetExecutable = resolveExecutableType(execution, implicitSourceType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1449 if (sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1450 sourceType = sourceParameter.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1451 } else { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1452 if (targetExecutable.hasUnexpectedValue(context)) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1453 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1454 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1455 sourceType = targetExecutable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1456 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1457 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1458 ImplicitCastData cast = getSpecialization().getNode().getTypeSystem().lookupCast(implicitSourceType, targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1459 if (cast != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1460 if (cast.getSourceType().needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1461 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1462 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1463 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1464 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1465 if (sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1466 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1467 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1468 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1469 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1470 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1471 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1472 private CodeTree createCatchUnexpectedTree(CodeTreeBuilder parent, CodeTree body, SpecializationData currentSpecialization, ExecutableTypeData currentExecutable, Parameter param, |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1473 boolean shortCircuit, Parameter unexpectedParameter) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1474 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1475 Parameter sourceParameter = currentExecutable.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1476 boolean unexpected = hasUnexpected(sourceParameter, param, unexpectedParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1477 if (!unexpected) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1478 return body; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1479 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1480 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1481 if (!shortCircuit) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1482 builder.declaration(param.getType(), valueName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1483 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1484 builder.startTryBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1485 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1486 if (containsNewLine(body)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1487 builder.tree(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1488 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1489 builder.statement(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1490 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1491 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1492 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1493 SpecializationData generic = currentSpecialization.getNode().getGenericSpecialization(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1494 Parameter genericParameter = generic.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1495 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1496 List<Parameter> genericParameters = generic.getParametersAfter(genericParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1497 builder.tree(createExecuteChildren(parent, currentExecutable, generic, genericParameters, genericParameter)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1498 if (currentSpecialization.isPolymorphic()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1499 builder.tree(createReturnOptimizeTypes(builder, currentExecutable, currentSpecialization, param)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1500 } else { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1501 builder.tree(createCallRewriteMonomorphic(builder, currentExecutable.hasUnexpectedValue(context), currentExecutable.getType(), param, "Expected " + param.getLocalName() + " instanceof " + |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1502 ElementUtils.getSimpleName(param.getType()))); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1503 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1504 builder.end(); // catch block |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1505 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1506 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1507 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1508 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1509 private CodeTree createReturnOptimizeTypes(CodeTreeBuilder parent, ExecutableTypeData currentExecutable, SpecializationData currentSpecialization, Parameter param) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1510 SpecializationData polymorphic = node.getPolymorphicSpecialization(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1511 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1512 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1513 builder.startStatement().string(polymorphicTypeName(param.getSpecification().getExecution())).string(" = ").typeLiteral(context.getType(Object.class)).end(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1514 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1515 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1516 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1517 CodeTreeBuilder execute = new CodeTreeBuilder(builder); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1518 execute.startCall("next0", EXECUTE_CHAINED); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1519 addInternalValueParameterNames(execute, currentSpecialization, polymorphic, param.getLocalName(), true, false, null); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1520 execute.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1521 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1522 TypeData sourceType = polymorphic.getReturnType().getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1523 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1524 builder.tree(createExpectExecutableType(sourceType, currentExecutable.hasUnexpectedValue(context), currentExecutable.getType(), execute.build())); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1525 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1526 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1527 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1528 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1529 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1530 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeExecutionData targetExecution, ExecutableTypeData targetExecutable, Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1531 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1532 if (targetExecution != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1533 builder.tree(createAccessChild(targetExecution, null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1534 builder.string("."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1535 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1536 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1537 builder.startCall(targetExecutable.getMethodName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1538 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1539 // TODO this should be merged with #createTemplateMethodCall |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1540 int index = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1541 for (Parameter parameter : targetExecutable.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1542 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1543 if (!parameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1544 builder.string(parameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1545 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1546 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1547 if (index < targetExecution.getChild().getExecuteWith().size()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1548 NodeChildData child = targetExecution.getChild().getExecuteWith().get(index); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1549 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1550 ParameterSpec spec = getSpecialization().getSpecification().findParameterSpec(child.getName()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1551 List<Parameter> specializationParams = getSpecialization().findParameters(spec); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1552 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1553 if (specializationParams.isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1554 builder.defaultValue(parameter.getType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1555 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1556 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1557 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1558 Parameter specializationParam = specializationParams.get(0); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1559 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1560 TypeData targetType = parameter.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1561 TypeData sourceType = specializationParam.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1562 String localName = specializationParam.getLocalName(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1563 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1564 if (unexpectedParameter != null && unexpectedParameter.getLocalName().equals(specializationParam.getLocalName())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1565 localName = "ex.getResult()"; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1566 sourceType = getSpecialization().getNode().getTypeSystem().getGenericTypeData(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1567 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1568 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1569 CodeTree value = CodeTreeBuilder.singleString(localName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1570 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1571 if (sourceType.needsCastTo(targetType)) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1572 value = TypeSystemCodeGenerator.cast(targetType, value); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1573 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1574 builder.tree(value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1575 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1576 builder.defaultValue(parameter.getType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1577 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1578 index++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1579 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1580 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1581 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1582 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1583 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1584 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1585 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1586 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1587 private CodeTree createShortCircuitTree(CodeTreeBuilder parent, CodeTree body, SpecializationData currentSpecialization, Parameter parameter, Parameter exceptionParam) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1588 NodeExecutionData execution = parameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1589 if (execution == null || !execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1590 return body; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1591 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1592 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1593 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1594 Parameter shortCircuitParam = currentSpecialization.getPreviousParam(parameter); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1595 builder.tree(createShortCircuitValue(builder, currentSpecialization, execution, shortCircuitParam, exceptionParam)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1596 builder.declaration(parameter.getType(), valueName(parameter), CodeTreeBuilder.createBuilder().defaultValue(parameter.getType())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1597 builder.startIf().string(shortCircuitParam.getLocalName()).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1598 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1599 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1600 if (containsNewLine(body)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1601 builder.tree(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1602 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1603 builder.statement(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1604 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1605 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1606 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1607 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1608 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1609 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1610 private static CodeTree createShortCircuitValue(CodeTreeBuilder parent, SpecializationData specialization, NodeExecutionData execution, Parameter shortCircuitParam, Parameter exceptionParam) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1611 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1612 int shortCircuitIndex = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1613 for (NodeExecutionData otherExectuion : specialization.getNode().getChildExecutions()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1614 if (otherExectuion.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1615 if (otherExectuion == execution) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1616 break; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1617 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1618 shortCircuitIndex++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1619 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1620 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1621 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1622 builder.startStatement().type(shortCircuitParam.getType()).string(" ").string(valueName(shortCircuitParam)).string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1623 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1624 builder.tree(createTemplateMethodCall(builder, null, specialization, shortCircuitData, exceptionParam != null ? exceptionParam.getLocalName() : null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1625 builder.end(); // statement |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1626 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1627 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1628 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1629 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1630 protected CodeTree createCallRewriteMonomorphic(CodeTreeBuilder parent, boolean hasUnexpected, TypeData returnType, Parameter exceptionParam, String reason) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1631 SpecializationData generic = node.getGenericSpecialization(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1632 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1633 specializeCall.startCall(REWRITE); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1634 addInternalValueParameterNames(specializeCall, generic, node.getGenericSpecialization(), exceptionParam != null ? exceptionParam.getLocalName() : null, true, false, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1635 specializeCall.doubleQuote(reason); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1636 specializeCall.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1637 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1638 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1639 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1640 builder.startReturn(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1641 builder.tree(createExpectExecutableType(generic.getReturnType().getTypeSystemType(), hasUnexpected, returnType, specializeCall.build())); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1642 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1643 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1644 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1645 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1646 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1647 static String valueNameEvaluated(Parameter targetParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1648 return valueName(targetParameter) + "Evaluated"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1649 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1650 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1651 static String implicitTypeName(Parameter param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1652 return param.getLocalName() + "ImplicitType"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1653 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1654 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1655 static String polymorphicTypeName(NodeExecutionData param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1656 return param.getName() + "PolymorphicType"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1657 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1658 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1659 static String valueName(Parameter param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1660 return param.getLocalName(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1661 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1662 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1663 private static CodeTree createAccessChild(NodeExecutionData targetExecution, String thisReference) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1664 String reference = thisReference; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1665 if (reference == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1666 reference = "this"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1667 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1668 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1669 Element accessElement = targetExecution.getChild().getAccessElement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1670 if (accessElement == null || accessElement.getKind() == ElementKind.METHOD) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1671 builder.string(reference).string(".").string(targetExecution.getChild().getName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1672 } else if (accessElement.getKind() == ElementKind.FIELD) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1673 builder.string(reference).string(".").string(accessElement.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1674 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1675 throw new AssertionError(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1676 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1677 if (targetExecution.isIndexed()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1678 builder.string("[" + targetExecution.getIndex() + "]"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1679 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1680 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1681 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1682 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1683 private static String castValueName(Parameter parameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1684 return valueName(parameter) + "Cast"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1685 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1686 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1687 static void addInternalValueParameterNames(CodeTreeBuilder builder, TemplateMethod source, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame, boolean disableFrame, |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1688 Map<String, String> customNames) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1689 if (forceFrame && !disableFrame && specialization.getSpecification().findParameterSpec("frame") != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1690 builder.string("frameValue"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1691 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1692 for (Parameter parameter : specialization.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1693 ParameterSpec spec = parameter.getSpecification(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1694 if ((disableFrame || forceFrame) && spec.getName().equals("frame")) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1695 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1696 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1697 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1698 if (parameter.getSpecification().isLocal()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1699 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1700 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1701 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1702 Parameter sourceParameter = source.findParameter(parameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1703 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1704 if (customNames != null && customNames.containsKey(parameter.getLocalName())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1705 builder.string(customNames.get(parameter.getLocalName())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1706 } else if (unexpectedValueName != null && parameter.getLocalName().equals(unexpectedValueName)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1707 builder.cast(parameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1708 } else if (sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1709 builder.string(valueName(sourceParameter, parameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1710 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1711 builder.string(valueName(parameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1712 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1713 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1714 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1715 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1716 private static String valueName(Parameter sourceParameter, Parameter targetParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1717 if (!sourceParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1718 return valueName(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1719 } else if (sourceParameter.getTypeSystemType() != null && targetParameter.getTypeSystemType() != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1720 if (sourceParameter.getTypeSystemType().needsCastTo(targetParameter.getTypeSystemType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1721 return castValueName(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1722 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1723 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1724 return valueName(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1725 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1726 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1727 static CodeTree createTemplateMethodCall(CodeTreeBuilder parent, CodeTree target, TemplateMethod sourceMethod, TemplateMethod targetMethod, String unexpectedValueName, |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1728 String... customSignatureValueNames) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1729 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1730 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1731 boolean castedValues = sourceMethod != targetMethod; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1732 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1733 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1734 ExecutableElement method = targetMethod.getMethod(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1735 if (method == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1736 throw new UnsupportedOperationException(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1737 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1738 TypeElement targetClass = ElementUtils.findNearestEnclosingType(method.getEnclosingElement()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1739 NodeData node = (NodeData) targetMethod.getTemplate(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1740 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1741 if (target == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1742 boolean accessible = targetMethod.canBeAccessedByInstanceOf(node.getNodeType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1743 if (accessible) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1744 if (builder.findMethod().getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1745 if (method.getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1746 builder.type(targetClass.asType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1747 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1748 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1749 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1750 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1751 if (targetMethod instanceof ExecutableTypeData) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1752 builder.string("this"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1753 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1754 builder.string("super"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1755 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1756 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1757 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1758 if (method.getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1759 builder.type(targetClass.asType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1760 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1761 Parameter firstParameter = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1762 for (Parameter searchParameter : targetMethod.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1763 if (searchParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1764 firstParameter = searchParameter; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1765 break; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1766 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1767 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1768 if (firstParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1769 throw new AssertionError(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1770 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1771 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1772 Parameter sourceParameter = sourceMethod.findParameter(firstParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1773 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1774 if (castedValues && sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1775 builder.string(valueName(sourceParameter, firstParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1776 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1777 builder.string(valueName(firstParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1778 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1779 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1780 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1781 builder.string("."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1782 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1783 builder.tree(target); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1784 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1785 builder.startCall(method.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1786 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1787 int signatureIndex = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1788 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1789 for (Parameter targetParameter : targetMethod.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1790 Parameter valueParameter = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1791 if (sourceMethod != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1792 valueParameter = sourceMethod.findParameter(targetParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1793 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1794 if (valueParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1795 valueParameter = targetParameter; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1796 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1797 TypeMirror targetType = targetParameter.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1798 TypeMirror valueType = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1799 if (valueParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1800 valueType = valueParameter.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1801 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1802 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1803 if (signatureIndex < customSignatureValueNames.length && targetParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1804 builder.string(customSignatureValueNames[signatureIndex]); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1805 signatureIndex++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1806 } else if (targetParameter.getSpecification().isLocal()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1807 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1808 if (builder.findMethod().getModifiers().contains(Modifier.STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1809 builder.string(THIS_NODE_LOCAL_VAR_NAME).string("."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1810 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1811 builder.string("this."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1812 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1813 builder.string(targetParameter.getSpecification().getName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1814 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1815 } else if (unexpectedValueName != null && targetParameter.getLocalName().equals(unexpectedValueName)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1816 builder.cast(targetParameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1817 } else if (!ElementUtils.needsCastTo(valueType, targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1818 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1819 builder.string(valueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1820 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1821 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1822 builder.string(castValueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1823 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1824 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1825 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1826 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1827 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1828 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1829 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1830 |
18754
59bf50cc5a32
Truffle-DSL: implemented @GenerateNodeFactory to enable generation of factories. Factory generation is now disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
1831 public static String baseClassName(NodeData node) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1832 String nodeid = resolveNodeId(node); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1833 String name = ElementUtils.firstLetterUpperCase(nodeid); |
18754
59bf50cc5a32
Truffle-DSL: implemented @GenerateNodeFactory to enable generation of factories. Factory generation is now disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
1834 name += "NodeGen"; |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1835 return name; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1836 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1837 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1838 /** |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1839 * <pre> |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1840 * variant1 $condition != null |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18766
diff
changeset
|
1841 * |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1842 * $type $name = defaultValue($type); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1843 * if ($condition) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1844 * $name = $value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1845 * } |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18766
diff
changeset
|
1846 * |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1847 * variant2 $condition != null |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1848 * $type $name = $value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1849 * </pre> |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1850 * |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1851 * . |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1852 */ |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1853 private static CodeTree createLazyAssignment(CodeTreeBuilder parent, String name, TypeMirror type, CodeTree condition, CodeTree value) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1854 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1855 if (condition == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1856 builder.declaration(type, name, value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1857 } else { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1858 builder.declaration(type, name, new CodeTreeBuilder(parent).defaultValue(type).build()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1859 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1860 builder.startIf().tree(condition).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1861 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1862 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1863 builder.string(name); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1864 builder.string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1865 builder.tree(value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1866 builder.end(); // statement |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1867 builder.end(); // block |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1868 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1869 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1870 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1871 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1872 void emitEncounteredSynthetic(CodeTreeBuilder builder, NodeData model, TemplateMethod current) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1873 CodeTreeBuilder nodes = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1874 CodeTreeBuilder arguments = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1875 nodes.startCommaGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1876 arguments.startCommaGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1877 boolean empty = true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1878 for (Parameter parameter : current.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1879 NodeExecutionData executionData = parameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1880 if (executionData != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1881 if (executionData.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1882 nodes.nullLiteral(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1883 arguments.string(valueName(parameter.getPreviousParameter())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1884 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1885 nodes.tree(createAccessChild(executionData, "rootNode")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1886 arguments.string(valueName(parameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1887 empty = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1888 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1889 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1890 nodes.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1891 arguments.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1892 builder.startStatement().startStaticCall(context.getTruffleTypes().getCompilerDirectives(), "transferToInterpreter").end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1893 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1894 builder.declaration(baseClassName(model), "rootNode", builder.create().startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_FIND_ROOT).string("this").end()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1895 builder.startThrow().startNew(context.getType(UnsupportedSpecializationException.class)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1896 builder.string("rootNode"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1897 builder.startNewArray(context.getTruffleTypes().getNodeArray(), null); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1898 builder.tree(nodes.build()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1899 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1900 if (!empty) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1901 builder.tree(arguments.build()); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1902 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1903 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1904 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1905 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1906 private static ExecutableElement findCopyConstructor(TypeMirror type) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1907 for (ExecutableElement constructor : ElementFilter.constructorsIn(ElementUtils.fromTypeMirror(type).getEnclosedElements())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1908 if (constructor.getModifiers().contains(PRIVATE)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1909 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1910 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1911 if (isCopyConstructor(constructor)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1912 return constructor; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1913 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1914 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1915 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1916 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1917 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1918 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1919 static String nodeSpecializationClassName(SpecializationData specialization) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1920 String nodeid = resolveNodeId(specialization.getNode()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1921 String name = ElementUtils.firstLetterUpperCase(nodeid); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1922 name += ElementUtils.firstLetterUpperCase(specialization.getId()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1923 name += "Node"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1924 return name; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1925 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1926 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1927 static String nodePolymorphicClassName(NodeData node) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1928 return ElementUtils.firstLetterUpperCase(resolveNodeId(node)) + "PolymorphicNode"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1929 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1930 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1931 private static String resolveNodeId(NodeData node) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1932 String nodeid = node.getNodeId(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1933 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1934 nodeid = nodeid.substring(0, nodeid.length() - 4); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1935 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1936 return nodeid; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1937 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1938 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1939 private static CodeTree createCastType(TypeData sourceType, TypeData targetType, boolean expect, CodeTree value) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1940 if (targetType == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1941 return value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1942 } else if (sourceType != null && !sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1943 return value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1944 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1945 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1946 if (expect) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1947 return TypeSystemCodeGenerator.expect(targetType, value); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1948 } else { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1949 return TypeSystemCodeGenerator.cast(targetType, value); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1950 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1951 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1952 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1953 private static CodeTree createExpectType(TypeData sourceType, TypeData targetType, CodeTree expression) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1954 return createCastType(sourceType, targetType, true, expression); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1955 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1956 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1957 static CodeTree createDeoptimize(CodeTreeBuilder parent) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1958 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1959 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1960 builder.startStaticCall(ProcessorContext.getInstance().getTruffleTypes().getCompilerDirectives(), "transferToInterpreterAndInvalidate").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1961 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
1962 return builder.build(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1963 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1964 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1965 private TypeMirror getUnexpectedValueException() { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1966 return context.getTruffleTypes().getUnexpectedValueException(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1967 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1968 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1969 interface CodeBlock<T> { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1970 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1971 CodeTree create(CodeTreeBuilder parent, T value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1972 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1973 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1974 |
18766
a720bf2e2f43
Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
1975 } |