Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeBaseFactory.java @ 18754:59bf50cc5a32
Truffle-DSL: implemented @GenerateNodeFactory to enable generation of factories. Factory generation is now disabled by default.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Dec 2014 23:38:25 +0100 |
parents | f6b8787dc113 |
children | 3912400fc33a |
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() { |
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
|
74 CodeTypeElement clazz = GeneratorUtils.createClass(node, modifiers(PRIVATE, ABSTRACT), baseClassName(node), node.getNodeType(), false); |
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); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
324 return builder.getRoot(); |
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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
327 private final void addInternalValueParameters(CodeExecutableElement executableMethod, TemplateMethod method, boolean forceFrame, boolean disableFrame, boolean evaluated) { |
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())) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
510 CodeTree size = builder.create().string("copy.", varName, ".length").getRoot(); |
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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
562 boolean needsFrame = node.isFrameUsedByAnyGuard(context); |
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(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
601 return builder.getRoot(); |
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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
610 boolean needsFrame = node.isFrameUsedByAnyGuard(context); |
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", |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
636 builder.create().startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_REWRITE).string("this").string("newNode").string("message").end().getRoot()); |
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"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
657 builder.tree(builder.create().startNew(nodeSpecializationClassName(node.getUninitializedSpecialization())).string(currentNode).end().getRoot()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
658 builder.tree(builder.create().startNew(polyClassName).string(currentNode).end().getRoot()); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
665 return builder.getRoot(); |
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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
672 final boolean needsFrame = node.isFrameUsedByAnyGuard(context); |
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); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
694 if (current.isGeneric()) { |
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 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
724 return builder.getRoot(); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
755 return builder.getRoot(); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
778 return builder.getRoot(); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
880 int ifCount = startGuardIf(builder, guardsBuilder, 0, elseGuards); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
881 builder.tree(castBuilder.getRoot()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
882 ifCount = startGuardIf(builder, guardsCastBuilder, ifCount, elseGuards); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
886 private static int startGuardIf(CodeTreeBuilder builder, CodeTreeBuilder conditionBuilder, int ifCount, List<GuardExpression> elseGuard) { |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
889 if (!conditionBuilder.isEmpty()) { |
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 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
895 builder.tree(conditionBuilder.getRoot()); |
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) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
934 NodeData childNode = execution.getChild().getNodeData(); |
18752
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 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
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 TypeData sourceType = source.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
939 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
940 if (!sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
941 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
942 } |
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 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
945 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
946 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
947 Parameter shortCircuit = source.getPreviousParameter(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
948 assert shortCircuit != null; |
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 builder.string("!").string(valueName(shortCircuit)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
951 builder.string(" || "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
952 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
953 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
954 String castMethodName; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
955 String castTypeName = null; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
956 List<TypeData> types = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
957 if (types.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
958 castMethodName = TypeSystemCodeGenerator.isImplicitTypeMethodName(targetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
959 if (typedCasts) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
960 castTypeName = implicitTypeName(source); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
961 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
962 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
963 castMethodName = TypeSystemCodeGenerator.isTypeMethodName(targetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
964 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
965 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
966 startCallTypeSystemMethod(builder, childNode.getTypeSystem(), castMethodName); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
967 builder.string(valueName(source)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
968 if (castTypeName != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
969 builder.string(castTypeName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
970 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
971 builder.end().end(); // call |
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 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
974 builder.string(")"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
975 } |
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 builder.end(); // group |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
978 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
979 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
980 } |
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 // TODO merge redundancies with #createTypeGuard |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
983 private CodeTree createCast(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType, boolean typedCasts) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
984 NodeData childNode = execution.getChild().getNodeData(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
985 TypeData sourceType = source.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
986 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
987 if (!sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
988 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
989 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
990 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
991 CodeTree condition = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
992 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
993 Parameter shortCircuit = source.getPreviousParameter(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
994 assert shortCircuit != null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
995 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
996 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
997 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
998 String castMethodName; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
999 String castTypeName = null; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1000 List<TypeData> types = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1001 if (types.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1002 castMethodName = TypeSystemCodeGenerator.asImplicitTypeMethodName(targetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1003 if (typedCasts) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1004 castTypeName = implicitTypeName(source); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1005 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1006 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1007 castMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1008 } |
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 List<CodeTree> args = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1011 args.add(CodeTreeBuilder.singleString(valueName(source))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1012 if (castTypeName != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1013 args.add(CodeTreeBuilder.singleString(castTypeName)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1014 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1015 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1016 CodeTree cast = createCallTypeSystemMethod(parent, childNode, castMethodName, args.toArray(new CodeTree[0])); |
18752
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 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1019 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
|
1020 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1021 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1022 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1023 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1024 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
|
1025 CodeTree condition = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1026 if (execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1027 Parameter shortCircuit = source.getPreviousParameter(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1028 assert shortCircuit != null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1029 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1030 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1031 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1032 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
|
1033 List<TypeData> types = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1034 if (types.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1035 CodeTree castType = createCallTypeSystemMethod(parent, execution.getChild().getNodeData(), TypeSystemCodeGenerator.getImplicitClass(targetType), |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1036 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
|
1037 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
|
1038 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1039 return builder.getRoot(); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1042 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
|
1043 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1044 builder.string(prefix); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1045 if (guard.isNegated()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1046 builder.string("!"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1047 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1048 builder.tree(createTemplateMethodCall(builder, null, source, guard.getResolvedGuard(), null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1049 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1050 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1051 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1052 protected CodeTree createGenericInvoke(CodeTreeBuilder parent, SpecializationData source, SpecializationData current) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1053 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1054 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1055 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
|
1056 emitEncounteredSynthetic(builder, getSpecialization().getNode(), current); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1057 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1058 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
|
1059 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1060 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1061 return encloseThrowsWithFallThrough(parent, current, builder.getRoot()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1062 } |
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 private CodeTree encloseThrowsWithFallThrough(CodeTreeBuilder parent, SpecializationData current, CodeTree tree) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1065 if (current.getExceptions().isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1066 return tree; |
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 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1069 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1070 builder.startTryBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1071 builder.tree(tree); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1072 for (SpecializationThrowsData exception : current.getExceptions()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1073 builder.end().startCatchBlock(exception.getJavaClass(), "rewriteEx"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1074 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
|
1075 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
|
1076 "Thrown " + ElementUtils.getSimpleName(exception.getJavaClass()))); |
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 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1079 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1080 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1081 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1082 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1083 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
|
1084 TypeData type = executable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1085 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1086 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1087 TypeData primaryType = castExecutable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1088 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1089 boolean needsTry = castExecutable.hasUnexpectedValue(context); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1090 boolean returnVoid = type.isVoid(); |
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 List<Parameter> executeParameters = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1093 for (Parameter sourceParameter : executable.getSignatureParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1094 Parameter targetParameter = castExecutable.findParameter(sourceParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1095 if (targetParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1096 executeParameters.add(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1097 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1098 } |
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 // execute names are enforced no cast |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1101 String[] executeParameterNames = new String[executeParameters.size()]; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1102 for (int i = 0; i < executeParameterNames.length; i++) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1103 executeParameterNames[i] = valueName(executeParameters.get(i)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1104 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1105 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1106 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
|
1107 boolean hasUnexpected = executable.hasUnexpectedValue(context); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1108 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1109 CodeTree primaryExecuteCall = createTemplateMethodCall(builder, null, executable, castExecutable, null, executeParameterNames); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1110 if (needsTry) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1111 if (!returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1112 builder.declaration(primaryType.getPrimitiveType(), "value"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1113 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1114 builder.startTryBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1115 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1116 if (returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1117 builder.statement(primaryExecuteCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1118 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1119 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1120 builder.string("value = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1121 builder.tree(primaryExecuteCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1122 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1123 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1124 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1125 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1126 if (returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1127 builder.string("// ignore").newLine(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1128 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1129 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1130 builder.tree(createExpectExecutableType(node, specialization.getNode().getTypeSystem().getGenericTypeData(), hasUnexpected, executable.getType(), |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1131 CodeTreeBuilder.singleString("ex.getResult()"))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1132 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1133 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1134 builder.end(); |
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 if (!returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1137 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1138 builder.tree(createExpectExecutableType(node, castExecutable.getReturnType().getTypeSystemType(), hasUnexpected, executable.getType(), CodeTreeBuilder.singleString("value"))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1139 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1140 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1141 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1142 if (returnVoid) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1143 builder.statement(primaryExecuteCall); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1144 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1145 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1146 builder.tree(createExpectExecutableType(node, castExecutable.getReturnType().getTypeSystemType(), hasUnexpected, executable.getType(), primaryExecuteCall)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1147 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1148 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1149 } |
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 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1152 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1153 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1154 private static CodeTree createExpectExecutableType(NodeData node, TypeData sourceType, boolean hasUnexpected, TypeData exepctedType, CodeTree value) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1155 return createCastType(node.getTypeSystem(), sourceType, exepctedType, hasUnexpected, value); |
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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1158 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
|
1159 Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1160 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1161 for (Parameter targetParameter : targetParameters) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1162 if (!targetParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1163 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1164 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1165 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1166 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
|
1167 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
|
1168 unexpectedParameter); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1169 CodeTree shortCircuitTree = createShortCircuitTree(builder, unexpectedTree, currentSpecialization, targetParameter, unexpectedParameter); |
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 if (shortCircuitTree == executionExpressions) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1172 if (containsNewLine(executionExpressions)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1173 builder.declaration(targetParameter.getType(), valueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1174 builder.tree(shortCircuitTree); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1175 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1176 builder.startStatement().type(targetParameter.getType()).string(" ").tree(shortCircuitTree).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1177 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1178 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1179 builder.tree(shortCircuitTree); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1180 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1181 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1182 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1183 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1184 } |
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 private ExecutableTypeData resolveExecutableType(NodeExecutionData execution, TypeData type) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1187 ExecutableTypeData targetExecutable = execution.getChild().findExecutableType(context, type); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1188 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
|
1189 targetExecutable = execution.getChild().findAnyGenericExecutableType(context); |
18752
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 return targetExecutable; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1194 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
|
1195 if (specialization.isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1196 List<TypeData> possiblePolymorphicTypes = lookupPolymorphicTargetTypes(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1197 if (possiblePolymorphicTypes.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1198 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1199 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1200 boolean elseIf = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1201 for (TypeData possiblePolymoprhicType : possiblePolymorphicTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1202 if (possiblePolymoprhicType.isGeneric()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1203 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1204 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1205 elseIf = builder.startIf(elseIf); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1206 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1207 Parameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1208 TypeData sourceType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1209 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
|
1210 builder.end().startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1211 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1212 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
|
1213 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1214 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1215 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1216 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1217 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1218 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
|
1219 builder.end(); |
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 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1222 } |
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 return createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1225 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1226 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1227 protected static final List<Parameter> getImplicitTypeParameters(SpecializationData model) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1228 List<Parameter> parameter = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1229 for (Parameter param : model.getSignatureParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1230 NodeChildData child = param.getSpecification().getExecution().getChild(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1231 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1232 if (types.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1233 parameter.add(param); |
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 return parameter; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1237 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1238 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1239 private final List<TypeData> lookupPolymorphicTargetTypes(Parameter param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1240 Set<TypeData> possiblePolymorphicTypes = new HashSet<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1241 for (SpecializationData otherSpecialization : specialization.getNode().getSpecializations()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1242 if (!otherSpecialization.isSpecialized()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1243 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1244 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1245 Parameter otherParameter = otherSpecialization.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1246 if (otherParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1247 possiblePolymorphicTypes.add(otherParameter.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1248 } |
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 List<TypeData> types = new ArrayList<>(possiblePolymorphicTypes); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1251 Collections.sort(types); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1252 return types; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1255 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
|
1256 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1257 Parameter sourceParameter = sourceExecutable.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1258 String childExecuteName = createExecuteChildMethodName(param, sourceParameter != null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1259 if (childExecuteName != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1260 builder.string(valueName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1261 builder.string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1262 builder.startCall(childExecuteName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1263 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1264 for (Parameter parameters : sourceExecutable.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1265 if (parameters.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1266 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1267 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1268 builder.string(parameters.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1269 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1270 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1271 if (sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1272 builder.string(valueNameEvaluated(sourceParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1273 } |
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 builder.string(implicitTypeName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1276 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1277 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1278 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1279 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
|
1280 TypeData expectType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1281 if (sourceTypes.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1282 builder.tree(createExecuteChildImplicitExpressions(parent, param, expectType)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1283 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1284 builder.tree(createExecuteChildExpression(parent, execution, expectType, param, unexpectedParameter, 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 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1287 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1288 } |
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 private static String createExecuteChildMethodName(Parameter param, boolean expect) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1291 NodeExecutionData execution = param.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1292 NodeChildData child = execution.getChild(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1293 if (child.getExecuteWith().size() > 0) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1294 return null; |
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<TypeData> sourceTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1297 if (sourceTypes.size() <= 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1298 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1299 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1300 String prefix = expect ? "expect" : "execute"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1301 String suffix = execution.getIndex() > -1 ? String.valueOf(execution.getIndex()) : ""; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1302 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
|
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 private List<CodeExecutableElement> createExecuteChilds(Parameter param, Set<TypeData> expectTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1306 CodeExecutableElement executeMethod = createExecuteChild(param, null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1307 if (executeMethod == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1308 return Collections.emptyList(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1309 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1310 List<CodeExecutableElement> childs = new ArrayList<>(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1311 childs.add(executeMethod); |
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 for (TypeData expectType : expectTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1314 CodeExecutableElement method = createExecuteChild(param, expectType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1315 if (method != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1316 childs.add(method); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1317 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1318 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1319 return childs; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1320 } |
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 private CodeExecutableElement createExecuteChild(Parameter param, TypeData expectType) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1323 String childExecuteName = createExecuteChildMethodName(param, expectType != null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1324 if (childExecuteName == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1325 return null; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1328 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
|
1329 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
|
1330 method.addParameter(new CodeVariableElement(context.getTruffleTypes().getFrame(), "frameValue")); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1331 if (expectType != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1332 method.addParameter(new CodeVariableElement(expectType.getPrimitiveType(), valueNameEvaluated(param))); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1333 } |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1334 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
|
1335 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1336 CodeTreeBuilder builder = method.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1337 builder.declaration(param.getType(), valueName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1338 builder.tree(createExecuteChildImplicitExpressions(builder, param, expectType)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1339 builder.startReturn().string(valueName(param)).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1340 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1341 return method; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1342 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1343 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1344 private CodeTree createExecuteChildImplicitExpressions(CodeTreeBuilder parent, Parameter targetParameter, TypeData expectType) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1345 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1346 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1347 List<TypeData> sourceTypes = node.getTypeSystem().lookupSourceTypes(targetParameter.getTypeSystemType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1348 boolean elseIf = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1349 int index = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1350 for (TypeData sourceType : sourceTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1351 if (index < sourceTypes.size() - 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1352 elseIf = builder.startIf(elseIf); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1353 builder.string(implicitTypeName(targetParameter)).string(" == ").typeLiteral(sourceType.getPrimitiveType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1354 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1355 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1356 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1357 builder.startElseBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1358 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1359 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1360 ExecutableTypeData implictExecutableTypeData = execution.getChild().findExecutableType(context, sourceType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1361 if (implictExecutableTypeData == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1362 /* |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1363 * 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
|
1364 * 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
|
1365 * inserted automatically by #createExecuteExpression. |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1366 */ |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1367 implictExecutableTypeData = execution.getChild().getNodeData().findExecutableType(node.getTypeSystem().getGenericTypeData(), execution.getChild().getExecuteWith().size()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1368 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1369 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1370 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
|
1371 CodeTree execute = createExecuteChildExpression(builder, execution, expectType, targetParameter, null, cast); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1372 builder.statement(execute); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1373 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1374 index++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1375 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1376 return builder.getRoot(); |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1379 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
|
1380 ImplicitCastData cast) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1381 // assignments: targetType <- castTargetType <- castSourceType <- sourceType |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1382 TypeData sourceType = sourceParameterType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1383 TypeData targetType = targetParameter.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1384 TypeData castSourceType = targetType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1385 TypeData castTargetType = targetType; |
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 if (cast != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1388 castSourceType = cast.getSourceType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1389 castTargetType = cast.getTargetType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1390 } |
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 CodeTree expression; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1393 if (sourceType == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1394 ExecutableTypeData targetExecutable = resolveExecutableType(execution, castSourceType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1395 expression = createExecuteChildExpression(parent, execution, targetExecutable, unexpectedParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1396 sourceType = targetExecutable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1397 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1398 expression = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1399 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1400 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1401 // target = expectTargetType(implicitCast(expectCastSourceType(source))) |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1402 TypeSystemData typeSystem = execution.getChild().getNodeData().getTypeSystem(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1403 expression = createExpectType(typeSystem, sourceType, castSourceType, expression); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1404 expression = createImplicitCast(parent, typeSystem, cast, expression); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1405 expression = createExpectType(typeSystem, castTargetType, targetType, expression); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1406 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1407 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1408 builder.string(valueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1409 builder.string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1410 builder.tree(expression); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1411 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1412 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1413 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1414 private static CodeTree createImplicitCast(CodeTreeBuilder parent, TypeSystemData typeSystem, ImplicitCastData cast, CodeTree expression) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1415 if (cast == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1416 return expression; |
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 CodeTreeBuilder builder = parent.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1419 startCallTypeSystemMethod(builder, typeSystem, cast.getMethodName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1420 builder.tree(expression); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1421 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1422 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1423 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1424 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1425 private boolean containsNewLine(CodeTree tree) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1426 if (tree.getCodeKind() == CodeTreeKind.NEW_LINE) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1427 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1428 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1429 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1430 List<CodeTree> enclosing = tree.getEnclosedElements(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1431 if (enclosing != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1432 for (CodeTree codeTree : enclosing) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1433 if (containsNewLine(codeTree)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1434 return true; |
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 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1438 return false; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1441 private boolean hasUnexpected(Parameter sourceParameter, Parameter targetParameter, Parameter unexpectedParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1442 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1443 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1444 if (getSpecialization().isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1445 // check for other polymorphic types |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1446 List<TypeData> polymorphicTargetTypes = lookupPolymorphicTargetTypes(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1447 if (polymorphicTargetTypes.size() > 1) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1448 for (TypeData polymorphicTargetType : polymorphicTargetTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1449 if (hasUnexpectedType(execution, sourceParameter, polymorphicTargetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1450 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1451 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1452 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1453 } |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1456 if (hasUnexpectedType(execution, sourceParameter, targetParameter.getTypeSystemType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1457 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1458 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1459 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1460 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1461 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1462 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
|
1463 List<TypeData> implicitSourceTypes = getSpecialization().getNode().getTypeSystem().lookupSourceTypes(targetType); |
18752
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 for (TypeData implicitSourceType : implicitSourceTypes) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1466 TypeData sourceType; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1467 ExecutableTypeData targetExecutable = resolveExecutableType(execution, implicitSourceType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1468 if (sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1469 sourceType = sourceParameter.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1470 } else { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1471 if (targetExecutable.hasUnexpectedValue(context)) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1472 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1473 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1474 sourceType = targetExecutable.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1475 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1476 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1477 ImplicitCastData cast = getSpecialization().getNode().getTypeSystem().lookupCast(implicitSourceType, targetType); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1478 if (cast != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1479 if (cast.getSourceType().needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1480 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1481 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1482 } |
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 if (sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1485 return true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1486 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1487 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1488 return false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1489 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1490 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1491 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
|
1492 boolean shortCircuit, Parameter unexpectedParameter) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1493 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1494 Parameter sourceParameter = currentExecutable.findParameter(param.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1495 boolean unexpected = hasUnexpected(sourceParameter, param, unexpectedParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1496 if (!unexpected) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1497 return body; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1498 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1499 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1500 if (!shortCircuit) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1501 builder.declaration(param.getType(), valueName(param)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1502 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1503 builder.startTryBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1504 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1505 if (containsNewLine(body)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1506 builder.tree(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1507 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1508 builder.statement(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1509 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1510 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1511 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
|
1512 SpecializationData generic = currentSpecialization.getNode().getGenericSpecialization(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1513 Parameter genericParameter = generic.findParameter(param.getLocalName()); |
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 List<Parameter> genericParameters = generic.getParametersAfter(genericParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1516 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
|
1517 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
|
1518 builder.tree(createReturnOptimizeTypes(builder, currentExecutable, currentSpecialization, param)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1519 } else { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1520 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
|
1521 ElementUtils.getSimpleName(param.getType()))); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1522 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1523 builder.end(); // catch block |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1524 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1525 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1526 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1527 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1528 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
|
1529 SpecializationData polymorphic = node.getPolymorphicSpecialization(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1530 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1531 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
|
1532 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
|
1533 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1534 builder.startReturn(); |
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 CodeTreeBuilder execute = new CodeTreeBuilder(builder); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1537 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
|
1538 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
|
1539 execute.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1540 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1541 TypeData sourceType = polymorphic.getReturnType().getTypeSystemType(); |
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 builder.tree(createExpectExecutableType(node, sourceType, currentExecutable.hasUnexpectedValue(context), currentExecutable.getType(), execute.getRoot())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1544 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1545 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1546 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1547 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1548 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1549 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
|
1550 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1551 if (targetExecution != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1552 builder.tree(createAccessChild(targetExecution, null)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1553 builder.string("."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1554 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1555 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1556 builder.startCall(targetExecutable.getMethodName()); |
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 // TODO this should be merged with #createTemplateMethodCall |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1559 int index = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1560 for (Parameter parameter : targetExecutable.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1561 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1562 if (!parameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1563 builder.string(parameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1564 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1565 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1566 if (index < targetExecution.getChild().getExecuteWith().size()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1567 NodeChildData child = targetExecution.getChild().getExecuteWith().get(index); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1568 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1569 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
|
1570 List<Parameter> specializationParams = getSpecialization().findParameters(spec); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1571 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1572 if (specializationParams.isEmpty()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1573 builder.defaultValue(parameter.getType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1574 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1575 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1576 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1577 Parameter specializationParam = specializationParams.get(0); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1578 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1579 TypeData targetType = parameter.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1580 TypeData sourceType = specializationParam.getTypeSystemType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1581 String localName = specializationParam.getLocalName(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1582 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1583 if (unexpectedParameter != null && unexpectedParameter.getLocalName().equals(specializationParam.getLocalName())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1584 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
|
1585 sourceType = getSpecialization().getNode().getTypeSystem().getGenericTypeData(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1586 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1587 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1588 CodeTree value = CodeTreeBuilder.singleString(localName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1589 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1590 if (sourceType.needsCastTo(targetType)) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1591 value = createCallTypeSystemMethod(builder, getSpecialization().getNode(), TypeSystemCodeGenerator.asTypeMethodName(targetType), value); |
18752
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 builder.tree(value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1594 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1595 builder.defaultValue(parameter.getType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1596 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1597 index++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1598 } |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1601 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1602 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1603 return builder.getRoot(); |
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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1606 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
|
1607 NodeExecutionData execution = parameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1608 if (execution == null || !execution.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1609 return body; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1610 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1611 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1612 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
|
1613 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
|
1614 builder.tree(createShortCircuitValue(builder, currentSpecialization, execution, shortCircuitParam, exceptionParam)); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1615 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
|
1616 builder.startIf().string(shortCircuitParam.getLocalName()).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1617 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1618 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1619 if (containsNewLine(body)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1620 builder.tree(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1621 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1622 builder.statement(body); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1623 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1624 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1625 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1626 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1627 } |
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 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
|
1630 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1631 int shortCircuitIndex = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1632 for (NodeExecutionData otherExectuion : specialization.getNode().getChildExecutions()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1633 if (otherExectuion.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1634 if (otherExectuion == execution) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1635 break; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1636 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1637 shortCircuitIndex++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1638 } |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1641 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
|
1642 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1643 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
|
1644 builder.end(); // statement |
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 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1647 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1648 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
1649 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
|
1650 SpecializationData generic = node.getGenericSpecialization(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1651 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1652 specializeCall.startCall(REWRITE); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1653 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
|
1654 specializeCall.doubleQuote(reason); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1655 specializeCall.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1656 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1657 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
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 builder.startReturn(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1660 builder.tree(createExpectExecutableType(node, generic.getReturnType().getTypeSystemType(), hasUnexpected, returnType, specializeCall.getRoot())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1661 builder.end(); |
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 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1664 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1665 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1666 static String valueNameEvaluated(Parameter targetParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1667 return valueName(targetParameter) + "Evaluated"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1668 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1669 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1670 static String implicitTypeName(Parameter param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1671 return param.getLocalName() + "ImplicitType"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1672 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1673 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1674 static String polymorphicTypeName(NodeExecutionData param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1675 return param.getName() + "PolymorphicType"; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1678 static String valueName(Parameter param) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1679 return param.getLocalName(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1680 } |
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 private static CodeTree createAccessChild(NodeExecutionData targetExecution, String thisReference) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1683 String reference = thisReference; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1684 if (reference == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1685 reference = "this"; |
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 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1688 Element accessElement = targetExecution.getChild().getAccessElement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1689 if (accessElement == null || accessElement.getKind() == ElementKind.METHOD) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1690 builder.string(reference).string(".").string(targetExecution.getChild().getName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1691 } else if (accessElement.getKind() == ElementKind.FIELD) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1692 builder.string(reference).string(".").string(accessElement.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1693 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1694 throw new AssertionError(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1695 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1696 if (targetExecution.isIndexed()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1697 builder.string("[" + targetExecution.getIndex() + "]"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1698 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1699 return builder.getRoot(); |
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 private static String castValueName(Parameter parameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1703 return valueName(parameter) + "Cast"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1704 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1705 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1706 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
|
1707 Map<String, String> customNames) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1708 if (forceFrame && !disableFrame && specialization.getSpecification().findParameterSpec("frame") != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1709 builder.string("frameValue"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1710 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1711 for (Parameter parameter : specialization.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1712 ParameterSpec spec = parameter.getSpecification(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1713 if ((disableFrame || forceFrame) && spec.getName().equals("frame")) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1714 continue; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1717 if (parameter.getSpecification().isLocal()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1718 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1719 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1720 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1721 Parameter sourceParameter = source.findParameter(parameter.getLocalName()); |
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 if (customNames != null && customNames.containsKey(parameter.getLocalName())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1724 builder.string(customNames.get(parameter.getLocalName())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1725 } else if (unexpectedValueName != null && parameter.getLocalName().equals(unexpectedValueName)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1726 builder.cast(parameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1727 } else if (sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1728 builder.string(valueName(sourceParameter, parameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1729 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1730 builder.string(valueName(parameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1731 } |
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 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1734 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1735 private static String valueName(Parameter sourceParameter, Parameter targetParameter) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1736 if (!sourceParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1737 return valueName(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1738 } else if (sourceParameter.getTypeSystemType() != null && targetParameter.getTypeSystemType() != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1739 if (sourceParameter.getTypeSystemType().needsCastTo(targetParameter.getTypeSystemType())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1740 return castValueName(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1741 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1742 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1743 return valueName(targetParameter); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1744 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1745 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1746 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
|
1747 String... customSignatureValueNames) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1748 CodeTreeBuilder builder = parent.create(); |
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 boolean castedValues = sourceMethod != targetMethod; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1751 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1752 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1753 ExecutableElement method = targetMethod.getMethod(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1754 if (method == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1755 throw new UnsupportedOperationException(); |
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 TypeElement targetClass = ElementUtils.findNearestEnclosingType(method.getEnclosingElement()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1758 NodeData node = (NodeData) targetMethod.getTemplate(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1759 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1760 if (target == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1761 boolean accessible = targetMethod.canBeAccessedByInstanceOf(node.getNodeType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1762 if (accessible) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1763 if (builder.findMethod().getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1764 if (method.getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1765 builder.type(targetClass.asType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1766 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1767 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1768 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1769 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1770 if (targetMethod instanceof ExecutableTypeData) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1771 builder.string("this"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1772 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1773 builder.string("super"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1774 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1775 } |
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 if (method.getModifiers().contains(STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1778 builder.type(targetClass.asType()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1779 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1780 Parameter firstParameter = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1781 for (Parameter searchParameter : targetMethod.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1782 if (searchParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1783 firstParameter = searchParameter; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1784 break; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1785 } |
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 if (firstParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1788 throw new AssertionError(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1789 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1790 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1791 Parameter sourceParameter = sourceMethod.findParameter(firstParameter.getLocalName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1792 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1793 if (castedValues && sourceParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1794 builder.string(valueName(sourceParameter, firstParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1795 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1796 builder.string(valueName(firstParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1797 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1798 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1799 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1800 builder.string("."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1801 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1802 builder.tree(target); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1803 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1804 builder.startCall(method.getSimpleName().toString()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1805 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1806 int signatureIndex = 0; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1807 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1808 for (Parameter targetParameter : targetMethod.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1809 Parameter valueParameter = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1810 if (sourceMethod != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1811 valueParameter = sourceMethod.findParameter(targetParameter.getLocalName()); |
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 if (valueParameter == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1814 valueParameter = targetParameter; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1815 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1816 TypeMirror targetType = targetParameter.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1817 TypeMirror valueType = null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1818 if (valueParameter != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1819 valueType = valueParameter.getType(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1820 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1821 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1822 if (signatureIndex < customSignatureValueNames.length && targetParameter.getSpecification().isSignature()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1823 builder.string(customSignatureValueNames[signatureIndex]); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1824 signatureIndex++; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1825 } else if (targetParameter.getSpecification().isLocal()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1826 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1827 if (builder.findMethod().getModifiers().contains(Modifier.STATIC)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1828 builder.string(THIS_NODE_LOCAL_VAR_NAME).string("."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1829 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1830 builder.string("this."); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1831 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1832 builder.string(targetParameter.getSpecification().getName()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1833 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1834 } else if (unexpectedValueName != null && targetParameter.getLocalName().equals(unexpectedValueName)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1835 builder.cast(targetParameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1836 } else if (!ElementUtils.needsCastTo(valueType, targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1837 builder.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1838 builder.string(valueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1839 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1840 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1841 builder.string(castValueName(targetParameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1842 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1843 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1844 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1845 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1846 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1847 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1848 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1849 |
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
|
1850 public static String baseClassName(NodeData node) { |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1851 String nodeid = resolveNodeId(node); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1852 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
|
1853 name += "NodeGen"; |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1854 return name; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1855 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1856 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1857 static CodeTree createCallTypeSystemMethod(CodeTreeBuilder parent, NodeData node, String methodName, CodeTree... args) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1858 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1859 startCallTypeSystemMethod(builder, node.getTypeSystem(), methodName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1860 for (CodeTree arg : args) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1861 builder.tree(arg); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1862 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1863 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1864 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1865 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1866 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1867 private static void startCallTypeSystemMethod(CodeTreeBuilder body, TypeSystemData typeSystem, String methodName) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1868 GeneratedTypeMirror typeMirror = new GeneratedTypeMirror(ElementUtils.getPackageName(typeSystem.getTemplateType()), TypeSystemCodeGenerator.typeName(typeSystem)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1869 body.startGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1870 body.staticReference(typeMirror, TypeSystemCodeGenerator.singletonName(typeSystem)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1871 body.string(".").startCall(methodName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1872 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1873 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1874 /** |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1875 * <pre> |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1876 * variant1 $condition != null |
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
|
1877 * |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1878 * $type $name = defaultValue($type); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1879 * if ($condition) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1880 * $name = $value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1881 * } |
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
|
1882 * |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1883 * variant2 $condition != null |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1884 * $type $name = $value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1885 * </pre> |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1886 * |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1887 * . |
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 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
|
1890 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1891 if (condition == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1892 builder.declaration(type, name, value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1893 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1894 builder.declaration(type, name, new CodeTreeBuilder(parent).defaultValue(type).getRoot()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1895 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1896 builder.startIf().tree(condition).end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1897 builder.startBlock(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1898 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1899 builder.string(name); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1900 builder.string(" = "); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1901 builder.tree(value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1902 builder.end(); // statement |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1903 builder.end(); // block |
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 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1906 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1907 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1908 void emitEncounteredSynthetic(CodeTreeBuilder builder, NodeData model, TemplateMethod current) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1909 CodeTreeBuilder nodes = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1910 CodeTreeBuilder arguments = builder.create(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1911 nodes.startCommaGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1912 arguments.startCommaGroup(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1913 boolean empty = true; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1914 for (Parameter parameter : current.getParameters()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1915 NodeExecutionData executionData = parameter.getSpecification().getExecution(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1916 if (executionData != null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1917 if (executionData.isShortCircuit()) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1918 nodes.nullLiteral(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1919 arguments.string(valueName(parameter.getPreviousParameter())); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1920 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1921 nodes.tree(createAccessChild(executionData, "rootNode")); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1922 arguments.string(valueName(parameter)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1923 empty = false; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1924 } |
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 nodes.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1927 arguments.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1928 builder.startStatement().startStaticCall(context.getTruffleTypes().getCompilerDirectives(), "transferToInterpreter").end().end(); |
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 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
|
1931 builder.startThrow().startNew(context.getType(UnsupportedSpecializationException.class)); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1932 builder.string("rootNode"); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1933 builder.startNewArray(context.getTruffleTypes().getNodeArray(), null); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1934 builder.tree(nodes.getRoot()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1935 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1936 if (!empty) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1937 builder.tree(arguments.getRoot()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1938 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1939 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1940 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1941 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1942 private static ExecutableElement findCopyConstructor(TypeMirror type) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1943 for (ExecutableElement constructor : ElementFilter.constructorsIn(ElementUtils.fromTypeMirror(type).getEnclosedElements())) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1944 if (constructor.getModifiers().contains(PRIVATE)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1945 continue; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1946 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1947 if (isCopyConstructor(constructor)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1948 return constructor; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1949 } |
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 return null; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1953 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1954 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1955 static String nodeSpecializationClassName(SpecializationData specialization) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1956 String nodeid = resolveNodeId(specialization.getNode()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1957 String name = ElementUtils.firstLetterUpperCase(nodeid); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1958 name += ElementUtils.firstLetterUpperCase(specialization.getId()); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1959 name += "Node"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1960 return name; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1961 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1962 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1963 static String nodePolymorphicClassName(NodeData node) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1964 return ElementUtils.firstLetterUpperCase(resolveNodeId(node)) + "PolymorphicNode"; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1965 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1966 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1967 private static String resolveNodeId(NodeData node) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1968 String nodeid = node.getNodeId(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1969 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1970 nodeid = nodeid.substring(0, nodeid.length() - 4); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1971 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1972 return nodeid; |
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 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1975 private static CodeTree createCastType(TypeSystemData typeSystem, TypeData sourceType, TypeData targetType, boolean expect, CodeTree value) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1976 if (targetType == null) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1977 return value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1978 } else if (sourceType != null && !sourceType.needsCastTo(targetType)) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1979 return value; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1980 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1981 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1982 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1983 String targetMethodName; |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1984 if (expect) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1985 targetMethodName = TypeSystemCodeGenerator.expectTypeMethodName(targetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1986 } else { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1987 targetMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1988 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1989 startCallTypeSystemMethod(builder, typeSystem, targetMethodName); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1990 builder.tree(value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1991 builder.end().end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1992 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1993 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1994 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1995 private static CodeTree createExpectType(TypeSystemData typeSystem, TypeData sourceType, TypeData targetType, CodeTree expression) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1996 return createCastType(typeSystem, sourceType, targetType, true, expression); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1997 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1998 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1999 static CodeTree createDeoptimize(CodeTreeBuilder parent) { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2000 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2001 builder.startStatement(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2002 builder.startStaticCall(ProcessorContext.getInstance().getTruffleTypes().getCompilerDirectives(), "transferToInterpreterAndInvalidate").end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2003 builder.end(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2004 return builder.getRoot(); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2005 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2006 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2007 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
|
2008 return context.getTruffleTypes().getUnexpectedValueException(); |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2009 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2010 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2011 interface CodeBlock<T> { |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2012 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2013 CodeTree create(CodeTreeBuilder parent, T value); |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2014 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2015 } |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2016 |
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2017 } |