Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/operation/OperationData.java @ 7291:a748e4d44694
Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 21 Dec 2012 10:44:31 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7290:a81db08fe930 | 7291:a748e4d44694 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 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.codegen.processor.operation; | |
24 | |
25 import java.util.*; | |
26 | |
27 import javax.lang.model.element.*; | |
28 import javax.lang.model.type.*; | |
29 | |
30 import com.oracle.truffle.codegen.processor.template.*; | |
31 import com.oracle.truffle.codegen.processor.typesystem.*; | |
32 | |
33 public class OperationData extends Template { | |
34 | |
35 private final TypeSystemData typeSystem; | |
36 private final String[] values; | |
37 private final String[] shortCircuitValues; | |
38 private final OperationFieldData[] operationFields; | |
39 private final OperationFieldData[] constructorFields; | |
40 private final OperationFieldData[] superFields; | |
41 private final TypeMirror nodeType; | |
42 | |
43 private MethodSpec specification; | |
44 private SpecializationData genericSpecialization; | |
45 private SpecializationData[] specializations; | |
46 private TemplateMethod[] specializationListeners; | |
47 private GuardData[] guards; | |
48 | |
49 boolean generateFactory = true; | |
50 | |
51 public OperationData(TypeElement templateType, AnnotationMirror templateTypeAnnotation, | |
52 TypeSystemData typeSystem, TypeMirror nodeType, | |
53 String[] values, String[] shortCircuitValues, | |
54 OperationFieldData[] operationFields, | |
55 OperationFieldData[] constructorFields, | |
56 OperationFieldData[] superFields) { | |
57 super(templateType, templateTypeAnnotation); | |
58 this.nodeType = nodeType; | |
59 this.typeSystem = typeSystem; | |
60 this.values = values; | |
61 this.shortCircuitValues = shortCircuitValues; | |
62 this.operationFields = operationFields; | |
63 this.constructorFields = constructorFields; | |
64 this.superFields = superFields; | |
65 } | |
66 | |
67 public boolean isUseSingleton() { | |
68 return constructorFields.length == 0; | |
69 } | |
70 | |
71 public boolean hasExtensions() { | |
72 return !getExtensionElements().isEmpty(); | |
73 } | |
74 | |
75 public List<GuardData> findGuards(String name) { | |
76 List<GuardData> foundGuards = new ArrayList<>(); | |
77 for (GuardData guardData : guards) { | |
78 if (guardData.getMethodName().equals(name)) { | |
79 foundGuards.add(guardData); | |
80 } | |
81 } | |
82 for (GuardData guardData : getTypeSystem().getGuards()) { | |
83 if (guardData.getMethodName().equals(name)) { | |
84 foundGuards.add(guardData); | |
85 } | |
86 } | |
87 return foundGuards; | |
88 } | |
89 | |
90 | |
91 void setGuards(GuardData[] guards) { | |
92 this.guards = guards; | |
93 } | |
94 | |
95 void setSpecification(MethodSpec specification) { | |
96 this.specification = specification; | |
97 } | |
98 | |
99 void setGenericSpecialization(SpecializationData genericSpecialization) { | |
100 this.genericSpecialization = genericSpecialization; | |
101 } | |
102 | |
103 void setSpecializations(SpecializationData[] specializations) { | |
104 this.specializations = specializations; | |
105 for (SpecializationData specialization : specializations) { | |
106 specialization.setOperation(this); | |
107 } | |
108 } | |
109 | |
110 void setSpecializationListeners(TemplateMethod[] specializationListeners) { | |
111 this.specializationListeners = specializationListeners; | |
112 } | |
113 | |
114 public String[] getValues() { | |
115 return values; | |
116 } | |
117 | |
118 public OperationFieldData[] getOperationFields() { | |
119 return operationFields; | |
120 } | |
121 | |
122 public String[] getShortCircuitValues() { | |
123 return shortCircuitValues; | |
124 } | |
125 | |
126 public TypeSystemData getTypeSystem() { | |
127 return typeSystem; | |
128 } | |
129 | |
130 public TypeMirror getNodeType() { | |
131 return nodeType; | |
132 } | |
133 | |
134 public SpecializationData[] getSpecializations() { | |
135 return specializations; | |
136 } | |
137 | |
138 public SpecializationData getGenericSpecialization() { | |
139 return genericSpecialization; | |
140 } | |
141 | |
142 public OperationFieldData[] getConstructorFields() { | |
143 return constructorFields; | |
144 } | |
145 | |
146 public OperationFieldData[] getSuperFields() { | |
147 return superFields; | |
148 } | |
149 | |
150 public MethodSpec getSpecification() { | |
151 return specification; | |
152 } | |
153 | |
154 public SpecializationData[] getAllMethods() { | |
155 return specializations; | |
156 } | |
157 | |
158 public boolean needsRewrites() { | |
159 boolean needsRewrites = getValues().length > 0 || getShortCircuitValues().length > 0; | |
160 needsRewrites &= specializations.length >= 2; | |
161 return needsRewrites; | |
162 } | |
163 | |
164 public TemplateMethod[] getSpecializationListeners() { | |
165 return specializationListeners; | |
166 } | |
167 | |
168 public GuardData[] getGuards() { | |
169 return guards; | |
170 } | |
171 | |
172 public SpecializationData findUniqueSpecialization(TypeData type) { | |
173 SpecializationData result = null; | |
174 for (SpecializationData specialization : specializations) { | |
175 if (specialization.getReturnType().getActualTypeData(getTypeSystem()) == type) { | |
176 if (result != null) { | |
177 // Result not unique; | |
178 return null; | |
179 } | |
180 result = specialization; | |
181 } | |
182 } | |
183 return result; | |
184 } | |
185 } |