annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java @ 9287:8e3a1635cc9e

Implemented @NodeChild(executeWith={...}).
author Christian Humer <christian.humer@gmail.com>
date Wed, 24 Apr 2013 21:50:03 +0200
parents 2a4b57f02fb4
children 0e4db5ee0695
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.codegen.processor.node;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import java.util.*;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 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
28 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
29
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 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
31 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
32 import com.oracle.truffle.codegen.processor.template.*;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 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
34
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 public class NodeData extends Template {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
37 private final String nodeId;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
38 private NodeData declaringNode;
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
39 private List<NodeData> declaredNodes = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
40 private boolean splitByMethodName;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
42 private TypeSystemData typeSystem;
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
43 private List<NodeChildData> children;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
44 private List<NodeFieldData> fields;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
45 private TypeMirror nodeType;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
46 private ParameterSpec instanceParameterSpec;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
48 private List<SpecializationData> specializations;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
49 private List<SpecializationListenerData> specializationListeners;
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
50 private Map<Integer, List<ExecutableTypeData>> executableTypes;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
51 private List<ShortCircuitData> shortCircuits;
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
52 private List<String> assumptions;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
54 public NodeData(TypeElement type, String id) {
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
55 super(type, null, null);
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
56 this.nodeId = id;
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
57 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
58
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
59 public NodeData(NodeData splitSource, String templateMethodName, String nodeId) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
60 super(splitSource.getTemplateType(), templateMethodName, null);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
61 this.nodeId = nodeId;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
62 this.declaringNode = splitSource.declaringNode;
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
63 this.declaredNodes = splitSource.declaredNodes;
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
64 this.typeSystem = splitSource.typeSystem;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
65 this.nodeType = splitSource.nodeType;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
66 this.specializations = splitSource.specializations;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
67 this.specializationListeners = splitSource.specializationListeners;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
68 this.executableTypes = splitSource.executableTypes;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
69 this.shortCircuits = splitSource.shortCircuits;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
70 this.fields = splitSource.fields;
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
71 this.children = splitSource.children;
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
72 this.assumptions = splitSource.assumptions;
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
73 }
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
74
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
75 public boolean isSplitByMethodName() {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
76 return splitByMethodName;
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
77 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
78
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
79 void setTypeSystem(TypeSystemData typeSystem) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 this.typeSystem = typeSystem;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82
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
83 void setFields(List<NodeFieldData> fields) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
84 this.fields = fields;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
85 }
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
86
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
87 public List<NodeFieldData> getFields() {
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
88 return fields;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
89 }
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
90
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
91 void setSplitByMethodName(boolean splitByMethodName) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
92 this.splitByMethodName = splitByMethodName;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
93 }
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
94
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
95 @Override
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
96 protected List<MessageContainer> findChildContainers() {
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
97 List<MessageContainer> containerChildren = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
98 if (declaredNodes != 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
99 containerChildren.addAll(declaredNodes);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
100 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
101 if (typeSystem != 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
102 containerChildren.add(typeSystem);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
103 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
104 if (specializations != null) {
8315
3fbe6772dbf6 Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8279
diff changeset
105 for (MessageContainer specialization : specializations) {
3fbe6772dbf6 Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8279
diff changeset
106 if (specialization.getMessageElement() != 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
107 containerChildren.add(specialization);
8315
3fbe6772dbf6 Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8279
diff changeset
108 }
3fbe6772dbf6 Cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 8279
diff changeset
109 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
110 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
111 if (specializationListeners != 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
112 containerChildren.addAll(specializationListeners);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
113 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
114 if (executableTypes != 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
115 containerChildren.addAll(getExecutableTypes());
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
116 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
117 if (shortCircuits != 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
118 containerChildren.addAll(shortCircuits);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
119 }
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9224
diff changeset
120 if (children != null) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9224
diff changeset
121 containerChildren.addAll(children);
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9224
diff changeset
122 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9224
diff changeset
123 if (fields != null) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9224
diff changeset
124 containerChildren.addAll(fields);
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
125 }
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
126 return containerChildren;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
127 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
128
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
129 public ParameterSpec getInstanceParameterSpec() {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
130 return instanceParameterSpec;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
131 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
132
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
133 public void setInstanceParameterSpec(ParameterSpec instanceParameter) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
134 this.instanceParameterSpec = instanceParameter;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
135 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
136
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
137 public String getNodeId() {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
138 return nodeId;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
139 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
140
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 public TypeMirror getNodeType() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 if (nodeType != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 return nodeType;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 return getTemplateType().asType();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
148 void setAssumptions(List<String> assumptions) {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
149 this.assumptions = assumptions;
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
150 }
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
151
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
152 public List<String> getAssumptions() {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
153 return assumptions;
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
154 }
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
155
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 public boolean needsFactory() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 if (specializations == null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 return false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 }
9224
b69312e4eceb Minor fix for private template types.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
160 if (getTemplateType().getModifiers().contains(Modifier.PRIVATE)) {
b69312e4eceb Minor fix for private template types.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
161 return false;
b69312e4eceb Minor fix for private template types.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
162 }
b69312e4eceb Minor fix for private template types.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
163
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 boolean noSpecialization = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 for (SpecializationData specialization : specializations) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 noSpecialization = noSpecialization && specialization.isGeneric() || specialization.isUninitialized();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168 return !noSpecialization;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
171 public boolean supportsFrame() {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
172 if (executableTypes != null) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
173 for (ExecutableTypeData execType : getExecutableTypes(-1)) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
174 if (execType.findParameter("frameValue") == null) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
175 return false;
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
176 }
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
177 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
178 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
179 return true;
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
180 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7855
diff changeset
181
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
182 public List<NodeData> getNodeDeclaringChildren() {
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 List<NodeData> nodeChildren = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
184 for (NodeData child : getDeclaredNodes()) {
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7794
diff changeset
185 if (child.needsFactory()) {
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 nodeChildren.add(child);
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7794
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 nodeChildren.addAll(child.getNodeDeclaringChildren());
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7794
diff changeset
189 }
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
190 return nodeChildren;
7855
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7794
diff changeset
191 }
6e4fb0ccebb1 Generated factories implement the new NodeFactory interface.
Christian Humer <christian.humer@gmail.com>
parents: 7794
diff changeset
192
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 void setDeclaredNodes(List<NodeData> declaredChildren) {
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
194 this.declaredNodes = declaredChildren;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
195
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
196 for (NodeData child : declaredChildren) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
197 child.declaringNode = this;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
200
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
201 public NodeData getParent() {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
202 return declaringNode;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204
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
205 public List<NodeData> 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
206 return declaredNodes;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
207 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
208
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209 public void setNodeType(TypeMirror nodeType) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
210 this.nodeType = nodeType;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
211 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
212
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
213 public List<TemplateMethod> getAllTemplateMethods() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
214 List<TemplateMethod> methods = new ArrayList<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
215
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
216 for (SpecializationData specialization : getSpecializations()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
217 methods.add(specialization);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
218 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
219
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
220 methods.addAll(getSpecializationListeners());
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
221 methods.addAll(getExecutableTypes());
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
222 methods.addAll(getShortCircuits());
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
223
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
224 return methods;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
225 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
226
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
227 public ExecutableTypeData findGenericExecutableType(ProcessorContext context, TypeData type, int evaluatedCount) {
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
228 List<ExecutableTypeData> types = findGenericExecutableTypes(context, evaluatedCount);
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7754
diff changeset
229 for (ExecutableTypeData availableType : types) {
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7754
diff changeset
230 if (Utils.typeEquals(availableType.getType().getBoxedType(), type.getBoxedType())) {
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7754
diff changeset
231 return availableType;
7752
388848bbe03d Fixed resolve of generic execute type.
Christian Humer <christian.humer@gmail.com>
parents: 7679
diff changeset
232 }
388848bbe03d Fixed resolve of generic execute type.
Christian Humer <christian.humer@gmail.com>
parents: 7679
diff changeset
233 }
7794
b891ec348f8a Made the usage of generic types more flexible for short circuits and generic specializations.
Christian Humer <christian.humer@gmail.com>
parents: 7754
diff changeset
234 return null;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
235 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
236
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
237 public ExecutableTypeData findAnyGenericExecutableType(ProcessorContext context, int evaluatedCount) {
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
238 List<ExecutableTypeData> types = findGenericExecutableTypes(context, evaluatedCount);
8279
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
239 for (ExecutableTypeData type : types) {
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
240 if (type.getType().isGeneric()) {
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
241 return type;
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
242 }
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
243 }
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
244
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
245 for (ExecutableTypeData type : types) {
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
246 if (!type.getType().isVoid()) {
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
247 return type;
cc83fc474fd5 Fixed unsupported generic generation which could also take void as a type.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
248 }
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
249 }
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
250 return null;
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
251 }
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
252
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
253 public List<ExecutableTypeData> getExecutableTypes(int evaluatedCount) {
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
254 if (executableTypes == null) {
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
255 return Collections.emptyList();
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
256 }
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
257 if (evaluatedCount == -1) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
258 List<ExecutableTypeData> typeData = new ArrayList<>();
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
259 for (int currentEvaluationCount : executableTypes.keySet()) {
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
260 typeData.addAll(executableTypes.get(currentEvaluationCount));
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
261 }
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
262 return typeData;
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
263 } else {
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
264 List<ExecutableTypeData> types = executableTypes.get(evaluatedCount);
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
265 if (types == null) {
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
266 return Collections.emptyList();
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
267 }
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
268 return types;
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
269 }
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
270 }
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
271
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
272 public List<ExecutableTypeData> findGenericExecutableTypes(ProcessorContext context, int evaluatedCount) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 List<ExecutableTypeData> types = new ArrayList<>();
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
274 for (ExecutableTypeData type : getExecutableTypes(evaluatedCount)) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 if (!type.hasUnexpectedValue(context)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
276 types.add(type);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279 return types;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
281
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
282 public ExecutableTypeData findExecutableType(TypeData prmitiveType, int evaluatedCount) {
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9279
diff changeset
283 for (ExecutableTypeData type : getExecutableTypes(evaluatedCount)) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
284 if (Utils.typeEquals(type.getType().getPrimitiveType(), prmitiveType.getPrimitiveType())) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
285 return type;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
286 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
287 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
288 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
289 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
290
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
291 public SpecializationData findUniqueSpecialization(TypeData type) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
292 SpecializationData result = null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
293 for (SpecializationData specialization : specializations) {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
294 if (specialization.getReturnType().getTypeSystemType() == type) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
295 if (result != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
296 // Result not unique;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
297 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
298 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
299 result = specialization;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
300 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
301 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
302 return result;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
303 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
304
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
305 public NodeChildData[] filterFields(ExecutionKind usage) {
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
306 List<NodeChildData> filteredFields = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
307 for (NodeChildData field : getChildren()) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
308 if (usage == null || field.getExecutionKind() == usage) {
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
309 filteredFields.add(field);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
310 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311 }
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
312 return filteredFields.toArray(new NodeChildData[filteredFields.size()]);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
314
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
315 public boolean needsRewrites(ProcessorContext context) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 boolean needsRewrites = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
317
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
318 for (SpecializationData specialization : getSpecializations()) {
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
319 if (specialization.hasRewrite(context)) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320 needsRewrites = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321 break;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 }
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
324 return needsRewrites || getSpecializations().size() > 1;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
325 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
326
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
327 public SpecializationData getGenericSpecialization() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
328 for (SpecializationData specialization : specializations) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
329 if (specialization.isGeneric()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330 return specialization;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
331 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
334 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
335
8592
a80bf36c6a1e Refactor to shared template method signature comparison.
Christian Humer <christian.humer@gmail.com>
parents: 8315
diff changeset
336 @Override
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
337 public TypeSystemData getTypeSystem() {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
338 return typeSystem;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
339 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
340
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
341 public String dump() {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
342 return dump(0);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
343 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
344
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
345 private String dump(int level) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
346 String indent = "";
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
347 for (int i = 0; i < level; i++) {
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
348 indent += " ";
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
349 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
350 StringBuilder builder = new StringBuilder();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
351
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
352 builder.append(String.format("%s%s {", indent, toString()));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
353
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
354 dumpProperty(builder, indent, "templateClass", Utils.getQualifiedName(getTemplateType()));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
355 dumpProperty(builder, indent, "typeSystem", getTypeSystem());
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
356 dumpProperty(builder, indent, "fields", getChildren());
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
357 dumpProperty(builder, indent, "executableTypes", getExecutableTypes());
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
358 dumpProperty(builder, indent, "specializations", getSpecializations());
9279
2a4b57f02fb4 Implemented basic support for assumptions for sourcecode generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
359 dumpProperty(builder, indent, "assumptions", getAssumptions());
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
360 dumpProperty(builder, indent, "messages", collectMessages());
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
361 if (getDeclaredNodes().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
362 builder.append(String.format("\n%s children = [", indent));
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
363 for (NodeData node : getDeclaredNodes()) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
364 builder.append("\n");
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
365 builder.append(node.dump(level + 1));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
366 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
367 builder.append(String.format("\n%s ]", indent));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
368 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
369 builder.append(String.format("%s}", indent));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
370 return builder.toString();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
371 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
372
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
373 private static void dumpProperty(StringBuilder b, String indent, String propertyName, Object value) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
374 if (value instanceof List) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
375 List<?> list = (List<?>) value;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
376 if (!list.isEmpty()) {
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
377 b.append(String.format("\n%s %s = %s", indent, propertyName, dumpList(indent, (List<?>) value)));
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
378 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
379 } else {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
380 if (value != null) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
381 b.append(String.format("\n%s %s = %s", indent, propertyName, value));
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
382 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
383 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
385
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
386 private static String dumpList(String indent, List<?> array) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
387 if (array == null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 return "null";
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
391 if (array.isEmpty()) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
392 return "[]";
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
393 } else if (array.size() == 1) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
394 return "[" + array.get(0).toString() + "]";
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
395 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
396
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397 StringBuilder b = new StringBuilder();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
398 b.append("[");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 for (Object object : array) {
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
400 b.append("\n ");
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
401 b.append(indent);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402 b.append(object);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
403 b.append(", ");
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404 }
8595
8a1115c92271 Implemented codegen guard definitions can now omit unused parameters.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
405 b.append("\n ").append(indent).append("]");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
406 return b.toString();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
407 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408
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
409 public NodeChildData findChild(String name) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
410 for (NodeChildData field : getChildren()) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 if (field.getName().equals(name)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
412 return field;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
413 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
414 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
415 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417
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
418 public List<NodeChildData> 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
419 return children;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
420 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
421
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
422 void setChildren(List<NodeChildData> fields) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9217
diff changeset
423 this.children = fields;
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
424 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
425
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
426 public List<SpecializationData> getSpecializations() {
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
427 return getSpecializations(false);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
428 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
429
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
430 public List<SpecializationData> getSpecializations(boolean userDefinedOnly) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
431 if (userDefinedOnly) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
432 List<SpecializationData> specs = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
433 for (SpecializationData spec : specializations) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
434 if (spec.getMethod() != null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
435 specs.add(spec);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
436 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
437 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
438 return specs;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
439 } else {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
440 return specializations;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
441 }
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
442 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
443
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
444 public List<SpecializationListenerData> getSpecializationListeners() {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
445 return specializationListeners;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
446 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
447
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
448 public List<ExecutableTypeData> getExecutableTypes() {
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
449 return getExecutableTypes(-1);
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
450 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
451
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
452 public List<ShortCircuitData> getShortCircuits() {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
453 return shortCircuits;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
454 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
455
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
456 void setSpecializations(List<SpecializationData> specializations) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
457 this.specializations = specializations;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
458 if (this.specializations != null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
459 for (SpecializationData specialization : specializations) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
460 specialization.setNode(this);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
461 }
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
462 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
463 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
464
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
465 void setSpecializationListeners(List<SpecializationListenerData> specializationListeners) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
466 this.specializationListeners = specializationListeners;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
467 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
468
9217
61ba6fc21ba4 Sourcegen can now generate execute methods of signature execute(frame, evaluatedValue).
Christian Humer <christian.humer@gmail.com>
parents: 9216
diff changeset
469 void setExecutableTypes(Map<Integer, List<ExecutableTypeData>> executableTypes) {
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
470 this.executableTypes = executableTypes;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
471 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
472
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
473 void setShortCircuits(List<ShortCircuitData> shortCircuits) {
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
474 this.shortCircuits = shortCircuits;
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
475 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
476
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
477 @Override
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
478 public String toString() {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
479 return getClass().getSimpleName() + "[" + getNodeId() + "]";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
480 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
481
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
482 }