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