Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 9258:07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 15:34:06 +0200 |
parents | ee3a9188c65e |
children | fe5bc02fcd19 |
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 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 public NodeCodeGenerator(ProcessorContext context) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 private TypeMirror getUnexpectedValueException() { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 return getContext().getTruffleTypes().getUnexpectedValueException(); |
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 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 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
|
55 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
|
56 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
58 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
|
59 String nodeid = specialization.getNode().getNodeId(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
60 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
|
61 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
|
62 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
63 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
64 String name = Utils.firstLetterUpperCase(nodeid); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
65 name += Utils.firstLetterUpperCase(specialization.getId()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
66 name += "Node"; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 return name; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
70 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
|
71 return param.getLocalName(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
74 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
|
75 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
|
76 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
77 |
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 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
|
79 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
|
80 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
|
81 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 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
|
83 ParameterSpec spec = parameter.getSpecification(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 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
|
85 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 } |
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
|
87 if (spec.isLocal()) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
88 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
89 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
90 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
91 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
|
92 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
95 private static void addInternalValueParameterNames(CodeTreeBuilder builder, TemplateMethod source, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame, |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
96 boolean includeImplicit) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
97 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
|
98 builder.string("frameValue"); |
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 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
|
101 ParameterSpec spec = parameter.getSpecification(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 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
|
103 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 |
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
|
106 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
|
107 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
|
108 } |
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
|
109 if (parameter.getSpecification().isLocal()) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
110 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
111 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
112 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
113 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
|
114 |
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
|
115 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
|
116 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
|
117 } 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
|
118 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
|
119 } 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
|
120 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
|
121 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
125 private static String valueName(ActualParameter sourceParameter, ActualParameter targetParameter) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 } else if (sourceParameter.getTypeSystemType() != null && targetParameter.getTypeSystemType() != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
130 if (sourceParameter.getTypeSystemType().needsCastTo(targetParameter.getTypeSystemType())) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
131 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
|
132 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
133 } |
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 { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
136 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
|
137 } |
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 |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
140 private CodeTree createTemplateMethodCall(CodeTreeBuilder parent, 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
|
141 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
|
142 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
143 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
|
144 |
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
|
145 builder.startGroup(); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
146 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
|
147 if (method == null) { |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
148 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
|
149 } |
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 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
|
151 NodeData node = (NodeData) targetMethod.getTemplate(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
152 |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
153 boolean accessible = targetMethod.canBeAccessedByInstanceOf(getContext(), node.getNodeType()); |
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
|
154 if (accessible) { |
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 if (builder.findMethod().getModifiers().contains(STATIC)) { |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
156 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
|
157 builder.type(targetClass.asType()); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
158 } else { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
159 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
160 } |
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
|
161 } else { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
162 if (targetMethod instanceof ExecutableTypeData) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
163 builder.string("this"); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
164 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
165 builder.string("super"); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
166 } |
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
|
167 } |
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
|
168 } 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
|
169 if (method.getModifiers().contains(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
|
170 builder.type(targetClass.asType()); |
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
|
171 } 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
|
172 ActualParameter parameter = null; |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
173 for (ActualParameter searchParameter : targetMethod.getParameters()) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
174 if (searchParameter.getSpecification().isSignature()) { |
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
|
175 parameter = searchParameter; |
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
|
176 break; |
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
|
177 } |
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
|
178 } |
8662
5eeade940236
Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents:
8661
diff
changeset
|
179 ActualParameter sourceParameter = sourceMethod.findParameter(parameter.getLocalName()); |
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
|
180 assert parameter != null; |
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
|
181 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
182 if (castedValues && sourceParameter != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
183 builder.string(valueName(sourceParameter, parameter)); |
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
|
184 } 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
|
185 builder.string(valueName(parameter)); |
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
|
186 } |
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
|
187 } |
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
|
188 } |
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
|
189 builder.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
|
190 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
|
191 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
192 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
|
193 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
|
194 if (valueParameter == null) { |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
195 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
|
196 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
197 TypeData targetType = targetParameter.getTypeSystemType(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
198 |
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 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
|
200 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
201 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
202 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
203 TypeData valueType = null; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
204 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
|
205 valueType = valueParameter.getTypeSystemType(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
206 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
207 |
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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 } 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
|
213 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
|
214 } |
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
|
215 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
|
216 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
|
217 } 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
|
218 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
|
219 } 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
|
220 builder.startGroup(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
221 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
222 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
|
223 builder.string("("); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
224 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
|
225 builder.string(") "); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
226 } |
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
|
227 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
|
228 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
229 } 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
|
230 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
|
231 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
232 } |
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
|
233 |
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
|
234 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
|
235 |
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
|
236 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
237 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
238 |
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
|
239 private static String genClassName(NodeData 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
|
240 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
|
241 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
|
242 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
|
243 } |
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
|
244 String name = Utils.firstLetterUpperCase(nodeid); |
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
|
245 name += "GenNode"; |
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
|
246 return name; |
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 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
249 private String generatedGenericMethodName(SpecializationData specialization) { |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
250 final String prefix = "generic"; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
251 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
252 if (specialization == null) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
253 return prefix; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
254 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
255 |
8277
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
256 if (!specialization.getNode().needsRewrites(context)) { |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
257 return prefix; |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
258 } |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
259 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
260 SpecializationData prev = null; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
261 for (SpecializationData current : specialization.getNode().getSpecializations()) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
262 if (specialization == current) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
263 if (prev == null || prev.isUninitialized()) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
264 return prefix; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
265 } else { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
266 return prefix + current.getId(); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
267 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
268 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
269 prev = current; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
270 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
271 return prefix; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
272 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
273 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
281 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7502
diff
changeset
|
282 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
|
283 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
|
284 assert singleton != null; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
285 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
286 body.startGroup(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
287 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
|
288 body.string(".").startCall(methodName); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
289 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
290 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
291 private CodeTree createGuardAndCast(CodeTreeBuilder parent, String conditionPrefix, SpecializationData sourceSpecialization, SpecializationData targetSpecialization, boolean castValues, |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
292 CodeTree guardedStatements, CodeTree elseStatements) { |
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
|
293 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
294 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
|
295 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
296 CodeTree implicitGuards = createImplicitGuards(parent, conditionPrefix, sourceSpecialization, targetSpecialization); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
297 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
|
298 |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
299 Set<String> valuesNeedsCast; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
300 if (castValues) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
301 // cast all |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
302 valuesNeedsCast = null; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
303 } else { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
304 // 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
|
305 valuesNeedsCast = new HashSet<>(); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
306 for (GuardData guard : targetSpecialization.getGuards()) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
307 for (ActualParameter parameter : guard.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
|
308 NodeChildData field = node.findChild(parameter.getSpecification().getName()); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
309 if (field == null) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
310 continue; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
311 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
312 TypeData typeData = parameter.getTypeSystemType(); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
313 if (typeData != null && !typeData.isGeneric()) { |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
314 valuesNeedsCast.add(parameter.getLocalName()); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
315 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
316 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
317 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
318 } |
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
|
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 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
|
321 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 } |
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 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
330 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
|
331 |
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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 } |
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 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
340 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
|
341 builder.startIf(); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
342 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
|
343 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
|
344 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
|
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 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
347 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
|
348 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
349 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
|
350 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
|
351 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
|
352 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
353 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
|
354 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
355 |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
356 private CodeTree createExplicitGuards(CodeTreeBuilder parent, String conditionPrefix, SpecializationData 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
|
357 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
|
358 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
|
359 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
|
360 // Explicitly specified guards |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8361
diff
changeset
|
361 for (GuardData guard : guardedSpecialization.getGuards()) { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8361
diff
changeset
|
362 builder.string(andOperator); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
363 builder.tree(createTemplateMethodCall(parent, valueSpecialization, guard, null)); |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8361
diff
changeset
|
364 andOperator = " && "; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
365 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
366 } |
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
|
367 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
368 return builder.isEmpty() ? null : builder.getRoot(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
369 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
370 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
371 private CodeTree createCasts(CodeTreeBuilder parent, Set<String> castWhiteList, SpecializationData 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
|
372 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
373 // 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
|
374 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
|
375 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
|
376 if (field == null) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
377 continue; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
378 } |
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
|
379 ActualParameter valueParam = valueSpecialization.findParameter(guardedParam.getLocalName()); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
380 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
381 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
|
382 continue; |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
383 } |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
384 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
385 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
|
386 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
|
387 continue; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
388 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
389 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
|
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 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
392 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
|
393 } |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
394 |
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 private CodeTree createImplicitGuards(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
396 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
|
397 // 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
|
398 String andOperator = conditionPrefix != null ? conditionPrefix + " && " : ""; |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
399 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
|
400 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
|
401 if (field == null) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
402 continue; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
403 } |
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
|
404 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
|
405 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
406 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
|
407 if (implicitGuard == null) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
408 continue; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
409 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
410 |
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
|
411 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
|
412 builder.tree(implicitGuard); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
413 andOperator = " && "; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
414 } |
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
|
415 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
416 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
|
417 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
418 |
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
|
419 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
|
420 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
|
421 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
|
422 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
423 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
|
424 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
|
425 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
426 if (targetType.equalsType(sourceType) || targetType.isGeneric()) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
427 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
|
428 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
429 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
430 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
|
431 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 } |
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 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
|
441 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
|
442 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
|
443 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
444 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
|
445 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
|
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 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
448 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
|
449 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
450 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
|
451 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
452 |
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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
458 if (!sourceType.needsCastTo(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
|
459 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
|
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 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
468 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
469 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
|
470 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
471 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
|
472 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
473 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
474 /** |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
475 * <pre> |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
476 * 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
|
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 * $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
|
479 * 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
|
480 * $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
|
481 * } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
482 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
483 * 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
|
484 * $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
|
485 * </pre> |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
486 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
487 * . |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
488 */ |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
489 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
|
490 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
|
491 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
|
492 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
|
493 } else { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
494 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
|
495 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
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 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
|
506 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
507 |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
508 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
|
509 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
|
510 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
511 |
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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 } |
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
|
518 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
|
519 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
|
520 } |
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
|
521 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
|
522 } |
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
|
523 |
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
|
524 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
|
525 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
|
526 } |
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
|
527 |
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
|
528 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
|
529 } |
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 |
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 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
|
532 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
|
533 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
|
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 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
|
536 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
|
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 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
|
539 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
|
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 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
|
542 } |
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 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
544 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
552 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
553 |
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
|
554 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
|
555 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
|
556 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
557 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
558 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
559 private class NodeGenFactory extends ClassElementFactory<NodeData> { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
560 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
561 public NodeGenFactory(ProcessorContext context) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
562 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
563 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
564 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
565 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
566 protected CodeTypeElement create(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
|
567 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, ABSTRACT, STATIC), genClassName(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
|
568 |
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
|
569 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
|
570 clazz.add(createChildField(child)); |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
571 |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
572 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
|
573 ExecutableElement getter = (ExecutableElement) child.getAccessElement(); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
574 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), getter); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
575 method.getModifiers().remove(Modifier.ABSTRACT); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
576 method.createBuilder().startReturn().string("this.").string(child.getName()).end(); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
577 clazz.add(method); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9220
diff
changeset
|
578 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
579 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
580 |
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
|
581 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
|
582 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
583 if (node.getExtensionElements() != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
584 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
|
585 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
586 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
587 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
588 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
589 |
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
|
590 private void createConstructors(NodeData node, CodeTypeElement 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
|
591 List<ExecutableElement> signatureConstructors = 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
|
592 ExecutableElement copyConstructor = 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
|
593 List<? extends ExecutableElement> constructors = ElementFilter.constructorsIn(Utils.fromTypeMirror(node.getNodeType()).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
|
594 for (ExecutableElement constructor : 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
|
595 if (constructor.getModifiers().contains(Modifier.PRIVATE) || constructor.getParameters().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
|
596 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
|
597 } |
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
|
598 |
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
|
599 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
|
600 assert copyConstructor == 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
|
601 copyConstructor = createConstructor(clazz, constructor, 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
|
602 } 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
|
603 signatureConstructors.add(createConstructor(clazz, constructor, 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
|
604 } |
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
|
605 } |
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
|
606 |
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
|
607 if (copyConstructor == null && node.needsRewrites(getContext())) { |
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
|
608 clazz.add(createConstructor(clazz, null, 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
|
609 } else if (copyConstructor != 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
|
610 clazz.add(copyConstructor); |
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
|
611 } |
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
|
612 |
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
|
613 if (signatureConstructors.isEmpty() && !node.getChildren().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
|
614 clazz.add(createConstructor(clazz, null, 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
|
615 } 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
|
616 clazz.getEnclosedElements().addAll(signatureConstructors); |
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
|
617 } |
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
|
618 } |
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
|
619 |
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
|
620 private CodeExecutableElement createConstructor(CodeTypeElement type, ExecutableElement superConstructor, boolean copyConstructor) { |
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
|
621 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
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
|
622 CodeTreeBuilder builder = method.createBuilder(); |
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
|
623 if (!copyConstructor) { |
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
|
624 if (superConstructor != 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
|
625 for (VariableElement param : superConstructor.getParameters()) { |
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 method.getParameters().add(CodeVariableElement.clone(param)); |
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
|
627 } |
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
|
628 } |
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
|
629 for (NodeChildData child : getModel().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
|
630 method.getParameters().add(new CodeVariableElement(child.getNodeType(), child.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
|
631 } |
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
|
632 } 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
|
633 if (!(superConstructor == null && getModel().getChildren().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
|
634 method.getParameters().add(new CodeVariableElement(type.asType(), "copy")); |
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
|
635 } |
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
|
636 } |
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
|
637 |
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
|
638 if (superConstructor != 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
|
639 builder.startStatement(); |
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
|
640 builder.startSuperCall(); |
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
|
641 if (copyConstructor) { |
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
|
642 builder.string("copy"); |
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
|
643 } 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
|
644 for (VariableElement param : superConstructor.getParameters()) { |
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
|
645 builder.string(param.getSimpleName().toString()); |
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
|
646 } |
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 } |
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
|
648 builder.end(); |
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
|
649 builder.end(); |
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
|
650 } |
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
|
651 |
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
|
652 for (NodeChildData child : getModel().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
|
653 |
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 builder.startStatement(); |
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
|
655 builder.string("this.").string(child.getName()).string(" = "); |
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
|
656 |
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
|
657 if (child.getCardinality() == Cardinality.MANY) { |
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
|
658 builder.startCall("adoptChildren"); |
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
|
659 } 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
|
660 builder.startCall("adoptChild"); |
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
|
661 } |
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
|
662 |
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
|
663 builder.startGroup(); |
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
|
664 if (copyConstructor) { |
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
|
665 builder.string("copy."); |
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
|
666 } |
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
|
667 builder.string(child.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
|
668 builder.end(); |
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 builder.end(); |
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
|
671 builder.end(); |
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
|
672 |
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 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
|
676 } |
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
|
677 |
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
|
678 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
|
679 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
|
680 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
|
681 |
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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 } 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
|
687 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
|
688 } |
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
|
689 |
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
|
690 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
|
691 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
|
692 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
693 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
694 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
695 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
|
696 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
697 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
|
698 |
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
|
699 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
|
700 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
701 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
|
702 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
703 this.childTypes = childElements; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
704 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
705 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
706 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
707 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
|
708 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
|
709 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
|
710 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
711 clazz.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
712 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
713 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
|
714 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
|
715 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
716 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
717 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
718 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
719 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
|
720 CodeTypeElement clazz = getElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
721 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
722 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
|
723 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
724 if (node.needsFactory()) { |
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
|
725 NodeGenFactory factory = new NodeGenFactory(context); |
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
|
726 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
|
727 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
|
728 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
729 createFactoryMethods(node, clazz, createVisibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
730 |
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
|
731 if (node.getSpecializations().size() > 1) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
732 clazz.add(createCreateSpecializedMethod(node, createVisibility)); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
733 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
734 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
735 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
|
736 clazz.add(createSpecializeMethod(node)); |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
737 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
738 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
739 if (node.getGenericSpecialization() != null) { |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
740 List<CodeExecutableElement> genericMethods = createGeneratedGenericMethod(node); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
741 for (CodeExecutableElement method : genericMethods) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
742 clazz.add(method); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
743 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
744 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
745 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
746 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
|
747 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
|
748 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
749 |
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
|
750 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
|
751 clazz.getImplements().add(nodeFactory); |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
752 clazz.add(createCreateNodeMethod(node)); |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
753 clazz.add(createCreateNodeSpecializedMethod(node)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
754 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
|
755 clazz.add(createGetNodeSignaturesMethod()); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
756 clazz.add(createGetChildrenSignatureMethod(node)); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
757 clazz.add(createGetInstanceMethod(node, createVisibility)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
758 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
|
759 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
760 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
761 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
|
762 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
|
763 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
764 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
765 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
766 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
|
767 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
|
768 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
|
769 typeModifiers.clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
770 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
771 typeModifiers.add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
772 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
773 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
774 typeModifiers.add(Modifier.STATIC); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
775 typeModifiers.add(Modifier.FINAL); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
776 clazz.add(type); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
777 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
778 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
779 |
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
|
780 List<NodeData> children = node.getNodeDeclaringChildren(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
781 if (node.getParent() == null && children.size() > 0) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
782 clazz.add(createGetFactories(node)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
783 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
784 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
785 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
786 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
787 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
|
788 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
|
789 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
|
790 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
791 builder.startReturn().typeLiteral(node.getNodeType()).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
792 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
793 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
794 |
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
|
795 private CodeExecutableElement createGetNodeSignaturesMethod() { |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
796 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
|
797 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
|
798 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
|
799 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
|
800 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
801 builder.startReturn(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
802 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
|
803 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
|
804 for (ExecutableElement constructor : constructors) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
805 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
|
806 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
807 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
808 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
809 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
810 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
811 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
812 private CodeExecutableElement createGetChildrenSignatureMethod(NodeData node) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
813 Types types = getContext().getEnvironment().getTypeUtils(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
814 TypeElement listType = Utils.fromTypeMirror(getContext().getType(List.class)); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
815 TypeMirror classType = getContext().getType(Class.class); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
816 TypeMirror nodeType = getContext().getTruffleTypes().getNode(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
817 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
|
818 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
|
819 TypeMirror returnType = Utils.getDeclaredType(listType, classType); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
820 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
821 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
|
822 CodeTreeBuilder builder = method.createBuilder(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
823 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
824 List<TypeMirror> signatureTypes = new ArrayList<>(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
825 assert !node.getSpecializations().isEmpty(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
826 SpecializationData data = node.getSpecializations().get(0); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
827 for (ActualParameter parameter : data.getParameters()) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
828 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
|
829 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
|
830 if (field == null) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
831 continue; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
832 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
833 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
834 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
|
835 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
|
836 type = ((ArrayType) field.getNodeType()).getComponentType(); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
837 } 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
|
838 type = field.getNodeType(); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
839 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
840 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
841 signatureTypes.add(type); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
842 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
843 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
844 builder.startReturn().tree(createAsList(builder, signatureTypes, classType)).end(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
845 return method; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
846 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
847 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
848 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
|
849 CodeTreeBuilder builder = parent.create(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
850 builder.startGroup(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
851 builder.type(getContext().getType(Arrays.class)); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
852 builder.string(".<").type(elementClass).string(">"); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
853 builder.startCall("asList"); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
854 for (TypeMirror typeMirror : types) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
855 builder.typeLiteral(typeMirror); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
856 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
857 builder.end().end(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
858 return builder.getRoot(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
859 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
860 |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
861 private CodeExecutableElement createCreateNodeMethod(NodeData node) { |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
862 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
|
863 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
|
864 method.setVarArgs(true); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
865 method.addParameter(arguments); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
866 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
867 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
|
868 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
|
869 boolean ifStarted = false; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
870 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
871 for (ExecutableElement element : signatures) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
872 ifStarted = builder.startIf(ifStarted); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
873 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
|
874 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
875 int index = 0; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
876 for (VariableElement param : element.getParameters()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
877 builder.string(" && "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
878 if (!param.asType().getKind().isPrimitive()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
879 builder.string("(arguments[" + index + "] == null || "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
880 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
881 builder.string("arguments[" + index + "] instanceof "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
882 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
|
883 if (!param.asType().getKind().isPrimitive()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
884 builder.string(")"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
885 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
886 index++; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
887 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
888 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
889 builder.startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
890 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
891 builder.startReturn().startCall("create"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
892 index = 0; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
893 for (VariableElement param : element.getParameters()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
894 builder.startGroup(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
895 builder.string("(").type(param.asType()).string(") "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
896 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
|
897 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
898 index++; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
899 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
900 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
901 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
902 builder.end(); // block |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
903 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
904 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
905 builder.startElseBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
906 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
|
907 builder.doubleQuote("Invalid create signature."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
908 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
909 builder.end(); // else block |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
910 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
911 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
912 |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
913 private CodeExecutableElement createCreateNodeSpecializedMethod(NodeData node) { |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
914 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNodeSpecialized"); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
915 CodeVariableElement nodeParam = new CodeVariableElement(node.getNodeType(), "thisNode"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
916 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
|
917 method.addParameter(nodeParam); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
918 method.addParameter(arguments); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
919 method.setVarArgs(true); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
920 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
921 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
922 if (!node.needsRewrites(getContext())) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
923 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
|
924 } else { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
925 builder.startIf(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
926 builder.string("types.length == 1"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
927 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
928 builder.startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
929 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
930 builder.startReturn().startCall("createSpecialized"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
931 builder.string("thisNode"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
932 builder.string("types[0]"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
933 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
934 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
935 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
936 builder.startElseBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
937 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
|
938 builder.doubleQuote("Invalid createSpecialized signature."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
939 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
940 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
941 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
942 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
943 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
944 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
945 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
946 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
947 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
|
948 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
|
949 |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
950 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
|
951 if (visibility != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
952 method.getModifiers().add(visibility); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
953 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
954 method.getModifiers().add(Modifier.STATIC); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
955 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
956 String varName = instanceVarName(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
957 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
958 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
959 builder.startIf(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
960 builder.string(varName).string(" == null"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
961 builder.end().startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
962 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
963 builder.startStatement(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
964 builder.string(varName); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
965 builder.string(" = "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
966 builder.startNew(factoryClassName(node)).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
967 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
968 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
969 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
970 builder.startReturn().string(varName).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
971 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
972 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
973 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
974 private String instanceVarName(NodeData node) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
975 if (node.getParent() != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
976 return Utils.firstLetterLowerCase(factoryClassName(node)) + "Instance"; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
977 } else { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
978 return "instance"; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
979 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
980 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
981 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
982 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
|
983 String varName = instanceVarName(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
984 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
|
985 var.getModifiers().add(Modifier.PRIVATE); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
986 var.getModifiers().add(Modifier.STATIC); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
987 return var; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
988 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
989 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
990 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
|
991 List<NodeData> children = node.getNodeDeclaringChildren(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
992 if (node.needsFactory()) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
993 children.add(node); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
994 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
995 |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
996 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
|
997 TypeMirror prev = null; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
998 boolean allSame = true; |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
999 for (NodeData child : children) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1000 nodeTypesList.add(child.getNodeType()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1001 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
|
1002 allSame = false; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1003 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1004 prev = child.getNodeType(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1005 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1006 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
|
1007 |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1008 Types types = getContext().getEnvironment().getTypeUtils(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1009 TypeMirror factoryType = getContext().getType(NodeFactory.class); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
1010 TypeMirror baseType; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1011 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
|
1012 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
|
1013 } 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
|
1014 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
|
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 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
|
1017 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1018 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
|
1019 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1020 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1021 builder.startReturn(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1022 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
|
1023 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1024 for (NodeData child : children) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1025 builder.startGroup(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1026 NodeData childNode = child; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1027 List<NodeData> factories = new ArrayList<>(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1028 while (childNode.getParent() != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1029 factories.add(childNode); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1030 childNode = childNode.getParent(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1031 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1032 Collections.reverse(factories); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1033 for (NodeData nodeData : factories) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1034 builder.string(factoryClassName(nodeData)).string("."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1035 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1036 builder.string("getInstance()"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1037 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1038 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1039 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1040 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1041 return method; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1042 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1043 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1044 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
|
1045 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
|
1046 for (ExecutableElement constructor : constructors) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1047 clazz.add(createCreateMethod(node, createVisibility, constructor)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1048 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1049 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
1050 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1051 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
|
1052 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
|
1053 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
|
1054 method.getModifiers().clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1055 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1056 method.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1057 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1058 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
|
1059 method.setReturnType(node.getNodeType()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1060 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1061 CodeTreeBuilder body = method.createBuilder(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1062 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
|
1063 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
|
1064 body.null_(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1065 } else { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1066 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
|
1067 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
|
1068 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
|
1069 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1070 body.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1071 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1072 body.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1073 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1074 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1075 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1076 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
|
1077 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
|
1078 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1079 method.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1080 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1081 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
|
1082 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1083 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
|
1084 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
|
1085 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1086 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
|
1087 |
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
|
1088 body.startStatement(); |
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
|
1089 body.type(generatedNode.asType()).string(" ").string(THIS_NODE_LOCAL_VAR_NAME + "Cast"); |
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
|
1090 body.string(" = ").string("(").type(generatedNode.asType()).string(") ").string(THIS_NODE_LOCAL_VAR_NAME); |
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
|
1091 body.end(); |
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
|
1092 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1093 boolean first = true; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1094 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
|
1095 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
|
1096 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
|
1097 if (first) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1098 body.startIf(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1099 first = false; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1100 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1101 body.startElseIf(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1102 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1103 body.string("specializationClass == ").type(type.getBoxedType()).string(".class").end().startBlock(); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1104 body.startReturn().startNew(nodeSpecializationClassName(specialization)); |
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
|
1105 body.string(THIS_NODE_LOCAL_VAR_NAME + "Cast"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1106 body.end().end(); // new, return |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1107 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1108 body.end(); // if |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1109 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1110 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1111 body.startReturn().startNew(nodeSpecializationClassName(node.getGenericSpecialization())); |
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
|
1112 body.string(THIS_NODE_LOCAL_VAR_NAME + "Cast"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1113 body.end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1114 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1115 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1116 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1117 private CodeExecutableElement createSpecializeMethod(NodeData node) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1118 CodeExecutableElement method = new CodeExecutableElement(modifiers(PRIVATE, STATIC), node.getNodeType(), "specialize"); |
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
|
1119 method.addParameter(new CodeVariableElement(generatedNode.asType(), THIS_NODE_LOCAL_VAR_NAME)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1120 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState")); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
1121 addInternalValueParameters(method, node.getGenericSpecialization(), true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1122 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1123 CodeTreeBuilder body = method.createBuilder(); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1124 body.startStatement().string("boolean allowed = (minimumState == ").string(nodeSpecializationClassName(node.getSpecializations().get(0))).string(".class)").end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1125 |
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
|
1126 for (int i = 1; i < node.getSpecializations().size(); i++) { |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8237
diff
changeset
|
1127 SpecializationData specialization = node.getSpecializations().get(i); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1128 body.startStatement().string("allowed = allowed || (minimumState == ").string(nodeSpecializationClassName(specialization)).string(".class)").end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1129 |
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
|
1130 CodeTreeBuilder guarded = new CodeTreeBuilder(body); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1131 guarded.startReturn().startNew(nodeSpecializationClassName(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
|
1132 guarded.string(THIS_NODE_LOCAL_VAR_NAME); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1133 guarded.end().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
|
1134 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
1135 body.tree(createGuardAndCast(body, "allowed", node.getGenericSpecialization(), specialization, false, guarded.getRoot(), null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1136 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1137 body.startThrow().startNew(getContext().getType(IllegalArgumentException.class)).end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1138 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1139 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1140 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1141 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1142 private List<CodeExecutableElement> createGeneratedGenericMethod(NodeData node) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1143 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getType(); |
8277
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1144 if (node.needsRewrites(context)) { |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1145 List<CodeExecutableElement> methods = new ArrayList<>(); |
7751
ef1b41ea0a90
Implemented an option to turn off generated generic generation using specializations in @Generic.
Christian Humer <christian.humer@gmail.com>
parents:
7750
diff
changeset
|
1146 |
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
|
1147 List<SpecializationData> specializations = node.getSpecializations(); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1148 SpecializationData prev = null; |
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
|
1149 for (int i = 0; i < specializations.size(); i++) { |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8237
diff
changeset
|
1150 SpecializationData current = specializations.get(i); |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8237
diff
changeset
|
1151 SpecializationData next = i + 1 < specializations.size() ? specializations.get(i + 1) : null; |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1152 if (prev == null || current.isUninitialized()) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1153 prev = current; |
7751
ef1b41ea0a90
Implemented an option to turn off generated generic generation using specializations in @Generic.
Christian Humer <christian.humer@gmail.com>
parents:
7750
diff
changeset
|
1154 continue; |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1155 } else { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1156 String methodName = generatedGenericMethodName(current); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1157 CodeExecutableElement method = new CodeExecutableElement(modifiers(PRIVATE, STATIC), genericReturnType, methodName); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1158 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME)); |
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
|
1159 addInternalValueParameters(method, node.getGenericSpecialization(), true); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1160 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1161 emitGeneratedGenericSpecialization(method.createBuilder(), current, next); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1162 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1163 methods.add(method); |
7751
ef1b41ea0a90
Implemented an option to turn off generated generic generation using specializations in @Generic.
Christian Humer <christian.humer@gmail.com>
parents:
7750
diff
changeset
|
1164 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1165 prev = current; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1166 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1167 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1168 return methods; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1169 } else { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1170 CodeExecutableElement method = new CodeExecutableElement(modifiers(PRIVATE, STATIC), genericReturnType, generatedGenericMethodName(null)); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1171 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME)); |
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
|
1172 addInternalValueParameters(method, node.getGenericSpecialization(), true); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1173 emitInvokeDoMethod(method.createBuilder(), node.getGenericSpecialization(), 0); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1174 return Arrays.asList(method); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1175 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1176 } |
7751
ef1b41ea0a90
Implemented an option to turn off generated generic generation using specializations in @Generic.
Christian Humer <christian.humer@gmail.com>
parents:
7750
diff
changeset
|
1177 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1178 private void emitGeneratedGenericSpecialization(CodeTreeBuilder builder, SpecializationData current, SpecializationData next) { |
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
|
1179 CodeTreeBuilder invokeMethodBuilder = new CodeTreeBuilder(builder); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1180 emitInvokeDoMethod(invokeMethodBuilder, current, 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
|
1181 CodeTree invokeMethod = invokeMethodBuilder.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
|
1182 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1183 if (next != null) { |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1184 CodeTreeBuilder nextBuilder = builder.create(); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1185 |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1186 nextBuilder.startReturn().startCall(generatedGenericMethodName(next)); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1187 nextBuilder.string(THIS_NODE_LOCAL_VAR_NAME); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1188 addInternalValueParameterNames(nextBuilder, next, next, null, true, true); |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1189 nextBuilder.end().end(); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1190 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
1191 invokeMethod = createGuardAndCast(builder, null, current.getNode().getGenericSpecialization(), current, true, invokeMethod, nextBuilder.getRoot()); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1192 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1193 |
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
|
1194 builder.tree(invokeMethod); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1195 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1196 if (next != null) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1197 builder.end(); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1198 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1199 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1200 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1201 private void emitInvokeDoMethod(CodeTreeBuilder builder, SpecializationData specialization, int level) { |
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
|
1202 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
|
1203 builder.startTryBlock(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1204 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1205 |
8256 | 1206 if (specialization.getMethod() == null) { |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1207 emitEncounteredSynthetic(builder); |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1208 } else { |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1209 builder.startReturn(); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
1210 builder.tree(createTemplateMethodCall(builder, specialization.getNode().getGenericSpecialization(), specialization, null)); |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1211 builder.end(); // return |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1212 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1213 |
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
|
1214 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
|
1215 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
|
1216 builder.end().startCatchBlock(exception.getJavaClass(), "ex" + level); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1217 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1218 builder.startReturn().startCall(generatedGenericMethodName(exception.getTransitionTo())); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1219 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1220 addInternalValueParameterNames(builder, exception.getTransitionTo(), exception.getTransitionTo(), null, true, true); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1221 builder.end().end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1222 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1223 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1224 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1225 } |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1226 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1227 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1228 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1229 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
|
1230 |
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
|
1231 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
|
1232 |
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
|
1233 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
|
1234 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
|
1235 this.nodeGen = nodeGen; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1236 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1237 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1238 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1239 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
|
1240 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
|
1241 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
|
1242 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
|
1243 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
|
1244 } |
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
|
1245 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1246 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1247 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1248 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1249 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1250 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
|
1251 CodeTypeElement clazz = getElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1252 NodeData node = specialization.getNode(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1253 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1254 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
|
1255 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
|
1256 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
|
1257 if (superConstructor != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1258 clazz.add(superConstructor); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1259 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1260 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1261 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1262 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
|
1263 if (execType.isFinal()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1264 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1265 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1266 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
|
1267 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
|
1268 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
|
1269 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
|
1270 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
|
1271 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
|
1272 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1273 clazz.remove(executeMethod); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1274 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1275 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1276 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1277 if (node.needsRewrites(getContext()) && !specialization.isGeneric() && !specialization.isUninitialized()) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1278 buildSpecializeAndExecute(clazz, specialization); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1279 } |
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 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1282 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
|
1283 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
|
1284 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1285 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
|
1286 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1287 ExecutableTypeData foundEvaluatedPrimaryType = findFunctionalExecutableType(specialization, execType.getEvaluatedCount()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1288 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1289 if (execType == foundEvaluatedPrimaryType || foundEvaluatedPrimaryType == null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1290 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
|
1291 } else if (needsCastingExecuteMethod(execType, primaryType)) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1292 builder.tree(createCastingExecute(builder, specialization, execType, foundEvaluatedPrimaryType)); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1293 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1294 return null; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1295 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1296 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1297 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
|
1298 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1299 |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1300 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
|
1301 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
|
1302 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1303 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
|
1304 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
|
1305 CodeVariableElement var = CodeVariableElement.clone(param); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1306 var.setName(valueName(execType.getParameters().get(i))); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1307 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
|
1308 i++; |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1309 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1310 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1311 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
|
1312 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
|
1313 return method; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1314 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1315 |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1316 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
|
1317 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
|
1318 return true; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1319 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1320 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
|
1321 return true; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1322 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1323 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
|
1324 return true; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1325 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1326 return false; |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1327 } |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1328 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1329 private ExecutableTypeData findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1330 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
|
1331 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
|
1332 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1333 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
|
1334 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
|
1335 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
|
1336 continue; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1337 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1338 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
|
1339 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1340 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1341 for (ExecutableTypeData compareType : filteredTypes) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1342 if (compareType.startsWithSignature(specialization)) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1343 return compareType; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1344 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1345 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1346 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1347 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
|
1348 if (compareType.startsWithSignature(specialization)) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1349 return compareType; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1350 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1351 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1352 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1353 return null; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1354 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1355 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1356 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
|
1357 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
|
1358 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
|
1359 NodeData node = specialization.getNode(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1360 |
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
|
1361 ExecutableTypeData castedType = node.findExecutableType(type); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1362 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
|
1363 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1364 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
|
1365 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
|
1366 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1367 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
|
1368 for (ActualParameter sourceParameter : executable.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
|
1369 NodeChildData field = specialization.getNode().findChild(sourceParameter.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
|
1370 if (field == null) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1371 continue; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1372 } |
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
|
1373 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1374 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
|
1375 if (targetParameter != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1376 TypeData sourceType = sourceParameter.getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1377 TypeData targetType = targetParameter.getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1378 if (sourceType.needsCastTo(targetType)) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1379 executeParameters.add(targetParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1380 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1381 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1382 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1383 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1384 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
|
1385 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1386 CodeTree primaryExecuteCall = createTemplateMethodCall(builder, executable, castExecutable, null); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1387 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
|
1388 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
|
1389 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
|
1390 } |
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
|
1391 builder.startTryBlock(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1392 |
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
|
1393 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
|
1394 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
|
1395 } 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
|
1396 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
|
1397 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
|
1398 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
|
1399 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
|
1400 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1401 |
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
|
1402 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
|
1403 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
|
1404 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
|
1405 } 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
|
1406 builder.startReturn(); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1407 builder.tree(createExpectType(node, 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
|
1408 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
|
1409 } |
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
|
1410 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1411 |
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
|
1412 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
|
1413 builder.startReturn(); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1414 builder.tree(createExpectType(node, castedType, 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
|
1415 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
|
1416 } |
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
|
1417 } 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
|
1418 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
|
1419 builder.statement(primaryExecuteCall); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1420 } 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
|
1421 builder.startReturn(); |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1422 builder.tree(createExpectType(node, castedType, 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
|
1423 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1424 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1425 } |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1426 |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1427 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
|
1428 } |
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
|
1429 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1430 private CodeTree createExpectType(NodeData node, ExecutableTypeData castedType, CodeTree value) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1431 if (castedType == 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
|
1432 return value; |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1433 } else if (castedType.getType().isVoid()) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1434 return value; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1435 } else if (castedType.getType().isGeneric()) { |
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
|
1436 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
|
1437 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1438 |
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
|
1439 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
|
1440 String targetMethodName; |
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
|
1441 if (castedType.hasUnexpectedValue(getContext())) { |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1442 targetMethodName = TypeSystemCodeGenerator.expectTypeMethodName(castedType.getType()); |
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
|
1443 } 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
|
1444 targetMethodName = TypeSystemCodeGenerator.asTypeMethodName(castedType.getType()); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1445 } |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1446 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
|
1447 |
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
|
1448 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
|
1449 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
|
1450 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1451 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1452 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1453 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
|
1454 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1455 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
|
1456 builder.tree(createDeoptimize(builder)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1457 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1458 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1459 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
|
1460 |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1461 CodeTree executeNode; |
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
|
1462 if (specialization.isUninitialized()) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1463 builder.tree(createSpecializeCall(builder, executable, specialization)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1464 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1465 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
|
1466 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1467 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
|
1468 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
|
1469 if (next != null) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1470 returnSpecialized = createReturnSpecializeAndExecute(builder, executable, next, null); |
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
|
1471 } |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
1472 builder.tree(createGuardAndCast(builder, null, specialization, specialization, true, executeNode, returnSpecialized)); |
9215
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1473 |
bd067a48a9c2
Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
8662
diff
changeset
|
1474 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
|
1475 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1476 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1477 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
|
1478 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
|
1479 builder.startStatement(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1480 builder.startStaticCall(getContext().getTruffleTypes().getTruffleIntrinsics(), "deoptimize").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
|
1481 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
|
1482 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
|
1483 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1484 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1485 private CodeTree createSpecializeCall(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
|
1486 NodeData node = specialization.getNode(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1487 |
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
|
1488 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
|
1489 emitSpecializationListeners(builder, node); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1490 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1491 builder.startStatement(); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1492 builder.startCall("replace"); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1493 if (node.needsRewrites(getContext())) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1494 builder.startCall(factoryClassName(node), "specialize"); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1495 builder.string("this"); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1496 builder.typeLiteral(builder.findMethod().getEnclosingElement().asType()); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1497 addInternalValueParameterNames(builder, executable, specialization, null, true, true); |
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
|
1498 builder.end(); // call replace, call specialize |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1499 } else { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1500 builder.startCall(factoryClassName(node), "createSpecialized").string("this").string("null").end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1501 } |
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
|
1502 builder.end().end(); |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9231
diff
changeset
|
1503 emitSpecializationListeners(builder, node); |
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
|
1504 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
|
1505 } |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1506 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1507 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
|
1508 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
|
1509 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
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
|
1510 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
|
1511 builder.startTryBlock(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1512 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1513 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1514 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
|
1515 if (specialization.isUninitialized()) { |
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1516 String genericMethodName = generatedGenericMethodName(null); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1517 returnBuilder.startCall(factoryClassName(node), genericMethodName); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1518 returnBuilder.string("this"); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1519 addInternalValueParameterNames(returnBuilder, executable, specialization, null, true, true); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1520 returnBuilder.end(); |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1521 } 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
|
1522 emitEncounteredSynthetic(builder); |
8361
676fa31bd3f0
Uninitialized cases produced wrong call to throw new UnsuportedOperationException.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1523 } else if (specialization.isGeneric()) { |
8277
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1524 String genericMethodName; |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1525 if (!specialization.isUseSpecializationsForGeneric()) { |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1526 genericMethodName = generatedGenericMethodName(specialization); |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1527 } else { |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1528 genericMethodName = generatedGenericMethodName(null); |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1529 } |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
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 returnBuilder.startCall(factoryClassName(node), genericMethodName); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1532 returnBuilder.string("this"); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1533 addInternalValueParameterNames(returnBuilder, executable, specialization, null, true, true); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1534 returnBuilder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1535 } else { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1536 returnBuilder.tree(createTemplateMethodCall(returnBuilder, executable, specialization, null)); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1537 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1538 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1539 if (!returnBuilder.isEmpty()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1540 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
|
1541 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1542 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
|
1543 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
|
1544 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1545 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
|
1546 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
|
1547 } else if (sourceType.needsCastTo(targetType)) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1548 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
|
1549 } else { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1550 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
|
1551 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1552 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1553 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1554 |
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
|
1555 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
|
1556 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
|
1557 builder.end().startCatchBlock(exception.getJavaClass(), "ex"); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1558 builder.tree(createReturnSpecializeAndExecute(parent, executable, exception.getTransitionTo(), null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1559 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1560 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1561 } |
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
|
1562 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
|
1563 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1564 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1565 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
|
1566 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
|
1567 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
|
1568 |
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
|
1569 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
|
1570 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1571 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
|
1572 NodeChildData field = sourceNode.findChild(targetParameter.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
|
1573 if (field == null) { |
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
|
1574 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
|
1575 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1576 TypeData targetType = targetParameter.getTypeSystemType(); |
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
|
1577 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1578 ExecutableTypeData targetExecutable = field.getNodeData().findExecutableType(targetType); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1579 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1580 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
|
1581 |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1582 String targetVariableName = null; |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1583 CodeTree executionExpression = null; |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1584 if (cast || sourceParameter != null) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1585 TypeData sourceType = sourceParameter.getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1586 if (!sourceType.needsCastTo(targetType)) { |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1587 if (field.isShortCircuit() && sourceParameter != null) { |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1588 builder.tree(createShortCircuitValue(builder, sourceExecutable, specialization, field, targetParameter.getPreviousParameter(), unexpectedParameter)); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1589 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1590 continue; |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1591 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1592 executionExpression = createExpectType(sourceNode, targetExecutable, CodeTreeBuilder.singleString(valueName(targetParameter))); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1593 targetVariableName = castValueName(targetParameter); |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1594 } else if (sourceParameter == null) { |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1595 targetVariableName = valueName(targetParameter); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1596 executionExpression = createExecuteChildExpression(builder, field, targetParameter); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1597 } |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1598 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1599 CodeTreeVariable executionVar = new CodeTreeVariable(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1600 CodeTree shortCircuitTree = createShortCircuitTree(builder, executionVar, targetVariableName, sourceExecutable, specialization, targetParameter, unexpectedParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1601 CodeTree unexpectedTree = createCatchUnexpectedTree(builder, executionExpression, targetVariableName, specialization, sourceExecutable, targetExecutable, targetParameter, |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1602 shortCircuitTree != executionVar); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1603 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1604 executionVar.set(unexpectedTree); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1605 builder.tree(shortCircuitTree); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1606 } |
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
|
1607 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1608 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1609 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1610 private void emitSpecializationListeners(CodeTreeBuilder builder, NodeData node) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1611 for (TemplateMethod listener : node.getSpecializationListeners()) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1612 builder.startStatement(); |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
1613 builder.tree(createTemplateMethodCall(builder, listener, listener, null)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1614 builder.end(); // statement |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1615 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1616 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1617 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1618 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
|
1619 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
|
1620 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
|
1621 boolean unexpected = targetExecutable.hasUnexpectedValue(getContext()); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1622 builder.startStatement(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1623 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1624 if (!shortCircuit) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1625 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
|
1626 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1627 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1628 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
|
1629 if (!shortCircuit) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1630 builder.end(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1631 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1632 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
|
1633 builder.startStatement(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1634 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
|
1635 } 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
|
1636 builder.startStatement(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1637 builder.string(targetVariableName); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1638 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1639 builder.string(" = "); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1640 builder.tree(body); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1641 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1642 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1643 if (unexpected) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1644 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1645 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
|
1646 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
|
1647 |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1648 List<ActualParameter> genericParameters = generic.getParametersAfter(genericParameter); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1649 builder.tree(createExecuteChildren(parent, currentExecutable, generic, genericParameters, genericParameter, false)); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1650 builder.tree(createReturnSpecializeAndExecute(builder, currentExecutable, specialization.findNextSpecialization(), param)); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1651 builder.end(); // catch block |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1652 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
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 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1655 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1656 |
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
|
1657 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeChildData targetField, ActualParameter sourceParameter) { |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1658 TypeData type = sourceParameter.getTypeSystemType(); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1659 ExecutableTypeData execType = targetField.getNodeData().findExecutableType(type); |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1660 |
9231
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1661 /* |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1662 * FIXME Temporary deactivated due to partial evaluation failure else if |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1663 * (accessElement.getKind() == ElementKind.METHOD) { |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1664 * builder.startCall(accessElement.getSimpleName().toString()).end(); } |
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1665 */ |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1666 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
|
1667 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
|
1668 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
|
1669 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
|
1670 builder.string("this.").string(targetField.getName()); |
9231
ee3a9188c65e
Checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents:
9228
diff
changeset
|
1671 } 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
|
1672 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
|
1673 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1674 throw new AssertionError(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1675 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1676 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
|
1677 builder.string("[" + sourceParameter.getIndex() + "]"); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1678 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1679 builder.string("."); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1680 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1681 builder.startCall(execType.getMethodName()); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1682 if (execType.getParameters().size() == 1) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1683 builder.string("frameValue"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1684 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1685 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
|
1686 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1687 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1688 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1689 private CodeTree createShortCircuitTree(CodeTreeBuilder parent, CodeTree body, String targetVariableName, ExecutableTypeData currentExecutable, SpecializationData specialization, |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1690 ActualParameter parameter, ActualParameter exceptionParam) { |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1691 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
|
1692 |
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
|
1693 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
|
1694 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
|
1695 return body; |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1696 } |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1697 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1698 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
|
1699 return body; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1700 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1701 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1702 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
|
1703 |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1704 builder.tree(createShortCircuitValue(builder, currentExecutable, specialization, forField, shortCircuitParam, exceptionParam)); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1705 |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1706 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
|
1707 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
|
1708 builder.startBlock(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1709 builder.tree(body); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1710 builder.end(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1711 |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1712 return builder.getRoot(); |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1713 } |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1714 |
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
|
1715 private CodeTree createShortCircuitValue(CodeTreeBuilder parent, ExecutableTypeData currentExecutable, SpecializationData specialization, NodeChildData forField, |
9218
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1716 ActualParameter shortCircuitParam, ActualParameter exceptionParam) { |
797bb88bf004
Fixed evaluated execute generation for short circuit definitions.
Christian Humer <christian.humer@gmail.com>
parents:
9217
diff
changeset
|
1717 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
|
1718 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
|
1719 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
|
1720 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
|
1721 if (field == forField) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1722 break; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1723 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1724 shortCircuitIndex++; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1725 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1726 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1727 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1728 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
|
1729 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1730 builder.tree(createTemplateMethodCall(builder, currentExecutable, 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
|
1731 builder.end(); // statement |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1732 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1733 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1734 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1735 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1736 private CodeTree createReturnSpecializeAndExecute(CodeTreeBuilder parent, ExecutableTypeData executable, SpecializationData nextSpecialization, ActualParameter exceptionParam) { |
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
|
1737 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1738 specializeCall.startCall("specializeAndExecute"); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1739 specializeCall.string(nodeSpecializationClassName(nextSpecialization) + ".class"); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1740 addInternalValueParameterNames(specializeCall, executable, nextSpecialization.getNode().getGenericSpecialization(), exceptionParam != null ? exceptionParam.getLocalName() : null, true, |
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1741 true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1742 specializeCall.end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1743 |
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
|
1744 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1745 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
|
1746 builder.tree(createExpectType(nextSpecialization.getNode(), executable, specializeCall.getRoot())); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1747 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
|
1748 |
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
|
1749 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1750 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1751 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1752 private void buildSpecializeAndExecute(CodeTypeElement clazz, SpecializationData specialization) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1753 NodeData node = specialization.getNode(); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1754 TypeData returnType = node.getGenericSpecialization().getReturnType().getTypeSystemType(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1755 |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1756 CodeExecutableElement method = new CodeExecutableElement(modifiers(PRIVATE), returnType.getPrimitiveType(), "specializeAndExecute"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1757 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState")); |
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
|
1758 addInternalValueParameters(method, specialization.getNode().getGenericSpecialization(), true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1759 clazz.add(method); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1760 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1761 CodeTreeBuilder builder = method.createBuilder(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1762 |
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
|
1763 builder.tree(createDeoptimize(builder)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1764 emitSpecializationListeners(builder, specialization.getNode()); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1765 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1766 builder.startStatement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1767 builder.startCall("replace"); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1768 builder.startCall(factoryClassName(specialization.getNode()), "specialize").string("this").string("minimumState"); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1769 addInternalValueParameterNames(builder, specialization.getNode().getGenericSpecialization(), specialization.getNode().getGenericSpecialization(), null, true, true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1770 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1771 builder.end(); // call replace |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1772 builder.end(); // statement |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1773 |
8661
e0ff5cf358a4
Fixed when specializing nodes must always call the full generic case.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
1774 String generatedMethodName; |
e0ff5cf358a4
Fixed when specializing nodes must always call the full generic case.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
1775 if (specialization.getNode().getGenericSpecialization().isUseSpecializationsForGeneric()) { |
e0ff5cf358a4
Fixed when specializing nodes must always call the full generic case.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
1776 generatedMethodName = generatedGenericMethodName(null); |
e0ff5cf358a4
Fixed when specializing nodes must always call the full generic case.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
1777 } else { |
e0ff5cf358a4
Fixed when specializing nodes must always call the full generic case.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
1778 generatedMethodName = generatedGenericMethodName(specialization.findNextSpecialization()); |
e0ff5cf358a4
Fixed when specializing nodes must always call the full generic case.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
1779 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1780 ExecutableElement generatedGeneric = clazz.getEnclosingClass().getMethod(generatedMethodName); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1781 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1782 CodeTreeBuilder genericExecute = CodeTreeBuilder.createBuilder(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1783 genericExecute.startCall(factoryClassName(specialization.getNode()), generatedMethodName); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1784 genericExecute.string("this"); |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1785 addInternalValueParameterNames(genericExecute, specialization.getNode().getGenericSpecialization(), specialization.getNode().getGenericSpecialization(), null, true, true); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1786 genericExecute.end(); // call generated generic |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1787 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9215
diff
changeset
|
1788 CodeTree genericInvocation = genericExecute.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1789 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1790 if (generatedGeneric != null && Utils.isVoid(generatedGeneric.getReturnType())) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1791 builder.statement(genericInvocation); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1792 |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1793 if (!Utils.isVoid(builder.findMethod().asType())) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1794 builder.startReturn().defaultValue(returnType.getPrimitiveType()).end(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1795 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1796 } else { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1797 builder.startReturn().tree(genericInvocation).end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1798 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1799 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1800 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1801 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1802 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1803 } |