Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 9796:d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 23 May 2013 01:57:46 +0200 |
parents | c15fd053efb6 |
children | 476cbd115289 |
rev | line source |
---|---|
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.codegen.processor.node; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.codegen.processor.Utils.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static javax.lang.model.element.Modifier.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import java.util.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import javax.lang.model.element.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import javax.lang.model.type.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import javax.lang.model.util.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
34 import com.oracle.truffle.api.codegen.*; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.codegen.processor.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.codegen.processor.ast.*; |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
37 import com.oracle.truffle.codegen.processor.node.NodeChildData.Cardinality; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
38 import com.oracle.truffle.codegen.processor.node.NodeChildData.ExecutionKind; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 import com.oracle.truffle.codegen.processor.template.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 import com.oracle.truffle.codegen.processor.typesystem.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 public class NodeCodeGenerator extends CompilationUnitFactory<NodeData> { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 private static final String THIS_NODE_LOCAL_VAR_NAME = "thisNode"; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
46 private static final String EXECUTE_GENERIC_NAME = "executeGeneric_"; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
47 private static final String EXECUTE_SPECIALIZE_NAME = "executeAndSpecialize_"; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
48 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 public NodeCodeGenerator(ProcessorContext context) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 private TypeMirror getUnexpectedValueException() { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 return getContext().getTruffleTypes().getUnexpectedValueException(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 private static String factoryClassName(NodeData node) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
58 return node.getNodeId() + "Factory"; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
61 private static String nodeSpecializationClassName(SpecializationData specialization) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
62 String nodeid = specialization.getNode().getNodeId(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
63 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
64 nodeid = nodeid.substring(0, nodeid.length() - 4); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
65 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
66 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
67 String name = Utils.firstLetterUpperCase(nodeid); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
68 name += Utils.firstLetterUpperCase(specialization.getId()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
69 name += "Node"; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 return name; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
73 private static String valueNameEvaluated(ActualParameter targetParameter) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
74 return valueName(targetParameter) + "Evaluated"; |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
75 } |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
76 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
77 private static String valueName(ActualParameter param) { |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
78 return param.getLocalName(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
81 private static String castValueName(ActualParameter parameter) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
82 return valueName(parameter) + "Cast"; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
83 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
84 |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
85 private void addInternalValueParameters(CodeExecutableElement method, TemplateMethod specialization, boolean forceFrame) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
86 if (forceFrame && specialization.getSpecification().findParameterSpec("frame") != null) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
87 method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frameValue")); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 for (ActualParameter parameter : specialization.getParameters()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 ParameterSpec spec = parameter.getSpecification(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 if (forceFrame && spec.getName().equals("frame")) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 } |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
94 if (spec.isLocal()) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
95 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
96 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
97 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
98 method.addParameter(new CodeVariableElement(parameter.getType(), valueName(parameter))); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
102 private void addInternalValueParameterNames(CodeTreeBuilder builder, TemplateMethod source, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame, boolean includeImplicit) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
103 if (forceFrame && specialization.getSpecification().findParameterSpec("frame") != null) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
104 builder.string("frameValue"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 for (ActualParameter parameter : specialization.getParameters()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 ParameterSpec spec = parameter.getSpecification(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 if (forceFrame && spec.getName().equals("frame")) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
112 if (!includeImplicit && (parameter.isImplicit())) { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
113 continue; |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
114 } |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
115 if (parameter.getSpecification().isLocal()) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
116 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
117 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
118 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
119 ActualParameter sourceParameter = source.findParameter(parameter.getLocalName()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
120 |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
121 if (unexpectedValueName != null && parameter.getLocalName().equals(unexpectedValueName)) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
122 builder.cast(parameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
123 } else if (sourceParameter != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
124 builder.string(valueName(sourceParameter, parameter)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 } else { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
126 builder.string(valueName(parameter)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
131 private String valueName(ActualParameter sourceParameter, ActualParameter targetParameter) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
132 if (sourceParameter != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
133 if (!sourceParameter.getSpecification().isSignature()) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
134 return valueName(targetParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
135 } else if (sourceParameter.getTypeSystemType() != null && targetParameter.getTypeSystemType() != null) { |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
136 if (sourceParameter.getTypeSystemType().needsCastTo(getContext(), targetParameter.getTypeSystemType())) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
137 return castValueName(targetParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
138 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
139 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
140 return valueName(targetParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
141 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
142 return valueName(targetParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
143 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
144 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
145 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
146 private CodeTree createTemplateMethodCall(CodeTreeBuilder parent, CodeTree target, TemplateMethod sourceMethod, TemplateMethod targetMethod, String unexpectedValueName) { |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
147 CodeTreeBuilder builder = parent.create(); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
148 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
149 boolean castedValues = sourceMethod != targetMethod; |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
150 |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
151 builder.startGroup(); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
152 ExecutableElement method = targetMethod.getMethod(); |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
153 if (method == null) { |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
154 throw new IllegalStateException("Cannot call synthetic operation methods."); |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
155 } |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
156 TypeElement targetClass = Utils.findNearestEnclosingType(method.getEnclosingElement()); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
157 NodeData node = (NodeData) targetMethod.getTemplate(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
158 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
159 if (target == null) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
160 boolean accessible = targetMethod.canBeAccessedByInstanceOf(getContext(), node.getNodeType()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
161 if (accessible) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
162 if (builder.findMethod().getModifiers().contains(STATIC)) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
163 if (method.getModifiers().contains(STATIC)) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
164 builder.type(targetClass.asType()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
165 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
166 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
167 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
168 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
169 if (targetMethod instanceof ExecutableTypeData) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
170 builder.string("this"); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
171 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
172 builder.string("super"); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
173 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
174 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
175 } else { |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
176 if (method.getModifiers().contains(STATIC)) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
177 builder.type(targetClass.asType()); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
178 } else { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
179 ActualParameter parameter = null; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
180 for (ActualParameter searchParameter : targetMethod.getParameters()) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
181 if (searchParameter.getSpecification().isSignature()) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
182 parameter = searchParameter; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
183 break; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
184 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
185 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
186 ActualParameter sourceParameter = sourceMethod.findParameter(parameter.getLocalName()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
187 assert parameter != null; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
188 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
189 if (castedValues && sourceParameter != null) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
190 builder.string(valueName(sourceParameter, parameter)); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
191 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
192 builder.string(valueName(parameter)); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
193 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
194 } |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
195 } |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
196 builder.string("."); |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
197 } else { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
198 builder.tree(target); |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
199 } |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
200 builder.startCall(method.getSimpleName().toString()); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
201 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
202 for (ActualParameter targetParameter : targetMethod.getParameters()) { |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
203 ActualParameter valueParameter = sourceMethod.findParameter(targetParameter.getLocalName()); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
204 if (valueParameter == null) { |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
205 valueParameter = targetParameter; |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
206 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
207 TypeData targetType = targetParameter.getTypeSystemType(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
208 |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
209 if (targetParameter.isImplicit() || valueParameter.isImplicit()) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
210 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
211 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
212 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
213 TypeData valueType = null; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
214 if (valueParameter != null) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
215 valueType = valueParameter.getTypeSystemType(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
216 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
217 |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
218 if (targetParameter.getSpecification().isLocal()) { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
219 builder.startGroup(); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
220 if (builder.findMethod().getModifiers().contains(Modifier.STATIC)) { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
221 builder.string(THIS_NODE_LOCAL_VAR_NAME).string("."); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
222 } else { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
223 builder.string("this."); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
224 } |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
225 builder.string(targetParameter.getSpecification().getName()); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
226 builder.end(); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
227 } else if (unexpectedValueName != null && targetParameter.getLocalName().equals(unexpectedValueName)) { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
228 builder.string("ex.getResult()"); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
229 } else if (targetType == null || targetType.isGeneric() || (valueType != null && valueType.equalsType(targetType))) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
230 builder.startGroup(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
231 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
232 if (valueType != null && sourceMethod.getMethodName().equals(targetMethod.getMethodName()) && !valueType.isGeneric() && targetType.isGeneric()) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
233 builder.string("("); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
234 builder.type(targetType.getPrimitiveType()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
235 builder.string(") "); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
236 } |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
237 builder.string(valueName(targetParameter)); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
238 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
239 } else { |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
240 builder.string(castValueName(targetParameter)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
241 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
242 } |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
243 |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
244 builder.end().end(); |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
245 |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
246 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
247 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
248 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
249 private static String baseClassName(NodeData node) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
250 String nodeid = node.getNodeId(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
251 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
252 nodeid = nodeid.substring(0, nodeid.length() - 4); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
253 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
254 String name = Utils.firstLetterUpperCase(nodeid); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
255 name += "BaseNode"; |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
256 return name; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
257 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
259 private static CodeTree createCallTypeSystemMethod(ProcessorContext context, CodeTreeBuilder parent, NodeData node, String methodName, CodeTree value) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
260 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
261 startCallTypeSystemMethod(context, builder, node, methodName); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
262 builder.tree(value); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
263 builder.end().end(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
264 return builder.getRoot(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
265 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
266 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7502
diff
changeset
|
267 private static void startCallTypeSystemMethod(ProcessorContext context, CodeTreeBuilder body, NodeData node, String methodName) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
268 VariableElement singleton = TypeSystemCodeGenerator.findSingleton(context, node.getTypeSystem()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
269 assert singleton != null; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
270 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
271 body.startGroup(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
272 body.staticReference(singleton.getEnclosingElement().asType(), singleton.getSimpleName().toString()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
273 body.string(".").startCall(methodName); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
274 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
275 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
276 private CodeTree createGuardAndCast(CodeTreeBuilder parent, String conditionPrefix, SpecializationData sourceSpecialization, SpecializationData targetSpecialization, boolean castValues, |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
277 CodeTree guardedStatements, CodeTree elseStatements, boolean emitAssumptions) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
278 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
279 NodeData node = targetSpecialization.getNode(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
280 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
281 CodeTree implicitGuards = createImplicitGuards(parent, conditionPrefix, sourceSpecialization, targetSpecialization, emitAssumptions); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
282 CodeTree explicitGuards = createExplicitGuards(parent, implicitGuards == null ? conditionPrefix : null, sourceSpecialization, targetSpecialization); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
283 |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
284 Set<String> valuesNeedsCast; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
285 if (castValues) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
286 // cast all |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
287 valuesNeedsCast = null; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
288 } else { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
289 // find out which values needs a cast |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
290 valuesNeedsCast = new HashSet<>(); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
291 for (GuardData guard : targetSpecialization.getGuards()) { |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
292 for (ActualParameter targetParameter : guard.getParameters()) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
293 NodeChildData field = node.findChild(targetParameter.getSpecification().getName()); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
294 if (field == null) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
295 continue; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
296 } |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
297 TypeData targetType = targetParameter.getTypeSystemType(); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
298 ActualParameter sourceParameter = sourceSpecialization.findParameter(targetParameter.getLocalName()); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
299 if (sourceParameter == null) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
300 sourceParameter = targetParameter; |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
301 } |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
302 TypeData sourceType = sourceParameter.getTypeSystemType(); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
303 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
304 if (sourceType.needsCastTo(getContext(), targetType)) { |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
305 valuesNeedsCast.add(targetParameter.getLocalName()); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
306 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
307 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
308 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
309 } |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
310 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
311 int ifCount = 0; |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
312 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
313 if (implicitGuards != null) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
314 builder.startIf(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
315 builder.tree(implicitGuards); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
316 builder.end(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
317 builder.startBlock(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
318 ifCount++; |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
319 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
320 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
321 builder.tree(createCasts(parent, valuesNeedsCast, sourceSpecialization, targetSpecialization)); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
322 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
323 if (explicitGuards != null) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
324 builder.startIf(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
325 builder.tree(explicitGuards); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
326 builder.end(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
327 builder.startBlock(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
328 ifCount++; |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
329 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
330 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
331 if (implicitGuards == null && explicitGuards == null && conditionPrefix != null && !conditionPrefix.isEmpty()) { |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
332 builder.startIf(); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
333 builder.string(conditionPrefix); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
334 builder.end().startBlock(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
335 ifCount++; |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
336 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
337 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
338 builder.tree(guardedStatements); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
339 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
340 builder.end(ifCount); |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
341 if (elseStatements != null && ifCount > 0) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
342 builder.tree(elseStatements); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
343 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
344 return builder.getRoot(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
345 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
346 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
347 private CodeTree createExplicitGuards(CodeTreeBuilder parent, String conditionPrefix, TemplateMethod valueSpecialization, SpecializationData guardedSpecialization) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
348 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
349 String andOperator = conditionPrefix != null ? conditionPrefix + " && " : ""; |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
350 if (guardedSpecialization.getGuards().size() > 0) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
351 // Explicitly specified guards |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8361
diff
changeset
|
352 for (GuardData guard : guardedSpecialization.getGuards()) { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8361
diff
changeset
|
353 builder.string(andOperator); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
354 builder.tree(createTemplateMethodCall(parent, null, valueSpecialization, guard, null)); |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8361
diff
changeset
|
355 andOperator = " && "; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
356 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
357 } |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
358 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
359 return builder.isEmpty() ? null : builder.getRoot(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
360 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
361 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
362 private CodeTree createCasts(CodeTreeBuilder parent, Set<String> castWhiteList, TemplateMethod valueSpecialization, SpecializationData guardedSpecialization) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
363 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
364 // Implict guards based on method signature |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
365 for (ActualParameter guardedParam : guardedSpecialization.getParameters()) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
366 NodeChildData field = guardedSpecialization.getNode().findChild(guardedParam.getSpecification().getName()); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
367 if (field == null) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
368 continue; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
369 } |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
370 ActualParameter valueParam = valueSpecialization.findParameter(guardedParam.getLocalName()); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
371 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
372 if (valueParam == null) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
373 /* |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
374 * If used inside a function execute method. The value param may not exist. In that |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
375 * case it assumes that the value is already converted. |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
376 */ |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
377 valueParam = guardedParam; |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
378 } |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
379 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
380 if (castWhiteList != null && !castWhiteList.contains(guardedParam.getLocalName())) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
381 continue; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
382 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
383 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
384 CodeTree cast = createCast(parent, field, valueParam, guardedParam); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
385 if (cast == null) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
386 continue; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
387 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
388 builder.tree(cast); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
389 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
390 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
391 return builder.getRoot(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
392 } |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
393 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
394 private CodeTree createImplicitGuards(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization, boolean emitAssumptions) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
395 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
396 // Implict guards based on method signature |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
397 String andOperator = conditionPrefix != null ? conditionPrefix + " && " : ""; |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
398 |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
399 if (emitAssumptions) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
400 for (String assumption : guardedSpecialization.getAssumptions()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
401 builder.string(andOperator); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
402 builder.string("this"); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
403 builder.string(".").string(assumption).string(".isValid()"); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
404 andOperator = " && "; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
405 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
406 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
407 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
408 for (ActualParameter guardedParam : guardedSpecialization.getParameters()) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
409 NodeChildData field = guardedSpecialization.getNode().findChild(guardedParam.getSpecification().getName()); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
410 if (field == null) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
411 continue; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
412 } |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
413 ActualParameter valueParam = valueSpecialization.findParameter(guardedParam.getLocalName()); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
414 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
415 if (valueParam == null) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
416 /* |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
417 * If used inside a function execute method. The value param may not exist. In that |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
418 * case it assumes that the value is already converted. |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
419 */ |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
420 valueParam = guardedParam; |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
421 } |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
422 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
423 CodeTree implicitGuard = createImplicitGuard(builder, field, valueParam, guardedParam); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
424 if (implicitGuard == null) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
425 continue; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
426 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
427 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
428 builder.string(andOperator); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
429 builder.tree(implicitGuard); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
430 andOperator = " && "; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
431 } |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
432 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
433 return builder.isEmpty() ? null : builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
434 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
435 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
436 private CodeTree createImplicitGuard(CodeTreeBuilder parent, NodeChildData field, ActualParameter source, ActualParameter target) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
437 NodeData node = field.getNodeData(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
438 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
439 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
440 TypeData targetType = target.getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
441 TypeData sourceType = source.getTypeSystemType(); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
442 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
443 if (!sourceType.needsCastTo(getContext(), targetType)) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
444 return null; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
445 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
446 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
447 builder.startGroup(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
448 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
449 if (field.isShortCircuit()) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
450 ActualParameter shortCircuit = target.getPreviousParameter(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
451 assert shortCircuit != null; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
452 builder.string("("); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
453 builder.string("!").string(valueName(shortCircuit)); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
454 builder.string(" || "); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
455 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
456 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
457 startCallTypeSystemMethod(getContext(), builder, node, TypeSystemCodeGenerator.isTypeMethodName(target.getTypeSystemType())); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
458 builder.string(valueName(source)); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
459 builder.end().end(); // call |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
460 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
461 if (field.isShortCircuit()) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
462 builder.string(")"); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
463 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
464 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
465 builder.end(); // group |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
466 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
467 return builder.getRoot(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
468 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
469 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
470 private CodeTree createCast(CodeTreeBuilder parent, NodeChildData field, ActualParameter source, ActualParameter target) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
471 NodeData node = field.getNodeData(); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
472 TypeData sourceType = source.getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
473 TypeData targetType = target.getTypeSystemType(); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
474 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
475 if (!sourceType.needsCastTo(getContext(), targetType)) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
476 return null; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
477 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
478 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
479 CodeTree condition = null; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
480 if (field.isShortCircuit()) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
481 ActualParameter shortCircuit = target.getPreviousParameter(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
482 assert shortCircuit != null; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
483 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
484 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
485 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
486 CodeTree value = createCallTypeSystemMethod(context, parent, node, TypeSystemCodeGenerator.asTypeMethodName(targetType), CodeTreeBuilder.singleString(valueName(target))); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
487 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
488 return createLazyAssignment(parent, castValueName(target), target.getType(), condition, value); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
489 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
490 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
491 /** |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
492 * <pre> |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
493 * variant1 $condition != null |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
494 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
495 * $type $name = defaultValue($type); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
496 * if ($condition) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
497 * $name = $value; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
498 * } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
499 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
500 * variant2 $condition != null |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
501 * $type $name = $value; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
502 * </pre> |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
503 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
504 * . |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
505 */ |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
506 private static CodeTree createLazyAssignment(CodeTreeBuilder parent, String name, TypeMirror type, CodeTree condition, CodeTree value) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
507 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
508 if (condition == null) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
509 builder.declaration(type, name, value); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
510 } else { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
511 builder.declaration(type, name, new CodeTreeBuilder(parent).defaultValue(type).getRoot()); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
512 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
513 builder.startIf().tree(condition).end(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
514 builder.startBlock(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
515 builder.startStatement(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
516 builder.string(name); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
517 builder.string(" = "); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
518 builder.tree(value); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
519 builder.end(); // statement |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
520 builder.end(); // block |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
521 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
522 return builder.getRoot(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
523 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
524 |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
525 private void emitEncounteredSynthetic(CodeTreeBuilder builder) { |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
526 builder.startThrow().startNew(getContext().getType(UnsupportedOperationException.class)).end().end(); |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
527 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
528 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
529 private static List<ExecutableElement> findUserConstructors(TypeMirror nodeType) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
530 List<ExecutableElement> constructors = new ArrayList<>(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
531 for (ExecutableElement constructor : ElementFilter.constructorsIn(Utils.fromTypeMirror(nodeType).getEnclosedElements())) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
532 if (constructor.getModifiers().contains(PRIVATE)) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
533 continue; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
534 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
535 if (isCopyConstructor(constructor)) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
536 continue; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
537 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
538 constructors.add(constructor); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
539 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
540 |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
541 if (constructors.isEmpty()) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
542 constructors.add(new CodeExecutableElement(null, Utils.getSimpleName(nodeType))); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
543 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
544 |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
545 return constructors; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
546 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
547 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
548 private static ExecutableElement findCopyConstructor(TypeMirror type) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
549 for (ExecutableElement constructor : ElementFilter.constructorsIn(Utils.fromTypeMirror(type).getEnclosedElements())) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
550 if (constructor.getModifiers().contains(PRIVATE)) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
551 continue; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
552 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
553 if (isCopyConstructor(constructor)) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
554 return constructor; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
555 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
556 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
557 |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
558 return null; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
559 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
560 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
561 private static boolean isCopyConstructor(ExecutableElement element) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
562 if (element.getParameters().size() != 1) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
563 return false; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
564 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
565 VariableElement var = element.getParameters().get(0); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
566 TypeElement type = Utils.findNearestEnclosingType(var); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
567 |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
568 if (!Utils.typeEquals(var.asType(), type.asType())) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
569 return false; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
570 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
571 return true; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
572 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
573 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
574 private static CodeTree createReturnNewSpecialization(CodeTreeBuilder parent, SpecializationData specialization, String thisLocalVariableName, boolean hasCopyConstructor) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
575 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
576 builder.startReturn().startNew(nodeSpecializationClassName(specialization)); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
577 if (hasCopyConstructor) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
578 builder.string(thisLocalVariableName); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
579 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
580 builder.end().end(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
581 return builder.getRoot(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
582 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
583 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
584 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
585 protected void createChildren(NodeData node) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
586 Map<NodeData, List<TypeElement>> childTypes = new LinkedHashMap<>(); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
587 if (node.getDeclaredNodes() != null && !node.getDeclaredNodes().isEmpty()) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
588 for (NodeData nodeChild : node.getDeclaredNodes()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
589 NodeCodeGenerator generator = new NodeCodeGenerator(getContext()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
590 childTypes.put(nodeChild, generator.process(null, nodeChild).getEnclosedElements()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
591 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
592 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
593 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
594 if (node.needsFactory() || node.getNodeDeclaringChildren().size() > 0) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
595 add(new NodeFactoryFactory(context, childTypes), node); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
596 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
597 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
598 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
599 private class NodeBaseFactory extends ClassElementFactory<NodeData> { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
600 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
601 public NodeBaseFactory(ProcessorContext context) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
602 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
603 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
604 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
605 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
606 protected CodeTypeElement create(NodeData node) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
607 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, ABSTRACT, STATIC), baseClassName(node), node.getNodeType(), false); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
608 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
609 for (NodeChildData child : node.getChildren()) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
610 clazz.add(createChildField(child)); |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
611 |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
612 if (child.getAccessElement() != null && child.getAccessElement().getModifiers().contains(Modifier.ABSTRACT)) { |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
613 ExecutableElement getter = (ExecutableElement) child.getAccessElement(); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
614 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), getter); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
615 method.getModifiers().remove(Modifier.ABSTRACT); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
616 method.createBuilder().startReturn().string("this.").string(child.getName()).end(); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
617 clazz.add(method); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
618 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
619 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
620 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
621 for (String assumption : node.getAssumptions()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
622 clazz.add(createAssumptionField(assumption)); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
623 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
624 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
625 createConstructors(node, clazz); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
626 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
627 if (node.getExtensionElements() != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
628 clazz.getEnclosedElements().addAll(node.getExtensionElements()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
629 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
630 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
631 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
632 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
633 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
634 @Override |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
635 protected void createChildren(NodeData node) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
636 CodeTypeElement clazz = getElement(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
637 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
638 if (node.needsRewrites(context)) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
639 clazz.add(createGenericExecute(node, EXECUTE_SPECIALIZE_NAME, true)); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
640 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
641 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
642 if (node.getGenericSpecialization() != null) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
643 clazz.add(createGenericExecute(node, EXECUTE_GENERIC_NAME, false)); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
644 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
645 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
646 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
647 private void createConstructors(NodeData node, CodeTypeElement clazz) { |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
648 List<ExecutableElement> constructors = findUserConstructors(node.getNodeType()); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
649 if (constructors.isEmpty()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
650 clazz.add(createUserConstructor(clazz, null)); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
651 } else { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
652 for (ExecutableElement constructor : constructors) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
653 clazz.add(createUserConstructor(clazz, constructor)); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
654 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
655 } |
9281
e16363e50252
Fixed minor bug in gen constructor generation.
Christian Humer <christian.humer@gmail.com>
parents:
9279
diff
changeset
|
656 if (node.needsRewrites(getContext())) { |
e16363e50252
Fixed minor bug in gen constructor generation.
Christian Humer <christian.humer@gmail.com>
parents:
9279
diff
changeset
|
657 clazz.add(createCopyConstructor(clazz, findCopyConstructor(node.getNodeType()))); |
e16363e50252
Fixed minor bug in gen constructor generation.
Christian Humer <christian.humer@gmail.com>
parents:
9279
diff
changeset
|
658 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
659 } |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
660 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
661 private CodeExecutableElement createUserConstructor(CodeTypeElement type, ExecutableElement superConstructor) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
662 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
663 CodeTreeBuilder builder = method.createBuilder(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
664 |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
665 if (superConstructor != null) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
666 for (VariableElement param : superConstructor.getParameters()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
667 method.getParameters().add(CodeVariableElement.clone(param)); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
668 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
669 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
670 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
671 for (VariableElement var : type.getFields()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
672 method.getParameters().add(new CodeVariableElement(var.asType(), var.getSimpleName().toString())); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
673 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
674 |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
675 if (superConstructor != null) { |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
676 builder.startStatement().startSuperCall(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
677 for (VariableElement param : superConstructor.getParameters()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
678 builder.string(param.getSimpleName().toString()); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
679 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
680 builder.end().end(); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
681 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
682 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
683 for (VariableElement var : type.getFields()) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
684 builder.startStatement(); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
685 String varName = var.getSimpleName().toString(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
686 builder.string("this.").string(varName); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
687 if (Utils.isAssignable(getContext(), var.asType(), getContext().getTruffleTypes().getNode())) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
688 builder.string(" = adoptChild(").string(varName).string(")"); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
689 } else if (Utils.isAssignable(getContext(), var.asType(), getContext().getTruffleTypes().getNodeArray())) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
690 builder.string(" = adoptChildren(").string(varName).string(")"); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
691 } else { |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
692 builder.string(" = ").string(varName); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
693 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
694 builder.end(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
695 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
696 return method; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
697 } |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
698 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
699 private CodeExecutableElement createCopyConstructor(CodeTypeElement type, ExecutableElement superConstructor) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
700 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
701 CodeTreeBuilder builder = method.createBuilder(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
702 if (!(superConstructor == null && type.getFields().isEmpty())) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
703 method.getParameters().add(new CodeVariableElement(type.asType(), "copy")); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
704 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
705 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
706 if (superConstructor != null) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
707 builder.startStatement().startSuperCall().string("copy").end().end(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
708 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
709 |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
710 for (VariableElement var : type.getFields()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
711 builder.startStatement(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
712 String varName = var.getSimpleName().toString(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
713 builder.string("this.").string(varName); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
714 if (Utils.isAssignable(getContext(), var.asType(), getContext().getTruffleTypes().getNode())) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
715 builder.string(" = adoptChild(copy.").string(varName).string(")"); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
716 } else if (Utils.isAssignable(getContext(), var.asType(), getContext().getTruffleTypes().getNodeArray())) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
717 builder.string(" = adoptChildren(copy.").string(varName).string(")"); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
718 } else { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
719 builder.string(" = copy.").string(varName); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
720 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
721 builder.end(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
722 } |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
723 return method; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
724 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
725 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
726 private CodeVariableElement createAssumptionField(String assumption) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
727 CodeVariableElement var = new CodeVariableElement(getContext().getTruffleTypes().getAssumption(), assumption); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
728 var.getModifiers().add(Modifier.FINAL); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
729 return var; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
730 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
731 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
732 private CodeVariableElement createChildField(NodeChildData child) { |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9231
diff
changeset
|
733 CodeVariableElement var = new CodeVariableElement(child.getNodeType(), child.getName()); |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9231
diff
changeset
|
734 var.getModifiers().add(Modifier.PROTECTED); |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9231
diff
changeset
|
735 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
736 DeclaredType annotationType; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
737 if (child.getCardinality() == Cardinality.MANY) { |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9231
diff
changeset
|
738 var.getModifiers().add(Modifier.FINAL); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
739 annotationType = getContext().getTruffleTypes().getChildrenAnnotation(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
740 } else { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
741 annotationType = getContext().getTruffleTypes().getChildAnnotation(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
742 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
743 |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
744 var.getAnnotationMirrors().add(new CodeAnnotationMirror(annotationType)); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
745 return var; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
746 } |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
747 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
748 private CodeExecutableElement createGenericExecute(NodeData node, String name, boolean specialize) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
749 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getType(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
750 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
751 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), genericReturnType, name); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
752 CodeTreeBuilder builder = method.createBuilder(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
753 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
754 String prefix = null; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
755 if (specialize) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
756 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState")); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
757 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
758 builder.startStatement(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
759 builder.startStaticCall(getContext().getTruffleTypes().getCompilerAsserts(), "neverPartOfCompilation").end(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
760 builder.end(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
761 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
762 emitSpecializationListeners(builder, node); |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
763 builder.defaultDeclaration(node.getGenericSpecialization().getReturnSignature().getPrimitiveType(), "result"); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
764 if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
765 builder.defaultDeclaration(getContext().getType(boolean.class), "resultIsSet"); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
766 } |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
767 builder.startStatement().string("boolean allowed = (minimumState == ").string(nodeSpecializationClassName(node.getSpecializations().get(0))).string(".class)").end(); |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
768 prefix = null; |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
769 |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
770 builder.startStatement().string("StringBuilder message = new StringBuilder(reason)").end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
771 builder.startStatement().startCall("message", "append").doubleQuote(" (").end().end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
772 |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
773 String sep = null; |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
774 for (ActualParameter parameter : node.getGenericSpecialization().getParameters()) { |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
775 if (!parameter.getSpecification().isSignature()) { |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
776 continue; |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
777 } |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
778 |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
779 builder.startStatement(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
780 builder.string("message"); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
781 if (sep != null) { |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
782 builder.startCall(".append").doubleQuote(sep).end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
783 } |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
784 builder.startCall(".append").doubleQuote(parameter.getLocalName()).end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
785 builder.startCall(".append").doubleQuote(" = ").end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
786 builder.startCall(".append").string(parameter.getLocalName()).end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
787 builder.end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
788 |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
789 builder.startIf().string(parameter.getLocalName() + " != null").end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
790 builder.startBlock(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
791 builder.startStatement(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
792 builder.startCall("message.append").doubleQuote(" (").end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
793 builder.startCall(".append").string(parameter.getLocalName() + ".getClass().getSimpleName()").end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
794 builder.startCall(".append").doubleQuote(")").end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
795 builder.end().end(); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
796 |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
797 sep = ", "; |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
798 } |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
799 |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
800 builder.startStatement().startCall("message", "append").doubleQuote(")").end().end(); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
801 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
802 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
803 addInternalValueParameters(method, node.getGenericSpecialization(), true); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
804 |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
805 if (specialize) { |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
806 method.addParameter(new CodeVariableElement(getContext().getType(String.class), "reason")); |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
807 } |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
808 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
809 List<SpecializationData> specializations = node.getSpecializations(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
810 if (!specialize && !node.getGenericSpecialization().isUseSpecializationsForGeneric()) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
811 specializations = Arrays.asList(node.getGenericSpecialization()); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
812 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
813 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
814 // group specializations for reachabiltiy |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
815 List<SpecializationData> unreachableSpecializations = new ArrayList<>(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
816 List<SpecializationData> filteredSpecializations = new ArrayList<>(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
817 if (!specialize) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
818 unreachableSpecializations = new ArrayList<>(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
819 filteredSpecializations = new ArrayList<>(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
820 boolean unreachable = false; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
821 for (SpecializationData specialization : specializations) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
822 if (unreachable) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
823 unreachableSpecializations.add(specialization); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
824 } else { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
825 filteredSpecializations.add(specialization); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
826 if (!specialization.isUninitialized() && !specialization.hasRewrite(getContext())) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
827 unreachable = true; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
828 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
829 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
830 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
831 } else { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
832 unreachableSpecializations = Collections.emptyList(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
833 filteredSpecializations = specializations; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
834 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
835 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
836 for (SpecializationData current : filteredSpecializations) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
837 if (current.isUninitialized()) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
838 continue; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
839 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
840 CodeTreeBuilder execute = new CodeTreeBuilder(builder); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
841 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
842 execute.tree(createGenericInvoke(builder, current, specialize)); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
843 |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
844 if (specialize && !current.isGeneric()) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
845 builder.startStatement().string("allowed = allowed || (minimumState == ").string(nodeSpecializationClassName(current)).string(".class)").end(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
846 } |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
847 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
848 builder.tree(createGuardAndCast(builder, prefix, current.getNode().getGenericSpecialization(), current, true, execute.getRoot(), null, true)); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
849 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
850 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
851 for (SpecializationData specializationData : unreachableSpecializations) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
852 builder.string("// unreachable ").string(specializationData.getId()).newLine(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
853 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
854 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
855 return method; |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
856 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
857 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
858 private CodeTree createGenericInvoke(CodeTreeBuilder parent, SpecializationData current, boolean specialize) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
859 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
860 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
861 if (!current.getExceptions().isEmpty()) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
862 builder.startTryBlock(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
863 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
864 |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
865 CodeTree executeCall = null; |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
866 if (current.getMethod() != null) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
867 executeCall = createTemplateMethodCall(builder, null, current.getNode().getGenericSpecialization(), current, null); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
868 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
869 |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
870 if (specialize && executeCall == null && !current.getNode().getGenericSpecialization().isUseSpecializationsForGeneric()) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
871 emitEncounteredSynthetic(builder); |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
872 } else if (specialize) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
873 |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
874 if (current.getNode().getGenericSpecialization().isUseSpecializationsForGeneric()) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
875 builder.startIf().string("!resultIsSet").end().startBlock(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
876 if (executeCall != null) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
877 if (current.getReturnSignature().isVoid()) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
878 builder.statement(executeCall); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
879 } else { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
880 builder.startStatement().string("result = ").tree(executeCall).end(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
881 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
882 builder.statement("resultIsSet = true"); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
883 } else { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
884 emitEncounteredSynthetic(builder); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
885 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
886 builder.end(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
887 } |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
888 |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
889 if (!current.isGeneric()) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
890 builder.startIf().string("allowed").end().startBlock(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
891 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
892 |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
893 if (!current.getNode().getGenericSpecialization().isUseSpecializationsForGeneric()) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
894 if (current.getReturnSignature().isVoid()) { |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
895 builder.statement(executeCall); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
896 } else { |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
897 builder.startStatement().string("result = ").tree(executeCall).end(); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
898 } |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
899 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
900 |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
901 builder.startStatement().startCall("super", "replace"); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
902 builder.startGroup().startNew(nodeSpecializationClassName(current)).string("this").end().end(); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
903 builder.string("message.toString()"); |
9356
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
904 builder.end().end(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
905 |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
906 if (current.getReturnSignature().isVoid()) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
907 builder.returnStatement(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
908 } else { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
909 builder.startReturn().string("result").end(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
910 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
911 if (!current.isGeneric()) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
912 builder.end(); |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
913 } |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
914 } else { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
915 if (executeCall == null) { |
86d981cd8e22
Fixed a bug in new code generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
9345
diff
changeset
|
916 emitEncounteredSynthetic(builder); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
917 } else { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
918 builder.startReturn().tree(executeCall).end(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
919 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
920 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
921 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
922 if (!current.getExceptions().isEmpty()) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
923 for (SpecializationThrowsData exception : current.getExceptions()) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
924 builder.end().startCatchBlock(exception.getJavaClass(), "rewriteEx"); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
925 builder.string("// fall through").newLine(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
926 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
927 builder.end(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
928 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
929 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
930 return builder.getRoot(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
931 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
932 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
933 private void emitSpecializationListeners(CodeTreeBuilder builder, NodeData node) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
934 for (TemplateMethod listener : node.getSpecializationListeners()) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
935 builder.startStatement(); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
936 builder.tree(createTemplateMethodCall(builder, null, listener, listener, null)); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
937 builder.end(); // statement |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
938 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
939 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
940 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
941 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
942 private class NodeFactoryFactory extends ClassElementFactory<NodeData> { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
943 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
944 private final Map<NodeData, List<TypeElement>> childTypes; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
945 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
946 private CodeTypeElement generatedNode; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
947 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
948 public NodeFactoryFactory(ProcessorContext context, Map<NodeData, List<TypeElement>> childElements) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
949 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
950 this.childTypes = childElements; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
951 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
952 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
953 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
954 protected CodeTypeElement create(NodeData node) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
955 Modifier visibility = Utils.getVisibility(node.getTemplateType().getModifiers()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
956 CodeTypeElement clazz = createClass(node, modifiers(), factoryClassName(node), null, false); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
957 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
958 clazz.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
959 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
960 clazz.getModifiers().add(Modifier.FINAL); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
961 clazz.add(createConstructorUsingFields(modifiers(PRIVATE), clazz)); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
962 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
963 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
964 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
965 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
966 protected void createChildren(NodeData node) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
967 CodeTypeElement clazz = getElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
968 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
969 Modifier createVisibility = Utils.getVisibility(clazz.getModifiers()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
970 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
971 if (node.needsFactory()) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
972 NodeBaseFactory factory = new NodeBaseFactory(context); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
973 add(factory, node); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
974 generatedNode = factory.getElement(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
975 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
976 if (node.needsRewrites(context)) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
977 clazz.add(createCreateSpecializedMethod(node, createVisibility)); |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
978 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
979 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
980 createFactoryMethods(node, clazz, createVisibility); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
981 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
982 for (SpecializationData specialization : node.getSpecializations()) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
983 add(new SpecializedNodeFactory(context, generatedNode), specialization); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
984 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
985 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
986 TypeMirror nodeFactory = Utils.getDeclaredType(Utils.fromTypeMirror(getContext().getType(NodeFactory.class)), node.getNodeType()); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
987 clazz.getImplements().add(nodeFactory); |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
988 clazz.add(createCreateNodeMethod(node)); |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
989 clazz.add(createCreateNodeSpecializedMethod(node)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
990 clazz.add(createGetNodeClassMethod(node)); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
991 clazz.add(createGetNodeSignaturesMethod()); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
992 clazz.add(createGetChildrenSignatureMethod(node)); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
993 clazz.add(createGetInstanceMethod(node, createVisibility)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
994 clazz.add(createInstanceConstant(node, clazz.asType())); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
995 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
996 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
997 for (NodeData childNode : childTypes.keySet()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
998 if (childNode.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
999 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1000 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1001 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1002 for (TypeElement type : childTypes.get(childNode)) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1003 Set<Modifier> typeModifiers = ((CodeTypeElement) type).getModifiers(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1004 Modifier visibility = Utils.getVisibility(type.getModifiers()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1005 typeModifiers.clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1006 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1007 typeModifiers.add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1008 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1009 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1010 typeModifiers.add(Modifier.STATIC); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1011 typeModifiers.add(Modifier.FINAL); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1012 clazz.add(type); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1013 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1014 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1015 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1016 List<NodeData> children = node.getNodeDeclaringChildren(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1017 if (node.getParent() == null && children.size() > 0) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1018 clazz.add(createGetFactories(node)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1019 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1020 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1021 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1022 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1023 private CodeExecutableElement createGetNodeClassMethod(NodeData node) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1024 TypeMirror returnType = Utils.getDeclaredType(Utils.fromTypeMirror(getContext().getType(Class.class)), node.getNodeType()); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1025 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getNodeClass"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1026 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1027 builder.startReturn().typeLiteral(node.getNodeType()).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1028 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1029 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1030 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1031 private CodeExecutableElement createGetNodeSignaturesMethod() { |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1032 TypeElement listType = Utils.fromTypeMirror(getContext().getType(List.class)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1033 TypeMirror classType = getContext().getType(Class.class); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1034 TypeMirror returnType = Utils.getDeclaredType(listType, Utils.getDeclaredType(listType, classType)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1035 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getNodeSignatures"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1036 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1037 builder.startReturn(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1038 builder.startStaticCall(getContext().getType(Arrays.class), "asList"); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1039 List<ExecutableElement> constructors = findUserConstructors(generatedNode.asType()); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1040 for (ExecutableElement constructor : constructors) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1041 builder.tree(createAsList(builder, Utils.asTypeMirrors(constructor.getParameters()), classType)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1042 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1043 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1044 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1045 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1046 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1047 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1048 private CodeExecutableElement createGetChildrenSignatureMethod(NodeData node) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1049 Types types = getContext().getEnvironment().getTypeUtils(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1050 TypeElement listType = Utils.fromTypeMirror(getContext().getType(List.class)); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1051 TypeMirror classType = getContext().getType(Class.class); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1052 TypeMirror nodeType = getContext().getTruffleTypes().getNode(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1053 TypeMirror wildcardNodeType = types.getWildcardType(nodeType, null); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1054 classType = Utils.getDeclaredType(Utils.fromTypeMirror(classType), wildcardNodeType); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1055 TypeMirror returnType = Utils.getDeclaredType(listType, classType); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1056 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1057 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getExecutionSignature"); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1058 CodeTreeBuilder builder = method.createBuilder(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1059 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1060 List<TypeMirror> signatureTypes = new ArrayList<>(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1061 assert !node.getSpecializations().isEmpty(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1062 SpecializationData data = node.getSpecializations().get(0); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1063 for (ActualParameter parameter : data.getParameters()) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1064 ParameterSpec spec = parameter.getSpecification(); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1065 NodeChildData field = node.findChild(spec.getName()); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1066 if (field == null) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1067 continue; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1068 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1069 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1070 TypeMirror type; |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1071 if (field.getCardinality() == Cardinality.MANY && field.getNodeType().getKind() == TypeKind.ARRAY) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1072 type = ((ArrayType) field.getNodeType()).getComponentType(); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1073 } else { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1074 type = field.getNodeType(); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1075 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1076 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1077 signatureTypes.add(type); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1078 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1079 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1080 builder.startReturn().tree(createAsList(builder, signatureTypes, classType)).end(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1081 return method; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1082 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1083 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1084 private CodeTree createAsList(CodeTreeBuilder parent, List<TypeMirror> types, TypeMirror elementClass) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1085 CodeTreeBuilder builder = parent.create(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1086 builder.startGroup(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1087 builder.type(getContext().getType(Arrays.class)); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1088 builder.string(".<").type(elementClass).string(">"); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1089 builder.startCall("asList"); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1090 for (TypeMirror typeMirror : types) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1091 builder.typeLiteral(typeMirror); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1092 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1093 builder.end().end(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1094 return builder.getRoot(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1095 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
1096 |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
1097 private CodeExecutableElement createCreateNodeMethod(NodeData node) { |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
1098 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNode"); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1099 CodeVariableElement arguments = new CodeVariableElement(getContext().getType(Object.class), "arguments"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1100 method.setVarArgs(true); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1101 method.addParameter(arguments); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1102 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1103 CodeTreeBuilder builder = method.createBuilder(); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1104 List<ExecutableElement> signatures = findUserConstructors(generatedNode.asType()); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1105 boolean ifStarted = false; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1106 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1107 for (ExecutableElement element : signatures) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1108 ifStarted = builder.startIf(ifStarted); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1109 builder.string("arguments.length == " + element.getParameters().size()); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1110 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1111 int index = 0; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1112 for (VariableElement param : element.getParameters()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1113 builder.string(" && "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1114 if (!param.asType().getKind().isPrimitive()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1115 builder.string("(arguments[" + index + "] == null || "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1116 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1117 builder.string("arguments[" + index + "] instanceof "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1118 builder.type(Utils.boxType(getContext(), param.asType())); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1119 if (!param.asType().getKind().isPrimitive()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1120 builder.string(")"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1121 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1122 index++; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1123 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1124 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1125 builder.startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1126 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1127 builder.startReturn().startCall("create"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1128 index = 0; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1129 for (VariableElement param : element.getParameters()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1130 builder.startGroup(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1131 builder.string("(").type(param.asType()).string(") "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1132 builder.string("arguments[").string(String.valueOf(index)).string("]"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1133 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1134 index++; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1135 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1136 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1137 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1138 builder.end(); // block |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1139 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1140 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1141 builder.startElseBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1142 builder.startThrow().startNew(getContext().getType(IllegalArgumentException.class)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1143 builder.doubleQuote("Invalid create signature."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1144 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1145 builder.end(); // else block |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1146 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1147 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1148 |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
1149 private CodeExecutableElement createCreateNodeSpecializedMethod(NodeData node) { |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
1150 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNodeSpecialized"); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1151 CodeVariableElement nodeParam = new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1152 CodeVariableElement arguments = new CodeVariableElement(getContext().getType(Class.class), "types"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1153 method.addParameter(nodeParam); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1154 method.addParameter(arguments); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1155 method.setVarArgs(true); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1156 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1157 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1158 if (!node.needsRewrites(getContext())) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1159 builder.startThrow().startNew(getContext().getType(UnsupportedOperationException.class)).end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1160 } else { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1161 builder.startIf(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1162 builder.string("types.length == 1"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1163 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1164 builder.startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1165 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1166 builder.startReturn().startCall("createSpecialized"); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1167 builder.startGroup(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1168 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1169 builder.end(); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1170 builder.string("types[0]"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1171 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1172 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1173 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1174 builder.startElseBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1175 builder.startThrow().startNew(getContext().getType(IllegalArgumentException.class)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1176 builder.doubleQuote("Invalid createSpecialized signature."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1177 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1178 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1179 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1180 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1181 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1182 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1183 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1184 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1185 TypeElement nodeFactoryType = Utils.fromTypeMirror(getContext().getType(NodeFactory.class)); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1186 TypeMirror returnType = Utils.getDeclaredType(nodeFactoryType, node.getNodeType()); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1187 |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1188 CodeExecutableElement method = new CodeExecutableElement(modifiers(), returnType, "getInstance"); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1189 if (visibility != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1190 method.getModifiers().add(visibility); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1191 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1192 method.getModifiers().add(Modifier.STATIC); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1193 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1194 String varName = instanceVarName(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1195 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1196 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1197 builder.startIf(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1198 builder.string(varName).string(" == null"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1199 builder.end().startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1200 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1201 builder.startStatement(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1202 builder.string(varName); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1203 builder.string(" = "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1204 builder.startNew(factoryClassName(node)).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1205 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1206 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1207 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1208 builder.startReturn().string(varName).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1209 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1210 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1211 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1212 private String instanceVarName(NodeData node) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1213 if (node.getParent() != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1214 return Utils.firstLetterLowerCase(factoryClassName(node)) + "Instance"; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1215 } else { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1216 return "instance"; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1217 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1218 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1219 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1220 private CodeVariableElement createInstanceConstant(NodeData node, TypeMirror factoryType) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1221 String varName = instanceVarName(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1222 CodeVariableElement var = new CodeVariableElement(modifiers(), factoryType, varName); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1223 var.getModifiers().add(Modifier.PRIVATE); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1224 var.getModifiers().add(Modifier.STATIC); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1225 return var; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1226 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1227 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1228 private ExecutableElement createGetFactories(NodeData node) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1229 List<NodeData> children = node.getNodeDeclaringChildren(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1230 if (node.needsFactory()) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1231 children.add(node); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1232 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1233 |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1234 List<TypeMirror> nodeTypesList = new ArrayList<>(); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1235 TypeMirror prev = null; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1236 boolean allSame = true; |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1237 for (NodeData child : children) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1238 nodeTypesList.add(child.getNodeType()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1239 if (prev != null && !Utils.typeEquals(child.getNodeType(), prev)) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1240 allSame = false; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1241 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1242 prev = child.getNodeType(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1243 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1244 TypeMirror commonNodeSuperType = Utils.getCommonSuperType(getContext(), nodeTypesList.toArray(new TypeMirror[nodeTypesList.size()])); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1245 |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1246 Types types = getContext().getEnvironment().getTypeUtils(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1247 TypeMirror factoryType = getContext().getType(NodeFactory.class); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1248 TypeMirror baseType; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1249 if (allSame) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1250 baseType = Utils.getDeclaredType(Utils.fromTypeMirror(factoryType), commonNodeSuperType); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1251 } else { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1252 baseType = Utils.getDeclaredType(Utils.fromTypeMirror(factoryType), types.getWildcardType(commonNodeSuperType, null)); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1253 } |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1254 TypeMirror listType = Utils.getDeclaredType(Utils.fromTypeMirror(getContext().getType(List.class)), baseType); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1255 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1256 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), listType, "getFactories"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1257 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1258 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1259 builder.startReturn(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1260 builder.startStaticCall(getContext().getType(Arrays.class), "asList"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1261 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1262 for (NodeData child : children) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1263 builder.startGroup(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1264 NodeData childNode = child; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1265 List<NodeData> factories = new ArrayList<>(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1266 while (childNode.getParent() != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1267 factories.add(childNode); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1268 childNode = childNode.getParent(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1269 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1270 Collections.reverse(factories); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1271 for (NodeData nodeData : factories) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1272 builder.string(factoryClassName(nodeData)).string("."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1273 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1274 builder.string("getInstance()"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1275 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1276 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1277 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1278 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1279 return method; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1280 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1281 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1282 private void createFactoryMethods(NodeData node, CodeTypeElement clazz, Modifier createVisibility) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1283 List<ExecutableElement> constructors = findUserConstructors(generatedNode.asType()); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1284 for (ExecutableElement constructor : constructors) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1285 clazz.add(createCreateMethod(node, createVisibility, constructor)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1286 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1287 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1288 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1289 private CodeExecutableElement createCreateMethod(NodeData node, Modifier visibility, ExecutableElement constructor) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1290 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), constructor); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1291 method.setSimpleName(CodeNames.of("create")); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1292 method.getModifiers().clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1293 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1294 method.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1295 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1296 method.getModifiers().add(Modifier.STATIC); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1297 method.setReturnType(node.getNodeType()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1298 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1299 CodeTreeBuilder body = method.createBuilder(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1300 body.startReturn(); |
8242
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8237
diff
changeset
|
1301 if (node.getSpecializations().isEmpty()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1302 body.null_(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1303 } else { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1304 body.startNew(nodeSpecializationClassName(node.getSpecializations().get(0))); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1305 for (VariableElement var : method.getParameters()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1306 body.string(var.getSimpleName().toString()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1307 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1308 body.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1309 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1310 body.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1311 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1312 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1313 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1314 private CodeExecutableElement createCreateSpecializedMethod(NodeData node, Modifier visibility) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1315 CodeExecutableElement method = new CodeExecutableElement(modifiers(), node.getNodeType(), "createSpecialized"); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1316 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1317 method.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1318 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1319 method.getModifiers().add(Modifier.STATIC); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1320 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1321 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME)); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1322 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "specializationClass")); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1323 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1324 CodeTreeBuilder body = method.createBuilder(); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1325 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1326 boolean hasCopyConstructor = findCopyConstructor(generatedNode.asType()) != null; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1327 |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1328 final String thisLocalVariableName = THIS_NODE_LOCAL_VAR_NAME + "Cast"; |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1329 |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1330 if (hasCopyConstructor) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1331 body.startStatement(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1332 body.type(generatedNode.asType()).string(" ").string(thisLocalVariableName); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1333 body.string(" = ").string("(").type(generatedNode.asType()).string(") ").string(THIS_NODE_LOCAL_VAR_NAME); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1334 body.end(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1335 } |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1336 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1337 boolean first = true; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1338 for (TypeData type : node.getTypeSystem().getTypes()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1339 SpecializationData specialization = node.findUniqueSpecialization(type); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1340 if (specialization != null && !type.isGeneric()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1341 if (first) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1342 body.startIf(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1343 first = false; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1344 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1345 body.startElseIf(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1346 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1347 body.string("specializationClass == ").type(type.getBoxedType()).string(".class").end().startBlock(); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1348 body.tree(createReturnNewSpecialization(body, specialization, thisLocalVariableName, hasCopyConstructor)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1349 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1350 body.end(); // if |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1351 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1352 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1353 body.tree(createReturnNewSpecialization(body, node.getGenericSpecialization(), thisLocalVariableName, hasCopyConstructor)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1354 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1355 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1356 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1357 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1358 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1359 private class SpecializedNodeFactory extends ClassElementFactory<SpecializationData> { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1360 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1361 private final CodeTypeElement nodeGen; |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1362 |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1363 public SpecializedNodeFactory(ProcessorContext context, CodeTypeElement nodeGen) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1364 super(context); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1365 this.nodeGen = nodeGen; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1366 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1367 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1368 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1369 public CodeTypeElement create(SpecializationData specialization) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1370 NodeData node = specialization.getNode(); |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1371 TypeMirror baseType = node.getNodeType(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1372 if (nodeGen != null) { |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1373 baseType = nodeGen.asType(); |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1374 } |
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1375 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false); |
9779
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1376 |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1377 String shortName = specialization.getNode().getShortName(); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1378 CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation()); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1379 if (shortName != null) { |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1380 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName)); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1381 } |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1382 |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1383 DeclaredType nodeinfoKind = getContext().getTruffleTypes().getNodeInfoKind(); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1384 VariableElement kind; |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1385 if (specialization.isGeneric()) { |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1386 kind = Utils.findVariableElement(nodeinfoKind, "GENERIC"); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1387 } else if (specialization.isUninitialized()) { |
9781
c15fd053efb6
Fixed typo in NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
9780
diff
changeset
|
1388 kind = Utils.findVariableElement(nodeinfoKind, "UNINITIALIZED"); |
9779
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1389 } else { |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1390 kind = Utils.findVariableElement(nodeinfoKind, "SPECIALIZED"); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1391 } |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1392 |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1393 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("kind"), new CodeAnnotationValue(kind)); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1394 |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1395 clazz.getAnnotationMirrors().add(nodeInfoMirror); |
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9536
diff
changeset
|
1396 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1397 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1398 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1399 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1400 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1401 protected void createChildren(SpecializationData specialization) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1402 CodeTypeElement clazz = getElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1403 NodeData node = specialization.getNode(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1404 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1405 TypeElement superTypeElement = Utils.fromTypeMirror(clazz.getSuperclass()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1406 for (ExecutableElement constructor : ElementFilter.constructorsIn(superTypeElement.getEnclosedElements())) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1407 ExecutableElement superConstructor = createSuperConstructor(clazz, constructor); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1408 if (superConstructor != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1409 clazz.add(superConstructor); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1410 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1411 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1412 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1413 for (ExecutableTypeData execType : node.getExecutableTypes()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1414 if (execType.isFinal()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1415 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1416 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1417 CodeExecutableElement executeMethod = createExecutableTypeOverride(execType); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1418 clazz.add(executeMethod); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1419 CodeTreeBuilder builder = executeMethod.createBuilder(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1420 CodeTree result = createExecuteBody(builder, specialization, execType); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1421 if (result != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1422 builder.tree(result); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1423 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1424 clazz.remove(executeMethod); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1425 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1426 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1427 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1428 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1429 private CodeTree createExecuteBody(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData execType) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1430 TypeData primaryType = specialization.getReturnType().getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1431 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1432 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1433 |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1434 List<ExecutableTypeData> primaryExecutes = findFunctionalExecutableType(specialization, execType.getEvaluatedCount()); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1435 |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1436 if (primaryExecutes.contains(execType) || primaryExecutes.isEmpty()) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1437 builder.tree(createFunctionalExecute(builder, specialization, execType)); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1438 } else if (needsCastingExecuteMethod(execType, primaryType)) { |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1439 assert !primaryExecutes.isEmpty(); |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1440 builder.tree(createCastingExecute(builder, specialization, execType, primaryExecutes.get(0))); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1441 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1442 return null; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1443 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1444 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1445 return builder.getRoot(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1446 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1447 |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1448 private CodeExecutableElement createExecutableTypeOverride(ExecutableTypeData execType) { |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1449 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), execType.getMethod()); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1450 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1451 int i = 0; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1452 for (VariableElement param : method.getParameters()) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1453 CodeVariableElement var = CodeVariableElement.clone(param); |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1454 ActualParameter actualParameter = execType.getParameters().get(i); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1455 if (actualParameter.getSpecification().isSignature()) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1456 var.setName(valueNameEvaluated(actualParameter)); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1457 } else { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1458 var.setName(valueName(actualParameter)); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1459 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1460 method.getParameters().set(i, var); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1461 i++; |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1462 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1463 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1464 method.getAnnotationMirrors().clear(); |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1465 method.getModifiers().remove(Modifier.ABSTRACT); |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1466 return method; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1467 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1468 |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1469 private boolean needsCastingExecuteMethod(ExecutableTypeData execType, TypeData primaryType) { |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1470 if (execType.isAbstract()) { |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1471 return true; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1472 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1473 if (Utils.isPrimitiveOrVoid(primaryType.getPrimitiveType()) && Utils.isPrimitiveOrVoid(execType.getType().getPrimitiveType())) { |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1474 return true; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1475 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1476 if (execType.getType().isGeneric()) { |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1477 return true; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1478 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1479 return false; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1480 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1481 |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1482 private List<ExecutableTypeData> findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1483 TypeData primaryType = specialization.getReturnType().getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1484 List<ExecutableTypeData> otherTypes = specialization.getNode().getExecutableTypes(evaluatedCount); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1485 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1486 List<ExecutableTypeData> filteredTypes = new ArrayList<>(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1487 for (ExecutableTypeData compareType : otherTypes) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1488 if (!Utils.typeEquals(compareType.getType().getPrimitiveType(), primaryType.getPrimitiveType())) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1489 continue; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1490 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1491 filteredTypes.add(compareType); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1492 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1493 |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1494 // no direct matches found use generic where the type is Object |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1495 if (filteredTypes.isEmpty()) { |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1496 for (ExecutableTypeData compareType : otherTypes) { |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1497 if (compareType.getType().isGeneric() && !compareType.hasUnexpectedValue(getContext())) { |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1498 filteredTypes.add(compareType); |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1499 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1500 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1501 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1502 |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1503 if (filteredTypes.isEmpty()) { |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1504 for (ExecutableTypeData compareType : otherTypes) { |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1505 if (compareType.getType().isGeneric()) { |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1506 filteredTypes.add(compareType); |
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1507 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1508 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1509 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1510 |
9780
763100239da6
Fixed GRAAL-276.
Christian Humer <christian.humer@gmail.com>
parents:
9779
diff
changeset
|
1511 return filteredTypes; |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1512 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1513 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1514 private CodeTree createCastingExecute(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData executable, ExecutableTypeData castExecutable) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1515 TypeData type = executable.getType(); |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1516 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1517 NodeData node = specialization.getNode(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1518 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1519 ExecutableTypeData castedType = node.findExecutableType(type, 0); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1520 TypeData primaryType = castExecutable.getType(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1521 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1522 boolean needsTry = castExecutable.hasUnexpectedValue(getContext()); |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1523 boolean returnVoid = type.isVoid(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1524 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1525 List<ActualParameter> executeParameters = new ArrayList<>(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1526 for (ActualParameter sourceParameter : executable.getParameters()) { |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1527 if (!sourceParameter.getSpecification().isSignature()) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1528 continue; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1529 } |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1530 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1531 ActualParameter targetParameter = castExecutable.findParameter(sourceParameter.getLocalName()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1532 if (targetParameter != null) { |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1533 executeParameters.add(targetParameter); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1534 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1535 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1536 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1537 builder.tree(createExecuteChildren(builder, executable, specialization, executeParameters, null, true)); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1538 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1539 CodeTree primaryExecuteCall = createTemplateMethodCall(builder, null, executable, castExecutable, null); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1540 if (needsTry) { |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1541 if (!returnVoid) { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1542 builder.declaration(primaryType.getPrimitiveType(), "value"); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1543 } |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1544 builder.startTryBlock(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1545 |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1546 if (returnVoid) { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1547 builder.statement(primaryExecuteCall); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1548 } else { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1549 builder.startStatement(); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1550 builder.string("value = "); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1551 builder.tree(primaryExecuteCall); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1552 builder.end(); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1553 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1554 |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1555 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1556 if (returnVoid) { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1557 builder.string("// ignore").newLine(); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1558 } else { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1559 builder.startReturn(); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1560 builder.tree(createExpectExecutableType(node, specialization.getNode().getTypeSystem().getGenericTypeData(), castedType, CodeTreeBuilder.singleString("ex.getResult()"))); |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1561 builder.end(); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1562 } |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1563 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1564 |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1565 if (!returnVoid) { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1566 builder.startReturn(); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1567 builder.tree(createExpectExecutableType(node, castExecutable.getReturnSignature(), executable, CodeTreeBuilder.singleString("value"))); |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1568 builder.end(); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1569 } |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1570 } else { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1571 if (returnVoid) { |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1572 builder.statement(primaryExecuteCall); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1573 } else { |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1574 builder.startReturn(); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1575 builder.tree(createExpectExecutableType(node, castExecutable.getReturnSignature(), executable, primaryExecuteCall)); |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1576 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1577 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1578 } |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1579 |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1580 return builder.getRoot(); |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1581 } |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1582 |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1583 private CodeTree createExpectExecutableType(NodeData node, TypeData sourceType, ExecutableTypeData castedType, CodeTree value) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1584 boolean hasUnexpected = castedType.hasUnexpectedValue(getContext()); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1585 return createCastType(node, sourceType, castedType.getType(), hasUnexpected, value); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1586 } |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1587 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1588 private CodeTree createCastType(NodeData node, TypeData sourceType, TypeData targetType, boolean expect, CodeTree value) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1589 if (targetType == null) { |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1590 return value; |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1591 } else if (!sourceType.needsCastTo(getContext(), targetType)) { |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1592 return value; |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1593 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1594 |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1595 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1596 String targetMethodName; |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1597 if (expect) { |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1598 targetMethodName = TypeSystemCodeGenerator.expectTypeMethodName(targetType); |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1599 } else { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1600 targetMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1601 } |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1602 startCallTypeSystemMethod(getContext(), builder, node, targetMethodName); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1603 |
7750
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1604 builder.tree(value); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1605 builder.end().end(); |
bdcb3cc47e16
Generated nodes can now handle the case were a non generic execute methods does not throw an UVE.
Christian Humer <christian.humer@gmail.com>
parents:
7679
diff
changeset
|
1606 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1607 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1608 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1609 private CodeTree createFunctionalExecute(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData executable) { |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1610 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1611 if (specialization.isUninitialized()) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1612 builder.tree(createDeoptimize(builder)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1613 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1614 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1615 builder.tree(createExecuteChildren(builder, executable, specialization, specialization.getParameters(), null, false)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1616 |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1617 CodeTree executeNode; |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1618 executeNode = createExecute(builder, executable, specialization); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1619 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1620 SpecializationData next = specialization.findNextSpecialization(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1621 CodeTree returnSpecialized = null; |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1622 if (next != null) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1623 CodeTreeBuilder returnBuilder = new CodeTreeBuilder(builder); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1624 returnBuilder.tree(createDeoptimize(builder)); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1625 returnBuilder.tree(createReturnExecuteAndSpecialize(builder, executable, next, null, "One of guards " + specialization.getGuards() + " failed")); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1626 returnSpecialized = returnBuilder.getRoot(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1627 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1628 builder.tree(createGuardAndCast(builder, null, specialization, specialization, true, executeNode, returnSpecialized, false)); |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1629 |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1630 return builder.getRoot(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1631 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1632 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1633 private CodeTree createDeoptimize(CodeTreeBuilder parent) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1634 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1635 builder.startStatement(); |
9272
fe5bc02fcd19
Replace TruffleIntrinsics.deoptimize() calls with CompilerDirectives.transferToInterpreter(). Remove obsolete TruffleIntrinsics class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9258
diff
changeset
|
1636 builder.startStaticCall(getContext().getTruffleTypes().getCompilerDirectives(), "transferToInterpreter").end(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1637 builder.end(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1638 return builder.getRoot(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1639 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1640 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1641 private CodeTree createExecute(CodeTreeBuilder parent, ExecutableTypeData executable, SpecializationData specialization) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1642 NodeData node = specialization.getNode(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1643 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1644 if (!specialization.getExceptions().isEmpty() || !specialization.getAssumptions().isEmpty()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1645 builder.startTryBlock(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1646 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1647 |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1648 for (String assumption : specialization.getAssumptions()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1649 builder.startStatement(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1650 builder.string("this.").string(assumption).string(".check()"); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1651 builder.end(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1652 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1653 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1654 CodeTreeBuilder returnBuilder = new CodeTreeBuilder(parent); |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1655 if (specialization.isUninitialized()) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1656 returnBuilder.startCall("super", EXECUTE_SPECIALIZE_NAME); |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1657 returnBuilder.startGroup().string(nodeSpecializationClassName(specialization)).string(".class").end(); |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1658 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, true, true); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1659 returnBuilder.doubleQuote("Uninitialized"); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1660 returnBuilder.end(); |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1661 } else if (specialization.getMethod() == null && !node.needsRewrites(context)) { |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1662 emitEncounteredSynthetic(builder); |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1663 } else if (specialization.isGeneric()) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1664 returnBuilder.startCall("super", EXECUTE_GENERIC_NAME); |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1665 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, true, true); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1666 returnBuilder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1667 } else { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1668 returnBuilder.tree(createTemplateMethodCall(returnBuilder, null, specialization, specialization, null)); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1669 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1670 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1671 if (!returnBuilder.isEmpty()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1672 builder.startReturn(); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1673 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1674 TypeData targetType = node.getTypeSystem().findTypeData(builder.findMethod().getReturnType()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1675 TypeData sourceType = specialization.getReturnType().getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1676 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1677 if (targetType == null || sourceType == null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1678 builder.tree(returnBuilder.getRoot()); |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
1679 } else if (sourceType.needsCastTo(getContext(), targetType)) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1680 builder.tree(createCallTypeSystemMethod(context, parent, node, TypeSystemCodeGenerator.expectTypeMethodName(targetType), returnBuilder.getRoot())); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1681 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1682 builder.tree(returnBuilder.getRoot()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1683 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1684 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1685 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1686 |
8243
d81ff782fa1a
Removed @SpecializationThrows from codegen API. Replaced it by a simplier version in @Specialization.
Christian Humer <christian.humer@gmail.com>
parents:
8242
diff
changeset
|
1687 if (!specialization.getExceptions().isEmpty()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1688 for (SpecializationThrowsData exception : specialization.getExceptions()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1689 builder.end().startCatchBlock(exception.getJavaClass(), "ex"); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1690 builder.tree(createDeoptimize(builder)); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1691 builder.tree(createReturnExecuteAndSpecialize(parent, executable, exception.getTransitionTo(), null, "Thrown " + Utils.getSimpleName(exception.getJavaClass()))); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1692 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1693 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1694 } |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1695 if (!specialization.getAssumptions().isEmpty()) { |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1696 builder.end().startCatchBlock(getContext().getTruffleTypes().getInvalidAssumption(), "ex"); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1697 builder.tree(createReturnExecuteAndSpecialize(parent, executable, specialization.findNextSpecialization(), null, "Assumption failed")); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1698 builder.end(); |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1699 } |
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9272
diff
changeset
|
1700 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1701 return builder.getRoot(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1702 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1703 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1704 private CodeTree createExecuteChildren(CodeTreeBuilder parent, ExecutableTypeData sourceExecutable, SpecializationData specialization, List<ActualParameter> targetParameters, |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1705 ActualParameter unexpectedParameter, boolean cast) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1706 NodeData sourceNode = specialization.getNode(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1707 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1708 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1709 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1710 for (ActualParameter targetParameter : targetParameters) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1711 NodeChildData field = sourceNode.findChild(targetParameter.getSpecification().getName()); |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1712 if (!targetParameter.getSpecification().isSignature()) { |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1713 continue; |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1714 } |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1715 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1716 TypeData targetType = targetParameter.getTypeSystemType(); |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1717 ExecutableTypeData targetExecutable = null; |
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1718 if (field != null) { |
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1719 targetExecutable = field.findExecutableType(getContext(), targetType); |
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1720 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1721 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1722 ActualParameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1723 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1724 String targetVariableName = valueName(targetParameter); |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1725 CodeTree executionExpression = null; |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1726 if ((sourceParameter != null && cast) || sourceParameter != null) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1727 TypeData sourceType = sourceParameter.getTypeSystemType(); |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1728 if (targetExecutable == null || !sourceType.needsCastTo(getContext(), targetType)) { |
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1729 if (field != null && field.isShortCircuit() && sourceParameter != null) { |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1730 builder.tree(createShortCircuitValue(builder, specialization, field, targetParameter.getPreviousParameter(), unexpectedParameter)); |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1731 } |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1732 builder.startStatement(); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1733 builder.type(targetParameter.getType()).string(" "); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1734 builder.string(valueName(targetParameter)).string(" = "); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1735 builder.tree(CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter))); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1736 builder.end(); |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1737 continue; |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1738 } else { |
9536
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1739 CodeTree valueTree = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter)); |
238431ec62a2
Fixed bug in casting execute generation when evaluated parameters for both executed methods were not mapped to a child node.
Christian Humer <christian.humer@gmail.com>
parents:
9356
diff
changeset
|
1740 executionExpression = createExpectExecutableType(sourceNode, sourceType, targetExecutable, valueTree); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1741 } |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1742 } else if (sourceParameter == null) { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1743 executionExpression = createExecuteChildExpression(builder, field, targetParameter, unexpectedParameter); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1744 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1745 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1746 if (executionExpression != null) { |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1747 CodeTreeVariable executionVar = new CodeTreeVariable(); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1748 CodeTree shortCircuitTree = createShortCircuitTree(builder, executionVar, targetVariableName, specialization, targetParameter, unexpectedParameter); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1749 CodeTree unexpectedTree = createCatchUnexpectedTree(builder, executionExpression, targetVariableName, specialization, sourceExecutable, targetExecutable, targetParameter, |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1750 shortCircuitTree != executionVar); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1751 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1752 executionVar.set(unexpectedTree); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1753 builder.tree(shortCircuitTree); |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1754 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1755 } |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1756 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1757 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1758 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1759 private CodeTree createCatchUnexpectedTree(CodeTreeBuilder parent, CodeTree body, String targetVariableName, SpecializationData specialization, ExecutableTypeData currentExecutable, |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1760 ExecutableTypeData targetExecutable, ActualParameter param, boolean shortCircuit) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1761 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1762 boolean unexpected = targetExecutable.hasUnexpectedValue(getContext()); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1763 boolean cast = false; |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
1764 if (targetExecutable.getType().needsCastTo(getContext(), param.getTypeSystemType())) { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1765 unexpected = true; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1766 cast = true; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1767 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1768 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1769 builder.startStatement(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1770 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1771 if (!shortCircuit) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1772 builder.type(param.getType()).string(" ").string(targetVariableName); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1773 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1774 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1775 if (unexpected) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1776 if (!shortCircuit) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1777 builder.end(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1778 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1779 builder.startTryBlock(); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1780 builder.startStatement(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1781 builder.string(targetVariableName); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1782 } else if (shortCircuit) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1783 builder.startStatement(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1784 builder.string(targetVariableName); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1785 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1786 builder.string(" = "); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1787 if (cast) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1788 builder.tree(createCastType(specialization.getNode(), targetExecutable.getType(), param.getTypeSystemType(), true, body)); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1789 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1790 builder.tree(body); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1791 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1792 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1793 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1794 if (unexpected) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1795 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1796 SpecializationData generic = specialization.getNode().getGenericSpecialization(); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1797 ActualParameter genericParameter = generic.findParameter(param.getLocalName()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1798 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1799 List<ActualParameter> genericParameters = generic.getParametersAfter(genericParameter); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1800 builder.tree(createDeoptimize(builder)); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1801 builder.tree(createExecuteChildren(parent, currentExecutable, generic, genericParameters, genericParameter, false)); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1802 builder.tree(createReturnExecuteAndSpecialize(builder, currentExecutable, specialization.findNextSpecialization(), param, |
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1803 "Expected " + param.getLocalName() + " instanceof " + Utils.getSimpleName(param.getType()))); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1804 builder.end(); // catch block |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1805 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1806 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1807 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1808 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1809 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1810 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeChildData targetField, ActualParameter sourceParameter, ActualParameter unexpectedParameter) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1811 TypeData type = sourceParameter.getTypeSystemType(); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1812 ExecutableTypeData execType = targetField.findExecutableType(getContext(), type); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1813 |
9231
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1814 /* |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1815 * FIXME Temporary deactivated due to partial evaluation failure else if |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1816 * (accessElement.getKind() == ElementKind.METHOD) { |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1817 * builder.startCall(accessElement.getSimpleName().toString()).end(); } |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1818 */ |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1819 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1820 if (targetField != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1821 Element accessElement = targetField.getAccessElement(); |
9228
bc82cde765b9
Disabled access using the getter in the generated code to avoid frame escapes in PE.
Christian Humer <christian.humer@gmail.com>
parents:
9227
diff
changeset
|
1822 if (accessElement == null || accessElement.getKind() == ElementKind.METHOD) { |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1823 builder.string("this.").string(targetField.getName()); |
9231
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1824 } else if (accessElement.getKind() == ElementKind.FIELD) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1825 builder.string("this.").string(accessElement.getSimpleName().toString()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1826 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1827 throw new AssertionError(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1828 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1829 if (sourceParameter.getSpecification().isIndexed()) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1830 builder.string("[" + sourceParameter.getIndex() + "]"); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1831 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1832 builder.string("."); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1833 } |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1834 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1835 builder.startCall(execType.getMethodName()); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1836 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1837 List<ActualParameter> signatureParameters = getModel().getSignatureParameters(); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1838 int index = 0; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1839 for (ActualParameter parameter : execType.getParameters()) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1840 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1841 if (!parameter.getSpecification().isSignature()) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1842 builder.string(parameter.getLocalName()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1843 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1844 if (index < signatureParameters.size()) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1845 ActualParameter specializationParam = signatureParameters.get(index); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1846 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
1847 TypeData targetType = parameter.getTypeSystemType(); |
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
1848 TypeData sourceType = specializationParam.getTypeSystemType(); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1849 String localName = specializationParam.getLocalName(); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1850 if (unexpectedParameter != null && unexpectedParameter.getLocalName().equals(specializationParam.getLocalName())) { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1851 localName = "ex.getResult()"; |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
1852 sourceType = getModel().getNode().getTypeSystem().getGenericTypeData(); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1853 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1854 |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1855 CodeTree value = CodeTreeBuilder.singleString(localName); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1856 |
9305
e6251a86e8e3
Fixed some minor bugs in executeWith supprt.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
1857 if (sourceType.needsCastTo(getContext(), targetType)) { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1858 value = createCallTypeSystemMethod(getContext(), builder, getModel().getNode(), TypeSystemCodeGenerator.asTypeMethodName(targetType), value); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1859 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1860 builder.tree(value); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1861 } else { |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1862 builder.defaultValue(parameter.getType()); |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1863 } |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1864 index++; |
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1865 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1866 } |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1867 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1868 builder.end(); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1869 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1870 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1871 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1872 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1873 private CodeTree createShortCircuitTree(CodeTreeBuilder parent, CodeTree body, String targetVariableName, SpecializationData specialization, ActualParameter parameter, |
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1874 ActualParameter exceptionParam) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1875 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1876 |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1877 NodeChildData forField = specialization.getNode().findChild(parameter.getSpecification().getName()); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1878 if (forField == null) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1879 return body; |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1880 } |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1881 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1882 if (forField.getExecutionKind() != ExecutionKind.SHORT_CIRCUIT) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1883 return body; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1884 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1885 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1886 ActualParameter shortCircuitParam = specialization.getPreviousParam(parameter); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1887 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1888 builder.tree(createShortCircuitValue(builder, specialization, forField, shortCircuitParam, exceptionParam)); |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1889 |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1890 builder.declaration(parameter.getType(), targetVariableName, CodeTreeBuilder.createBuilder().defaultValue(parameter.getType())); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1891 builder.startIf().string(shortCircuitParam.getLocalName()).end(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1892 builder.startBlock(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1893 builder.tree(body); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1894 builder.end(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1895 |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1896 return builder.getRoot(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1897 } |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1898 |
9286
39f08ef7b5d8
Fixed bugs for execute evaluated generation.
Christian Humer <christian.humer@gmail.com>
parents:
9281
diff
changeset
|
1899 private CodeTree createShortCircuitValue(CodeTreeBuilder parent, SpecializationData specialization, NodeChildData forField, ActualParameter shortCircuitParam, ActualParameter exceptionParam) { |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1900 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1901 int shortCircuitIndex = 0; |
9220
97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents:
9218
diff
changeset
|
1902 for (NodeChildData field : specialization.getNode().getChildren()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1903 if (field.getExecutionKind() == ExecutionKind.SHORT_CIRCUIT) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1904 if (field == forField) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1905 break; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1906 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1907 shortCircuitIndex++; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1908 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1909 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1910 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1911 builder.startStatement().type(shortCircuitParam.getType()).string(" ").string(valueName(shortCircuitParam)).string(" = "); |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1912 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex); |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
1913 builder.tree(createTemplateMethodCall(builder, null, specialization, shortCircuitData, exceptionParam != null ? exceptionParam.getLocalName() : null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1914 builder.end(); // statement |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1915 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1916 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1917 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1918 |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1919 private CodeTree createReturnExecuteAndSpecialize(CodeTreeBuilder parent, ExecutableTypeData executable, SpecializationData nextSpecialization, ActualParameter exceptionParam, String reason) { |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1920 |
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1921 SpecializationData generic = nextSpecialization.getNode().getGenericSpecialization(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1922 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1923 specializeCall.startCall(EXECUTE_SPECIALIZE_NAME); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1924 specializeCall.string(nodeSpecializationClassName(nextSpecialization) + ".class"); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1925 addInternalValueParameterNames(specializeCall, generic, nextSpecialization.getNode().getGenericSpecialization(), exceptionParam != null ? exceptionParam.getLocalName() : null, true, true); |
9796
d6d5e3dc2713
Implemented generation of a proper rewrite reason for generated nodes.
Christian Humer <christian.humer@gmail.com>
parents:
9781
diff
changeset
|
1926 specializeCall.doubleQuote(reason); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1927 specializeCall.end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1928 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1929 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1930 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1931 builder.startReturn(); |
9345
0a8bf24d660a
Implemented improvements to the generated source code.
Christian Humer <christian.humer@gmail.com>
parents:
9305
diff
changeset
|
1932 builder.tree(createExpectExecutableType(nextSpecialization.getNode(), generic.getReturnSignature(), executable, specializeCall.getRoot())); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1933 builder.end(); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1934 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1935 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1936 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1937 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1938 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1939 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1940 } |