annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java @ 9279:2a4b57f02fb4

Implemented basic support for assumptions for sourcecode generation.
author Christian Humer <christian.humer@gmail.com>
date Wed, 24 Apr 2013 17:44:15 +0200
parents 6d92fdf1c999
children 39f08ef7b5d8
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, 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 java.lang.annotation.*;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import java.util.*;
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 javax.lang.model.element.*;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 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
30 import javax.lang.model.util.*;
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
31 import javax.tools.Diagnostic.Kind;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 import com.oracle.truffle.api.codegen.*;
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
34 import com.oracle.truffle.api.codegen.NodeClass.InheritNode;
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.*;
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
36 import com.oracle.truffle.codegen.processor.node.NodeChildData.Cardinality;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
37 import com.oracle.truffle.codegen.processor.node.NodeChildData.ExecutionKind;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
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
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7506
diff changeset
41 public class NodeParser extends TemplateParser<NodeData> {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
43 public static final List<Class<? extends Annotation>> ANNOTATIONS = Arrays.asList(Generic.class, TypeSystemReference.class, ShortCircuit.class, Specialization.class, SpecializationListener.class,
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
44 ExecuteChildren.class, NodeClass.class, NodeChild.class, NodeChildren.class, NodeId.class);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 private Map<String, NodeData> parsedNodes;
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 public NodeParser(ProcessorContext c) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 super(c);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 }
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 @Override
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 protected NodeData parse(Element element, AnnotationMirror mirror) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 assert element instanceof TypeElement;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
55 NodeData node = null;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 try {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 parsedNodes = new HashMap<>();
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
58 node = resolveNode((TypeElement) element);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
59 if (Log.DEBUG) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
60 NodeData parsed = parsedNodes.get(Utils.getQualifiedName((TypeElement) element));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
61 if (node != null) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
62 String dump = parsed.dump();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
63 log.message(Kind.ERROR, null, null, null, dump);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
64 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
65 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 } finally {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 parsedNodes = null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
69
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
70 return node;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 @Override
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
74 protected NodeData filterErrorElements(NodeData model) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
75 for (Iterator<NodeData> iterator = model.getDeclaredNodes().iterator(); iterator.hasNext();) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
76 NodeData node = filterErrorElements(iterator.next());
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
77 if (node == null) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
78 iterator.remove();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
79 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
80 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
81 if (model.hasErrors()) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
82 return null;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
83 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
84 return model;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
85 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
86
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
87 @Override
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 public boolean isDelegateToRootDeclaredType() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 return true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
92 private NodeData resolveNode(TypeElement rootType) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
93 String typeName = Utils.getQualifiedName(rootType);
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
94 if (parsedNodes.containsKey(typeName)) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
95 return parsedNodes.get(typeName);
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
96 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
97
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 List<? extends TypeElement> types = ElementFilter.typesIn(rootType.getEnclosedElements());
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
99
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 List<NodeData> children = new ArrayList<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 for (TypeElement childElement : types) {
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
102 NodeData childNode = resolveNode(childElement);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 if (childNode != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 children.add(childNode);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
107
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
108 NodeData rootNode = parseNode(rootType);
8663
e2b471ba533a Fixed rootNode should not get replaced if an error occured otherwise no errors were outputted.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
109 if (rootNode == null && children.size() > 0) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
110 rootNode = new NodeData(rootType, rootType.getSimpleName().toString());
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 }
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
112
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
113 parsedNodes.put(typeName, rootNode);
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
114
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 if (rootNode != null) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
116 children.addAll(rootNode.getDeclaredNodes());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
117 rootNode.setDeclaredNodes(children);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 }
7859
3c68170fc9b0 Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents: 7856
diff changeset
119
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
120 return rootNode;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
123 private NodeData parseNode(TypeElement originalTemplateType) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
124 // reloading the type elements is needed for ecj
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
125 TypeElement templateType = Utils.fromTypeMirror(context.reloadTypeElement(originalTemplateType));
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
126
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
127 if (Utils.findAnnotationMirror(processingEnv, originalTemplateType, GeneratedBy.class) != null) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
128 // generated nodes should not get called again.
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 }
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
131
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
132 List<TypeElement> lookupTypes = findSuperClasses(new ArrayList<TypeElement>(), templateType);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
133 Collections.reverse(lookupTypes);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
134
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
135 AnnotationMirror nodeClass = findFirstAnnotation(lookupTypes, NodeClass.class);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
136 TypeMirror nodeType = null;
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
137 if (Utils.isAssignable(context, templateType.asType(), context.getTruffleTypes().getNode())) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
138 nodeType = templateType.asType();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
139 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
140 if (nodeClass != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
141 nodeType = inheritType(nodeClass, "value", nodeType);
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
142 }
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
143
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
144 if (nodeType == null) {
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
145 if (nodeClass == null) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
146 // no node
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
147 return null;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
148 } else {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
149 // FIXME nodeType not specified error
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
150 return null;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
151 }
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
152 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
153
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
154 Set<Element> elementSet = new HashSet<>(context.getEnvironment().getElementUtils().getAllMembers(templateType));
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
155 if (!Utils.typeEquals(templateType.asType(), nodeType)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
156 elementSet.addAll(context.getEnvironment().getElementUtils().getAllMembers(Utils.fromTypeMirror(nodeType)));
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
157
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
158 List<TypeElement> nodeLookupTypes = findSuperClasses(new ArrayList<TypeElement>(), Utils.fromTypeMirror(nodeType));
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
159 Collections.reverse(nodeLookupTypes);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
160 lookupTypes.addAll(nodeLookupTypes);
8644
586b5e117c44 Fixed NodeParser error synchronization was done too late.
Christian Humer <christian.humer@gmail.com>
parents: 8595
diff changeset
161
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
162 Set<TypeElement> types = new HashSet<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
163 for (ListIterator<TypeElement> iterator = lookupTypes.listIterator(); iterator.hasNext();) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
164 TypeElement typeElement = iterator.next();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
165 if (types.contains(typeElement)) {
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
166 iterator.remove();
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
167 } else {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
168 types.add(typeElement);
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
169 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
170 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
171 }
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
172 List<Element> elements = new ArrayList<>(elementSet);
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
173
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
174 NodeData node = parseNodeData(templateType, nodeType, elements, lookupTypes);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
175
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
176 if (node.hasErrors()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
177 return node; // error sync point
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
178 }
8644
586b5e117c44 Fixed NodeParser error synchronization was done too late.
Christian Humer <christian.humer@gmail.com>
parents: 8595
diff changeset
179
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
180 parseMethods(node, elements);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
181
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
182 if (node.hasErrors()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
183 return node;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
184 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
185
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
186 List<NodeData> nodes;
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
187
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
188 if (node.isSplitByMethodName()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
189 nodes = splitNodeData(node);
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
190 } else {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
191 nodes = new ArrayList<>();
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
192 nodes.add(node);
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
193 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
194
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
195 for (NodeData splittedNode : nodes) {
8592
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
196 finalizeSpecializations(elements, splittedNode);
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
197 verifyNode(splittedNode, elements);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
198 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
199
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
200 if (node.isSplitByMethodName()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
201 node.setDeclaredNodes(nodes);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
202 node.setSpecializationListeners(new ArrayList<SpecializationListenerData>());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
203 node.setSpecializations(new ArrayList<SpecializationData>());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
204 return node;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
205 } else {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
206 return node;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
207 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
208 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
209
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
210 private static List<NodeData> splitNodeData(NodeData node) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
211 SortedMap<String, List<SpecializationData>> groupedSpecializations = groupByNodeId(node.getSpecializations());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
212 SortedMap<String, List<SpecializationListenerData>> groupedListeners = groupByNodeId(node.getSpecializationListeners());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
213
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
214 Set<String> ids = new TreeSet<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
215 ids.addAll(groupedSpecializations.keySet());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
216 ids.addAll(groupedListeners.keySet());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
217
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
218 List<NodeData> splitted = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
219 for (String id : ids) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
220 List<SpecializationData> specializations = groupedSpecializations.get(id);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
221 List<SpecializationListenerData> listeners = groupedListeners.get(id);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
222
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
223 if (specializations == null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
224 specializations = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
225 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
226
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
227 if (listeners == null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
228 listeners = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
229 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
230
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
231 String nodeId = node.getNodeId();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
232 if (nodeId.endsWith("Node") && !nodeId.equals("Node")) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
233 nodeId = nodeId.substring(0, nodeId.length() - 4);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
234 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
235 String newNodeId = nodeId + Utils.firstLetterUpperCase(id);
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
236 NodeData copy = new NodeData(node, id, newNodeId);
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
237
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
238 copy.setSpecializations(specializations);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
239 copy.setSpecializationListeners(listeners);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
240
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
241 splitted.add(copy);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
242 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
243
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
244 node.setSpecializations(new ArrayList<SpecializationData>());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
245 node.setSpecializationListeners(new ArrayList<SpecializationListenerData>());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
246
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
247 return splitted;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
248 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
249
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
250 private static <M extends TemplateMethod> SortedMap<String, List<M>> groupByNodeId(List<M> methods) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
251 SortedMap<String, List<M>> grouped = new TreeMap<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
252 for (M m : methods) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
253 List<M> list = grouped.get(m.getId());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
254 if (list == null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
255 list = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
256 grouped.put(m.getId(), list);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
257 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
258 list.add(m);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
259 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
260 return grouped;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
261 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
262
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
263 private void parseMethods(final NodeData node, List<Element> elements) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
264 node.setShortCircuits(new ShortCircuitParser(context, node).parse(elements));
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
265 node.setSpecializationListeners(new SpecializationListenerParser(context, node).parse(elements));
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
266 List<SpecializationData> generics = new GenericParser(context, node).parse(elements);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
267 List<SpecializationData> specializations = new SpecializationMethodParser(context, node).parse(elements);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
268
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
269 List<SpecializationData> allSpecializations = new ArrayList<>();
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
270 allSpecializations.addAll(generics);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
271 allSpecializations.addAll(specializations);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
272
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
273 node.setSpecializations(allSpecializations);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
274 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
275
8592
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
276 private void finalizeSpecializations(List<Element> elements, final NodeData node) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
277 List<SpecializationData> specializations = new ArrayList<>(node.getSpecializations());
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
278
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
279 if (specializations.isEmpty()) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
280 return;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
281 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
282
8592
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
283 for (SpecializationData specialization : specializations) {
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
284 matchGuards(elements, specialization);
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
285 }
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
286
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
287 List<SpecializationData> generics = new ArrayList<>();
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
288 for (SpecializationData spec : specializations) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
289 if (spec.isGeneric()) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
290 generics.add(spec);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
291 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
292 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
293
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
294 if (generics.size() == 1 && specializations.size() == 1) {
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
295 for (SpecializationData generic : generics) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
296 generic.addError("@%s defined but no @%s.", Generic.class.getSimpleName(), Specialization.class.getSimpleName());
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
297 }
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
298 }
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
299
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
300 SpecializationData genericSpecialization = null;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
301 if (generics.size() > 1) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
302 for (SpecializationData generic : generics) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
303 generic.addError("Only @%s is allowed per operation.", Generic.class.getSimpleName());
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
304 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
305 return;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
306 } else if (generics.size() == 1) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
307 genericSpecialization = generics.get(0);
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
308 } else if (node.needsRewrites(context)) {
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
309 SpecializationData specialization = specializations.get(0);
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
310 GenericParser parser = new GenericParser(context, node);
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
311 MethodSpec specification = parser.createDefaultMethodSpec(specialization.getMethod(), null, true, null);
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
312
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
313 ExecutableTypeData anyGenericReturnType = node.findAnyGenericExecutableType(context);
8256
4dc7034317ec Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
314 assert anyGenericReturnType != null;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
315
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
316 ActualParameter returnType = new ActualParameter(specification.getReturnType(), anyGenericReturnType.getType(), 0, false);
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
317 List<ActualParameter> parameters = new ArrayList<>();
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
318 for (ActualParameter specializationParameter : specialization.getParameters()) {
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
319 ParameterSpec parameterSpec = specification.findParameterSpec(specializationParameter.getSpecification().getName());
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
320 NodeChildData child = node.findChild(parameterSpec.getName());
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
321 TypeData actualType;
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
322 if (child == null) {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
323 actualType = specializationParameter.getTypeSystemType();
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
324 } else {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
325 ExecutableTypeData paramType = child.getNodeData().findAnyGenericExecutableType(context);
8256
4dc7034317ec Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
326 assert paramType != null;
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
327 actualType = paramType.getType();
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
328 }
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
329
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
330 if (actualType != null) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
331 parameters.add(new ActualParameter(parameterSpec, actualType, specializationParameter.getIndex(), specializationParameter.isImplicit()));
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
332 } else {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
333 parameters.add(new ActualParameter(parameterSpec, specializationParameter.getType(), specializationParameter.getIndex(), specializationParameter.isImplicit()));
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
334 }
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
335 }
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
336 TemplateMethod genericMethod = new TemplateMethod("Generic", node, specification, null, null, returnType, parameters);
8256
4dc7034317ec Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
337 genericSpecialization = new SpecializationData(genericMethod, true, false);
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
338
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
339 specializations.add(genericSpecialization);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
340 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
341
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
342 if (genericSpecialization != null) {
8662
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
343 if (genericSpecialization.isUseSpecializationsForGeneric()) {
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
344 for (ActualParameter parameter : genericSpecialization.getReturnTypeAndParameters()) {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
345 if (Utils.isObject(parameter.getType())) {
8662
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
346 continue;
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
347 }
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
348 Set<String> types = new HashSet<>();
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
349 for (SpecializationData specialization : specializations) {
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
350 ActualParameter actualParameter = specialization.findParameter(parameter.getLocalName());
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
351 if (actualParameter != null) {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
352 types.add(Utils.getQualifiedName(actualParameter.getType()));
8662
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
353 }
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
354 }
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
355 if (types.size() > 1) {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
356 genericSpecialization.replaceParameter(parameter.getLocalName(), new ActualParameter(parameter, node.getTypeSystem().getGenericTypeData()));
8662
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
357 }
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
358 }
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8644
diff changeset
359 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
360 TemplateMethod uninializedMethod = new TemplateMethod("Uninitialized", node, genericSpecialization.getSpecification(), null, null, genericSpecialization.getReturnType(),
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
361 genericSpecialization.getParameters());
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
362 // should not use messages from generic specialization
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
363 uninializedMethod.getMessages().clear();
8256
4dc7034317ec Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
364 specializations.add(new SpecializationData(uninializedMethod, false, true));
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
365 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
366
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
367 Collections.sort(specializations);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
368
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
369 node.setSpecializations(specializations);
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
370
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
371 List<SpecializationData> needsId = new ArrayList<>();
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
372 for (SpecializationData specialization : specializations) {
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
373 if (specialization.isGeneric()) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
374 specialization.setId("Generic");
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
375 } else if (specialization.isUninitialized()) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
376 specialization.setId("Uninitialized");
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
377 } else {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
378 needsId.add(specialization);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
379 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
380 }
9211
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
381
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
382 // verify specialization parameter length
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
383 if (verifySpecializationParameters(node)) {
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
384 List<String> ids = calculateSpecializationIds(needsId);
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
385 for (int i = 0; i < ids.size(); i++) {
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
386 needsId.get(i).setId(ids.get(i));
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
387 }
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
388 }
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
389 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
390
8592
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
391 private void matchGuards(List<Element> elements, SpecializationData specialization) {
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
392 if (specialization.getGuardDefinitions().isEmpty()) {
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
393 specialization.setGuards(Collections.<GuardData> emptyList());
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
394 return;
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
395 }
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
396
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
397 List<GuardData> foundGuards = new ArrayList<>();
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
398 List<ExecutableElement> methods = ElementFilter.methodsIn(elements);
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
399 for (String guardDefinition : specialization.getGuardDefinitions()) {
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
400 GuardParser parser = new GuardParser(context, specialization, guardDefinition);
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
401 List<GuardData> guards = parser.parse(methods);
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
402 if (!guards.isEmpty()) {
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
403 foundGuards.add(guards.get(0));
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
404 } else {
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
405 // error no guard found
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
406 MethodSpec spec = parser.createSpecification(specialization.getMethod(), null);
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
407 spec.applyTypeDefinitions("types");
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
408 specialization.addError("Guard with method name '%s' not found. Expected signature: %n%s", guardDefinition, spec.toSignatureString("guard"));
8592
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
409 }
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
410 }
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
411
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
412 specialization.setGuards(foundGuards);
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
413
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
414 }
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8316
diff changeset
415
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
416 private static List<String> calculateSpecializationIds(List<SpecializationData> specializations) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
417 int lastSize = -1;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
418 List<List<String>> signatureChunks = new ArrayList<>();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
419 for (SpecializationData other : specializations) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
420 if (other.isUninitialized() || other.isGeneric()) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
421 continue;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
422 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
423 List<String> paramIds = new LinkedList<>();
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
424 paramIds.add(Utils.getTypeId(other.getReturnType().getType()));
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
425 for (ActualParameter param : other.getParameters()) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
426 if (other.getNode().findChild(param.getSpecification().getName()) == null) {
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
427 continue;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
428 }
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
429 paramIds.add(Utils.getTypeId(param.getType()));
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
430 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
431 assert lastSize == -1 || lastSize == paramIds.size();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
432 if (lastSize != -1 && lastSize != paramIds.size()) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
433 throw new AssertionError();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
434 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
435 signatureChunks.add(paramIds);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
436 lastSize = paramIds.size();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
437 }
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
438
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
439 // reduce id vertically
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
440 for (int i = 0; i < lastSize; i++) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
441 String prev = null;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
442 boolean allSame = true;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
443 for (List<String> signature : signatureChunks) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
444 String arg = signature.get(i);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
445 if (prev == null) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
446 prev = arg;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
447 continue;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
448 } else if (!prev.equals(arg)) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
449 allSame = false;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
450 break;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
451 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
452 prev = arg;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
453 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
454
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
455 if (allSame) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
456 for (List<String> signature : signatureChunks) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
457 signature.remove(i);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
458 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
459 lastSize--;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
460 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
461 }
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
462
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
463 // reduce id horizontally
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
464 for (List<String> signature : signatureChunks) {
8316
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
465 if (signature.isEmpty()) {
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
466 continue;
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
467 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
468 String prev = null;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
469 boolean allSame = true;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
470 for (String arg : signature) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
471 if (prev == null) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
472 prev = arg;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
473 continue;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
474 } else if (!prev.equals(arg)) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
475 allSame = false;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
476 break;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
477 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
478 prev = arg;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
479 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
480
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
481 if (allSame) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
482 signature.clear();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
483 signature.add(prev);
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
484 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
485 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
486
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
487 // create signatures
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
488 List<String> signatures = new ArrayList<>();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
489 for (List<String> signatureChunk : signatureChunks) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
490 StringBuilder b = new StringBuilder();
8316
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
491 if (signatureChunk.isEmpty()) {
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
492 b.append("Default");
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
493 } else {
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
494 for (String s : signatureChunk) {
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
495 b.append(s);
c210577168e7 Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents: 8312
diff changeset
496 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
497 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
498 signatures.add(b.toString());
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
499 }
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
500
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
501 Map<String, Integer> counts = new HashMap<>();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
502 for (String s1 : signatures) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
503 Integer count = counts.get(s1);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
504 if (count == null) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
505 count = 0;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
506 }
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
507 count++;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
508 counts.put(s1, count);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
509 }
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
510
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
511 for (String s : counts.keySet()) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
512 int count = counts.get(s);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
513 if (count > 1) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
514 int number = 0;
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
515 for (ListIterator<String> iterator = signatures.listIterator(); iterator.hasNext();) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
516 String s2 = iterator.next();
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
517 if (s.equals(s2)) {
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
518 iterator.set(s2 + number);
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
519 number++;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
520 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
521 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
522 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
523 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
524
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
525 return signatures;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
526 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
527
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
528 private void verifyNode(NodeData nodeData, List<? extends Element> elements) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
529 // verify order is not ambiguous
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
530 verifySpecializationOrder(nodeData);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
531
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
532 verifyMissingAbstractMethods(nodeData, elements);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
533
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
534 assignShortCircuitsToSpecializations(nodeData);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
535
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
536 verifyConstructors(nodeData);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
537
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
538 verifyNamingConvention(nodeData.getShortCircuits(), "needs");
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
539
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
540 verifySpecializationThrows(nodeData);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
541 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
542
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
543 private NodeData parseNodeData(TypeElement templateType, TypeMirror nodeType, List<? extends Element> elements, List<TypeElement> lookupTypes) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
544 NodeData nodeData = new NodeData(templateType, templateType.getSimpleName().toString());
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
545
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
546 AnnotationMirror typeSystemMirror = findFirstAnnotation(lookupTypes, TypeSystemReference.class);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
547 if (typeSystemMirror == null) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
548 nodeData.addError("No @%s annotation found in type hierarchy of %s.", TypeSystemReference.class.getSimpleName(), Utils.getQualifiedName(nodeType));
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
549 return nodeData;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
550 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
552 TypeMirror typeSytemType = Utils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
553 final TypeSystemData typeSystem = (TypeSystemData) context.getTemplate(typeSytemType, true);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
554 if (typeSystem == null) {
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
555 nodeData.addError("The used type system '%s' is invalid or not a Node.", Utils.getQualifiedName(typeSytemType));
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
556 return nodeData;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
557 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
558
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
559 boolean splitByMethodName = false;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
560 AnnotationMirror nodeClass = findFirstAnnotation(lookupTypes, NodeClass.class);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
561 if (nodeClass != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
562 splitByMethodName = Utils.getAnnotationValue(Boolean.class, nodeClass, "splitByMethodName");
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
563 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
564
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
565 List<String> assumptionsList = new ArrayList<>();
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
566
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
567 for (int i = lookupTypes.size() - 1; i >= 0; i--) {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
568 TypeElement type = lookupTypes.get(i);
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
569 AnnotationMirror assumptions = Utils.findAnnotationMirror(context.getEnvironment(), type, NodeAssumptions.class);
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
570 if (assumptions != null) {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
571 List<String> assumptionStrings = Utils.getAnnotationValueList(String.class, assumptions, "value");
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
572 for (String string : assumptionStrings) {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
573 if (assumptionsList.contains(string)) {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
574 assumptionsList.remove(string);
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
575 }
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
576 assumptionsList.add(string);
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
577 }
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
578 }
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
579 }
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
580 nodeData.setAssumptions(new ArrayList<>(assumptionsList));
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
581 nodeData.setNodeType(nodeType);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
582 nodeData.setSplitByMethodName(splitByMethodName);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
583 nodeData.setTypeSystem(typeSystem);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
584 nodeData.setFields(parseFields(elements));
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
585 nodeData.setExecutableTypes(groupExecutableTypes(new ExecutableTypeMethodParser(context, nodeData).parse(elements)));
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
586 parsedNodes.put(Utils.getQualifiedName(templateType), nodeData);
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
587
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
588 // parseChildren invokes cyclic parsing.
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
589 nodeData.setChildren(parseChildren(templateType, elements, lookupTypes));
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8243
diff changeset
590
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
591 return nodeData;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
592 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
593
9211
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
594 private static boolean verifySpecializationParameters(NodeData nodeData) {
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
595 boolean valid = true;
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
596 int args = -1;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
597 for (SpecializationData specializationData : nodeData.getSpecializations()) {
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
598 int signatureArgs = 0;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
599 for (ActualParameter param : specializationData.getParameters()) {
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
600 if (param.getSpecification().isSignature()) {
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
601 signatureArgs++;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
602 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
603 }
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
604 if (args != -1 && args != signatureArgs) {
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
605 valid = false;
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
606 break;
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
607 }
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
608 args = signatureArgs;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
609 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
610 if (!valid) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
611 for (SpecializationData specialization : nodeData.getSpecializations()) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
612 specialization.addError("All specializations must have the same number of arguments.");
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
613 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
614 }
9211
77c17c97f713 Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents: 8663
diff changeset
615 return valid;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
616 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
617
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
618 private static void verifyMissingAbstractMethods(NodeData nodeData, List<? extends Element> originalElements) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
619 if (!nodeData.needsFactory()) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
620 // missing abstract methods only needs to be implemented
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
621 // if we need go generate factory for it.
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
622 return;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
623 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
624
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
625 List<Element> elements = new ArrayList<>(originalElements);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
626
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
627 Set<Element> unusedElements = new HashSet<>(elements);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
628 for (TemplateMethod method : nodeData.getAllTemplateMethods()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
629 unusedElements.remove(method.getMethod());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
630 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
631 if (nodeData.getExtensionElements() != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
632 unusedElements.removeAll(nodeData.getExtensionElements());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
633 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
634
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
635 for (NodeChildData child : nodeData.getChildren()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
636 if (child.getAccessElement() != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
637 unusedElements.remove(child.getAccessElement());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
638 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
639 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
640
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
641 for (ExecutableElement unusedMethod : ElementFilter.methodsIn(unusedElements)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
642 if (unusedMethod.getModifiers().contains(Modifier.ABSTRACT)) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
643 nodeData.addError("The type %s must implement the inherited abstract method %s.", Utils.getSimpleName(nodeData.getTemplateType()), Utils.getReadableSignature(unusedMethod));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
644 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
645 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
646 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
647
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
648 private void verifyConstructors(NodeData nodeData) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
649 if (!nodeData.needsRewrites(context)) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
650 // no specialization constructor is needed if the node never rewrites.
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
651 return;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
652 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
653
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
654 TypeElement type = Utils.fromTypeMirror(nodeData.getNodeType());
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
655 List<ExecutableElement> constructors = ElementFilter.constructorsIn(type.getEnclosedElements());
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
656
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
657 boolean parametersFound = false;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
658 for (ExecutableElement constructor : constructors) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
659 if (!constructor.getParameters().isEmpty()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
660 parametersFound = true;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
661 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
662 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
663 if (!parametersFound) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
664 return;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
665 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
666 for (ExecutableElement e : constructors) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
667 if (e.getParameters().size() == 1) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
668 TypeMirror firstArg = e.getParameters().get(0).asType();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
669 if (Utils.typeEquals(firstArg, nodeData.getNodeType())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
670 if (e.getModifiers().contains(Modifier.PRIVATE)) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
671 nodeData.addError("The specialization constructor must not be private.");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
672 } else if (constructors.size() <= 1) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
673 nodeData.addError("The specialization constructor must not be the only constructor. The definition of an alternative constructor is required.");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
674 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
675 return;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
676 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
677 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
678 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
679
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
680 // not found
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
681 nodeData.addError("Specialization constructor '%s(%s previousNode) { this(...); }' is required.", Utils.getSimpleName(type), Utils.getSimpleName(type));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
682 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
683
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
684 private static Map<Integer, List<ExecutableTypeData>> groupExecutableTypes(List<ExecutableTypeData> executableTypes) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
685 Map<Integer, List<ExecutableTypeData>> groupedTypes = new HashMap<>();
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
686 for (ExecutableTypeData type : executableTypes) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
687 int evaluatedCount = type.getEvaluatedCount();
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
688
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
689 List<ExecutableTypeData> types = groupedTypes.get(evaluatedCount);
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
690 if (types == null) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
691 types = new ArrayList<>();
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
692 groupedTypes.put(evaluatedCount, types);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
693 }
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
694 types.add(type);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
695 }
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
696
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
697 for (List<ExecutableTypeData> types : groupedTypes.values()) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
698 Collections.sort(types);
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
699 }
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
700 return groupedTypes;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
703 private AnnotationMirror findFirstAnnotation(List<? extends Element> elements, Class<? extends Annotation> annotation) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704 for (Element element : elements) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
705 AnnotationMirror mirror = Utils.findAnnotationMirror(processingEnv, element, annotation);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
706 if (mirror != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
707 return mirror;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
708 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
709 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
710 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
711 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
712
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
713 private static List<NodeFieldData> parseFields(List<? extends Element> elements) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
714 List<NodeFieldData> fields = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
715 for (VariableElement field : ElementFilter.fieldsIn(elements)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
716 if (field.getModifiers().contains(Modifier.STATIC)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
717 continue;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
718 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
719 if (field.getModifiers().contains(Modifier.PUBLIC) || field.getModifiers().contains(Modifier.PROTECTED)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
720 fields.add(new NodeFieldData(field));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
721 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
722 }
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
723 return fields;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
724 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
726 private List<NodeChildData> parseChildren(TypeElement templateType, List<? extends Element> elements, final List<TypeElement> typeHierarchy) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
727 Set<String> shortCircuits = new HashSet<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
728 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
729 AnnotationMirror mirror = Utils.findAnnotationMirror(processingEnv, method, ShortCircuit.class);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
730 if (mirror != null) {
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
731 shortCircuits.add(Utils.getAnnotationValue(String.class, mirror, "value"));
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
732 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
733 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
734
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
735 List<NodeChildData> parsedChildren = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
736 List<TypeElement> typeHierarchyReversed = new ArrayList<>(typeHierarchy);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
737 Collections.reverse(typeHierarchyReversed);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
738 for (TypeElement type : typeHierarchyReversed) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
739 AnnotationMirror nodeClassMirror = Utils.findAnnotationMirror(processingEnv, type, NodeClass.class);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
740 AnnotationMirror nodeChildrenMirror = Utils.findAnnotationMirror(processingEnv, type, NodeChildren.class);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
741
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
742 TypeMirror nodeClassType = type.getSuperclass();
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
743 if (!Utils.isAssignable(context, nodeClassType, context.getTruffleTypes().getNode())) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
744 nodeClassType = null;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
745 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
746
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
747 if (nodeClassMirror != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
748 nodeClassType = inheritType(nodeClassMirror, "value", nodeClassType);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
749 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
750
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
751 List<AnnotationMirror> children = Utils.collectAnnotations(context, nodeChildrenMirror, "value", type, NodeChild.class);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
752 for (AnnotationMirror childMirror : children) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
753 String name = Utils.getAnnotationValue(String.class, childMirror, "value");
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
754
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
755 Cardinality cardinality = Cardinality.ONE;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
756
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
757 TypeMirror childType = inheritType(childMirror, "type", nodeClassType);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
758 if (childType.getKind() == TypeKind.ARRAY) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
759 cardinality = Cardinality.MANY;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
760 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
762 Element getter = findGetter(elements, name, childType);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
763
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
764 ExecutionKind kind = ExecutionKind.DEFAULT;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
765 if (shortCircuits.contains(name)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
766 kind = ExecutionKind.SHORT_CIRCUIT;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
767 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
769 NodeChildData nodeChild = new NodeChildData(templateType, childMirror, name, childType, getter, cardinality, kind);
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
770
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
771 parsedChildren.add(nodeChild);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
772
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
773 verifyNodeChild(nodeChild);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
774 if (nodeChild.hasErrors()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
775 continue;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
776 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
777
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
778 NodeData fieldNodeData = resolveNode(Utils.fromTypeMirror(childType));
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
779 nodeChild.setNode(fieldNodeData);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
780 if (fieldNodeData == null) {
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9225
diff changeset
781 nodeChild.addError("Node type '%s' is invalid or not a valid Node.", Utils.getQualifiedName(childType));
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
782 } else if (fieldNodeData.findGenericExecutableTypes(context).isEmpty()) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
783 nodeChild.addError("No executable generic types found for node '%s'.", Utils.getQualifiedName(type));
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
784 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785 }
8312
b1dff27a1da6 Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
786 }
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
787
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
788 List<NodeChildData> filteredChildren = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
789 Set<String> encounteredNames = new HashSet<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
790 for (int i = parsedChildren.size() - 1; i >= 0; i--) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
791 NodeChildData child = parsedChildren.get(i);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
792 if (!encounteredNames.contains(child.getName())) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
793 filteredChildren.add(0, child);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
794 encounteredNames.add(child.getName());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
795 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 }
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
797 return filteredChildren;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
800 private static void verifyNodeChild(NodeChildData nodeChild) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
801 if (nodeChild.getNodeType() == null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
802 nodeChild.addError("No valid node type could be resoleved.");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 }
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
804 // FIXME verify node child
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
805 // FIXME verify node type set
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
806 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
808 private TypeMirror inheritType(AnnotationMirror annotation, String valueName, TypeMirror parentType) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
809 TypeMirror inhertNodeType = context.getType(InheritNode.class);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
810 TypeMirror value = Utils.getAnnotationValue(TypeMirror.class, annotation, valueName);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
811 if (Utils.typeEquals(inhertNodeType, value)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
812 return parentType;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 } else {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
814 return value;
7502
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 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
817
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
818 private Element findGetter(List<? extends Element> elements, String variableName, TypeMirror type) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
819 if (type == null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
820 return null;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
821 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
822 String methodName;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
823 if (Utils.typeEquals(type, context.getType(boolean.class))) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
824 methodName = "is" + Utils.firstLetterUpperCase(variableName);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
825 } else {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
826 methodName = "get" + Utils.firstLetterUpperCase(variableName);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
827 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7506
diff changeset
828
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
829 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
830 if (method.getSimpleName().toString().equals(methodName) && method.getParameters().size() == 0 && Utils.typeEquals(method.getReturnType(), type)) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
831 return method;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
832 }
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
833 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
834 return null;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
837 private void assignShortCircuitsToSpecializations(NodeData node) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
838 Map<String, List<ShortCircuitData>> groupedShortCircuits = groupShortCircuits(node.getShortCircuits());
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
839
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
840 boolean valid = true;
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
841 for (NodeChildData field : node.filterFields(ExecutionKind.SHORT_CIRCUIT)) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 String valueName = field.getName();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
843 List<ShortCircuitData> availableCircuits = groupedShortCircuits.get(valueName);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 if (availableCircuits == null || availableCircuits.isEmpty()) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
846 node.addError("@%s method for short cut value '%s' required.", ShortCircuit.class.getSimpleName(), valueName);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
847 valid = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
849 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 boolean sameMethodName = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
852 String methodName = availableCircuits.get(0).getMethodName();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
853 for (ShortCircuitData circuit : availableCircuits) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
854 if (!circuit.getMethodName().equals(methodName)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
855 sameMethodName = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
859 if (!sameMethodName) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860 for (ShortCircuitData circuit : availableCircuits) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
861 circuit.addError("All short circuits for short cut value '%s' must have the same method name.", valueName);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
862 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
863 valid = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
864 continue;
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
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
867 ShortCircuitData genericCircuit = null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
868 for (ShortCircuitData circuit : availableCircuits) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
869 if (isGenericShortCutMethod(node, circuit)) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
870 genericCircuit = circuit;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
871 break;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
872 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
873 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
874
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
875 if (genericCircuit == null) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
876 node.addError("No generic @%s method available for short cut value '%s'.", ShortCircuit.class.getSimpleName(), valueName);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
877 valid = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
878 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
879 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
880
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
881 for (ShortCircuitData circuit : availableCircuits) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
882 if (circuit != genericCircuit) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
883 circuit.setGenericShortCircuitMethod(genericCircuit);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
884 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
885 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
886 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
887
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
888 if (!valid) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
889 return;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
890 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
891
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
892 NodeChildData[] fields = node.filterFields(ExecutionKind.SHORT_CIRCUIT);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
893 for (SpecializationData specialization : node.getSpecializations()) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
894 List<ShortCircuitData> assignedShortCuts = new ArrayList<>(fields.length);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
895
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
896 for (int i = 0; i < fields.length; i++) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
897 List<ShortCircuitData> availableShortCuts = groupedShortCircuits.get(fields[i].getName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
898
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
899 ShortCircuitData genericShortCircuit = null;
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
900 ShortCircuitData compatibleShortCircuit = null;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
901 for (ShortCircuitData circuit : availableShortCuts) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
902 if (circuit.isGeneric()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
903 genericShortCircuit = circuit;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
904 } else if (circuit.isCompatibleTo(specialization)) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
905 compatibleShortCircuit = circuit;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
906 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
907 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
908
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
909 if (compatibleShortCircuit == null) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
910 compatibleShortCircuit = genericShortCircuit;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
911 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
912 assignedShortCuts.add(compatibleShortCircuit);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
913 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914 specialization.setShortCircuits(assignedShortCuts);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
915 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
916 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
917
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
918 private static void verifyNamingConvention(List<? extends TemplateMethod> methods, String prefix) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
919 for (int i = 0; i < methods.size(); i++) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
920 TemplateMethod m1 = methods.get(i);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
921 if (m1.getMethodName().length() < 3 || !m1.getMethodName().startsWith(prefix)) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
922 m1.addError("Naming convention: method name must start with '%s'.", prefix);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
923 }
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
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
927 private boolean isGenericShortCutMethod(NodeData node, TemplateMethod method) {
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7859
diff changeset
928 for (ActualParameter parameter : method.getParameters()) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
929 NodeChildData field = node.findChild(parameter.getSpecification().getName());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
930 if (field == null) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
931 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
932 }
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
933 ExecutableTypeData found = null;
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
934 List<ExecutableTypeData> executableElements = field.getNodeData().findGenericExecutableTypes(context);
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
935 for (ExecutableTypeData executable : executableElements) {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9211
diff changeset
936 if (executable.getType().equalsType(parameter.getTypeSystemType())) {
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
937 found = executable;
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
938 break;
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
939 }
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
940 }
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7681
diff changeset
941 if (found == null) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
942 return false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
943 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
944 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
945 return true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
946 }
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 private static Map<String, List<ShortCircuitData>> groupShortCircuits(List<ShortCircuitData> shortCircuits) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
949 Map<String, List<ShortCircuitData>> group = new HashMap<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
950 for (ShortCircuitData shortCircuit : shortCircuits) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
951 List<ShortCircuitData> circuits = group.get(shortCircuit.getValueName());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
952 if (circuits == null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
953 circuits = new ArrayList<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
954 group.put(shortCircuit.getValueName(), circuits);
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 circuits.add(shortCircuit);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
957 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
958 return group;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
959 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
960
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
961 private static List<TypeElement> findSuperClasses(List<TypeElement> collection, TypeElement element) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
962 if (element.getSuperclass() != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
963 TypeElement superElement = Utils.fromTypeMirror(element.getSuperclass());
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
964 if (superElement != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
965 findSuperClasses(collection, superElement);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
966 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
967 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
968 collection.add(element);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
969 return collection;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
970 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
971
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
972 private static void verifySpecializationOrder(NodeData node) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
973 List<SpecializationData> specializations = node.getSpecializations();
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
974 for (int i = 0; i < specializations.size(); i++) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
975 SpecializationData m1 = specializations.get(i);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
976 for (int j = i + 1; j < specializations.size(); j++) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
977 SpecializationData m2 = specializations.get(j);
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
978 int inferredOrder = m1.compareBySignature(m2);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
979
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
980 if (m1.getOrder() != Specialization.DEFAULT_ORDER && m2.getOrder() != Specialization.DEFAULT_ORDER) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
981 int specOrder = m1.getOrder() - m2.getOrder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
982 if (specOrder == 0) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
983 m1.addError("Order value %d used multiple times", m1.getOrder());
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
984 m2.addError("Order value %d used multiple times", m1.getOrder());
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
985 return;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
986 } else if ((specOrder < 0 && inferredOrder > 0) || (specOrder > 0 && inferredOrder < 0)) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
987 m1.addError("Explicit order values %d and %d are inconsistent with type lattice ordering.", m1.getOrder(), m2.getOrder());
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
988 m2.addError("Explicit order values %d and %d are inconsistent with type lattice ordering.", m1.getOrder(), m2.getOrder());
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
989 return;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
990 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
991 } else if (inferredOrder == 0) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
992 SpecializationData m = (m1.getOrder() == Specialization.DEFAULT_ORDER ? m1 : m2);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
993 m.addError("Cannot calculate a consistent order for this specialization. Define the order attribute to resolve this.");
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
994 return;
7502
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 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
999
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
1000 private static void verifySpecializationThrows(NodeData node) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1001 Map<String, SpecializationData> specializationMap = new HashMap<>();
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
1002 for (SpecializationData spec : node.getSpecializations()) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1003 specializationMap.put(spec.getMethodName(), spec);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1004 }
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8240
diff changeset
1005 for (SpecializationData sourceSpecialization : node.getSpecializations()) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1006 if (sourceSpecialization.getExceptions() != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1007 for (SpecializationThrowsData throwsData : sourceSpecialization.getExceptions()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1008 for (SpecializationThrowsData otherThrowsData : sourceSpecialization.getExceptions()) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7506
diff changeset
1009 if (otherThrowsData != throwsData && Utils.typeEquals(otherThrowsData.getJavaClass(), throwsData.getJavaClass())) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
1010 throwsData.addError("Duplicate exception type.");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1011 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1012 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1013 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1014 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1015 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1016 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1017
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1018 @Override
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7506
diff changeset
1019 public Class<? extends Annotation> getAnnotationType() {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1020 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1021 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1022
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1023 @Override
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7506
diff changeset
1024 public List<Class<? extends Annotation>> getTypeDelegatedAnnotationTypes() {
7506
40133ce026c6 Project dependency fixes.
Christian Humer <christian.humer@gmail.com>
parents: 7504
diff changeset
1025 return ANNOTATIONS;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1026 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1027
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1028 }