annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java @ 7859:3c68170fc9b0

Fixed a visibility bug in NodeFactory generation.
author Christian Humer <christian.humer@gmail.com>
date Mon, 25 Feb 2013 17:00:52 +0100
parents 4958cbdbf360
children 6b74ffe38183
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);
7859
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7858
diff changeset
514 clazz.add(createCreateNodeMethod(node));
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7858
diff changeset
515 clazz.add(createCreateNodeSpecializedMethod(node));
7855
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
7859
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7858
diff changeset
583 private CodeExecutableElement createCreateNodeMethod(NodeData node) {
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7858
diff changeset
584 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNode");
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
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 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
590 List<ExecutableElement> signatures = findUserConstructors(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
591 boolean ifStarted = false;
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 for (ExecutableElement element : signatures) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
594 ifStarted = builder.startIf(ifStarted);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
595 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
596
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
597 int index = 0;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
598 for (VariableElement param : element.getParameters()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
599 builder.string(" && ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
600 if (!param.asType().getKind().isPrimitive()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
601 builder.string("(arguments[" + index + "] == null || ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
602 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
603 builder.string("arguments[" + index + "] instanceof ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
604 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
605 if (!param.asType().getKind().isPrimitive()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
606 builder.string(")");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
607 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
608 index++;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
609 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
610 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
611 builder.startBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
612
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
613 builder.startReturn().startCall("create");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
614 index = 0;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
615 for (VariableElement param : element.getParameters()) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
616 builder.startGroup();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
617 builder.string("(").type(param.asType()).string(") ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
618 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
619 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
620 index++;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
621 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
622 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
623
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
624 builder.end(); // block
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
625 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
626
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
627 builder.startElseBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
628 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
629 builder.doubleQuote("Invalid create signature.");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
630 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
631 builder.end(); // else block
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
632 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
633 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
634
7859
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7858
diff changeset
635 private CodeExecutableElement createCreateNodeSpecializedMethod(NodeData node) {
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7858
diff changeset
636 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNodeSpecialized");
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
637 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
638 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
639 method.addParameter(nodeParam);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
640 method.addParameter(arguments);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
641 method.setVarArgs(true);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
642
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
643 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
644 if (!node.needsRewrites(getContext())) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
645 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
646 } else {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
647 builder.startIf();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
648 builder.string("types.length == 1");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
649 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
650 builder.startBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
651
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
652 builder.startReturn().startCall("createSpecialized");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
653 builder.string("thisNode");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
654 builder.string("types[0]");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
655 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
656
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
657 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
658 builder.startElseBlock();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
659 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
660 builder.doubleQuote("Invalid createSpecialized signature.");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
661 builder.end().end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
662 builder.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
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
665 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
666 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
667
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
668 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
669 Types types = getContext().getEnvironment().getTypeUtils();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
670 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
671 TypeMirror returnType = types.getDeclaredType(nodeFactoryType, node.getNodeType());
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
672
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
673 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
674 if (visibility != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
675 method.getModifiers().add(visibility);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
676 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
677 method.getModifiers().add(Modifier.STATIC);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
678
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
679 String varName = instanceVarName(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
680
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
681 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
682 builder.startIf();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
683 builder.string(varName).string(" == null");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
684 builder.end().startBlock();
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 builder.startStatement();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
687 builder.string(varName);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
688 builder.string(" = ");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
689 builder.startNew(factoryClassName(node)).end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
690 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
691
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
692 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
693 builder.startReturn().string(varName).end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
694 return method;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
695 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
696
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
697 private String instanceVarName(NodeData node) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
698 if (node.getParent() != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
699 return Utils.firstLetterLowerCase(factoryClassName(node)) + "Instance";
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
700 } else {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
701 return "instance";
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
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
705 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
706 String varName = instanceVarName(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
707 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
708 var.getModifiers().add(Modifier.PRIVATE);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
709 var.getModifiers().add(Modifier.STATIC);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
710 return var;
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
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
713 private ExecutableElement createGetFactories(NodeData node) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
714 List<NodeData> children = node.getNodeChildren();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
715 if (node.needsFactory()) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
716 children.add(node);
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
717 }
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
718
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
719 List<TypeMirror> nodeTypesList = new ArrayList<>();
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
720 for (NodeData child : children) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
721 nodeTypesList.add(child.getTemplateType().asType());
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
722 }
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
723 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
724
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
725 Types types = getContext().getEnvironment().getTypeUtils();
7858
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
726 TypeMirror factoryType = getContext().getType(NodeFactory.class);
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
727 TypeMirror baseType;
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
728 if (children.size() == 1) {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
729 baseType = types.getDeclaredType(Utils.fromTypeMirror(factoryType), commonNodeSuperType);
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
730 } else {
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
731 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
732 }
4958cbdbf360 Fixed minor bugs in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
733 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
734
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
735 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
736
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
737 CodeTreeBuilder builder = method.createBuilder();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
738 builder.startReturn();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
739 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
740
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
741 for (NodeData child : children) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
742 builder.startGroup();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
743 NodeData childNode = child;
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
744 List<NodeData> factories = new ArrayList<>();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
745 while (childNode.getParent() != null) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
746 factories.add(childNode);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
747 childNode = childNode.getParent();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
748 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
749 Collections.reverse(factories);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
750 for (NodeData nodeData : factories) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
751 builder.string(factoryClassName(nodeData)).string(".");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
752 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
753 builder.string("getInstance()");
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
754 builder.end();
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 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
757 builder.end();
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
758 return method;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
759 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
760
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761 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
762 List<ExecutableElement> constructors = findUserConstructors(node);
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
763 for (ExecutableElement constructor : constructors) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
764 clazz.add(createCreateMethod(node, createVisibility, constructor));
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
765 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
766 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
767
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
768 private List<ExecutableElement> findUserConstructors(NodeData node) {
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
769 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
770 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
771 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
772 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
773 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
774
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
775 // skip node rewrite constructor
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
776 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
777 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
778 }
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
779 constructors.add(constructor);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780 }
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7847
diff changeset
781 return constructors;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
782 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
783
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
784 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
785 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
786 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
787 method.getModifiers().clear();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
788 if (visibility != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789 method.getModifiers().add(visibility);
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 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
792 method.setReturnType(node.getNodeType());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
793
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
794 CodeTreeBuilder body = method.createBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 body.startReturn();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 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
797 body.null_();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799 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
800 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
801 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
802 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 body.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
804 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
805 body.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
806 return method;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
808
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
809 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
810 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
811 if (visibility != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 method.getModifiers().add(visibility);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814 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
815
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 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
817 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
818
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819 CodeTreeBuilder body = method.createBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
820 boolean first = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
821 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
822 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
823 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
824 if (first) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
825 body.startIf();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826 first = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828 body.startElseIf();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
829 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
830 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
831 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
832 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
833 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
834
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 body.end(); // if
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 }
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(node.getGenericSpecialization()));
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();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
841 return method;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 }
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 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
845 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
846 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
847 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
848 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
849
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850 CodeTreeBuilder body = method.createBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 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
852
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
853 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
854 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
855 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
856
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
857 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
858 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
859 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
860 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
861
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
862 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
863 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
864 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
865
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
866 return method;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
867 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
868
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
869 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
870 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
871 if (node.getGenericSpecialization().isUseSpecializationsForGeneric()) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
872 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
873
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
874 SpecializationData[] specializations = node.getSpecializations();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
875 SpecializationData prev = null;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
876 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
877 SpecializationData current = specializations[i];
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
878 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
879 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
880 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
881 continue;
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
882 } else {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
883 String methodName = generatedGenericMethodName(current);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
884 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
885 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
886 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
887
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
888 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
889
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
890 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
891 }
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
892 prev = current;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
893 }
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 return methods;
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
896 } else {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
897 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
898 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
899 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
900 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
901 return Arrays.asList(method);
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
902 }
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
903 }
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
904
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
905 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
906 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
907 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
908 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
909
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
910 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
911 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
912 }
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
913
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
914 builder.tree(invokeMethod);
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
915
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
916 if (next != null) {
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
917 builder.end();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
918
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
919 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
920 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
921 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
922 builder.end().end();
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
923 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
924 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
925
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
926 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
927 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
928 builder.startTryBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
929 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
930
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 builder.startReturn();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
932 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
933 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
934 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
935 builder.end(); // return
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 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
938 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
939 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
940
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
941 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
942 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
943 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
944 builder.end().end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
946 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
947 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
948 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
949 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
950
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
951 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
952
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953 public SpecializedNodeFactory(ProcessorContext context) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
954 super(context);
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 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
958 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
959 NodeData node = specialization.getNode();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960 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
961 return clazz;
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 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
966 CodeTypeElement clazz = getElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 NodeData node = specialization.getNode();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
968
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
969 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
970 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
971 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
972 if (superConstructor != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
973 clazz.add(superConstructor);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
974 }
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
977 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
978 if (execType.isFinal()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
979 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 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
982 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
983 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
984 var.setName("frame");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
985 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
986 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
987 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
988 clazz.add(method);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
989
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
990 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
991 if (primaryType == execType.getType()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 buildFunctionalExecuteMethod(method.createBuilder(), specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
993 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
994 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
995 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
996 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
997
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
998 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
999 buildSpecializeStateMethod(clazz, specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1000 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1002
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1003 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
1004 NodeData node = specialization.getNode();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1005 TypeSystemData typeSystem = node.getTypeSystem();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1006
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
1007 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
1008 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
1009 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
1010
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
1011 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
1012 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
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 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
1015
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
1016 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
1017 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
1018 primaryExecuteCall = executeBuilder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1019
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1020 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
1021 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
1022 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
1023 }
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 builder.startTryBlock();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1025
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
1026 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
1027 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
1028 } 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
1029 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
1030 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
1031 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
1032 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
1033 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1034
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
1035 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
1036 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
1037 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
1038 } 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
1039 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
1040 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
1041 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
1042 }
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 builder.end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1044
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
1045 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
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("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
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 } 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
1051 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
1052 builder.statement(primaryExecuteCall);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1053 } 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
1054 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
1055 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
1056 builder.end();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1057 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1058 }
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
1059 }
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
1060
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1061 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
1062 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
1063 return value;
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1064 } else if (castedType.getType().isVoid()) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1065 return value;
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1066 } 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
1067 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
1068 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1069
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 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
1071 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
1072 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
1073 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
1074 } 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
1075 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
1076 }
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1077 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
1078
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 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
1080 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
1081 return builder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1082 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1083
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1084 private void buildFunctionalExecuteMethod(CodeTreeBuilder builder, SpecializationData specialization) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1085 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
1086 builder.tree(createDeoptimize(builder));
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1087 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1088
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
1089 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
1090
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
1091 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
1092 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
1093 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1094
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
1095 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
1096
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1097 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
1098 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
1099 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
1100 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
1101 }
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1102 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
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
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 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
1106 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
1107 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
1108 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
1109 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
1110 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
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
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 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
1114 NodeData node = specialization.getNode();
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1115
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
1116 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
1117 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
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 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
1120 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
1121 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
1122 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
1123 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
1124 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
1125 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
1126 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
1127 } 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
1128 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
1129 }
7846
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1130 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
1131 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
1132 }
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1133
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
1134 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
1135 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
1136 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
1137 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
1138 builder.startTryBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1139 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1140
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1141 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
1142 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
1143 builder.string("this");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1144 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
1145 builder.end().end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1146 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1147 builder.startReturn();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1148
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1149 if (specialization.isUninitialized()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1150 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
1151 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1152 startCallOperationMethod(builder, specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1153 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1154 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
1155 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
1156 builder.end(); // return
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1157 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1158
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1159 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
1160 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
1161 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
1162 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
1163 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1164 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1165 }
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
1166 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
1167 }
91cc98eae8ee Refactor guard creation methods are not flexible enough to handle two if guards.
Christian Humer <christian.humer@gmail.com>
parents: 7845
diff changeset
1168
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 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
1170 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
1171 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
1172 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
1173 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
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 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
1177
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 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
1179 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
1180 } 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
1181 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
1182 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1183 }
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
1184 return builder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1185 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1186
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1187 private void emitSpecializationListeners(CodeTreeBuilder builder, NodeData node) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1188 for (TemplateMethod listener : node.getSpecializationListeners()) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1189 builder.startStatement();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1190 startCallOperationMethod(builder, listener);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1191 addValueParameterNames(builder, listener, null, false);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1192 builder.end().end();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1193 builder.end(); // statement
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1194 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1195 }
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1196
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1197 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
1198 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
1199 NodeData node = specialization.getNode();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
1200 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
1201
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1202 builder.startStatement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1203 if (!shortCircuit) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1204 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
1205 builder.string(" ");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1206 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1207
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1208 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
1209 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
1210 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
1211 if (genericExecutableType == null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1212 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
1213 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1214 buildExecute(builder, field, genericExecutableType);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1215 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1216
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1217 endShortCircuit(builder, shortCircuit);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1218 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1219
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1220 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
1221 if (field != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1222 Element accessElement = field.getAccessElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1223 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
1224 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
1225 } 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
1226 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
1227 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1228 throw new AssertionError();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1229 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1230 builder.string(".");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1231 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1232 builder.startCall(execType.getMethodName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1233 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
1234 builder.string("frame");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1235 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1236 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1237 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1238
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1239 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
1240 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
1241 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
1242
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1243 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
1244 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
1245 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1246
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1247 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
1248
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1249 if (execType.hasUnexpectedValue(getContext())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1250 builder.startTryBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1251 }
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 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
1254 buildExecute(builder, field, execType);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1255 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1256
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1257 if (execType.hasUnexpectedValue(getContext())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1258 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
1259 boolean execute = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1260 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
1261 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
1262 continue;
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 (execute) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1265 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
1266 } else if (exField == field) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1267 execute = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1268 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1269 }
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
1270 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
1271 builder.end(); // catch block
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1272 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1273
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1274 endShortCircuit(builder, shortCircuit);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1275 builder.newLine();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1276 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1277
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
1278 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
1279 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
1280 return false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1281 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1282
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1283 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
1284 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
1285
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1286 int shortCircuitIndex = 0;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1287 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
1288 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
1289 if (field == forField) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1290 break;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1291 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1292 shortCircuitIndex++;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1293 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1294 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1295
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1296 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
1297 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
1298
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1299 startCallOperationMethod(builder, shortCircuitData);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1300 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
1301 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
1302
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1303 builder.end(); // statement
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1304
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1305 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
1306 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
1307 builder.startBlock();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1308
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1309 return true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1310 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1311
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1312 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
1313 if (shortCircuit) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1314 builder.end();
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 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1317
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
1318 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
1319 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent);
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1320 specializeCall.startCall("specializeAndExecute");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1321 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
1322 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
1323 specializeCall.end().end();
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 CodeTreeBuilder builder = new CodeTreeBuilder(parent);
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1326 builder.startReturn();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1327 builder.tree(specializeCall.getRoot());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1328 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
1329 return builder.getRoot();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1330 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1331
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1332 private void buildSpecializeStateMethod(CodeTypeElement clazz, SpecializationData specialization) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1333 NodeData node = specialization.getNode();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1334 TypeData returnType = specialization.getReturnType().getActualTypeData(node.getTypeSystem());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1335 ExecutableTypeData returnExecutableType = node.findExecutableType(returnType);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1336 boolean canThrowUnexpected = returnExecutableType == null ? true : returnExecutableType.hasUnexpectedValue(getContext());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1337
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1338 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
1339 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
1340 if (canThrowUnexpected) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1341 method.addThrownType(getUnexpectedValueException());
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1342 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1343 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
1344 clazz.add(method);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1345
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1346 CodeTreeBuilder builder = method.createBuilder();
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1347
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
1348 builder.tree(createDeoptimize(builder));
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1349 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
1350
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1351 builder.startStatement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1352 builder.startCall("replace");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1353 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
1354 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
1355 builder.end();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1356 builder.end(); // call replace
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1357 builder.end(); // statement
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1358
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
1359 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
1360 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
1361
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1362 CodeTreeBuilder genericExecute = CodeTreeBuilder.createBuilder();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1363 genericExecute.startCall(factoryClassName(specialization.getNode()), generatedMethodName);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1364 genericExecute.string("this");
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1365 addValueParameterNames(genericExecute, specialization.getNode().getGenericSpecialization(), null, true);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1366 genericExecute.end(); // call generated generic
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1367
7847
06a7cd6aaf00 Casting is now done on demand using local variables for explicit guards.
Christian Humer <christian.humer@gmail.com>
parents: 7846
diff changeset
1368 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
1369
7777
ca51efac4d57 Fixed rewrite in generated generic did not invoke guards.
Christian Humer <christian.humer@gmail.com>
parents: 7751
diff changeset
1370 if (generatedGeneric != null && Utils.isVoid(generatedGeneric.getReturnType())) {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1371 builder.statement(genericInvocation);
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1372
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1373 if (!Utils.isVoid(builder.findMethod().asType())) {
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1374 builder.startReturn().defaultValue(returnType.getPrimitiveType()).end();
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1375 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1376 } else {
7843
4969921f57b7 Renamed generated specialize to specializeAndExecute.
Christian Humer <christian.humer@gmail.com>
parents: 7799
diff changeset
1377 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
1378 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1379 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1380
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1381 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1382
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1383 }