comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeChildData.java @ 10597:79041ab43660

Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author Christian Humer <christian.humer@gmail.com>
date Mon, 01 Jul 2013 20:58:32 +0200
parents
children 2fb276f5e3e9
comparison
equal deleted inserted replaced
10596:f43eb2f1bbbc 10597:79041ab43660
1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.dsl.processor.node;
24
25 import java.util.*;
26
27 import javax.lang.model.element.*;
28 import javax.lang.model.type.*;
29
30 import com.oracle.truffle.dsl.processor.*;
31 import com.oracle.truffle.dsl.processor.template.*;
32 import com.oracle.truffle.dsl.processor.typesystem.*;
33
34 public class NodeChildData extends MessageContainer {
35
36 public enum Cardinality {
37 ONE, MANY;
38
39 public boolean isMany() {
40 return this == MANY;
41 }
42
43 public boolean isOne() {
44 return this == ONE;
45 }
46 }
47
48 public enum ExecutionKind {
49 DEFAULT, SHORT_CIRCUIT
50 }
51
52 private final Element sourceElement;
53 private final AnnotationMirror sourceAnnotationMirror;
54
55 private final String name;
56 private final TypeMirror type;
57 private final TypeMirror originalType;
58 private final Element accessElement;
59
60 private final Cardinality cardinality;
61 private final ExecutionKind executionKind;
62
63 private List<NodeChildData> executeWith = Collections.emptyList();
64
65 private NodeData nodeData;
66
67 public NodeChildData(Element sourceElement, AnnotationMirror sourceMirror, String name, TypeMirror nodeType, TypeMirror originalNodeType, Element accessElement, Cardinality cardinality,
68 ExecutionKind executionKind) {
69 this.sourceElement = sourceElement;
70 this.sourceAnnotationMirror = sourceMirror;
71 this.name = name;
72 this.type = nodeType;
73 this.originalType = originalNodeType;
74 this.accessElement = accessElement;
75 this.cardinality = cardinality;
76 this.executionKind = executionKind;
77 }
78
79 public List<NodeChildData> getExecuteWith() {
80 return executeWith;
81 }
82
83 void setExecuteWith(List<NodeChildData> executeWith) {
84 this.executeWith = executeWith;
85 }
86
87 public ExecutableTypeData findExecutableType(ProcessorContext context, TypeData targetType) {
88 ExecutableTypeData executableType = nodeData.findExecutableType(targetType, getExecuteWith().size());
89 if (executableType == null) {
90 executableType = findAnyGenericExecutableType(context);
91 }
92 return executableType;
93 }
94
95 public List<ExecutableTypeData> findGenericExecutableTypes(ProcessorContext context) {
96 return nodeData.findGenericExecutableTypes(context, getExecuteWith().size());
97 }
98
99 public ExecutableTypeData findAnyGenericExecutableType(ProcessorContext context) {
100 return nodeData.findAnyGenericExecutableType(context, getExecuteWith().size());
101 }
102
103 public List<ExecutableTypeData> findExecutableTypes() {
104 return nodeData.getExecutableTypes(getExecuteWith().size());
105 }
106
107 public TypeMirror getOriginalType() {
108 return originalType;
109 }
110
111 @Override
112 public Element getMessageElement() {
113 return sourceElement;
114 }
115
116 @Override
117 public AnnotationMirror getMessageAnnotation() {
118 return sourceAnnotationMirror;
119 }
120
121 public boolean isShortCircuit() {
122 return executionKind == ExecutionKind.SHORT_CIRCUIT;
123 }
124
125 void setNode(NodeData nodeData) {
126 this.nodeData = nodeData;
127 if (nodeData != null) {
128 getMessages().addAll(nodeData.collectMessages());
129 }
130 }
131
132 public Element getAccessElement() {
133 return accessElement;
134 }
135
136 public TypeMirror getNodeType() {
137 return type;
138 }
139
140 public Cardinality getCardinality() {
141 return cardinality;
142 }
143
144 public ExecutionKind getExecutionKind() {
145 return executionKind;
146 }
147
148 public NodeData getNodeData() {
149 return nodeData;
150 }
151
152 public String getName() {
153 return name;
154 }
155
156 @Override
157 public String toString() {
158 return "NodeFieldData[name=" + getName() + ", kind=" + cardinality + ", execution=" + executionKind + ", node=" + getNodeData() + "]";
159 }
160
161 }