Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 8310:89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 15 Mar 2013 21:18:33 +0100 |
parents | 97ee911c4c74 |
children | 676fa31bd3f0 |
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.*; |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
37 import com.oracle.truffle.codegen.processor.node.NodeFieldData.ExecutionKind; |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
38 import com.oracle.truffle.codegen.processor.node.NodeFieldData.FieldKind; |
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 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
91 method.addParameter(new CodeVariableElement(parameter.getActualType(), 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 |
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
|
95 private static void addInternalValueParameterNames(CodeTreeBuilder builder, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame, boolean includeImplicit) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
96 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
|
97 builder.string("frameValue"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 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
|
100 ParameterSpec spec = parameter.getSpecification(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 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
|
102 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 |
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
|
105 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
|
106 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
|
107 } |
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 if (parameter.getSpecification().isLocal()) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
109 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
110 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
111 |
8310
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
112 if (unexpectedValueName != null && parameter.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
|
113 builder.cast(parameter.getActualType(), CodeTreeBuilder.singleString("ex.getResult()")); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 } 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
|
115 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
|
116 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 |
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
|
120 private CodeTree createTemplateMethodCall(CodeTreeBuilder parent, TemplateMethod target, TemplateMethod sourceMethod, TemplateMethod castMethod, String 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
|
121 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
|
122 |
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
|
123 boolean castedValues = sourceMethod != castMethod; |
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
|
124 |
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
|
125 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
|
126 ExecutableElement method = target.getMethod(); |
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
|
127 if (method == 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
|
128 throw new IllegalStateException("Cannot call synthtetic operation methods."); |
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
|
129 } |
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
|
130 TypeElement targetClass = Utils.findNearestEnclosingType(method.getEnclosingElement()); |
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
|
131 NodeData node = (NodeData) castMethod.getTemplate(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
132 TypeSystemData typeSystem = node.getTypeSystem(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
133 |
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
|
134 boolean accessible = target.canBeAccessedByInstanceOf(node.getNodeType()); |
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
|
135 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
|
136 if (builder.findMethod().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
|
137 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
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
|
138 } 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
|
139 builder.string("super"); |
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
|
140 } |
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 } 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
|
142 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
|
143 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
|
144 } 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
|
145 ActualParameter 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
|
146 for (ActualParameter searchParameter : target.getParameters()) { |
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 (!searchParameter.getSpecification().isOptional()) { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
148 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
|
149 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
|
150 } |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
151 } |
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
|
152 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
|
153 |
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 (castedValues) { |
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 NodeFieldData field = node.findField(parameter.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
|
156 if (field == 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
|
157 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
|
158 } 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
|
159 NodeData fieldNode = field.getNodeData(); |
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
|
160 ExecutableTypeData execType = fieldNode.findExecutableType(parameter.getActualTypeData(node.getTypeSystem())); |
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 if (execType.hasUnexpectedValue(getContext())) { |
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
|
162 builder.string(castValueName(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
|
163 } 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
|
164 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
|
165 } |
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
|
166 } |
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 } 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
|
168 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
|
169 } |
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 } |
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 } |
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 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
|
173 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
|
174 |
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 for (ActualParameter targetParameter : castMethod.getParameters()) { |
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 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
|
177 if (valueParameter == 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
|
178 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
|
179 } |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
180 TypeData targetType = targetParameter.getActualTypeData(typeSystem); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
181 |
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
|
182 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
|
183 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
184 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
185 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
186 TypeData valueType = null; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
187 if (valueParameter != null) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
188 valueType = valueParameter.getActualTypeData(typeSystem); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
189 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
190 |
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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 } 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
|
196 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
|
197 } |
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
|
198 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
|
199 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
|
200 } 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
|
201 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
|
202 } else if (targetType == null || targetType.isGeneric() || (valueType != null && valueType.equalsType(targetType))) { |
89006c76f737
Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents:
8277
diff
changeset
|
203 builder.string(valueName(targetParameter)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
204 } 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
|
205 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
|
206 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
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 |
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.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
|
210 |
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 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
213 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
214 private static String genClassName(Template operation) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
215 return getSimpleName(operation.getTemplateType()) + "Gen"; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
216 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
217 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
218 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
|
219 final String prefix = "generic"; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
220 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
221 if (specialization == null) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
222 return prefix; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
223 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
224 |
8277
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
225 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
|
226 return prefix; |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
227 } |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
228 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
229 SpecializationData prev = null; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
230 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
|
231 if (specialization == current) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
232 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
|
233 return prefix; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
234 } else { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
235 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
|
236 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
237 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
238 prev = current; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
239 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
240 return prefix; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
241 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
242 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
243 private static CodeTree createCallTypeSystemMethod(ProcessorContext context, CodeTreeBuilder parent, NodeData node, String methodName, String value) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
244 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
|
245 startCallTypeSystemMethod(context, builder, node, methodName); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
246 builder.string(value); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
247 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
|
248 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
|
249 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
250 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7502
diff
changeset
|
251 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
|
252 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
|
253 assert singleton != null; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
254 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
255 body.startGroup(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
256 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
|
257 body.string(".").startCall(methodName); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
259 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
260 private CodeTree createGuardAndCast(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization, boolean onSpecialization, |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
261 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
|
262 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
263 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
|
264 CodeTree implicitGuards = createImplicitGuards(parent, conditionPrefix, valueSpecialization, guardedSpecialization); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
265 CodeTree explicitGuards = createExplicitGuards(parent, implicitGuards == null ? conditionPrefix : null, valueSpecialization, guardedSpecialization, onSpecialization); |
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
|
266 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
267 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
|
268 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
276 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
277 if (explicitGuards != null || !onSpecialization) { |
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.tree(createCasts(parent, valueSpecialization, guardedSpecialization)); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
279 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
280 |
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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
288 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
289 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
|
290 builder.startIf(); |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 } |
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 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
296 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
|
297 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
302 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
|
303 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
304 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
305 private CodeTree createExplicitGuards(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization, boolean onSpecialization) { |
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
|
306 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
|
307 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
|
308 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
|
309 // Explicitly specified guards |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
310 for (SpecializationGuardData guard : guardedSpecialization.getGuards()) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7502
diff
changeset
|
311 if ((guard.isOnSpecialization() && onSpecialization) || (guard.isOnExecution() && !onSpecialization)) { |
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
|
312 builder.string(andOperator); |
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
|
313 builder.tree(createTemplateMethodCall(parent, guard.getGuardDeclaration(), valueSpecialization, guardedSpecialization, null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
314 andOperator = " && "; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
315 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
316 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
317 } |
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
|
318 |
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 return builder.isEmpty() ? null : builder.getRoot(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
320 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
321 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
322 private CodeTree createCasts(CodeTreeBuilder parent, 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
|
323 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
324 // 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
|
325 for (ActualParameter guardedParam : guardedSpecialization.getParameters()) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
326 NodeFieldData field = guardedSpecialization.getNode().findField(guardedParam.getSpecification().getName()); |
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
|
327 if (field == null || field.getKind() == FieldKind.FIELD) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
328 continue; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
329 } |
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
|
330 ActualParameter valueParam = valueSpecialization.findParameter(guardedParam.getLocalName()); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
331 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
332 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
|
333 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
|
334 continue; |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
335 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
336 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
|
337 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
338 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
339 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
|
340 } |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
341 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
342 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
|
343 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
|
344 // 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
|
345 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
|
346 for (ActualParameter guardedParam : guardedSpecialization.getParameters()) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
347 NodeFieldData field = guardedSpecialization.getNode().findField(guardedParam.getSpecification().getName()); |
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
|
348 if (field == null || field.getKind() == FieldKind.FIELD) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
349 continue; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
350 } |
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
|
351 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
|
352 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
353 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
|
354 if (implicitGuard == null) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
355 continue; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
356 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
357 |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
358 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
|
359 builder.tree(implicitGuard); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
360 andOperator = " && "; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
361 } |
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
|
362 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
363 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
|
364 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
365 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
366 private CodeTree createImplicitGuard(CodeTreeBuilder parent, NodeFieldData field, ActualParameter source, ActualParameter target) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
367 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
|
368 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
|
369 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
370 TypeData targetType = target.getActualTypeData(node.getTypeSystem()); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
371 TypeData sourceType = source.getActualTypeData(node.getTypeSystem()); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
372 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
373 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
|
374 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
|
375 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
376 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
377 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
|
378 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
386 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
387 startCallTypeSystemMethod(getContext(), builder, node, TypeSystemCodeGenerator.isTypeMethodName(target.getActualTypeData(node.getTypeSystem()))); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
388 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
|
389 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
|
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 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
|
392 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
|
393 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
394 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
395 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
|
396 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
397 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
|
398 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
399 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
400 private CodeTree createCast(CodeTreeBuilder parent, NodeFieldData field, ActualParameter source, ActualParameter target) { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
401 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
|
402 TypeSystemData typeSystem = node.getTypeSystem(); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
403 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
404 TypeData sourceType = source.getActualTypeData(typeSystem); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
405 TypeData targetType = target.getActualTypeData(typeSystem); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
406 |
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 (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
|
408 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
|
409 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
410 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
411 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
417 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
418 CodeTree value = createCallTypeSystemMethod(context, parent, node, TypeSystemCodeGenerator.asTypeMethodName(targetType), valueName(target)); |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
419 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
420 return createLazyAssignment(parent, castValueName(target), target.getActualType(), 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
|
421 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
422 |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
423 /** |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
424 * <pre> |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
425 * 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
|
426 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
427 * $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
|
428 * 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
|
429 * $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
|
430 * } |
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 * 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
|
433 * $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
|
434 * </pre> |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
435 * |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
436 * . |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
437 */ |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 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
|
442 } else { |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
443 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
|
444 |
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.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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
454 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
|
455 } |
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
456 |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
457 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
|
458 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
|
459 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
460 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
461 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
462 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
|
463 Map<NodeData, List<TypeElement>> childTypes = new LinkedHashMap<>(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
464 if (node.getDeclaredChildren() != null && !node.getDeclaredChildren().isEmpty()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
465 for (NodeData nodeChild : node.getDeclaredChildren()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
466 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
|
467 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
|
468 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
469 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
470 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
471 if (node.getExtensionElements() != null && !node.getExtensionElements().isEmpty()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
472 NodeGenFactory factory = new NodeGenFactory(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
473 add(factory, node); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
474 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
475 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
476 if (node.needsFactory() || node.getNodeChildren().size() > 0) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
477 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
|
478 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
479 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
480 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
481 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
|
482 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
483 public NodeGenFactory(ProcessorContext context) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
484 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
485 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
486 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
487 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
488 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
|
489 CodeTypeElement clazz = createClass(node, modifiers(PUBLIC, ABSTRACT), genClassName(node), node.getTemplateType().asType(), false); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
490 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
491 for (ExecutableElement executable : ElementFilter.constructorsIn(node.getTemplateType().getEnclosedElements())) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
492 CodeExecutableElement superConstructor = createSuperConstructor(clazz, executable); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
493 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
494 if (superConstructor != null) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7502
diff
changeset
|
495 if (superConstructor.getParameters().size() == 1 && Utils.typeEquals(superConstructor.getParameters().get(0).asType(), node.getTemplateType().asType())) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
496 String originalName = superConstructor.getParameters().get(0).getSimpleName().toString(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
497 superConstructor.getParameters().clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
498 superConstructor.getParameters().add(new CodeVariableElement(clazz.asType(), originalName)); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
499 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
500 clazz.add(superConstructor); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
501 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
502 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
503 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
504 if (node.getExtensionElements() != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
505 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
|
506 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
507 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
508 node.setNodeType(clazz.asType()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
509 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
510 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
511 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
512 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
513 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
514 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
515 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
|
516 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
517 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
|
518 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
519 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
|
520 super(context); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
521 this.childTypes = childElements; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
522 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
523 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
524 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
529 clazz.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
530 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
531 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
|
532 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
|
533 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
534 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
535 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
536 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
537 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
|
538 CodeTypeElement clazz = getElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
539 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
540 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
|
541 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
542 if (node.needsFactory()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
543 createFactoryMethods(node, clazz, createVisibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
544 |
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
|
545 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
|
546 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
|
547 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
548 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
549 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
|
550 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
|
551 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
552 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
553 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
|
554 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
|
555 for (CodeExecutableElement method : genericMethods) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
556 clazz.add(method); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
557 } |
7502
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 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
560 for (SpecializationData specialization : node.getSpecializations()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
561 add(new SpecializedNodeFactory(context), specialization); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
562 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
563 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
564 TypeMirror nodeFactory = getContext().getEnvironment().getTypeUtils().getDeclaredType(Utils.fromTypeMirror(getContext().getType(NodeFactory.class)), node.getNodeType()); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
565 clazz.getImplements().add(nodeFactory); |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
566 clazz.add(createCreateNodeMethod(node)); |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
567 clazz.add(createCreateNodeSpecializedMethod(node)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
568 clazz.add(createGetNodeClassMethod(node)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
569 clazz.add(createGetNodeSignaturesMethod(node)); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
570 clazz.add(createGetChildrenSignatureMethod(node)); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
571 clazz.add(createGetInstanceMethod(node, createVisibility)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
572 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
|
573 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
574 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
575 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
|
576 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
|
577 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
578 } |
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 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
|
581 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
|
582 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
|
583 typeModifiers.clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
584 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
585 typeModifiers.add(visibility); |
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 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
588 typeModifiers.add(Modifier.STATIC); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
589 typeModifiers.add(Modifier.FINAL); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
590 clazz.add(type); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
591 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
592 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
593 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
594 List<NodeData> children = node.getNodeChildren(); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
595 if (node.getParent() == null && children.size() > 0) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
596 clazz.add(createGetFactories(node)); |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
597 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
598 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
599 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
600 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
601 private CodeExecutableElement createGetNodeClassMethod(NodeData node) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
602 Types types = getContext().getEnvironment().getTypeUtils(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
603 TypeMirror returnType = types.getDeclaredType(Utils.fromTypeMirror(getContext().getType(Class.class)), node.getNodeType()); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
604 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
|
605 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
606 builder.startReturn().typeLiteral(node.getNodeType()).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
607 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
608 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
609 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
610 private CodeExecutableElement createGetNodeSignaturesMethod(NodeData node) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
611 Types types = getContext().getEnvironment().getTypeUtils(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
612 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
|
613 TypeMirror classType = getContext().getType(Class.class); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
614 TypeMirror returnType = types.getDeclaredType(listType, types.getDeclaredType(listType, classType)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
615 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
|
616 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
617 builder.startReturn(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
618 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
|
619 List<ExecutableElement> constructors = findUserConstructors(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
620 for (ExecutableElement constructor : constructors) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
621 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
|
622 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
623 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
624 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
625 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
626 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
627 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
628 private CodeExecutableElement createGetChildrenSignatureMethod(NodeData node) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
629 Types types = getContext().getEnvironment().getTypeUtils(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
630 TypeElement listType = Utils.fromTypeMirror(getContext().getType(List.class)); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
631 TypeMirror classType = getContext().getType(Class.class); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
632 TypeMirror nodeType = getContext().getTruffleTypes().getNode(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
633 TypeMirror wildcardNodeType = types.getWildcardType(nodeType, null); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
634 classType = types.getDeclaredType(Utils.fromTypeMirror(classType), wildcardNodeType); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
635 TypeMirror returnType = types.getDeclaredType(listType, classType); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
636 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
637 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
|
638 CodeTreeBuilder builder = method.createBuilder(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
639 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
640 List<TypeMirror> signatureTypes = new ArrayList<>(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
641 assert !node.getSpecializations().isEmpty(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
642 SpecializationData data = node.getSpecializations().get(0); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
643 for (ActualParameter parameter : data.getParameters()) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
644 ParameterSpec spec = parameter.getSpecification(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
645 NodeFieldData field = node.findField(spec.getName()); |
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
|
646 if (field == null || field.getKind() == FieldKind.FIELD) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
647 continue; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
648 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
649 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
650 TypeMirror type; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
651 if (field.getKind() == FieldKind.CHILDREN && field.getType().getKind() == TypeKind.ARRAY) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
652 type = ((ArrayType) field.getType()).getComponentType(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
653 } else { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
654 type = field.getType(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
655 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
656 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
657 signatureTypes.add(type); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
658 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
659 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
660 builder.startReturn().tree(createAsList(builder, signatureTypes, classType)).end(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
661 return method; |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
662 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
663 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
664 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
|
665 CodeTreeBuilder builder = parent.create(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
666 builder.startGroup(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
667 builder.type(getContext().getType(Arrays.class)); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
668 builder.string(".<").type(elementClass).string(">"); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
669 builder.startCall("asList"); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
670 for (TypeMirror typeMirror : types) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
671 builder.typeLiteral(typeMirror); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
672 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
673 builder.end().end(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
674 return builder.getRoot(); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
675 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
676 |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
677 private CodeExecutableElement createCreateNodeMethod(NodeData node) { |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
678 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
|
679 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
|
680 method.setVarArgs(true); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
681 method.addParameter(arguments); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
682 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
683 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
684 List<ExecutableElement> signatures = findUserConstructors(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
685 boolean ifStarted = false; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
686 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
687 for (ExecutableElement element : signatures) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
688 ifStarted = builder.startIf(ifStarted); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
689 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
|
690 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
691 int index = 0; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
692 for (VariableElement param : element.getParameters()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
693 builder.string(" && "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
694 if (!param.asType().getKind().isPrimitive()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
695 builder.string("(arguments[" + index + "] == null || "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
696 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
697 builder.string("arguments[" + index + "] instanceof "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
698 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
|
699 if (!param.asType().getKind().isPrimitive()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
700 builder.string(")"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
701 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
702 index++; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
703 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
704 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
705 builder.startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
706 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
707 builder.startReturn().startCall("create"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
708 index = 0; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
709 for (VariableElement param : element.getParameters()) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
710 builder.startGroup(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
711 builder.string("(").type(param.asType()).string(") "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
712 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
|
713 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
714 index++; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
715 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
716 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
717 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
718 builder.end(); // block |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
719 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
720 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
721 builder.startElseBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
722 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
|
723 builder.doubleQuote("Invalid create signature."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
724 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
725 builder.end(); // else block |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
726 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
727 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
728 |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
729 private CodeExecutableElement createCreateNodeSpecializedMethod(NodeData node) { |
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7858
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 method.addParameter(nodeParam); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
734 method.addParameter(arguments); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
735 method.setVarArgs(true); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
736 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
737 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
738 if (!node.needsRewrites(getContext())) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
739 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
|
740 } else { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
741 builder.startIf(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
742 builder.string("types.length == 1"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
743 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
744 builder.startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
745 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
746 builder.startReturn().startCall("createSpecialized"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
747 builder.string("thisNode"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
748 builder.string("types[0]"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
749 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
750 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
751 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
752 builder.startElseBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
753 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
|
754 builder.doubleQuote("Invalid createSpecialized signature."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
755 builder.end().end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
756 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
757 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
758 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
759 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
760 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
761 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
762 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
763 Types types = getContext().getEnvironment().getTypeUtils(); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
764 TypeElement nodeFactoryType = Utils.fromTypeMirror(getContext().getType(NodeFactory.class)); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
765 TypeMirror returnType = types.getDeclaredType(nodeFactoryType, node.getNodeType()); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
766 |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
767 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
|
768 if (visibility != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
769 method.getModifiers().add(visibility); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
770 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
771 method.getModifiers().add(Modifier.STATIC); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
772 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
773 String varName = instanceVarName(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
774 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
775 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
776 builder.startIf(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
777 builder.string(varName).string(" == null"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
778 builder.end().startBlock(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
779 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
780 builder.startStatement(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
781 builder.string(varName); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
782 builder.string(" = "); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
783 builder.startNew(factoryClassName(node)).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
784 builder.end(); |
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 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
787 builder.startReturn().string(varName).end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
788 return method; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
789 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
790 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
791 private String instanceVarName(NodeData node) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
792 if (node.getParent() != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
793 return Utils.firstLetterLowerCase(factoryClassName(node)) + "Instance"; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
794 } else { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
795 return "instance"; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
796 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
797 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
798 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
799 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
|
800 String varName = instanceVarName(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
801 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
|
802 var.getModifiers().add(Modifier.PRIVATE); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
803 var.getModifiers().add(Modifier.STATIC); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
804 return var; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
805 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
806 |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
807 private ExecutableElement createGetFactories(NodeData node) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
808 List<NodeData> children = node.getNodeChildren(); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
809 if (node.needsFactory()) { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
810 children.add(node); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
811 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
812 |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
813 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
|
814 TypeMirror prev = null; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
815 boolean allSame = true; |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
816 for (NodeData child : children) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
817 nodeTypesList.add(child.getNodeType()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
818 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
|
819 allSame = false; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
820 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
821 prev = child.getNodeType(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
822 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
823 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
|
824 |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
825 Types types = getContext().getEnvironment().getTypeUtils(); |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
826 TypeMirror factoryType = getContext().getType(NodeFactory.class); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
827 TypeMirror baseType; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
828 if (allSame) { |
7858
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
829 baseType = types.getDeclaredType(Utils.fromTypeMirror(factoryType), commonNodeSuperType); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
830 } else { |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
831 baseType = types.getDeclaredType(Utils.fromTypeMirror(factoryType), types.getWildcardType(commonNodeSuperType, null)); |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
832 } |
4958cbdbf360
Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7855
diff
changeset
|
833 TypeMirror listType = types.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
|
834 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
835 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
|
836 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
837 CodeTreeBuilder builder = method.createBuilder(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
838 builder.startReturn(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
839 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
|
840 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
841 for (NodeData child : children) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
842 builder.startGroup(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
843 NodeData childNode = child; |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
844 List<NodeData> factories = new ArrayList<>(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
845 while (childNode.getParent() != null) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
846 factories.add(childNode); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
847 childNode = childNode.getParent(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
848 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
849 Collections.reverse(factories); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
850 for (NodeData nodeData : factories) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
851 builder.string(factoryClassName(nodeData)).string("."); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
852 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
853 builder.string("getInstance()"); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
854 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
855 } |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
856 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
857 builder.end(); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
858 return method; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
859 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
860 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
861 private void createFactoryMethods(NodeData node, CodeTypeElement clazz, Modifier createVisibility) { |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
862 List<ExecutableElement> constructors = findUserConstructors(node); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
863 for (ExecutableElement constructor : constructors) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
864 clazz.add(createCreateMethod(node, createVisibility, constructor)); |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
865 } |
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 |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
868 private List<ExecutableElement> findUserConstructors(NodeData node) { |
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
869 List<ExecutableElement> constructors = new ArrayList<>(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
870 for (ExecutableElement constructor : ElementFilter.constructorsIn(Utils.fromTypeMirror(node.getNodeType()).getEnclosedElements())) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
871 if (constructor.getModifiers().contains(PRIVATE)) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
872 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
873 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
874 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
875 // skip node rewrite constructor |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7502
diff
changeset
|
876 if (constructor.getParameters().size() == 1 && typeEquals(constructor.getParameters().get(0).asType(), node.getNodeType())) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
877 continue; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
878 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
879 constructors.add(constructor); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
880 } |
7855
6e4fb0ccebb1
Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents:
7847
diff
changeset
|
881 return constructors; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
882 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
883 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
884 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
|
885 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
|
886 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
|
887 method.getModifiers().clear(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
888 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
889 method.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
890 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
891 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
|
892 method.setReturnType(node.getNodeType()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
893 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
894 CodeTreeBuilder body = method.createBuilder(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
895 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
|
896 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
|
897 body.null_(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
898 } else { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
899 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
|
900 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
|
901 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
|
902 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
903 body.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
904 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
905 body.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
906 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
907 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
908 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
909 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
|
910 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
|
911 if (visibility != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
912 method.getModifiers().add(visibility); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
913 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
914 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
|
915 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
916 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
|
917 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
|
918 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
919 CodeTreeBuilder body = method.createBuilder(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
920 boolean first = true; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
921 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
|
922 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
|
923 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
|
924 if (first) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
925 body.startIf(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
926 first = false; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
927 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
928 body.startElseIf(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
929 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
930 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
|
931 body.startReturn().startNew(nodeSpecializationClassName(specialization)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
932 body.string(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
|
933 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
|
934 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
935 body.end(); // if |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
936 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
937 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
938 body.startReturn().startNew(nodeSpecializationClassName(node.getGenericSpecialization())); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
939 body.string(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
|
940 body.end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
941 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
942 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
943 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
944 private CodeExecutableElement createSpecializeMethod(NodeData node) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
945 CodeExecutableElement method = new CodeExecutableElement(modifiers(PRIVATE, STATIC), node.getNodeType(), "specialize"); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
946 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
|
947 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
|
948 addInternalValueParameters(method, node.getGenericSpecialization(), false); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
949 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
950 CodeTreeBuilder body = method.createBuilder(); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
951 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
|
952 |
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
|
953 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
|
954 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
|
955 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
|
956 |
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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
962 body.tree(createGuardAndCast(body, "allowed", node.getGenericSpecialization(), specialization, true, guarded.getRoot(), null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
963 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
964 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
|
965 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
966 return method; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
967 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
968 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
969 private List<CodeExecutableElement> createGeneratedGenericMethod(NodeData node) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
970 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getActualType(); |
8277
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
971 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
|
972 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
|
973 |
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
|
974 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
|
975 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
|
976 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
|
977 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
|
978 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
|
979 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
|
980 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
|
981 continue; |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
982 } else { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
983 String methodName = generatedGenericMethodName(current); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
984 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
|
985 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
|
986 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
|
987 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
988 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
|
989 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
990 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
|
991 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
992 prev = current; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
993 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
994 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
995 return methods; |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
996 } else { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
997 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
|
998 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
|
999 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
|
1000 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
|
1001 return Arrays.asList(method); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1002 } |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1003 } |
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
|
1004 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1010 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
|
1011 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
|
1012 |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1013 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
|
1014 nextBuilder.string(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
|
1015 addInternalValueParameterNames(nextBuilder, 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
|
1016 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
|
1017 |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1018 invokeMethod = createGuardAndCast(builder, null, current.getNode().getGenericSpecialization(), current, false, invokeMethod, nextBuilder.getRoot()); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1019 } |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1020 |
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
|
1021 builder.tree(invokeMethod); |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1022 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1023 if (next != null) { |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1024 builder.end(); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1025 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1026 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1027 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1028 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
|
1029 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
|
1030 builder.startTryBlock(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1031 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1032 |
8256 | 1033 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
|
1034 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
|
1035 } else { |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1036 builder.startReturn(); |
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
|
1037 builder.tree(createTemplateMethodCall(builder, specialization, 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
|
1038 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
|
1039 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1040 |
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
|
1041 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
|
1042 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
|
1043 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
|
1044 |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1045 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
|
1046 builder.string(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
|
1047 addInternalValueParameterNames(builder, 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
|
1048 builder.end().end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1049 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1050 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1051 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1052 } |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
1053 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1054 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1055 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1056 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
|
1057 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1058 public SpecializedNodeFactory(ProcessorContext context) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1059 super(context); |
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 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1062 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1063 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
|
1064 NodeData node = specialization.getNode(); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1065 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), node.getNodeType(), false); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1066 return clazz; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1067 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1068 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1069 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1070 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
|
1071 CodeTypeElement clazz = getElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1072 NodeData node = specialization.getNode(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1073 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1074 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
|
1075 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
|
1076 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
|
1077 if (superConstructor != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1078 clazz.add(superConstructor); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1079 } |
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 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1082 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
|
1083 if (execType.isFinal()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1084 continue; |
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 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), execType.getMethod()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1087 if (method.getParameters().size() == 1) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1088 CodeVariableElement var = CodeVariableElement.clone(method.getParameters().get(0)); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1089 var.setName("frameValue"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1090 method.getParameters().set(0, var); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1091 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1092 method.getModifiers().remove(Modifier.ABSTRACT); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1093 clazz.add(method); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1094 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1095 TypeData primaryType = specialization.getReturnType().getActualTypeData(node.getTypeSystem()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1096 if (primaryType == execType.getType()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1097 buildFunctionalExecuteMethod(method.createBuilder(), specialization); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1098 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1099 buildCastingExecuteMethod(method.createBuilder(), specialization, execType.getType()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1100 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1101 } |
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 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
|
1104 buildSpecializeAndExecute(clazz, specialization); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1105 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1106 } |
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 private void buildCastingExecuteMethod(CodeTreeBuilder builder, SpecializationData specialization, TypeData type) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1109 NodeData node = specialization.getNode(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1110 TypeSystemData typeSystem = node.getTypeSystem(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1111 |
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
|
1112 ExecutableTypeData castedType = node.findExecutableType(type); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1113 TypeData primaryType = specialization.getReturnType().getActualTypeData(typeSystem); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1114 ExecutableTypeData execType = specialization.getNode().findExecutableType(primaryType); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1115 |
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
|
1116 boolean needsTry = execType.hasUnexpectedValue(getContext()); |
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
|
1117 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
|
1118 |
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
|
1119 CodeTree primaryExecuteCall = null; |
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
|
1120 |
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
|
1121 CodeTreeBuilder executeBuilder = CodeTreeBuilder.createBuilder(); |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1122 buildExecute(executeBuilder, null, null, execType); |
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
|
1123 primaryExecuteCall = executeBuilder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1124 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1125 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
|
1126 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
|
1127 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
|
1128 } |
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
|
1129 builder.startTryBlock(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1130 |
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
|
1131 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
|
1132 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
|
1133 } 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
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1139 |
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
|
1140 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
|
1141 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
|
1142 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
|
1143 } 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
|
1144 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
|
1145 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
|
1146 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
|
1147 } |
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
|
1148 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1149 |
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
|
1150 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
|
1151 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
|
1152 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
|
1153 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
|
1154 } |
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
|
1155 } 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
|
1156 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
|
1157 builder.statement(primaryExecuteCall); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1158 } 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
|
1159 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
|
1160 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
|
1161 builder.end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1162 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1163 } |
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
|
1164 } |
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
|
1165 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1166 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
|
1167 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
|
1168 return value; |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1169 } else if (castedType.getType().isVoid()) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1170 return value; |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1171 } 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
|
1172 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
|
1173 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1174 |
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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 } 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
|
1180 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
|
1181 } |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1182 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
|
1183 |
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
|
1184 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
|
1185 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
|
1186 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1187 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1188 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1189 private void buildFunctionalExecuteMethod(CodeTreeBuilder builder, SpecializationData specialization) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1190 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
|
1191 builder.tree(createDeoptimize(builder)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1192 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
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(createExecuteChildren(builder, specialization)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1195 |
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
|
1196 if (specialization.isUninitialized()) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1197 builder.tree(createSpecializeCall(builder, specialization)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1198 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1199 |
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
|
1200 CodeTree executeNode = createExecute(builder, specialization); |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1201 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1202 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
|
1203 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
|
1204 if (next != 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
|
1205 returnSpecialized = createReturnSpecializeAndExecute(builder, next, 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
|
1206 } |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1207 builder.tree(createGuardAndCast(builder, null, specialization, specialization, false, executeNode, returnSpecialized)); |
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
|
1208 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1209 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1210 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
|
1211 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
|
1212 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
|
1213 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
|
1214 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
|
1215 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
|
1216 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1217 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1218 private CodeTree createSpecializeCall(CodeTreeBuilder parent, SpecializationData specialization) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1219 NodeData node = specialization.getNode(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1220 |
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
|
1221 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
|
1222 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
|
1223 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 builder.typeLiteral(builder.findMethod().getEnclosingElement().asType()); |
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
|
1230 addInternalValueParameterNames(builder, specialization, null, false, 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
|
1231 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
|
1232 } 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
|
1233 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
|
1234 } |
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
|
1235 builder.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
|
1236 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
|
1237 } |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1238 |
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
|
1239 private CodeTree createExecute(CodeTreeBuilder parent, SpecializationData specialization) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1240 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
|
1241 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
|
1242 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
|
1243 builder.startTryBlock(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1244 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1245 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1246 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
|
1247 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
|
1248 } else if (specialization.isUninitialized() || specialization.isGeneric()) { |
8277
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1249 String genericMethodName; |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1250 if (!specialization.isUseSpecializationsForGeneric()) { |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1251 genericMethodName = generatedGenericMethodName(specialization); |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1252 } else { |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1253 genericMethodName = generatedGenericMethodName(null); |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1254 } |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1255 |
97ee911c4c74
Fixed behaviour of useSpecializations for Generic specializations.
Christian Humer <christian.humer@gmail.com>
parents:
8256
diff
changeset
|
1256 builder.startReturn().startCall(factoryClassName(node), genericMethodName); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1257 builder.string("this"); |
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
|
1258 addInternalValueParameterNames(builder, specialization, null, true, true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1259 builder.end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1260 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1261 builder.startReturn(); |
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
|
1262 builder.tree(createTemplateMethodCall(builder, specialization, specialization, specialization, null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1263 builder.end(); // return |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1264 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1265 |
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
|
1266 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
|
1267 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
|
1268 builder.end().startCatchBlock(exception.getJavaClass(), "ex"); |
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
|
1269 builder.tree(createReturnSpecializeAndExecute(parent, exception.getTransitionTo(), null)); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1270 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1271 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1272 } |
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
|
1273 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
|
1274 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1275 |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1276 private CodeTree createExecuteChildren(CodeTreeBuilder parent, SpecializationData specialization) { |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1277 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
|
1278 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1279 for (ActualParameter parameter : specialization.getParameters()) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1280 NodeFieldData field = specialization.getNode().findField(parameter.getSpecification().getName()); |
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
|
1281 if (field == null || field.getKind() == FieldKind.FIELD) { |
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
|
1282 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
|
1283 } |
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1284 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1285 buildFieldExecute(builder, specialization, parameter, field, null); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1286 } |
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
|
1287 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1288 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1289 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1290 private void emitSpecializationListeners(CodeTreeBuilder builder, NodeData node) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1291 for (TemplateMethod listener : node.getSpecializationListeners()) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1292 builder.startStatement(); |
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
|
1293 builder.tree(createTemplateMethodCall(builder, listener, listener, listener, null)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1294 builder.end(); // statement |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1295 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1296 } |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1297 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1298 private void buildFieldExecute(CodeTreeBuilder builder, SpecializationData specialization, ActualParameter param, NodeFieldData field, ActualParameter exceptionParam) { |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1299 boolean shortCircuit = startShortCircuit(builder, specialization, param, exceptionParam); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1300 ExecutableTypeData execType = field.getNodeData().findExecutableType(param.getActualTypeData(field.getNodeData().getTypeSystem())); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1301 boolean unexpected = execType.hasUnexpectedValue(getContext()); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1302 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1303 if (!shortCircuit && unexpected) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1304 builder.startStatement().type(param.getActualType()).string(" ").string(valueName(param)).end(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1305 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1306 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1307 if (unexpected) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1308 builder.startTryBlock(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1309 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1310 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1311 if (!shortCircuit && !unexpected) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1312 builder.startStatement().type(param.getActualType()).string(" ").string(valueName(param)).string(" = "); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1313 } else { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1314 builder.startStatement().string(valueName(param)).string(" = "); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1315 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1316 buildExecute(builder, param, field, execType); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1317 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1318 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1319 if (unexpected) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1320 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1321 SpecializationData generic = specialization.getNode().getGenericSpecialization(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1322 boolean execute = false; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1323 for (ActualParameter exParam : generic.getParameters()) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1324 NodeFieldData exField = generic.getNode().findField(exParam.getSpecification().getName()); |
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
|
1325 if (exField == null || field.getKind() == FieldKind.FIELD) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1326 continue; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1327 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1328 if (execute) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1329 buildFieldExecute(builder, specialization.getNode().getGenericSpecialization(), exParam, exField, 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
|
1330 } else if (exParam.getLocalName().equals(param.getLocalName())) { |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1331 execute = true; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1332 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1333 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1334 builder.tree(createReturnSpecializeAndExecute(builder, specialization.findNextSpecialization(), param)); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1335 builder.end(); // catch block |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1336 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1337 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1338 endShortCircuit(builder, shortCircuit); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1339 builder.newLine(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1340 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1341 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1342 private void buildExecute(CodeTreeBuilder builder, ActualParameter parameter, NodeFieldData field, ExecutableTypeData execType) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1343 if (field != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1344 Element accessElement = field.getAccessElement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1345 if (accessElement.getKind() == ElementKind.METHOD) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1346 builder.startCall(accessElement.getSimpleName().toString()).end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1347 } else if (accessElement.getKind() == ElementKind.FIELD) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1348 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
|
1349 } else { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1350 throw new AssertionError(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1351 } |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1352 if (parameter.getSpecification().isIndexed()) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1353 builder.string("[" + parameter.getIndex() + "]"); |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1354 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1355 builder.string("."); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1356 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1357 builder.startCall(execType.getMethodName()); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1358 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
|
1359 builder.string("frameValue"); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1360 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1361 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1362 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1363 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1364 private boolean startShortCircuit(CodeTreeBuilder builder, SpecializationData specialization, ActualParameter parameter, ActualParameter exceptionParam) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1365 NodeFieldData forField = specialization.getNode().findField(parameter.getSpecification().getName()); |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1366 if (forField == null) { |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1367 return false; |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1368 } |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1369 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1370 if (forField.getExecutionKind() != ExecutionKind.SHORT_CIRCUIT) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1371 return false; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1372 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1373 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1374 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
|
1375 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1376 int shortCircuitIndex = 0; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1377 for (NodeFieldData field : specialization.getNode().getFields()) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1378 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
|
1379 if (field == forField) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1380 break; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1381 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1382 shortCircuitIndex++; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1383 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1384 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1385 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1386 builder.startStatement().type(shortCircuitParam.getActualType()).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
|
1387 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1388 |
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
|
1389 builder.tree(createTemplateMethodCall(builder, shortCircuitData, shortCircuitData, 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
|
1390 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1391 builder.end(); // statement |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1392 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1393 builder.declaration(parameter.getActualType(), valueName(parameter), CodeTreeBuilder.createBuilder().defaultValue(parameter.getActualType())); |
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
|
1394 builder.startIf().string(shortCircuitParam.getLocalName()).end(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1395 builder.startBlock(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1396 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1397 return true; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1398 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1399 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1400 private void endShortCircuit(CodeTreeBuilder builder, boolean shortCircuit) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1401 if (shortCircuit) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1402 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1403 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1404 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1405 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1406 private CodeTree createReturnSpecializeAndExecute(CodeTreeBuilder parent, 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
|
1407 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1408 specializeCall.startCall("specializeAndExecute"); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
1409 specializeCall.string(nodeSpecializationClassName(nextSpecialization) + ".class"); |
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
|
1410 addInternalValueParameterNames(specializeCall, nextSpecialization.getNode().getGenericSpecialization(), exceptionParam != null ? exceptionParam.getLocalName() : null, true, true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1411 specializeCall.end().end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1412 |
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
|
1413 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1414 builder.startReturn(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1415 builder.tree(specializeCall.getRoot()); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1416 builder.end(); |
7846
91cc98eae8ee
Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents:
7845
diff
changeset
|
1417 return builder.getRoot(); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1418 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1419 |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
1420 private void buildSpecializeAndExecute(CodeTypeElement clazz, SpecializationData specialization) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1421 NodeData node = specialization.getNode(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1422 TypeData returnType = specialization.getReturnType().getActualTypeData(node.getTypeSystem()); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1423 ExecutableTypeData returnExecutableType = node.findExecutableType(returnType); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1424 boolean canThrowUnexpected = returnExecutableType == null ? true : returnExecutableType.hasUnexpectedValue(getContext()); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1425 |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1426 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
|
1427 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState")); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1428 if (canThrowUnexpected) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1429 method.addThrownType(getUnexpectedValueException()); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1430 } |
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
|
1431 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
|
1432 clazz.add(method); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1433 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1434 CodeTreeBuilder builder = method.createBuilder(); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1435 |
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
|
1436 builder.tree(createDeoptimize(builder)); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1437 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
|
1438 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1439 builder.startStatement(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1440 builder.startCall("replace"); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1441 builder.startCall(factoryClassName(specialization.getNode()), "specialize").string("this").string("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
|
1442 addInternalValueParameterNames(builder, specialization.getNode().getGenericSpecialization(), null, false, true); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1443 builder.end(); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1444 builder.end(); // call replace |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1445 builder.end(); // statement |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1446 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1447 String generatedMethodName = generatedGenericMethodName(specialization.findNextSpecialization()); |
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1448 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
|
1449 |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1450 CodeTreeBuilder genericExecute = CodeTreeBuilder.createBuilder(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1451 genericExecute.startCall(factoryClassName(specialization.getNode()), generatedMethodName); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1452 genericExecute.string("this"); |
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
|
1453 addInternalValueParameterNames(genericExecute, specialization.getNode().getGenericSpecialization(), null, true, true); |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1454 genericExecute.end(); // call generated generic |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1455 |
7847
06a7cd6aaf00
Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents:
7846
diff
changeset
|
1456 CodeTree genericInvocation = createExpectType(node, returnExecutableType, genericExecute.getRoot()); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1457 |
7777
ca51efac4d57
Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents:
7751
diff
changeset
|
1458 if (generatedGeneric != null && Utils.isVoid(generatedGeneric.getReturnType())) { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1459 builder.statement(genericInvocation); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1460 |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1461 if (!Utils.isVoid(builder.findMethod().asType())) { |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1462 builder.startReturn().defaultValue(returnType.getPrimitiveType()).end(); |
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1463 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1464 } else { |
7843
4969921f57b7
Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents:
7799
diff
changeset
|
1465 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
|
1466 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1467 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1468 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1469 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1470 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1471 } |