annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 7858:4958cbdbf360

Fixed minor bugs in NodeFactory generation.
author Christian Humer <christian.humer@gmail.com>
date Mon, 25 Feb 2013 14:22:18 +0100
parents 6e4fb0ccebb1
children 3c68170fc9b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.*;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 import com.oracle.truffle.codegen.processor.node.NodeFieldData.ExecutionKind;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 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
39 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
40
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 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
42
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 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
44
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 public NodeCodeGenerator(ProcessorContext context) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 super(context);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 }
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 private TypeMirror getUnexpectedValueException() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 return getContext().getTruffleTypes().getUnexpectedValueException();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 private static String factoryClassName(NodeData node) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 return nodeClassName(node) + "Factory";
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 private static String nodeClassName(NodeData node) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 return Utils.getSimpleName(node.getTemplateType().asType());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 private static String nodeClassName(SpecializationData specialization) {
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
62 String name = specializationId(specialization);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
63 name += nodeClassName(specialization.getNode());
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
64 if (name.equals(Utils.getSimpleName(specialization.getNode().getNodeType())) || name.equals(Utils.getSimpleName(specialization.getNode().getTemplateType()))) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
65 name = name + "Impl";
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
66 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
67
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
68 return name;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
69 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
70
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
71 private static String specializationId(SpecializationData specialization) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 String name = "";
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
73 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
74 if (node.getSpecializations().length > 1) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 name = specialization.getMethodName();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 if (name.startsWith("do")) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 name = name.substring(2);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 return name;
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 private static String valueName(NodeFieldData field) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 return field.getName() + "Value";
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
87 private static String valueName(ActualParameter param) {
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
88 NodeData node = (NodeData) param.getMethod().getTemplate();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 NodeFieldData field = node.findField(param.getSpecification().getName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 if (field != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 return valueName(field);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 return param.getSpecification().getName();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
97 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
98 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
99 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
100
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
101 private static String castValueName(NodeFieldData field) {
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
102 return valueName(field) + "Cast";
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
103 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
104
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 private void addValueParameters(CodeExecutableElement method, TemplateMethod specialization, boolean forceFrame) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 if (forceFrame) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frame"));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 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
110 ParameterSpec spec = parameter.getSpecification();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 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
112 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113 }
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
114 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
115 }
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 private static void addValueParameterNames(CodeTreeBuilder builder, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 if (forceFrame) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 builder.string("frame");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122 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
123 ParameterSpec spec = parameter.getSpecification();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 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
125 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
128 if (unexpectedValueName != null && spec.getName().equals(unexpectedValueName)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 builder.string("ex.getResult()");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 } 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
131 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
132 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
133 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
135
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
136 private static void addValueParameterNamesWithCasts(CodeTreeBuilder body, SpecializationData valueSpecialization, SpecializationData targetSpecialization) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
137 NodeData node = targetSpecialization.getNode();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
138 TypeSystemData typeSystem = node.getTypeSystem();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
139
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
140 for (ActualParameter targetParameter : targetSpecialization.getParameters()) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
141 ActualParameter valueParameter = valueSpecialization.findParameter(targetParameter.getSpecification().getName());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
142 TypeData targetType = targetParameter.getActualTypeData(typeSystem);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
143
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
144 TypeData valueType = null;
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
145 if (valueParameter != null) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
146 valueType = valueParameter.getActualTypeData(typeSystem);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
147 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
148
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
149 if (targetType == null || targetType.isGeneric() || (valueType != null && valueType.equalsType(targetType))) {
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
150 body.string(valueName(targetParameter));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 } 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
152 body.string(castValueName(targetParameter));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
154 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 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
158 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
159 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
160
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
161 private static void startCallOperationMethod(CodeTreeBuilder body, TemplateMethod method) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
162 body.startGroup();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163 if (body.findMethod().getModifiers().contains(STATIC)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 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
165 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 body.string("super");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168 body.string(".");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169 body.startCall(method.getMethodName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
171
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
172 private static String generatedGenericMethodName(SpecializationData specialization) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
173 final String prefix = "generic";
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
174
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
175 if (specialization == null) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
176 return prefix;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
177 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
178
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
179 SpecializationData prev = null;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
180 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
181 if (specialization == current) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
182 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
183 return prefix;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
184 } else {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
185 return prefix + specializationId(current);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
186 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
187 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
188 prev = current;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
189 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
190 return prefix;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
191 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
192
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
193 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
194 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
195 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
196 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
197 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
198 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
199 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
200
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
201 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
202 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
203 assert singleton != null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
205 body.startGroup();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
206 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
207 body.string(".").startCall(methodName);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
208 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
210 private CodeTree createGuardAndCast(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization, boolean onSpecialization,
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
211 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
212
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
213 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
214 CodeTree implicitGuards = createImplicitGuards(parent, conditionPrefix, valueSpecialization, guardedSpecialization);
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
215 CodeTree explicitGuards = createExplicitGuards(parent, implicitGuards == null ? conditionPrefix : null, valueSpecialization, guardedSpecialization, onSpecialization);
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
216
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
217 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
218
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
219 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
220 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
221 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
222 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
223 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
224 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
225 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
226
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
227 if (explicitGuards != null || !onSpecialization) {
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
228 builder.tree(createCasts(parent, valueSpecialization, guardedSpecialization));
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
229 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
230
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
231 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
232 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
233 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
234 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
235 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
236 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
237 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
238
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
239 if (implicitGuards == null && explicitGuards == null && conditionPrefix != null && !conditionPrefix.isEmpty()) {
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
240 builder.startIf().string(conditionPrefix).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
241 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
242 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
243
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
244 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
245
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
246 builder.end(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
247 if (ifCount > 0 && elseStatements != 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
248 builder.startElseBlock();
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
249 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
250 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
251 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
252
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
253 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
254 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
255
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
256 private static CodeTree createExplicitGuards(CodeTreeBuilder parent, String conditionPrefix, SpecializationData valueSpecialization, SpecializationData guardedSpecialization,
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
257 boolean onSpecialization) {
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
258 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
259 String andOperator = conditionPrefix != null ? conditionPrefix + " && " : "";
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
260 if (guardedSpecialization.getGuards().length > 0) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261 // Explicitly specified guards
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
262 for (SpecializationGuardData guard : guardedSpecialization.getGuards()) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
263 if ((guard.isOnSpecialization() && onSpecialization) || (guard.isOnExecution() && !onSpecialization)) {
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
264 builder.string(andOperator);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265
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 startCallOperationMethod(builder, guard.getGuardDeclaration());
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
267 addValueParameterNamesWithCasts(builder, valueSpecialization, guardedSpecialization);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
268
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
269 builder.end().end(); // call
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
270 andOperator = " && ";
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 }
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
274
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
275 return builder.isEmpty() ? null : builder.getRoot();
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
276 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
277
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
278 private CodeTree createCasts(CodeTreeBuilder parent, SpecializationData valueSpecialization, SpecializationData guardedSpecialization) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
279 NodeData node = guardedSpecialization.getNode();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
280
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
281 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
282 // Implict guards based on method signature
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
283 for (NodeFieldData field : node.getFields()) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
284 ActualParameter guardedParam = guardedSpecialization.findParameter(field.getName());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
285 ActualParameter valueParam = valueSpecialization.findParameter(field.getName());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
286
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
287 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
288 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
289 continue;
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
290 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
291 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
292 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
293
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
294 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
295 }
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
296
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
297 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
298 NodeData node = guardedSpecialization.getNode();
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
299
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
300 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
301 // 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
302 String andOperator = conditionPrefix != null ? conditionPrefix + " && " : "";
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
303 for (NodeFieldData field : node.getFields()) {
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
304 ActualParameter guardedParam = guardedSpecialization.findParameter(field.getName());
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
305 ActualParameter valueParam = valueSpecialization.findParameter(field.getName());
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
306
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
307 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
308 if (implicitGuard == null) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
309 continue;
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
310 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
311
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
312 builder.string(andOperator);
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 builder.tree(implicitGuard);
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
314 andOperator = " && ";
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
315 }
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
316
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 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
318 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
319
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
320 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
321 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
322 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
323
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
324 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
325 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
326
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
327 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
328 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
329 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
330
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
331 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
332
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
333 if (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
334 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
335 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
336 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
337 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
338 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
339 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
340
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
341 startCallTypeSystemMethod(getContext(), builder, node, TypeSystemCodeGenerator.isTypeMethodName(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
342 builder.string(valueName(field));
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
343 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
344
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
345 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
346 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
347 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
348
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
349 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
350
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
351 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
352 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
353
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
354 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
355 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
356 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
357
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
358 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
359 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
360
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
361 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
362 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
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 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
366 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
367 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
368 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
369 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
370 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
371
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
372 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
373
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
374 return createLazyAssignment(parent, castValueName(field), target.getActualType(), condition, value);
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
375 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
376
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
377 /**
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
378 * <pre>
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
379 * 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
380 *
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
381 * $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
382 * 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
383 * $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
384 * }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
385 *
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
386 * 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
387 * $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
388 * </pre>
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
389 *
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
390 * .
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
391 */
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 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
393 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
394 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
395 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
396 } else {
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
397 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
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 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
408 return 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
409 }
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
410
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412 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
413 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
414 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
415 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
416 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
417 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
418 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
419 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
421 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
422 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
423 add(factory, node);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
426 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
427 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
428 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
429 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
431 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
432
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 public NodeGenFactory(ProcessorContext context) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
434 super(context);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
435 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
436
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438 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
439 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
440
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 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
442 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
443
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
444 if (superConstructor != null) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
445 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
446 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
447 superConstructor.getParameters().clear();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
448 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
449 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
450 clazz.add(superConstructor);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
451 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
452 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
453
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
454 if (node.getExtensionElements() != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
455 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
456 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
457
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
458 node.setNodeType(clazz.asType());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
459
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
460 return clazz;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
461 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
462
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
463 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
464
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
465 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
466
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
467 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
468
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
469 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
470 super(context);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
471 this.childTypes = childElements;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
472 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
473
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
474 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
475 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
476 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
477 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
478 if (visibility != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
479 clazz.getModifiers().add(visibility);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
480 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
481 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
482 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
483 return clazz;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
484 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
486 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
487 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
488 CodeTypeElement clazz = getElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
489
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 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
491
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492 if (node.needsFactory()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 createFactoryMethods(node, clazz, createVisibility);
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 if (node.getSpecializations().length > 1) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
496 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
497 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499 if (node.needsRewrites(getContext())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
500 clazz.add(createSpecializeMethod(node));
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
501
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
502 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
503 for (CodeExecutableElement method : genericMethods) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
504 clazz.add(method);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
505 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
506 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
507
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 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
509 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
510 }
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
511
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
512 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
513 clazz.getImplements().add(nodeFactory);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
514 clazz.add(createCreateNodeMethod(node, createVisibility));
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
515 clazz.add(createCreateNodeSpecializedMethod(node, createVisibility));
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
516 clazz.add(createGetNodeClassMethod(node));
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
517 clazz.add(createGetNodeSignaturesMethod(node));
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
518 clazz.add(createGetInstanceMethod(node, createVisibility));
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
519 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
520 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 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
523 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
524 continue;
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
527 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
528 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
529 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
530 typeModifiers.clear();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531 if (visibility != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
532 typeModifiers.add(visibility);
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
535 typeModifiers.add(Modifier.STATIC);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
536 typeModifiers.add(Modifier.FINAL);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
537 clazz.add(type);
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 }
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
540
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
541 List<NodeData> children = node.getNodeChildren();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
542 if (node.getParent() == null && children.size() > 0) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
543 clazz.add(createGetFactories(node));
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
544 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
545
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
546 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
547
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
548 private CodeExecutableElement createGetNodeClassMethod(NodeData node) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
549 Types types = getContext().getEnvironment().getTypeUtils();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
550 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
551 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
552 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
553 builder.startReturn().typeLiteral(node.getNodeType()).end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
554 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
555 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
556
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
557 private CodeExecutableElement createGetNodeSignaturesMethod(NodeData node) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
558 Types types = getContext().getEnvironment().getTypeUtils();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
559 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
560 TypeMirror classType = getContext().getType(Class.class);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
561 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
562 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
563 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
564 builder.startReturn();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
565 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
566 List<ExecutableElement> constructors = findUserConstructors(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
567 for (ExecutableElement constructor : constructors) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
568 builder.startGroup();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
569 builder.type(getContext().getType(Arrays.class));
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
570 builder.string(".<").type(getContext().getType(Class.class)).string(">");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
571 builder.startCall("asList");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
572 for (VariableElement param : constructor.getParameters()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
573 builder.typeLiteral(param.asType());
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
574 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
575 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
576 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
577 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
578 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
579 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
580 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
581 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
582
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
583 private CodeExecutableElement createCreateNodeMethod(NodeData node, Modifier visibility) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
584 CodeExecutableElement method = new CodeExecutableElement(modifiers(), node.getNodeType(), "createNode");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
585 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
586 method.setVarArgs(true);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
587 method.addParameter(arguments);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
588
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
589 if (visibility != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
590 method.getModifiers().add(visibility);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
591 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
592
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
593 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
594 List<ExecutableElement> signatures = findUserConstructors(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
595 boolean ifStarted = false;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
596
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
597 for (ExecutableElement element : signatures) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
598 ifStarted = builder.startIf(ifStarted);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
599 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
600
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
601 int index = 0;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
602 for (VariableElement param : element.getParameters()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
603 builder.string(" && ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
604 if (!param.asType().getKind().isPrimitive()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
605 builder.string("(arguments[" + index + "] == null || ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
606 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
607 builder.string("arguments[" + index + "] instanceof ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
608 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
609 if (!param.asType().getKind().isPrimitive()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
610 builder.string(")");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
611 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
612 index++;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
613 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
614 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
615 builder.startBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
616
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
617 builder.startReturn().startCall("create");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
618 index = 0;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
619 for (VariableElement param : element.getParameters()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
620 builder.startGroup();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
621 builder.string("(").type(param.asType()).string(") ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
622 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
623 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
624 index++;
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 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
627
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
628 builder.end(); // block
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
629 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
630
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
631 builder.startElseBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
632 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
633 builder.doubleQuote("Invalid create signature.");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
634 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
635 builder.end(); // else block
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
636 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
637 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
638
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
639 private CodeExecutableElement createCreateNodeSpecializedMethod(NodeData node, Modifier visibility) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
640 CodeExecutableElement method = new CodeExecutableElement(modifiers(), node.getNodeType(), "createNodeSpecialized");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
641 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
642 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
643 method.addParameter(nodeParam);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
644 method.addParameter(arguments);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
645 method.setVarArgs(true);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
646 if (visibility != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
647 method.getModifiers().add(visibility);
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
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
650 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
651 if (!node.needsRewrites(getContext())) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
652 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
653 } else {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
654 builder.startIf();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
655 builder.string("types.length == 1");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
656 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
657 builder.startBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
658
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
659 builder.startReturn().startCall("createSpecialized");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
660 builder.string("thisNode");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
661 builder.string("types[0]");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
662 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
663
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
664 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
665 builder.startElseBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
666 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
667 builder.doubleQuote("Invalid createSpecialized signature.");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
668 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
669 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
670 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
671
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
672 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
673 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
674
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
675 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
676 Types types = getContext().getEnvironment().getTypeUtils();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
677 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
678 TypeMirror returnType = types.getDeclaredType(nodeFactoryType, node.getNodeType());
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
679
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
680 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
681 if (visibility != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
682 method.getModifiers().add(visibility);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
683 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
684 method.getModifiers().add(Modifier.STATIC);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
685
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
686 String varName = instanceVarName(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
687
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
688 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
689 builder.startIf();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
690 builder.string(varName).string(" == null");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
691 builder.end().startBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
692
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
693 builder.startStatement();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
694 builder.string(varName);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
695 builder.string(" = ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
696 builder.startNew(factoryClassName(node)).end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
697 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
698
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
699 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
700 builder.startReturn().string(varName).end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
701 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
702 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
703
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
704 private String instanceVarName(NodeData node) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
705 if (node.getParent() != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
706 return Utils.firstLetterLowerCase(factoryClassName(node)) + "Instance";
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
707 } else {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
708 return "instance";
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
709 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
710 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
711
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
712 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
713 String varName = instanceVarName(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
714 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
715 var.getModifiers().add(Modifier.PRIVATE);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
716 var.getModifiers().add(Modifier.STATIC);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
717 return var;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
718 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
719
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
720 private ExecutableElement createGetFactories(NodeData node) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
721 List<NodeData> children = node.getNodeChildren();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
722 if (node.needsFactory()) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
723 children.add(node);
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
724 }
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
725
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
726 List<TypeMirror> nodeTypesList = new ArrayList<>();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
727 for (NodeData child : children) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
728 nodeTypesList.add(child.getTemplateType().asType());
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
729 }
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
730 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
731
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
732 Types types = getContext().getEnvironment().getTypeUtils();
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
733 TypeMirror factoryType = getContext().getType(NodeFactory.class);
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
734 TypeMirror baseType;
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
735 if (children.size() == 1) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
736 baseType = types.getDeclaredType(Utils.fromTypeMirror(factoryType), commonNodeSuperType);
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
737 } else {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
738 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
739 }
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
740 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
741
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
742 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
743
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
744 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
745 builder.startReturn();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
746 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
747
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
748 for (NodeData child : children) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
749 builder.startGroup();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
750 NodeData childNode = child;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
751 List<NodeData> factories = new ArrayList<>();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
752 while (childNode.getParent() != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
753 factories.add(childNode);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
754 childNode = childNode.getParent();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
755 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
756 Collections.reverse(factories);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
757 for (NodeData nodeData : factories) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
758 builder.string(factoryClassName(nodeData)).string(".");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
759 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
760 builder.string("getInstance()");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
761 builder.end();
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 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
764 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
765 return method;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
766 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
767
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768 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
769 List<ExecutableElement> constructors = findUserConstructors(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
770 for (ExecutableElement constructor : constructors) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
771 clazz.add(createCreateMethod(node, createVisibility, constructor));
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
772 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
773 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
774
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
775 private List<ExecutableElement> findUserConstructors(NodeData node) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
776 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
777 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
778 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
779 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
781
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
782 // skip node rewrite constructor
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
783 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
784 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785 }
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
786 constructors.add(constructor);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
787 }
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
788 return constructors;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
790
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
791 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
792 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
793 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
794 method.getModifiers().clear();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 if (visibility != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 method.getModifiers().add(visibility);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
797 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798 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
799 method.setReturnType(node.getNodeType());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
800
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
801 CodeTreeBuilder body = method.createBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
802 body.startReturn();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 if (node.getSpecializations().length == 0) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
804 body.null_();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
805 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
806 body.startNew(nodeClassName(node.getSpecializations()[0]));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807 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
808 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
809 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
810 body.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
811 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 body.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 return method;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
815
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 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
817 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
818 if (visibility != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819 method.getModifiers().add(visibility);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
820 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
821 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
822
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
823 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
824 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
825
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826 CodeTreeBuilder body = method.createBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 boolean first = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828 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
829 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
830 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
831 if (first) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
832 body.startIf();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
833 first = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
834 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 body.startElseIf();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
837 body.string("specializationClass == ").type(type.getBoxedType()).string(".class").end().startBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
838 body.startReturn().startNew(nodeClassName(specialization));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
839 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
840 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
841
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 body.end(); // if
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
843 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 body.startReturn().startNew(nodeClassName(node.getGenericSpecialization()));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
846 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
847 body.end().end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848 return method;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
849 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 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
852 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
853 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
854 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), "minimumState"));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
855 addValueParameters(method, node.getGenericSpecialization(), false);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857 CodeTreeBuilder body = method.createBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 body.startStatement().string("boolean allowed = (minimumState == ").string(nodeClassName(node.getSpecializations()[0])).string(".class)").end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
859
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860 for (int i = 1; i < node.getSpecializations().length; i++) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
861 SpecializationData specialization = node.getSpecializations()[i];
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
862 body.startStatement().string("allowed = allowed || (minimumState == ").string(nodeClassName(specialization)).string(".class)").end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
863
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
864 CodeTreeBuilder guarded = new CodeTreeBuilder(body);
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
865 guarded.startReturn().startNew(nodeClassName(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
866 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
867 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
868
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
869 body.tree(createGuardAndCast(body, "allowed", node.getGenericSpecialization(), specialization, true, guarded.getRoot(), null));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
870 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
871 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
872
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
873 return method;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
874 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
875
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
876 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
877 TypeMirror genericReturnType = node.getGenericSpecialization().getReturnType().getActualType();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
878 if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
879 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
880
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
881 SpecializationData[] specializations = node.getSpecializations();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
882 SpecializationData prev = null;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
883 for (int i = 0; i < specializations.length; i++) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
884 SpecializationData current = specializations[i];
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
885 SpecializationData next = i + 1 < specializations.length ? specializations[i + 1] : null;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
886 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
887 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
888 continue;
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
889 } else {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
890 String methodName = generatedGenericMethodName(current);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
891 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
892 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME));
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
893 addValueParameters(method, node.getGenericSpecialization(), true);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
894
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
895 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
896
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
897 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
898 }
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
899 prev = current;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
900 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
901
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
902 return methods;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
903 } else {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
904 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
905 method.addParameter(new CodeVariableElement(node.getNodeType(), THIS_NODE_LOCAL_VAR_NAME));
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
906 addValueParameters(method, node.getGenericSpecialization(), true);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
907 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
908 return Arrays.asList(method);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
909 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
910 }
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
911
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
912 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
913 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
914 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
915 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
916
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
917 if (next != null) {
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
918 invokeMethod = createGuardAndCast(builder, null, current.getNode().getGenericSpecialization(), current, false, invokeMethod, null);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
919 }
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
920
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
921 builder.tree(invokeMethod);
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
922
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
923 if (next != null) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
924 builder.end();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
925
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
926 builder.startReturn().startCall(generatedGenericMethodName(next));
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
927 builder.string(THIS_NODE_LOCAL_VAR_NAME);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
928 addValueParameterNames(builder, next, null, true);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
929 builder.end().end();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
930 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
932
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
933 private void emitInvokeDoMethod(CodeTreeBuilder builder, SpecializationData specialization, int level) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
934 if (specialization.getExceptions().length > 0) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
935 builder.startTryBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
936 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
937
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
938 builder.startReturn();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
939 startCallOperationMethod(builder, specialization);
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
940 addValueParameterNamesWithCasts(builder, specialization.getNode().getGenericSpecialization(), specialization);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
941 builder.end().end(); // start call operation
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
942 builder.end(); // return
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
944 if (specialization.getExceptions().length > 0) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945 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
946 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
947
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
948 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
949 builder.string(THIS_NODE_LOCAL_VAR_NAME);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
950 addValueParameterNames(builder, exception.getTransitionTo(), null, true);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
951 builder.end().end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
952 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
954 }
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 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
957
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
958 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
959
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960 public SpecializedNodeFactory(ProcessorContext context) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
961 super(context);
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
964 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
965 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
966 NodeData node = specialization.getNode();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeClassName(specialization), node.getNodeType(), false);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
968 return clazz;
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
971 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
972 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
973 CodeTypeElement clazz = getElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
974 NodeData node = specialization.getNode();
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 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
977 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
978 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
979 if (superConstructor != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980 clazz.add(superConstructor);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
982 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
983
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
984 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
985 if (execType.isFinal()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
986 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
987 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
988 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
989 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
990 CodeVariableElement var = CodeVariableElement.clone(method.getParameters().get(0));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
991 var.setName("frame");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 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
993 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
994 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
995 clazz.add(method);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
996
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
997 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
998 if (primaryType == execType.getType()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
999 buildFunctionalExecuteMethod(method.createBuilder(), specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1000 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 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
1002 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1003 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1004
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1005 if (node.needsRewrites(getContext()) && !specialization.isGeneric() && !specialization.isUninitialized()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1006 buildSpecializeStateMethod(clazz, specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1007 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1008 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1009
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1010 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
1011 NodeData node = specialization.getNode();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1012 TypeSystemData typeSystem = node.getTypeSystem();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1013
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
1014 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
1015 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
1016 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
1017
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
1018 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
1019 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
1020
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
1021 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
1022
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
1023 CodeTreeBuilder executeBuilder = CodeTreeBuilder.createBuilder();
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
1024 buildExecute(executeBuilder, null, execType);
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
1025 primaryExecuteCall = executeBuilder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1026
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1027 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
1028 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
1029 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
1030 }
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
1031 builder.startTryBlock();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1032
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
1033 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
1034 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
1035 } 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
1036 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
1037 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
1038 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
1039 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
1040 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1041
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
1042 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
1043 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
1044 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
1045 } 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
1046 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
1047 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
1048 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
1049 }
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
1050 builder.end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1051
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
1052 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
1053 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
1054 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
1055 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
1056 }
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
1057 } 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
1058 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
1059 builder.statement(primaryExecuteCall);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1060 } 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
1061 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
1062 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
1063 builder.end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1064 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1065 }
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
1066 }
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
1067
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1068 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
1069 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
1070 return value;
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1071 } else if (castedType.getType().isVoid()) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1072 return value;
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1073 } 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
1074 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
1075 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1076
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
1077 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
1078 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
1079 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
1080 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
1081 } 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
1082 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
1083 }
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1084 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
1085
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
1086 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
1087 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
1088 return builder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1089 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1090
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1091 private void buildFunctionalExecuteMethod(CodeTreeBuilder builder, SpecializationData specialization) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1092 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
1093 builder.tree(createDeoptimize(builder));
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1094 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1095
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
1096 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
1097
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
1098 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
1099 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
1100 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1101
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
1102 CodeTree executeNode = createExecute(builder, specialization);
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1103
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1104 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
1105 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
1106 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
1107 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
1108 }
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1109 builder.tree(createGuardAndCast(builder, null, specialization, specialization, false, executeNode, returnSpecialized));
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1110 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1111
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1112 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
1113 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
1114 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
1115 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
1116 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
1117 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
1118 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1119
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1120 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
1121 NodeData node = specialization.getNode();
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1122
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
1123 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
1124 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
1125
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1126 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
1127 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
1128 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
1129 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
1130 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
1131 builder.typeLiteral(builder.findMethod().getEnclosingElement().asType());
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1132 addValueParameterNames(builder, specialization, null, false);
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1133 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
1134 } 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
1135 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
1136 }
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
1137 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
1138 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
1139 }
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1140
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
1141 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
1142 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
1143 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1144 if (specialization.getExceptions().length > 0) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1145 builder.startTryBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1146 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1147
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1148 if ((specialization.isUninitialized() || specialization.isGeneric()) && node.needsRewrites(getContext())) {
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
1149 builder.startReturn().startCall(factoryClassName(node), generatedGenericMethodName(null));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1150 builder.string("this");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1151 addValueParameterNames(builder, specialization, null, true);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1152 builder.end().end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1153 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154 builder.startReturn();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1155
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1156 if (specialization.isUninitialized()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1157 startCallOperationMethod(builder, specialization.getNode().getGenericSpecialization());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1158 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1159 startCallOperationMethod(builder, specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1160 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1161 addValueParameterNames(builder, specialization, null, false);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1162 builder.end().end(); // operation call
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1163 builder.end(); // return
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1164 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1165
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1166 if (specialization.getExceptions().length > 0) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1167 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
1168 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
1169 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
1170 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1171 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1172 }
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
1173 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
1174 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1175
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1176 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
1177 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
1178 for (NodeFieldData field : specialization.getNode().getFields()) {
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1179 if (field.getExecutionKind() == ExecutionKind.IGNORE) {
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1180 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
1181 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1182
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1183 ActualParameter parameterType = specialization.findParameter(field.getName());
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1184
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1185 if (parameterType.getActualTypeData(specialization.getNode().getTypeSystem()).isGeneric()) {
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1186 buildGenericValueExecute(builder, specialization, field, 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
1187 } 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
1188 buildSpecializedValueExecute(builder, specialization, field);
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1189 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1190 }
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1191 return builder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1192 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1193
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1194 private void emitSpecializationListeners(CodeTreeBuilder builder, NodeData node) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1195 for (TemplateMethod listener : node.getSpecializationListeners()) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1196 builder.startStatement();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1197 startCallOperationMethod(builder, listener);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1198 addValueParameterNames(builder, listener, null, false);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1199 builder.end().end();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1200 builder.end(); // statement
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1201 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1202 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1203
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1204 private void buildGenericValueExecute(CodeTreeBuilder builder, SpecializationData specialization, NodeFieldData field, NodeFieldData exceptionSpec) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1205 ActualParameter specParameter = specialization.findParameter(field.getName());
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7777
diff changeset
1206 NodeData node = specialization.getNode();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
1207 boolean shortCircuit = startShortCircuit(builder, specialization, field, exceptionSpec);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1208
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1209 builder.startStatement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1210 if (!shortCircuit) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1211 builder.type(specialization.getNode().getTypeSystem().getGenericType());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1212 builder.string(" ");
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
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1215 builder.string(valueName(specParameter));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1216 builder.string(" = ");
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7777
diff changeset
1217 ExecutableTypeData genericExecutableType = field.getNodeData().findGenericExecutableType(getContext(), specParameter.getActualTypeData(node.getTypeSystem()));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1218 if (genericExecutableType == null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1219 throw new AssertionError("Must have generic executable type. Parser validation most likely failed. " + Arrays.toString(field.getNodeData().getExecutableTypes()));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1220 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1221 buildExecute(builder, field, genericExecutableType);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1222 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1223
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1224 endShortCircuit(builder, shortCircuit);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1225 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1226
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1227 private void buildExecute(CodeTreeBuilder builder, NodeFieldData field, ExecutableTypeData execType) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1228 if (field != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1229 Element accessElement = field.getAccessElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1230 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
1231 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
1232 } 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
1233 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
1234 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1235 throw new AssertionError();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1236 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1237 builder.string(".");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1238 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1239 builder.startCall(execType.getMethodName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1240 if (execType.getParameters().length == 1) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1241 builder.string("frame");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1242 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1243 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1244 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1245
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1246 private void buildSpecializedValueExecute(CodeTreeBuilder builder, SpecializationData specialization, NodeFieldData field) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1247 ActualParameter param = specialization.findParameter(field.getName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1248 boolean shortCircuit = startShortCircuit(builder, specialization, field, null);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1249
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250 if (!shortCircuit) {
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1251 builder.startStatement().type(param.getActualType()).string(" ").string(valueName(param)).end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1252 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1253
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1254 ExecutableTypeData execType = field.getNodeData().findExecutableType(param.getActualTypeData(field.getNodeData().getTypeSystem()));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1255
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1256 if (execType.hasUnexpectedValue(getContext())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1257 builder.startTryBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1258 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1259
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1260 builder.startStatement().string(valueName(field)).string(" = ");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1261 buildExecute(builder, field, execType);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1262 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1263
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1264 if (execType.hasUnexpectedValue(getContext())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1265 builder.end().startCatchBlock(getUnexpectedValueException(), "ex");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1266 boolean execute = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1267 for (NodeFieldData exField : specialization.getNode().getFields()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1268 if (exField.getExecutionKind() == ExecutionKind.IGNORE) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1269 continue;
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 if (execute) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1272 buildGenericValueExecute(builder, specialization.getNode().getGenericSpecialization(), exField, field);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1273 } else if (exField == field) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1274 execute = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1275 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1276 }
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
1277 builder.tree(createReturnSpecializeAndExecute(builder, specialization.findNextSpecialization(), param.getSpecification()));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1278 builder.end(); // catch block
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1279 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1280
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1281 endShortCircuit(builder, shortCircuit);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1282 builder.newLine();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1283 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1284
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
1285 private boolean startShortCircuit(CodeTreeBuilder builder, SpecializationData specialization, NodeFieldData forField, NodeFieldData exceptionField) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1286 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
1287 return false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1288 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1289
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1290 ActualParameter parameter = specialization.findParameter(forField.getName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1291 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
1292
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1293 int shortCircuitIndex = 0;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1294 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
1295 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
1296 if (field == forField) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1297 break;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1298 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1299 shortCircuitIndex++;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1301 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1302
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1303 builder.startStatement().type(shortCircuitParam.getActualType()).string(" ").string(valueName(shortCircuitParam)).string(" = ");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1304 ShortCircuitData shortCircuitData = specialization.getShortCircuits()[shortCircuitIndex];
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1305
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1306 startCallOperationMethod(builder, shortCircuitData);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1307 addValueParameterNames(builder, shortCircuitData, exceptionField != null ? exceptionField.getName() : null, false);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1308 builder.end().end(); // call operation
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1309
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1310 builder.end(); // statement
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1311
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1312 builder.declaration(parameter.getActualType(), valueName(parameter), CodeTreeBuilder.createBuilder().defaultValue(parameter.getActualType()));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1313 builder.startIf().string(shortCircuitParam.getSpecification().getName()).end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1314 builder.startBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1315
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1316 return true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1317 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1318
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1319 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
1320 if (shortCircuit) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1321 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1322 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1323 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1324
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
1325 private CodeTree createReturnSpecializeAndExecute(CodeTreeBuilder parent, SpecializationData nextSpecialization, ParameterSpec exceptionSpec) {
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1326 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent);
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1327 specializeCall.startCall("specializeAndExecute");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1328 specializeCall.string(nodeClassName(nextSpecialization) + ".class");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1329 addValueParameterNames(specializeCall, nextSpecialization.getNode().getGenericSpecialization(), exceptionSpec != null ? exceptionSpec.getName() : null, true);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1330 specializeCall.end().end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1331
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
1332 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1333 builder.startReturn();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1334 builder.tree(specializeCall.getRoot());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1335 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
1336 return builder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1337 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1338
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1339 private void buildSpecializeStateMethod(CodeTypeElement clazz, SpecializationData specialization) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1340 NodeData node = specialization.getNode();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1341 TypeData returnType = specialization.getReturnType().getActualTypeData(node.getTypeSystem());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1342 ExecutableTypeData returnExecutableType = node.findExecutableType(returnType);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1343 boolean canThrowUnexpected = returnExecutableType == null ? true : returnExecutableType.hasUnexpectedValue(getContext());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1344
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1345 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
1346 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
1347 if (canThrowUnexpected) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1348 method.addThrownType(getUnexpectedValueException());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1349 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1350 addValueParameters(method, specialization.getNode().getGenericSpecialization(), true);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1351 clazz.add(method);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1352
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1353 CodeTreeBuilder builder = method.createBuilder();
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1354
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
1355 builder.tree(createDeoptimize(builder));
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1356 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
1357
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1358 builder.startStatement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1359 builder.startCall("replace");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1360 builder.startCall(factoryClassName(specialization.getNode()), "specialize").string("this").string("minimumState");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1361 addValueParameterNames(builder, specialization.getNode().getGenericSpecialization(), null, false);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1362 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1363 builder.end(); // call replace
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1364 builder.end(); // statement
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1365
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
1366 String generatedMethodName = generatedGenericMethodName(specialization.findNextSpecialization());
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
1367 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
1368
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1369 CodeTreeBuilder genericExecute = CodeTreeBuilder.createBuilder();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1370 genericExecute.startCall(factoryClassName(specialization.getNode()), generatedMethodName);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1371 genericExecute.string("this");
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1372 addValueParameterNames(genericExecute, specialization.getNode().getGenericSpecialization(), null, true);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1373 genericExecute.end(); // call generated generic
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1374
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1375 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
1376
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
1377 if (generatedGeneric != null && Utils.isVoid(generatedGeneric.getReturnType())) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1378 builder.statement(genericInvocation);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1379
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1380 if (!Utils.isVoid(builder.findMethod().asType())) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1381 builder.startReturn().defaultValue(returnType.getPrimitiveType()).end();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1382 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1383 } else {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1384 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
1385 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1386 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1387
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1390 }