Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/GeneratorUtils.java @ 18777:76cbf5f33f82
Truffle-DSL: fixed bug for polymorphic execute optimization.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 05 Jan 2015 02:38:44 +0100 |
parents | a665483c3881 |
children | ae81dd154fb6 |
rev | line source |
---|---|
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.generator; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.dsl.processor.java.ElementUtils.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static javax.lang.model.element.Modifier.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import java.util.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import javax.lang.model.element.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import javax.lang.model.type.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import javax.lang.model.util.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
34 import com.oracle.truffle.api.*; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.dsl.*; |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
36 import com.oracle.truffle.api.dsl.internal.DSLOptions.*; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 import com.oracle.truffle.dsl.processor.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 import com.oracle.truffle.dsl.processor.java.model.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 import com.oracle.truffle.dsl.processor.model.*; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 public class GeneratorUtils { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
43 public static CodeTree createTransferToInterpreterAndInvalidate() { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
44 ProcessorContext context = ProcessorContext.getInstance(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
45 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
46 builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
47 return builder.build(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
48 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
49 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
50 public static CodeExecutableElement createConstructorUsingFields(Set<Modifier> modifiers, CodeTypeElement clazz) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
51 TypeElement superClass = fromTypeMirror(clazz.getSuperclass()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
52 ExecutableElement constructor = findConstructor(superClass); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
53 return createConstructorUsingFields(modifiers, clazz, constructor); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
54 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
55 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
56 public static CodeExecutableElement createConstructorUsingFields(Set<Modifier> modifiers, CodeTypeElement clazz, ExecutableElement constructor) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 CodeExecutableElement method = new CodeExecutableElement(modifiers, null, clazz.getSimpleName().toString()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 CodeTreeBuilder builder = method.createBuilder(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 if (constructor != null && constructor.getParameters().size() > 0) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 builder.startStatement(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 builder.startSuperCall(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 for (VariableElement parameter : constructor.getParameters()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 method.addParameter(new CodeVariableElement(parameter.asType(), parameter.getSimpleName().toString())); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 builder.string(parameter.getSimpleName().toString()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 builder.end(); // super |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 builder.end(); // statement |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 for (VariableElement field : clazz.getFields()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 if (field.getModifiers().contains(STATIC)) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 continue; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 String fieldName = field.getSimpleName().toString(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 method.addParameter(new CodeVariableElement(field.asType(), fieldName)); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 builder.startStatement(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 builder.string("this."); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 builder.string(fieldName); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 builder.string(" = "); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
80 builder.string(fieldName); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 builder.end(); // statement |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 return method; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
87 public static boolean isTypeBoxingOptimized(TypeBoxingOptimization boxing, TypeData type) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
88 switch (boxing) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
89 case NONE: |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
90 return false; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
91 case ALWAYS: |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
92 return !type.isGeneric() && !type.isVoid(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
93 case PRIMITIVE: |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
94 return type.isPrimitive(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
95 default: |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
96 throw new AssertionError(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
97 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
98 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
99 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 private static ExecutableElement findConstructor(TypeElement clazz) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 List<ExecutableElement> constructors = ElementFilter.constructorsIn(clazz.getEnclosedElements()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 if (constructors.isEmpty()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 return null; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 } else { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 return constructors.get(0); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 public static CodeExecutableElement createSuperConstructor(ProcessorContext context, TypeElement type, ExecutableElement element) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 if (element.getModifiers().contains(Modifier.PRIVATE)) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 return null; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 CodeExecutableElement executable = CodeExecutableElement.clone(context.getEnvironment(), element); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 executable.setReturnType(null); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 executable.setSimpleName(CodeNames.of(type.getSimpleName().toString())); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 CodeTreeBuilder b = executable.createBuilder(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 b.startStatement(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 b.startSuperCall(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 for (VariableElement v : element.getParameters()) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 b.string(v.getSimpleName().toString()); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 b.end(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 b.end(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 return executable; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
128 public static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
129 TypeElement templateType = sourceModel.getTemplateType(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 ProcessorContext context = ProcessorContext.getInstance(); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
134 CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 TypeMirror resolvedSuperType = superType; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
136 if (resolvedSuperType == null) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 resolvedSuperType = context.getType(Object.class); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 clazz.setSuperClass(resolvedSuperType); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class)); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType())); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
143 if (sourceMethod != null && sourceMethod.getMethod() != null) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
144 generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName())); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 clazz.addAnnotationMirror(generatedByAnnotation); |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 return clazz; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 } |