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