Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java @ 10596:f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Jul 2013 20:32:20 +0200 |
parents | 3cc5fb59916e |
children |
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.*; |
9779
0e4db5ee0695
Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents:
9287
diff
changeset
|
34 import com.oracle.truffle.api.nodes.*; |
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.*; |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
39 import com.oracle.truffle.codegen.processor.template.TemplateMethod.Signature; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 import com.oracle.truffle.codegen.processor.typesystem.*; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7506
diff
changeset
|
42 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
|
43 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
44 public static final List<Class<? extends Annotation>> ANNOTATIONS = Arrays.asList(Generic.class, TypeSystemReference.class, ShortCircuit.class, Specialization.class, SpecializationListener.class, |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
45 NodeContainer.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
|
46 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 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
|
48 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 public NodeParser(ProcessorContext c) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 super(c); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @Override |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 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
|
55 assert element instanceof TypeElement; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
56 NodeData node = null; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 try { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 parsedNodes = new HashMap<>(); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 } |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
66 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 } finally { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 parsedNodes = null; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 } |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
70 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
71 return node; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 @Override |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
79 iterator.remove(); |
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 } |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
82 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
|
83 return null; |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
84 } |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
85 return model; |
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 |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
88 @Override |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 public boolean isDelegateToRootDeclaredType() { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 return true; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
93 @Override |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
94 public Class<? extends Annotation> getAnnotationType() { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
95 return null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
96 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
97 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
98 @Override |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
99 public List<Class<? extends Annotation>> getTypeDelegatedAnnotationTypes() { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
100 return ANNOTATIONS; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
101 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
102 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
103 private NodeData resolveNode(TypeElement rootType) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
104 String typeName = Utils.getQualifiedName(rootType); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
105 if (parsedNodes.containsKey(typeName)) { |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
106 return parsedNodes.get(typeName); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
107 } |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
108 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 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
|
110 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 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
|
112 for (TypeElement childElement : types) { |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
113 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
|
114 if (childNode != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 children.add(childNode); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 } |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
118 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 } |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
123 |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
124 parsedNodes.put(typeName, rootNode); |
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
125 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 rootNode.setDeclaredNodes(children); |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 } |
7859
3c68170fc9b0
Fixed a visibility bug in NodeFactory generation.
Christian Humer <christian.humer@gmail.com>
parents:
7856
diff
changeset
|
130 |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
131 return rootNode; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
134 private NodeData parseNode(TypeElement originalTemplateType) { |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
135 // reloading the type elements is needed for ecj |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
136 TypeElement templateType = Utils.fromTypeMirror(context.reloadTypeElement(originalTemplateType)); |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
137 |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
138 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
|
139 // 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
|
140 return null; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 } |
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
|
142 |
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
|
143 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
|
144 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
|
145 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
146 AnnotationMirror nodeClass = findFirstAnnotation(lookupTypes, NodeContainer.class); |
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
|
147 TypeMirror nodeType = null; |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
148 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
|
149 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
|
150 } |
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
|
151 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
|
152 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
|
153 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
154 |
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
|
155 if (nodeType == null) { |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
156 return null; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
157 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
158 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
159 Elements elementUtil = context.getEnvironment().getElementUtils(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
160 Set<Element> elementSet = new HashSet<>(elementUtil.getAllMembers(templateType)); |
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
|
161 if (!Utils.typeEquals(templateType.asType(), nodeType)) { |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
162 elementSet.addAll(elementUtil.getAllMembers(Utils.fromTypeMirror(nodeType))); |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
163 |
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
|
164 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
|
165 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
|
166 lookupTypes.addAll(nodeLookupTypes); |
8644
586b5e117c44
Fixed NodeParser error synchronization was done too late.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
167 |
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
|
168 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
|
169 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
|
170 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
|
171 if (types.contains(typeElement)) { |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
172 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
|
173 } 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
|
174 types.add(typeElement); |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
175 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
176 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
177 } |
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
|
178 List<Element> elements = new ArrayList<>(elementSet); |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
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 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
|
181 |
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; // 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
|
184 } |
8644
586b5e117c44
Fixed NodeParser error synchronization was done too late.
Christian Humer <christian.humer@gmail.com>
parents:
8595
diff
changeset
|
185 |
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
|
186 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
|
187 |
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
|
188 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
|
189 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
|
190 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
191 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
192 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
|
193 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
194 if (node.isNodeContainer()) { |
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
|
195 nodes = splitNodeData(node); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
196 } else { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
197 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
|
198 nodes.add(node); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
199 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
200 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
201 for (NodeData splittedNode : nodes) { |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
202 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
|
203 verifyNode(splittedNode, elements); |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
204 splittedNode.setPolymorphicSpecializations(createPolymorphicSpecializations(splittedNode)); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
205 assignShortCircuitsToSpecializations(splittedNode); |
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
|
206 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
207 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
208 if (node.isNodeContainer()) { |
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
|
209 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
|
210 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
|
211 node.setSpecializations(new ArrayList<SpecializationData>()); |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
212 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
213 return node; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
214 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
215 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
216 private List<SpecializationData> createPolymorphicSpecializations(NodeData node) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
217 if (!node.needsRewrites(context) || node.getPolymorphicDepth() <= 1) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
218 return Collections.emptyList(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
219 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
220 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
221 Signature genericSignature = node.getGenericSpecialization().getSignature(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
222 Set<Signature> signatures = new HashSet<>(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
223 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
224 for (SpecializationData specialization1 : node.getSpecializations()) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
225 Signature signature = specialization1.getSignature(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
226 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
227 for (SpecializationData specialization2 : node.getSpecializations()) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
228 if (specialization1 == specialization2) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
229 continue; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
230 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
231 signatures.add(signature.combine(genericSignature, specialization2.getSignature())); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
232 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
233 } |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
234 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
235 while (true) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
236 List<Signature> newSignatures = new ArrayList<>(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
237 for (Signature signature1 : signatures) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
238 for (Signature signature2 : signatures) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
239 if (signature1 == signature2) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
240 continue; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
241 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
242 newSignatures.add(signature1.combine(genericSignature, signature2)); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
243 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
244 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
245 if (!signatures.addAll(newSignatures)) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
246 break; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
247 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
248 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
249 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
250 List<Signature> sortedSignatures = new ArrayList<>(signatures); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
251 Collections.sort(sortedSignatures); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
252 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
253 List<SpecializationData> specializations = new ArrayList<>(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
254 SpecializationData generic = node.getGenericSpecialization(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
255 for (Signature signature : sortedSignatures) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
256 SpecializationData specialization = new SpecializationData(generic, false, false, true); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
257 specialization.forceFrame(context.getTruffleTypes().getFrame()); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
258 specialization.setNode(node); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
259 specialization.updateSignature(signature); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
260 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
261 if (specialization.isGenericSpecialization(context)) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
262 specializations.add(0, specialization); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
263 } else { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
264 specializations.add(specialization); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
265 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
266 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
267 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
268 return specializations; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
269 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
270 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
271 private NodeData parseNodeData(TypeElement templateType, TypeMirror nodeType, List<? extends Element> elements, List<TypeElement> lookupTypes) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
272 NodeData nodeData = new NodeData(templateType, templateType.getSimpleName().toString()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
273 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
274 AnnotationMirror typeSystemMirror = findFirstAnnotation(lookupTypes, TypeSystemReference.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
275 if (typeSystemMirror == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
276 nodeData.addError("No @%s annotation found in type hierarchy of %s.", TypeSystemReference.class.getSimpleName(), Utils.getQualifiedName(nodeType)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
277 return nodeData; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
278 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
279 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
280 TypeMirror typeSytemType = Utils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value"); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
281 final TypeSystemData typeSystem = (TypeSystemData) context.getTemplate(typeSytemType, true); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
282 if (typeSystem == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
283 nodeData.addError("The used type system '%s' is invalid or not a Node.", Utils.getQualifiedName(typeSytemType)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
284 return nodeData; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
285 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
286 |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
287 AnnotationMirror polymorphicMirror = findFirstAnnotation(lookupTypes, PolymorphicLimit.class); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
288 if (polymorphicMirror != null) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
289 AnnotationValue limitValue = Utils.getAnnotationValue(polymorphicMirror, "value"); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
290 int polymorphicLimit = Utils.getAnnotationValue(Integer.class, polymorphicMirror, "value"); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
291 if (polymorphicLimit < 1) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
292 nodeData.addError(limitValue, "Invalid polymorphic limit %s.", polymorphicLimit); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
293 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
294 nodeData.setPolymorphicDepth(polymorphicLimit); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
295 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
296 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
297 List<String> assumptionsList = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
298 for (int i = lookupTypes.size() - 1; i >= 0; i--) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
299 TypeElement type = lookupTypes.get(i); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
300 AnnotationMirror assumptions = Utils.findAnnotationMirror(context.getEnvironment(), type, NodeAssumptions.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
301 if (assumptions != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
302 List<String> assumptionStrings = Utils.getAnnotationValueList(String.class, assumptions, "value"); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
303 for (String string : assumptionStrings) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
304 if (assumptionsList.contains(string)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
305 assumptionsList.remove(string); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
306 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
307 assumptionsList.add(string); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
308 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
309 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
310 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
311 AnnotationMirror nodeInfoMirror = findFirstAnnotation(lookupTypes, NodeInfo.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
312 if (nodeInfoMirror != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
313 nodeData.setShortName(Utils.getAnnotationValue(String.class, nodeInfoMirror, "shortName")); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
314 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
315 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
316 nodeData.setAssumptions(new ArrayList<>(assumptionsList)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
317 nodeData.setNodeType(nodeType); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
318 AnnotationMirror nodeContainer = findFirstAnnotation(lookupTypes, NodeContainer.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
319 nodeData.setNodeContainer(nodeContainer != null); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
320 nodeData.setTypeSystem(typeSystem); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
321 nodeData.setFields(parseFields(elements)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
322 parsedNodes.put(Utils.getQualifiedName(templateType), nodeData); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
323 // parseChildren invokes cyclic parsing. |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
324 nodeData.setChildren(parseChildren(elements, lookupTypes)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
325 nodeData.setExecutableTypes(groupExecutableTypes(new ExecutableTypeMethodParser(context, nodeData).parse(elements))); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
326 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
327 return nodeData; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
328 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
329 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
330 private static List<NodeFieldData> parseFields(List<? extends Element> elements) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
331 List<NodeFieldData> fields = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
332 for (VariableElement field : ElementFilter.fieldsIn(elements)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
333 if (field.getModifiers().contains(Modifier.STATIC)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
334 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
335 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
336 if (field.getModifiers().contains(Modifier.PUBLIC) || field.getModifiers().contains(Modifier.PROTECTED)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
337 fields.add(new NodeFieldData(field)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
338 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
339 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
340 return fields; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
341 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
342 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
343 private List<NodeChildData> parseChildren(List<? extends Element> elements, final List<TypeElement> typeHierarchy) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
344 Set<String> shortCircuits = new HashSet<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
345 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
346 AnnotationMirror mirror = Utils.findAnnotationMirror(processingEnv, method, ShortCircuit.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
347 if (mirror != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
348 shortCircuits.add(Utils.getAnnotationValue(String.class, mirror, "value")); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
349 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
350 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
351 Map<String, TypeMirror> castNodeTypes = new HashMap<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
352 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
353 AnnotationMirror mirror = Utils.findAnnotationMirror(processingEnv, method, CreateCast.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
354 if (mirror != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
355 List<String> children = (Utils.getAnnotationValueList(String.class, mirror, "value")); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
356 if (children != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
357 for (String child : children) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
358 castNodeTypes.put(child, method.getReturnType()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
359 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
360 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
361 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
362 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
363 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
364 List<NodeChildData> parsedChildren = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
365 List<TypeElement> typeHierarchyReversed = new ArrayList<>(typeHierarchy); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
366 Collections.reverse(typeHierarchyReversed); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
367 for (TypeElement type : typeHierarchyReversed) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
368 AnnotationMirror nodeClassMirror = Utils.findAnnotationMirror(processingEnv, type, NodeContainer.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
369 AnnotationMirror nodeChildrenMirror = Utils.findAnnotationMirror(processingEnv, type, NodeChildren.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
370 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
371 TypeMirror nodeClassType = type.getSuperclass(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
372 if (!Utils.isAssignable(context, nodeClassType, context.getTruffleTypes().getNode())) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
373 nodeClassType = null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
374 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
375 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
376 if (nodeClassMirror != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
377 nodeClassType = inheritType(nodeClassMirror, "value", nodeClassType); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
378 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
379 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
380 List<AnnotationMirror> children = Utils.collectAnnotations(context, nodeChildrenMirror, "value", type, NodeChild.class); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
381 int index = 0; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
382 for (AnnotationMirror childMirror : children) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
383 String name = Utils.getAnnotationValue(String.class, childMirror, "value"); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
384 if (name.equals("")) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
385 name = "child" + index; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
386 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
387 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
388 Cardinality cardinality = Cardinality.ONE; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
389 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
390 TypeMirror childType = inheritType(childMirror, "type", nodeClassType); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
391 if (childType.getKind() == TypeKind.ARRAY) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
392 cardinality = Cardinality.MANY; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
393 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
394 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
395 TypeMirror originalChildType = childType; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
396 TypeMirror castNodeType = castNodeTypes.get(name); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
397 if (castNodeType != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
398 childType = castNodeType; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
399 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
400 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
401 Element getter = findGetter(elements, name, childType); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
402 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
403 ExecutionKind kind = ExecutionKind.DEFAULT; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
404 if (shortCircuits.contains(name)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
405 kind = ExecutionKind.SHORT_CIRCUIT; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
406 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
407 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
408 NodeChildData nodeChild = new NodeChildData(type, childMirror, name, childType, originalChildType, getter, cardinality, kind); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
409 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
410 parsedChildren.add(nodeChild); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
411 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
412 verifyNodeChild(nodeChild); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
413 if (nodeChild.hasErrors()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
414 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
415 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
416 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
417 NodeData fieldNodeData = resolveNode(Utils.fromTypeMirror(childType)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
418 nodeChild.setNode(fieldNodeData); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
419 if (fieldNodeData == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
420 nodeChild.addError("Node type '%s' is invalid or not a valid Node.", Utils.getQualifiedName(childType)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
421 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
422 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
423 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
424 index++; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
425 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
426 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
427 List<NodeChildData> filteredChildren = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
428 Set<String> encounteredNames = new HashSet<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
429 for (int i = parsedChildren.size() - 1; i >= 0; i--) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
430 NodeChildData child = parsedChildren.get(i); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
431 if (!encounteredNames.contains(child.getName())) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
432 filteredChildren.add(0, child); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
433 encounteredNames.add(child.getName()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
434 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
435 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
436 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
437 for (NodeChildData child : filteredChildren) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
438 List<String> executeWithStrings = Utils.getAnnotationValueList(String.class, child.getMessageAnnotation(), "executeWith"); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
439 AnnotationValue executeWithValue = Utils.getAnnotationValue(child.getMessageAnnotation(), "executeWith"); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
440 List<NodeChildData> executeWith = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
441 for (String executeWithString : executeWithStrings) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
442 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
443 if (child.getName().equals(executeWithString)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
444 child.addError(executeWithValue, "The child node '%s' cannot be executed with itself.", executeWithString); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
445 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
446 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
447 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
448 NodeChildData found = null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
449 boolean before = true; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
450 for (NodeChildData resolveChild : filteredChildren) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
451 if (resolveChild == child) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
452 before = false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
453 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
454 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
455 if (resolveChild.getName().equals(executeWithString)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
456 found = resolveChild; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
457 break; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
458 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
459 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
460 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
461 if (found == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
462 child.addError(executeWithValue, "The child node '%s' cannot be executed with '%s'. The child node was not found.", child.getName(), executeWithString); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
463 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
464 } else if (!before) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
465 child.addError(executeWithValue, "The child node '%s' cannot be executed with '%s'. The node %s is executed after the current node.", child.getName(), executeWithString, |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
466 executeWithString); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
467 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
468 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
469 executeWith.add(found); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
470 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
471 child.setExecuteWith(executeWith); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
472 if (child.getNodeData() == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
473 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
474 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
475 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
476 List<ExecutableTypeData> types = child.findGenericExecutableTypes(context); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
477 if (types.isEmpty()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
478 child.addError(executeWithValue, "No generic execute method found with %s evaluated arguments for node type %s.", executeWith.size(), Utils.getSimpleName(child.getNodeType())); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
479 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
480 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
481 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
482 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
483 return filteredChildren; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
484 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
485 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
486 private void parseMethods(final NodeData node, List<Element> elements) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
487 node.setShortCircuits(new ShortCircuitParser(context, node).parse(elements)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
488 node.setSpecializationListeners(new SpecializationListenerParser(context, node).parse(elements)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
489 List<SpecializationData> generics = new GenericParser(context, node).parse(elements); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
490 List<SpecializationData> specializations = new SpecializationMethodParser(context, node).parse(elements); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
491 node.setCasts(new CreateCastParser(context, node).parse(elements)); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
492 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
493 List<SpecializationData> allSpecializations = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
494 allSpecializations.addAll(generics); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
495 allSpecializations.addAll(specializations); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
496 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
497 node.setSpecializations(allSpecializations); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
498 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
499 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
500 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
|
501 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
|
502 SortedMap<String, List<SpecializationListenerData>> groupedListeners = groupByNodeId(node.getSpecializationListeners()); |
10446
746fa60be266
Implemented CreateCast annotation for easier insertion of casts.
Christian Humer <christian.humer@gmail.com>
parents:
10444
diff
changeset
|
503 SortedMap<String, List<CreateCastData>> groupedCasts = groupByNodeId(node.getCasts()); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
504 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
505 Set<String> ids = new TreeSet<>(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
506 ids.addAll(groupedSpecializations.keySet()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
507 ids.addAll(groupedListeners.keySet()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
508 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
509 List<NodeData> splitted = new ArrayList<>(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
510 for (String id : ids) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
511 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
|
512 List<SpecializationListenerData> listeners = groupedListeners.get(id); |
10446
746fa60be266
Implemented CreateCast annotation for easier insertion of casts.
Christian Humer <christian.humer@gmail.com>
parents:
10444
diff
changeset
|
513 List<CreateCastData> casts = groupedCasts.get(id); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
514 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
515 if (specializations == null) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
516 specializations = new ArrayList<>(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
517 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
518 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
519 if (listeners == null) { |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
520 listeners = new ArrayList<>(); |
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 String nodeId = node.getNodeId(); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
524 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
|
525 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
|
526 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
527 String newNodeId = nodeId + Utils.firstLetterUpperCase(id); |
8248
c4c3f50fa9c2
Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents:
8245
diff
changeset
|
528 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
|
529 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
530 copy.setSpecializations(specializations); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
531 copy.setSpecializationListeners(listeners); |
10446
746fa60be266
Implemented CreateCast annotation for easier insertion of casts.
Christian Humer <christian.humer@gmail.com>
parents:
10444
diff
changeset
|
532 copy.setCasts(casts); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
533 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
534 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
|
535 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
536 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
537 node.setSpecializations(new ArrayList<SpecializationData>()); |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
538 node.setSpecializationListeners(new ArrayList<SpecializationListenerData>()); |
10446
746fa60be266
Implemented CreateCast annotation for easier insertion of casts.
Christian Humer <christian.humer@gmail.com>
parents:
10444
diff
changeset
|
539 node.setCasts(new ArrayList<CreateCastData>()); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
540 |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
541 return splitted; |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
542 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
543 |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
544 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
|
545 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
|
546 |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
547 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
|
548 return; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
549 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
550 |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
551 for (SpecializationData specialization : specializations) { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
552 matchGuards(elements, specialization); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
553 } |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
554 |
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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
560 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
561 |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
566 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
567 |
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
|
568 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
|
569 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
|
570 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
|
571 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
|
572 } |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
573 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
|
574 } 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
|
575 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
|
576 } 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
|
577 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
|
578 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
|
579 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
|
580 |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
581 ExecutableTypeData anyGenericReturnType = node.findAnyGenericExecutableType(context, 0); |
8256 | 582 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
|
583 |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9211
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 } else { |
9287
8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents:
9286
diff
changeset
|
593 ExecutableTypeData paramType = child.findAnyGenericExecutableType(context); |
8256 | 594 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
|
595 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
|
596 } |
9227
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
597 |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
598 if (actualType != null) { |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
599 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
|
600 } else { |
6d92fdf1c999
Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents:
9225
diff
changeset
|
601 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
|
602 } |
8251
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
603 } |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
604 TemplateMethod genericMethod = new TemplateMethod("Generic", node, specification, null, null, returnType, parameters); |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
605 genericSpecialization = new SpecializationData(genericMethod, true, false, 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
|
606 |
cb70ed101b5f
Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents:
8248
diff
changeset
|
607 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
|
608 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
609 |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
610 if (genericSpecialization != null) { |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
611 for (ActualParameter parameter : genericSpecialization.getReturnTypeAndParameters()) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
612 if (Utils.isObject(parameter.getType())) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
613 continue; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
614 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
615 Set<String> types = new HashSet<>(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
616 for (SpecializationData specialization : specializations) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
617 ActualParameter actualParameter = specialization.findParameter(parameter.getLocalName()); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
618 if (actualParameter != null) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
619 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
|
620 } |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
621 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
622 if (types.size() > 1) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
623 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
|
624 } |
5eeade940236
Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents:
8644
diff
changeset
|
625 } |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
626 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
|
627 genericSpecialization.getParameters()); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
628 // should not use messages from generic specialization |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
629 uninializedMethod.getMessages().clear(); |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
630 specializations.add(new SpecializationData(uninializedMethod, false, true, false)); |
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
|
631 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
632 |
8595
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
633 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
|
634 |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
635 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
|
636 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
637 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
|
638 for (SpecializationData specialization : specializations) { |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
639 if (specialization.isGeneric()) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
640 specialization.setId("Generic"); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
641 } else if (specialization.isUninitialized()) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
642 specialization.setId("Uninitialized"); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
643 } else { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
644 needsId.add(specialization); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
645 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
646 } |
9211
77c17c97f713
Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents:
8663
diff
changeset
|
647 |
77c17c97f713
Fixed verifying specialization argument length must be done before generating specialization ids.
Christian Humer <christian.humer@gmail.com>
parents:
8663
diff
changeset
|
648 // 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
654 } |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
655 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
656 // calculate reachability |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
657 int specializationCount = 0; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
658 boolean reachable = true; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
659 for (SpecializationData specialization : specializations) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
660 if (specialization.isUninitialized()) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
661 specialization.setReachable(true); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
662 continue; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
663 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
664 if (!reachable && specialization.getMethod() != null) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
665 specialization.addError("%s is not reachable.", specialization.isGeneric() ? "Generic" : "Specialization"); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
666 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
667 specialization.setReachable(reachable); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
668 if (!specialization.hasRewrite(context)) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
669 reachable = false; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
670 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
671 if (!specialization.isGeneric()) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
672 specializationCount++; |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
673 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
674 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
675 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
676 if (node.getPolymorphicDepth() < 0) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
677 node.setPolymorphicDepth(specializationCount - 1); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
678 } |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
679 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
680 // reduce polymorphicness if generic is not reachable |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
681 if (node.getGenericSpecialization() != null && !node.getGenericSpecialization().isReachable()) { |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
682 node.setPolymorphicDepth(1); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
683 } |
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
|
684 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
685 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
686 private void assignShortCircuitsToSpecializations(NodeData node) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
687 Map<String, List<ShortCircuitData>> groupedShortCircuits = groupShortCircuits(node.getShortCircuits()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
688 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
689 boolean valid = true; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
690 for (NodeChildData field : node.filterFields(ExecutionKind.SHORT_CIRCUIT)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
691 String valueName = field.getName(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
692 List<ShortCircuitData> availableCircuits = groupedShortCircuits.get(valueName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
693 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
694 if (availableCircuits == null || availableCircuits.isEmpty()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
695 node.addError("@%s method for short cut value '%s' required.", ShortCircuit.class.getSimpleName(), valueName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
696 valid = false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
697 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
698 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
699 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
700 boolean sameMethodName = true; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
701 String methodName = availableCircuits.get(0).getMethodName(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
702 for (ShortCircuitData circuit : availableCircuits) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
703 if (!circuit.getMethodName().equals(methodName)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
704 sameMethodName = false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
705 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
706 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
707 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
708 if (!sameMethodName) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
709 for (ShortCircuitData circuit : availableCircuits) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
710 circuit.addError("All short circuits for short cut value '%s' must have the same method name.", valueName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
711 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
712 valid = false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
713 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
714 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
715 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
716 ShortCircuitData genericCircuit = null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
717 for (ShortCircuitData circuit : availableCircuits) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
718 if (isGenericShortCutMethod(node, circuit)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
719 genericCircuit = circuit; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
720 break; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
721 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
722 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
723 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
724 if (genericCircuit == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
725 node.addError("No generic @%s method available for short cut value '%s'.", ShortCircuit.class.getSimpleName(), valueName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
726 valid = false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
727 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
728 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
729 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
730 for (ShortCircuitData circuit : availableCircuits) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
731 if (circuit != genericCircuit) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
732 circuit.setGenericShortCircuitMethod(genericCircuit); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
733 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
734 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
735 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
736 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
737 if (!valid) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
738 return; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
739 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
740 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
741 NodeChildData[] fields = node.filterFields(ExecutionKind.SHORT_CIRCUIT); |
10596
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
742 List<SpecializationData> specializations = new ArrayList<>(); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
743 specializations.addAll(node.getSpecializations()); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
744 specializations.addAll(node.getPolymorphicSpecializations()); |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
745 |
f43eb2f1bbbc
Truffle-DSL: code-generation of polymorphic caching
Christian Humer <christian.humer@gmail.com>
parents:
10591
diff
changeset
|
746 for (SpecializationData specialization : specializations) { |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
747 List<ShortCircuitData> assignedShortCuts = new ArrayList<>(fields.length); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
748 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
749 for (int i = 0; i < fields.length; i++) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
750 List<ShortCircuitData> availableShortCuts = groupedShortCircuits.get(fields[i].getName()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
751 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
752 ShortCircuitData genericShortCircuit = null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
753 ShortCircuitData compatibleShortCircuit = null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
754 for (ShortCircuitData circuit : availableShortCuts) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
755 if (circuit.isGeneric()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
756 genericShortCircuit = circuit; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
757 } else if (circuit.isCompatibleTo(specialization)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
758 compatibleShortCircuit = circuit; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
759 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
760 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
761 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
762 if (compatibleShortCircuit == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
763 compatibleShortCircuit = genericShortCircuit; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
764 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
765 assignedShortCuts.add(compatibleShortCircuit); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
766 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
767 specialization.setShortCircuits(assignedShortCuts); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
768 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
769 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
770 |
8592
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
771 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
|
772 if (specialization.getGuardDefinitions().isEmpty()) { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
773 specialization.setGuards(Collections.<GuardData> emptyList()); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
774 return; |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
775 } |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
776 |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
777 List<GuardData> foundGuards = new ArrayList<>(); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
778 List<ExecutableElement> methods = ElementFilter.methodsIn(elements); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
779 for (String guardDefinition : specialization.getGuardDefinitions()) { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
780 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
|
781 List<GuardData> guards = parser.parse(methods); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
782 if (!guards.isEmpty()) { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
783 foundGuards.add(guards.get(0)); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
784 } else { |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
785 // 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
|
786 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
|
787 spec.applyTypeDefinitions("types"); |
8a1115c92271
Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents:
8592
diff
changeset
|
788 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
|
789 } |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
790 } |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
791 |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
792 specialization.setGuards(foundGuards); |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
793 |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
794 } |
a80bf36c6a1e
Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents:
8316
diff
changeset
|
795 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
796 private static List<String> calculateSpecializationIds(List<SpecializationData> specializations) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
797 int lastSize = -1; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
798 List<List<String>> signatureChunks = new ArrayList<>(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
799 for (SpecializationData other : specializations) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
800 if (other.isUninitialized() || other.isGeneric()) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
801 continue; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
802 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
803 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
|
804 paramIds.add(Utils.getTypeId(other.getReturnType().getType())); |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
805 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
|
806 if (other.getNode().findChild(param.getSpecification().getName()) == null) { |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
807 continue; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
808 } |
9217
61ba6fc21ba4
Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents:
9211
diff
changeset
|
809 paramIds.add(Utils.getTypeId(param.getType())); |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
810 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
811 assert lastSize == -1 || lastSize == paramIds.size(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
812 if (lastSize != -1 && lastSize != paramIds.size()) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
813 throw new AssertionError(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
814 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
815 signatureChunks.add(paramIds); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
816 lastSize = paramIds.size(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
817 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
818 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
819 // reduce id vertically |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
820 for (int i = 0; i < lastSize; i++) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
821 String prev = null; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
822 boolean allSame = true; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
823 for (List<String> signature : signatureChunks) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
824 String arg = signature.get(i); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
825 if (prev == null) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
826 prev = arg; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
827 continue; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
828 } else if (!prev.equals(arg)) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
829 allSame = false; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
830 break; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
831 } |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
832 prev = arg; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
833 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
834 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
835 if (allSame) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
836 for (List<String> signature : signatureChunks) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
837 signature.remove(i); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
838 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
839 lastSize--; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
840 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
841 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
842 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
843 // reduce id horizontally |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
844 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
|
845 if (signature.isEmpty()) { |
c210577168e7
Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents:
8312
diff
changeset
|
846 continue; |
c210577168e7
Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents:
8312
diff
changeset
|
847 } |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
848 String prev = null; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
849 boolean allSame = true; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
850 for (String arg : signature) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
851 if (prev == null) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
852 prev = arg; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
853 continue; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
854 } else if (!prev.equals(arg)) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
855 allSame = false; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
856 break; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
857 } |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
858 prev = arg; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
859 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
860 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
861 if (allSame) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
862 signature.clear(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
863 signature.add(prev); |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
864 } |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
865 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
866 |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
867 // create signatures |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
868 List<String> signatures = new ArrayList<>(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
869 for (List<String> signatureChunk : signatureChunks) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
870 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
|
871 if (signatureChunk.isEmpty()) { |
c210577168e7
Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents:
8312
diff
changeset
|
872 b.append("Default"); |
c210577168e7
Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents:
8312
diff
changeset
|
873 } else { |
c210577168e7
Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents:
8312
diff
changeset
|
874 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
|
875 b.append(s); |
c210577168e7
Fixed not specializing nodes were named Null instead of Default.
Christian Humer <christian.humer@gmail.com>
parents:
8312
diff
changeset
|
876 } |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
877 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
878 signatures.add(b.toString()); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
879 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
880 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
881 Map<String, Integer> counts = new HashMap<>(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
882 for (String s1 : signatures) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
883 Integer count = counts.get(s1); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
884 if (count == null) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
885 count = 0; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
886 } |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
887 count++; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
888 counts.put(s1, count); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
889 } |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
890 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
891 for (String s : counts.keySet()) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
892 int count = counts.get(s); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
893 if (count > 1) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
894 int number = 0; |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
895 for (ListIterator<String> iterator = signatures.listIterator(); iterator.hasNext();) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
896 String s2 = iterator.next(); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
897 if (s.equals(s2)) { |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
898 iterator.set(s2 + number); |
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
899 number++; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
900 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
901 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
902 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
903 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
904 |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
905 return signatures; |
8245
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
906 } |
703c09f8640c
Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents:
8243
diff
changeset
|
907 |
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
|
908 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
|
909 // 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
|
910 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
|
911 |
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
|
912 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
|
913 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
914 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
|
915 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
916 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
|
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 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
|
919 } |
ac4e8c16ffdf
Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents:
8240
diff
changeset
|
920 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
921 private static void verifyNodeChild(NodeChildData nodeChild) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
922 if (nodeChild.getNodeType() == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
923 nodeChild.addError("No valid node type could be resoleved."); |
9279
2a4b57f02fb4
Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents:
9227
diff
changeset
|
924 } |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
925 // FIXME verify node child |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
926 // FIXME verify node type set |
8237
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
927 } |
6b74ffe38183
Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents:
7859
diff
changeset
|
928 |
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 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
|
930 if (!nodeData.needsFactory()) { |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
931 // 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
|
932 // 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
|
933 return; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
934 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
935 |
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
|
936 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
|
937 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
938 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
|
939 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
|
940 unusedElements.remove(method.getMethod()); |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
941 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
942 if (nodeData.getExtensionElements() != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
943 unusedElements.removeAll(nodeData.getExtensionElements()); |
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 |
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
|
946 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
|
947 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
|
948 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
|
949 } |
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
|
950 } |
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
|
951 |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
952 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
|
953 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
|
954 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
|
955 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
956 } |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
957 } |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
958 |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
959 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
|
960 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
|
961 // 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
|
962 return; |
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
963 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
964 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
965 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
|
966 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
|
967 |
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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 } |
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
|
973 } |
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
|
974 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
|
975 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
|
976 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
977 for (ExecutableElement e : constructors) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
978 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
|
979 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
|
980 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
|
981 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
|
982 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
|
983 } 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
|
984 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
|
985 } |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
986 return; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
987 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
988 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
989 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
990 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
991 // 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
|
992 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
|
993 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
994 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
995 private static boolean verifySpecializationParameters(NodeData nodeData) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
996 boolean valid = true; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
997 int args = -1; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
998 for (SpecializationData specializationData : nodeData.getSpecializations()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
999 int signatureArgs = 0; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1000 for (ActualParameter param : specializationData.getParameters()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1001 if (param.getSpecification().isSignature()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1002 signatureArgs++; |
10446
746fa60be266
Implemented CreateCast annotation for easier insertion of casts.
Christian Humer <christian.humer@gmail.com>
parents:
10444
diff
changeset
|
1003 } |
746fa60be266
Implemented CreateCast annotation for easier insertion of casts.
Christian Humer <christian.humer@gmail.com>
parents:
10444
diff
changeset
|
1004 } |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1005 if (args != -1 && args != signatureArgs) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1006 valid = false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1007 break; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1008 } |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1009 args = signatureArgs; |
8312
b1dff27a1da6
Fixed specialization id generation.
Christian Humer <christian.humer@gmail.com>
parents:
8310
diff
changeset
|
1010 } |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1011 if (!valid) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1012 for (SpecializationData specialization : nodeData.getSpecializations()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1013 specialization.addError("All specializations must have the same number of arguments."); |
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
|
1014 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1015 } |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1016 return valid; |
7502
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 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 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
|
1025 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
|
1026 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1027 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
|
1028 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
|
1029 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
|
1030 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
|
1031 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
|
1032 return; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1033 } 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
|
1034 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
|
1035 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
|
1036 return; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1037 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1038 } else if (inferredOrder == 0) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1039 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
|
1040 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
|
1041 return; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1042 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1043 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1044 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1045 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1046 |
8252
0905d796944a
Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents:
8251
diff
changeset
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 } |
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
|
1052 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
|
1053 if (sourceSpecialization.getExceptions() != null) { |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1054 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
|
1055 for (SpecializationThrowsData otherThrowsData : sourceSpecialization.getExceptions()) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7506
diff
changeset
|
1056 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
|
1057 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
|
1058 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1059 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1060 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1061 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1062 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1063 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1064 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1065 private static void verifyNamingConvention(List<? extends TemplateMethod> methods, String prefix) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1066 for (int i = 0; i < methods.size(); i++) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1067 TemplateMethod m1 = methods.get(i); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1068 if (m1.getMethodName().length() < 3 || !m1.getMethodName().startsWith(prefix)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1069 m1.addError("Naming convention: method name must start with '%s'.", prefix); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1070 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1071 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1072 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1073 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1074 private static Map<Integer, List<ExecutableTypeData>> groupExecutableTypes(List<ExecutableTypeData> executableTypes) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1075 Map<Integer, List<ExecutableTypeData>> groupedTypes = new HashMap<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1076 for (ExecutableTypeData type : executableTypes) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1077 int evaluatedCount = type.getEvaluatedCount(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1078 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1079 List<ExecutableTypeData> types = groupedTypes.get(evaluatedCount); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1080 if (types == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1081 types = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1082 groupedTypes.put(evaluatedCount, types); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1083 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1084 types.add(type); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1085 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1086 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1087 for (List<ExecutableTypeData> types : groupedTypes.values()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1088 Collections.sort(types); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1089 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1090 return groupedTypes; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1091 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1092 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1093 private AnnotationMirror findFirstAnnotation(List<? extends Element> elements, Class<? extends Annotation> annotation) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1094 for (Element element : elements) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1095 AnnotationMirror mirror = Utils.findAnnotationMirror(processingEnv, element, annotation); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1096 if (mirror != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1097 return mirror; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1098 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1099 } |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1100 return null; |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1101 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1102 |
10591
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1103 private TypeMirror inheritType(AnnotationMirror annotation, String valueName, TypeMirror parentType) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1104 TypeMirror inhertNodeType = context.getTruffleTypes().getNode(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1105 TypeMirror value = Utils.getAnnotationValue(TypeMirror.class, annotation, valueName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1106 if (Utils.typeEquals(inhertNodeType, value)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1107 return parentType; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1108 } else { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1109 return value; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1110 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1111 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1112 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1113 private Element findGetter(List<? extends Element> elements, String variableName, TypeMirror type) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1114 if (type == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1115 return null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1116 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1117 String methodName; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1118 if (Utils.typeEquals(type, context.getType(boolean.class))) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1119 methodName = "is" + Utils.firstLetterUpperCase(variableName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1120 } else { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1121 methodName = "get" + Utils.firstLetterUpperCase(variableName); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1122 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1123 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1124 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1125 if (method.getSimpleName().toString().equals(methodName) && method.getParameters().size() == 0 && Utils.isAssignable(context, type, method.getReturnType())) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1126 return method; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1127 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1128 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1129 return null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1130 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1131 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1132 private boolean isGenericShortCutMethod(NodeData node, TemplateMethod method) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1133 for (ActualParameter parameter : method.getParameters()) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1134 NodeChildData field = node.findChild(parameter.getSpecification().getName()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1135 if (field == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1136 continue; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1137 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1138 ExecutableTypeData found = null; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1139 List<ExecutableTypeData> executableElements = field.findGenericExecutableTypes(context); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1140 for (ExecutableTypeData executable : executableElements) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1141 if (executable.getType().equalsType(parameter.getTypeSystemType())) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1142 found = executable; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1143 break; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1144 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1145 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1146 if (found == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1147 return false; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1148 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1149 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1150 return true; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1151 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1152 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1153 private static Map<String, List<ShortCircuitData>> groupShortCircuits(List<ShortCircuitData> shortCircuits) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1154 Map<String, List<ShortCircuitData>> group = new HashMap<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1155 for (ShortCircuitData shortCircuit : shortCircuits) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1156 List<ShortCircuitData> circuits = group.get(shortCircuit.getValueName()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1157 if (circuits == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1158 circuits = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1159 group.put(shortCircuit.getValueName(), circuits); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1160 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1161 circuits.add(shortCircuit); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1162 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1163 return group; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1164 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1165 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1166 private static <M extends TemplateMethod> SortedMap<String, List<M>> groupByNodeId(List<M> methods) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1167 SortedMap<String, List<M>> grouped = new TreeMap<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1168 for (M m : methods) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1169 List<M> list = grouped.get(m.getId()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1170 if (list == null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1171 list = new ArrayList<>(); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1172 grouped.put(m.getId(), list); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1173 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1174 list.add(m); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1175 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1176 return grouped; |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1177 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1178 |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1179 private static List<TypeElement> findSuperClasses(List<TypeElement> collection, TypeElement element) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1180 if (element.getSuperclass() != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1181 TypeElement superElement = Utils.fromTypeMirror(element.getSuperclass()); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1182 if (superElement != null) { |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1183 findSuperClasses(collection, superElement); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1184 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1185 } |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1186 collection.add(element); |
3cc5fb59916e
Truffle-DSL: Renamed @NodeClass to @NodeContainer. splitByMethodName is not an option anymore and is always enabled if a @NodeContainer is used.
Christian Humer <christian.humer@gmail.com>
parents:
10446
diff
changeset
|
1187 return collection; |
7502
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1188 } |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1189 |
6343a09b2ec1
Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1190 } |