comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/PolymorphicNodeFactory.java @ 18752:1acaa69ff61b

Truffle-DSL: refactor generator classes
author Christian Humer <christian.humer@gmail.com>
date Mon, 29 Dec 2014 23:38:16 +0100
parents
children f6b8787dc113
comparison
equal deleted inserted replaced
18751:e55e18c1f40d 18752:1acaa69ff61b
1 /*
2 * Copyright (c) 2014, 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.generator;
24
25 import static com.oracle.truffle.dsl.processor.java.ElementUtils.*;
26 import static javax.lang.model.element.Modifier.*;
27
28 import java.util.*;
29
30 import javax.lang.model.type.*;
31
32 import com.oracle.truffle.api.nodes.*;
33 import com.oracle.truffle.dsl.processor.java.model.*;
34 import com.oracle.truffle.dsl.processor.model.*;
35
36 class PolymorphicNodeFactory extends SpecializedNodeFactory {
37
38 public PolymorphicNodeFactory(CodeTypeElement nodeGen) {
39 super(nodeGen);
40 }
41
42 @Override
43 public CodeTypeElement create(SpecializationData polymorph) {
44 NodeData node = polymorph.getNode();
45 TypeMirror baseType = node.getNodeType();
46 if (nodeGen != null) {
47 baseType = nodeGen.asType();
48 }
49 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false);
50
51 clazz.getAnnotationMirrors().add(createNodeInfo(node, NodeCost.POLYMORPHIC));
52
53 for (Parameter polymorphParameter : polymorph.getSignatureParameters()) {
54 if (!polymorphParameter.getTypeSystemType().isGeneric()) {
55 continue;
56 }
57 Set<TypeData> types = new HashSet<>();
58 for (SpecializationData specialization : node.getSpecializations()) {
59 if (!specialization.isSpecialized()) {
60 continue;
61 }
62 Parameter parameter = specialization.findParameter(polymorphParameter.getLocalName());
63 assert parameter != null;
64 types.add(parameter.getTypeSystemType());
65 }
66
67 }
68
69 for (NodeExecutionData execution : getModel().getNode().getChildExecutions()) {
70 String fieldName = polymorphicTypeName(execution);
71 CodeVariableElement var = new CodeVariableElement(modifiers(PRIVATE), getContext().getType(Class.class), fieldName);
72 var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getCompilationFinal()));
73 clazz.add(var);
74 }
75
76 return clazz;
77 }
78
79 @Override
80 protected void createChildren(SpecializationData specialization) {
81 CodeTypeElement clazz = getElement();
82
83 createConstructors(clazz);
84 createExecuteMethods(specialization);
85
86 clazz.add(createUpdateTypes0());
87 createCachedExecuteMethods(specialization);
88 }
89
90 }