annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java @ 10091:51b8585a1d70

more restrictive condition in ForeignCallNode.setStateAfter
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 19 Jun 2013 16:46:41 +0200
parents 0e4db5ee0695
children 746fa60be266
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.codegen.processor;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import java.io.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import java.lang.annotation.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import java.util.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import javax.annotation.processing.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import javax.lang.model.element.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import javax.lang.model.type.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import javax.lang.model.util.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 import com.oracle.truffle.codegen.processor.ast.*;
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
35 import com.oracle.truffle.codegen.processor.ast.CodeTypeMirror.DeclaredCodeTypeMirror;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 import com.oracle.truffle.codegen.processor.compiler.*;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 /**
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 * THIS IS NOT PUBLIC API.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 */
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 public class Utils {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
9779
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
43 public static ExecutableElement findExecutableElement(DeclaredType type, String name) {
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
44 List<? extends ExecutableElement> elements = ElementFilter.methodsIn(type.asElement().getEnclosedElements());
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
45 for (ExecutableElement executableElement : elements) {
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
46 if (executableElement.getSimpleName().toString().equals(name)) {
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
47 return executableElement;
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
48 }
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
49 }
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
50 return null;
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
51 }
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
52
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
53 public static VariableElement findVariableElement(DeclaredType type, String name) {
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
54 List<? extends VariableElement> elements = ElementFilter.fieldsIn(type.asElement().getEnclosedElements());
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
55 for (VariableElement variableElement : elements) {
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
56 if (variableElement.getSimpleName().toString().equals(name)) {
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
57 return variableElement;
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
58 }
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
59 }
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
60 return null;
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
61 }
0e4db5ee0695 Added support for the kind field in @NodeInfo for the source code generation.
Christian Humer <christian.humer@gmail.com>
parents: 9227
diff changeset
62
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 public static String getMethodBody(ProcessingEnvironment env, ExecutableElement method) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 if (method instanceof CodeExecutableElement) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 return ((CodeExecutableElement) method).getBody();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 } else {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 return CompilerFactory.getCompiler(method).getMethodBody(env, method);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
71 public static TypeMirror boxType(ProcessorContext context, TypeMirror primitiveType) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
72 TypeMirror boxedType = primitiveType;
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
73 if (boxedType.getKind().isPrimitive()) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
74 boxedType = context.getEnvironment().getTypeUtils().boxedClass((PrimitiveType) boxedType).asType();
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
75 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
76 return boxedType;
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
77 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
78
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
79 public static List<TypeMirror> asTypeMirrors(List<? extends Element> elements) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
80 List<TypeMirror> types = new ArrayList<>(elements.size());
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
81 for (Element element : elements) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
82 types.add(element.asType());
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
83 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
84 return types;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
85 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
86
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
87 public static DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
88 return new DeclaredCodeTypeMirror(typeElem, Arrays.asList(typeArgs));
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
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: 9215
diff changeset
90
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
91 public static List<AnnotationMirror> collectAnnotations(ProcessorContext context, AnnotationMirror markerAnnotation, String elementName, Element element,
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
92 Class<? extends Annotation> annotationClass) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
93 List<AnnotationMirror> result = new ArrayList<>();
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
94 if (markerAnnotation != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
95 result.addAll(Utils.getAnnotationValueList(AnnotationMirror.class, markerAnnotation, elementName));
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
96 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 AnnotationMirror explicit = Utils.findAnnotationMirror(context.getEnvironment(), element, annotationClass);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 if (explicit != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 result.add(explicit);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 return result;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
104 public static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror[] types) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
105 if (types.length == 0) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
106 return context.getType(Object.class);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
107 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
108 TypeMirror prev = types[0];
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
109 for (int i = 1; i < types.length; i++) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
110 prev = getCommonSuperType(context, prev, types[i]);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
111 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
112 return prev;
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
113 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
114
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
115 public static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror type1, TypeMirror type2) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
116 if (typeEquals(type1, type2)) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
117 return type1;
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
118 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
119 TypeElement element1 = fromTypeMirror(type1);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
120 TypeElement element2 = fromTypeMirror(type2);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
121 if (element1 == null || element2 == null) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
122 return context.getType(Object.class);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
123 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
124
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
125 List<TypeElement> element1Types = getDirectSuperTypes(element1);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
126 element1Types.add(0, element1);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
127 List<TypeElement> element2Types = getDirectSuperTypes(element2);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
128 element2Types.add(0, element2);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
129
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
130 for (TypeElement superType1 : element1Types) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
131 for (TypeElement superType2 : element2Types) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
132 if (typeEquals(superType1.asType(), superType2.asType())) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
133 return superType2.asType();
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
134 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
135 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
136 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
137 return context.getType(Object.class);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
138 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
139
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
140 public static String getReadableSignature(ExecutableElement method) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
141 // TODO toString does not guarantee a good signature
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
142 return method.toString();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
143 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
144
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 public static boolean hasError(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 switch (mirror.getKind()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147 case BOOLEAN:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 case BYTE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 case CHAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 case DOUBLE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 case FLOAT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 case INT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153 case SHORT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
154 case LONG:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 case DECLARED:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 case VOID:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 case TYPEVAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 case ARRAY:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
160 return hasError(((ArrayType) mirror).getComponentType());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
161 case ERROR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
162 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163 default:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 throw new RuntimeException("Unknown type specified " + mirror.getKind() + " mirror: " + mirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
168 public static boolean isAssignable(ProcessorContext context, TypeMirror from, TypeMirror to) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
169 if (!(from instanceof CodeTypeMirror) && !(to instanceof CodeTypeMirror)) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
170 return context.getEnvironment().getTypeUtils().isAssignable(context.reloadType(from), context.reloadType(to));
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
171 } else {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
172 return isAssignableImpl(context, from, to);
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
173 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
174 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
175
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
176 private static boolean isAssignableImpl(ProcessorContext context, TypeMirror from, TypeMirror to) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
177 // JLS 5.1.1 identity conversion
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
178 if (Utils.typeEquals(from, to)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180 }
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
181
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
182 // JLS 5.1.2 widening primitives
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
183 if (Utils.isPrimitive(from) && Utils.isPrimitive(to)) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
184 TypeKind fromKind = from.getKind();
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
185 TypeKind toKind = to.getKind();
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
186 switch (fromKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
187 case BYTE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
188 switch (toKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
189 case SHORT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
190 case INT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
191 case LONG:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
192 case FLOAT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
193 case DOUBLE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
194 return true;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
195 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
196 break;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
197 case SHORT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
198 switch (toKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
199 case INT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
200 case LONG:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
201 case FLOAT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
202 case DOUBLE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
203 return true;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
204 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
205 break;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
206 case CHAR:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
207 switch (toKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
208 case INT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
209 case LONG:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
210 case FLOAT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
211 case DOUBLE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
212 return true;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
213 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
214 break;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
215 case INT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
216 switch (toKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
217 case LONG:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
218 case FLOAT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
219 case DOUBLE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
220 return true;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
221 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
222 break;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
223 case LONG:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
224 switch (toKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
225 case FLOAT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
226 case DOUBLE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
227 return true;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
228 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
229 break;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
230 case FLOAT:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
231 switch (toKind) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
232 case DOUBLE:
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
233 return true;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
234 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
235 break;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
236
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
237 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
238 return false;
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
239 } else if (Utils.isPrimitive(from) || Utils.isPrimitive(to)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
240 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
243 if (from instanceof ArrayType && to instanceof ArrayType) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
244 return isAssignable(context, ((ArrayType) from).getComponentType(), ((ArrayType) to).getComponentType());
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
245 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
246
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
247 TypeElement fromType = Utils.fromTypeMirror(from);
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
248 TypeElement toType = Utils.fromTypeMirror(to);
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
249 if (fromType == null || toType == null) {
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
250 return false;
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
251 }
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
252 // JLS 5.1.6 narrowing reference conversion
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
253
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
254 List<TypeElement> superTypes = Utils.getSuperTypes(fromType);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
255 for (TypeElement superType : superTypes) {
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
256 if (Utils.typeEquals(superType.asType(), to)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
257 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
258 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 }
9227
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
260
6d92fdf1c999 Fixes several minor issues.
Christian Humer <christian.humer@gmail.com>
parents: 9220
diff changeset
261 // TODO more spec
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
262 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
264
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265 public static Set<Modifier> modifiers(Modifier... modifier) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266 return new LinkedHashSet<>(Arrays.asList(modifier));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
267 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
268
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
269 public static String getTypeId(TypeMirror mirror) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
270 switch (mirror.getKind()) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
271 case BOOLEAN:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
272 return "Boolean";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
273 case BYTE:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
274 return "Byte";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
275 case CHAR:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
276 return "Char";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
277 case DOUBLE:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
278 return "Double";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
279 case FLOAT:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
280 return "Float";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
281 case SHORT:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
282 return "Short";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
283 case INT:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
284 return "Int";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
285 case LONG:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
286 return "Long";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
287 case DECLARED:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
288 return ((DeclaredType) mirror).asElement().getSimpleName().toString();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
289 case ARRAY:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
290 return getTypeId(((ArrayType) mirror).getComponentType()) + "Array";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
291 case VOID:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
292 return "Void";
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
293 case WILDCARD:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
294 StringBuilder b = new StringBuilder();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
295 WildcardType type = (WildcardType) mirror;
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
296 if (type.getExtendsBound() != null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
297 b.append("Extends").append(getTypeId(type.getExtendsBound()));
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
298 } else if (type.getSuperBound() != null) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
299 b.append("Super").append(getTypeId(type.getExtendsBound()));
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
300 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
301 return b.toString();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
302 case TYPEVAR:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
303 return "Any";
9210
160f088e40db Made handling of compile errors more robust in the truffle annotation parser.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
304 case ERROR:
160f088e40db Made handling of compile errors more robust in the truffle annotation parser.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
305 throw new CompileErrorException("Type error " + mirror);
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
306 default:
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
307 throw new RuntimeException("Unknown type specified " + mirror.getKind() + " mirror: " + mirror);
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
308 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
309 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
310
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311 public static String getSimpleName(TypeElement element) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
312 return getSimpleName(element.asType());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
314
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
315 public static String getSimpleName(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 switch (mirror.getKind()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
317 case BOOLEAN:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
318 return "boolean";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
319 case BYTE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320 return "byte";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321 case CHAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322 return "char";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 case DOUBLE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
324 return "double";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
325 case FLOAT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
326 return "float";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
327 case SHORT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
328 return "short";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
329 case INT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330 return "int";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
331 case LONG:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332 return "long";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333 case DECLARED:
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
334 return getDeclaredName((DeclaredType) mirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
335 case ARRAY:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
336 return getSimpleName(((ArrayType) mirror).getComponentType()) + "[]";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
337 case VOID:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
338 return "void";
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
339 case WILDCARD:
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
340 return getWildcardName((WildcardType) mirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
341 case TYPEVAR:
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
342 return "?";
9210
160f088e40db Made handling of compile errors more robust in the truffle annotation parser.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
343 case ERROR:
160f088e40db Made handling of compile errors more robust in the truffle annotation parser.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
344 throw new CompileErrorException("Type error " + mirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
345 default:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
346 throw new RuntimeException("Unknown type specified " + mirror.getKind() + " mirror: " + mirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
347 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
348 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
349
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
350 private static String getWildcardName(WildcardType type) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
351 StringBuilder b = new StringBuilder();
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
352 if (type.getExtendsBound() != null) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
353 b.append("? extends ").append(getSimpleName(type.getExtendsBound()));
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
354 } else if (type.getSuperBound() != null) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
355 b.append("? super ").append(getSimpleName(type.getExtendsBound()));
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
356 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
357 return b.toString();
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
358 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
359
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
360 private static String getDeclaredName(DeclaredType element) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
361 String simpleName = element.asElement().getSimpleName().toString();
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
362
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
363 if (element.getTypeArguments().size() == 0) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
364 return simpleName;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
365 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
366
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
367 StringBuilder b = new StringBuilder(simpleName);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
368 b.append("<");
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
369 if (element.getTypeArguments().size() > 0) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
370 for (int i = 0; i < element.getTypeArguments().size(); i++) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
371 b.append(getSimpleName(element.getTypeArguments().get(i)));
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
372 if (i < element.getTypeArguments().size() - 1) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
373 b.append(", ");
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
374 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
375 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
376 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
377 b.append(">");
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
378 return b.toString();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
379 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
380
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
381 public static String getQualifiedName(TypeElement element) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
382 return element.getQualifiedName().toString();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
383 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
384
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
385 public static String getQualifiedName(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
386 switch (mirror.getKind()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
387 case BOOLEAN:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 return "boolean";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389 case BYTE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
390 return "byte";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
391 case CHAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
392 return "char";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
393 case DOUBLE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
394 return "double";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
395 case SHORT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 return "short";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397 case FLOAT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
398 return "float";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
399 case INT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400 return "int";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401 case LONG:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
402 return "long";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
403 case DECLARED:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404 return getQualifiedName(fromTypeMirror(mirror));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
405 case ARRAY:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
406 return getQualifiedName(((ArrayType) mirror).getComponentType());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
407 case VOID:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408 return "void";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409 case TYPEVAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
410 return getSimpleName(mirror);
9210
160f088e40db Made handling of compile errors more robust in the truffle annotation parser.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
411 case ERROR:
160f088e40db Made handling of compile errors more robust in the truffle annotation parser.
Christian Humer <christian.humer@gmail.com>
parents: 8662
diff changeset
412 throw new CompileErrorException("Type error " + mirror);
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
413 case NONE:
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
414 return "$none";
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
415 default:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 throw new RuntimeException("Unknown type specified " + mirror + " mirror: " + mirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
418 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
419
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420 public static boolean isVoid(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
421 return mirror.getKind() == TypeKind.VOID;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
422 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
423
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 public static boolean isPrimitive(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425 return mirror.getKind().isPrimitive();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
426 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
427
9215
bd067a48a9c2 Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 9210
diff changeset
428 public static boolean isPrimitiveOrVoid(TypeMirror mirror) {
bd067a48a9c2 Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 9210
diff changeset
429 return isPrimitive(mirror) || isVoid(mirror);
bd067a48a9c2 Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 9210
diff changeset
430 }
bd067a48a9c2 Changed execute method generation strategy. Limited it for primitive execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 9210
diff changeset
431
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
432 public static List<String> getQualifiedSuperTypeNames(TypeElement element) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 List<TypeElement> types = getSuperTypes(element);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
434 List<String> qualifiedNames = new ArrayList<>();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
435 for (TypeElement type : types) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
436 qualifiedNames.add(getQualifiedName(type));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438 return qualifiedNames;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 public static List<TypeElement> getDeclaredTypes(TypeElement element) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442 return ElementFilter.typesIn(element.getEnclosedElements());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
444
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
445 public static VariableElement findDeclaredField(TypeMirror type, String singletonName) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
446 List<VariableElement> elements = ElementFilter.fieldsIn(fromTypeMirror(type).getEnclosedElements());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
447 for (VariableElement var : elements) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
448 if (var.getSimpleName().toString().equals(singletonName)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
449 return var;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
450 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
451 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
452 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
453 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
454
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
455 public static TypeElement findRootEnclosingType(Element element) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
456 List<Element> elements = getElementHierarchy(element);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
457
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
458 for (int i = elements.size() - 1; i >= 0; i--) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
459 if (elements.get(i).getKind().isClass()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
460 return (TypeElement) elements.get(i);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
461 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
462 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
463
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
464 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
465 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
466
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
467 public static List<Element> getElementHierarchy(Element e) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
468 List<Element> elements = new ArrayList<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
469 elements.add(e);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
470
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
471 Element enclosing = e.getEnclosingElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
472 while (enclosing != null && enclosing.getKind() != ElementKind.PACKAGE) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
473 elements.add(enclosing);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
474 enclosing = enclosing.getEnclosingElement();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
475 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
476 if (enclosing != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
477 elements.add(enclosing);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
478 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
479 return elements;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
480 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
481
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
482 public static TypeElement findNearestEnclosingType(Element element) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
483 List<Element> elements = getElementHierarchy(element);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
484 for (Element e : elements) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
485 if (e.getKind().isClass()) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
486 return (TypeElement) e;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
487 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
488 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
489 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
491
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
492 public static List<TypeElement> getDirectSuperTypes(TypeElement element) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
493 List<TypeElement> types = new ArrayList<>();
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
494 if (element.getSuperclass() != null) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
495 TypeElement superElement = fromTypeMirror(element.getSuperclass());
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
496 if (superElement != null) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
497 types.add(superElement);
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
498 types.addAll(getDirectSuperTypes(superElement));
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
499 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
500 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
501
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
502 return types;
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
503 }
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
504
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
505 public static List<TypeElement> getSuperTypes(TypeElement element) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
506 List<TypeElement> types = new ArrayList<>();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
507 List<TypeElement> superTypes = null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 List<TypeElement> superInterfaces = null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
509 if (element.getSuperclass() != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
510 TypeElement superElement = fromTypeMirror(element.getSuperclass());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
511 if (superElement != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
512 types.add(superElement);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
513 superTypes = getSuperTypes(superElement);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
514 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
515 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
516 for (TypeMirror interfaceMirror : element.getInterfaces()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
517 TypeElement interfaceElement = fromTypeMirror(interfaceMirror);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
518 if (interfaceElement != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
519 types.add(interfaceElement);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
520 superInterfaces = getSuperTypes(interfaceElement);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
523
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
524 if (superTypes != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
525 types.addAll(superTypes);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
526 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
527
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
528 if (superInterfaces != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
529 types.addAll(superInterfaces);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
530 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
532 return types;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
533 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
534
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
535 public static String getPackageName(TypeElement element) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
536 return findPackageElement(element).getQualifiedName().toString();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
537 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
538
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
539 public static String getPackageName(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
540 switch (mirror.getKind()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
541 case BOOLEAN:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
542 case BYTE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
543 case CHAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
544 case DOUBLE:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
545 case FLOAT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
546 case SHORT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
547 case INT:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
548 case LONG:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
549 case VOID:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
550 case TYPEVAR:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
552 case DECLARED:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
553 PackageElement pack = findPackageElement(fromTypeMirror(mirror));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
554 if (pack == null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
555 throw new IllegalArgumentException("No package element found for declared type " + getSimpleName(mirror));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
556 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
557 return pack.getQualifiedName().toString();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
558 case ARRAY:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
559 return getSimpleName(((ArrayType) mirror).getComponentType());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
560 default:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
561 throw new RuntimeException("Unknown type specified " + mirror.getKind());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
562 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
563 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
564
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
565 public static String createConstantName(String simpleName) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
566 // TODO use camel case to produce underscores.
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
567 return simpleName.toString().toUpperCase();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
568 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
569
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
570 public static TypeElement fromTypeMirror(TypeMirror mirror) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
571 switch (mirror.getKind()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
572 case DECLARED:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
573 return (TypeElement) ((DeclaredType) mirror).asElement();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
574 case ARRAY:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
575 return fromTypeMirror(((ArrayType) mirror).getComponentType());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
576 default:
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
577 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
578 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
579 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
580
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
581 @SuppressWarnings("unchecked")
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
582 public static <T> List<T> getAnnotationValueList(Class<T> expectedListType, AnnotationMirror mirror, String name) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
583 List<? extends AnnotationValue> values = getAnnotationValue(List.class, mirror, name);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
584 List<T> result = new ArrayList<>();
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
585
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
586 for (AnnotationValue value : values) {
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
587 result.add(resolveAnnotationValue(expectedListType, value));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
588 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
589 return result;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
590 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
591
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
592 public static <T> T getAnnotationValue(Class<T> expectedType, AnnotationMirror mirror, String name) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
593 return resolveAnnotationValue(expectedType, getAnnotationValue(mirror, name));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
594 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
595
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
596 @SuppressWarnings({"unchecked"})
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
597 private static <T> T resolveAnnotationValue(Class<T> expectedType, AnnotationValue value) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
598 Object unboxedValue = value.accept(new AnnotationValueVisitorImpl(), null);
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
599 if (unboxedValue != null) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
600 if (expectedType == TypeMirror.class && unboxedValue instanceof String) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
601 return null;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
602 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
603 if (!expectedType.isAssignableFrom(unboxedValue.getClass())) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
604 throw new ClassCastException(unboxedValue.getClass().getName() + " not assignable from " + expectedType.getName());
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
605 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
606 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
607 return (T) unboxedValue;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
608 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
609
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
610 public static AnnotationValue getAnnotationValue(AnnotationMirror mirror, String name) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
611 ExecutableElement valueMethod = null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
612 for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
613 if (method.getSimpleName().toString().equals(name)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
614 valueMethod = method;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
615 break;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
616 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
617 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
618
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
619 if (valueMethod == null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
620 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
621 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
622
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
623 AnnotationValue value = mirror.getElementValues().get(valueMethod);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
624 if (value == null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
625 value = valueMethod.getDefaultValue();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
626 }
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
627
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
628 return value;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
629 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
630
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
631 private static class AnnotationValueVisitorImpl extends AbstractAnnotationValueVisitor7<Object, Void> {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
632
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
633 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
634 public Object visitBoolean(boolean b, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
635 return Boolean.valueOf(b);
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
636 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
637
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
638 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
639 public Object visitByte(byte b, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
640 return Byte.valueOf(b);
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
641 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
642
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
643 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
644 public Object visitChar(char c, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
645 return c;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
646 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
647
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
648 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
649 public Object visitDouble(double d, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
650 return d;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
651 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
652
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
653 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
654 public Object visitFloat(float f, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
655 return f;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
656 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
657
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
658 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
659 public Object visitInt(int i, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
660 return i;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
661 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
662
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
663 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
664 public Object visitLong(long i, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
665 return i;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
666 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
667
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
668 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
669 public Object visitShort(short s, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
670 return s;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
671 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
672
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
673 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
674 public Object visitString(String s, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
675 return s;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
676 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
677
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
678 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
679 public Object visitType(TypeMirror t, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
680 return t;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
681 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
682
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
683 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
684 public Object visitEnumConstant(VariableElement c, Void p) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
685 return c;
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
686 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
687
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
688 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
689 public Object visitAnnotation(AnnotationMirror a, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
690 return a;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
691 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
692
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
693 @Override
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
694 public Object visitArray(List<? extends AnnotationValue> vals, Void p) {
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
695 return vals;
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
696 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
697
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
698 }
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
699
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
700 public static boolean getAnnotationValueBoolean(AnnotationMirror mirror, String name) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
701 return (Boolean) getAnnotationValue(mirror, name).getValue();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
703
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
704 public static String printException(Throwable e) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
705 StringWriter string = new StringWriter();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
706 PrintWriter writer = new PrintWriter(string);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
707 e.printStackTrace(writer);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
708 writer.flush();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
709 return e.getMessage() + "\r\n" + string.toString();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
710 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
711
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
712 public static AnnotationMirror findAnnotationMirror(ProcessingEnvironment processingEnv, Element element, Class<?> annotationClass) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
713 return findAnnotationMirror(processingEnv, element.getAnnotationMirrors(), annotationClass);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
714 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
715
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
716 public static AnnotationMirror findAnnotationMirror(ProcessingEnvironment processingEnv, List<? extends AnnotationMirror> mirrors, Class<?> annotationClass) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
717 TypeElement expectedAnnotationType = processingEnv.getElementUtils().getTypeElement(annotationClass.getCanonicalName());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
718 for (AnnotationMirror mirror : mirrors) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
719 DeclaredType annotationType = mirror.getAnnotationType();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
720 TypeElement actualAnnotationType = (TypeElement) annotationType.asElement();
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
721 if (actualAnnotationType.equals(expectedAnnotationType)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
722 return mirror;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
723 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
724 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
725 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
726 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
727
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
728 private static PackageElement findPackageElement(Element type) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
729 List<Element> hierarchy = getElementHierarchy(type);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
730 for (Element element : hierarchy) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
731 if (element.getKind() == ElementKind.PACKAGE) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
732 return (PackageElement) element;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
733 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
734 }
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
735 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
736 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
737
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
738 public static String firstLetterUpperCase(String name) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
739 if (name == null || name.isEmpty()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
740 return name;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
741 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
742 return Character.toUpperCase(name.charAt(0)) + name.substring(1, name.length());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
743 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
744
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
745 public static String firstLetterLowerCase(String name) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
746 if (name == null || name.isEmpty()) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
747 return name;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
748 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
749 return Character.toLowerCase(name.charAt(0)) + name.substring(1, name.length());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
750 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
751
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
752 private static ExecutableElement getDeclaredMethod(TypeElement element, String name, TypeMirror[] params) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
753 List<ExecutableElement> methods = ElementFilter.methodsIn(element.getEnclosedElements());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
754 method: for (ExecutableElement method : methods) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
755 if (!method.getSimpleName().toString().equals(name)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
756 continue;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
757 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
758 if (method.getParameters().size() != params.length) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
759 continue;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
760 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
761 for (int i = 0; i < params.length; i++) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
762 TypeMirror param1 = params[i];
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
763 TypeMirror param2 = method.getParameters().get(i).asType();
7851
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
764 if (param1.getKind() != TypeKind.TYPEVAR && param2.getKind() != TypeKind.TYPEVAR) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
765 if (!getQualifiedName(param1).equals(getQualifiedName(param2))) {
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
766 continue method;
e25ad0220267 Codewriter now supports writing generic type hierarchies and wildcards.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
767 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
768 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
769 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
770 return method;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
771 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
772 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
773 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
774
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
775 private static boolean isDeclaredMethod(TypeElement element, String name, TypeMirror[] params) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
776 return getDeclaredMethod(element, name, params) != null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
777 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
778
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
779 public static boolean isDeclaredMethodInSuperType(TypeElement element, String name, TypeMirror[] params) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
780 List<TypeElement> superElements = getSuperTypes(element);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
781
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
782 for (TypeElement typeElement : superElements) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
783 if (isDeclaredMethod(typeElement, name, params)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
784 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
785 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
786 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
787 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
788 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
789
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
790 private static ExecutableElement getDeclaredMethodInSuperType(TypeElement element, String name, TypeMirror[] params) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
791 List<TypeElement> superElements = getSuperTypes(element);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
792
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
793 for (TypeElement typeElement : superElements) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
794 ExecutableElement declared = getDeclaredMethod(typeElement, name, params);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
795 if (declared != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
796 return declared;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
797 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
798 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
799 return null;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
800 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
801
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
802 public static ExecutableElement getDeclaredMethodRecursive(TypeElement element, String name, TypeMirror[] params) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
803 ExecutableElement declared = getDeclaredMethod(element, name, params);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
804 if (declared != null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
805 return declared;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
806 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
807 return getDeclaredMethodInSuperType(element, name, params);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
808 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
809
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
810 public static boolean typeEquals(TypeMirror type1, TypeMirror type2) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
811 if (type1 == null && type2 == null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
812 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
813 } else if (type1 == null || type2 == null) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
814 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
815 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
816 String qualified1 = getQualifiedName(type1);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
817 String qualified2 = getQualifiedName(type2);
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
818
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
819 if (type1.getKind() == TypeKind.ARRAY || type2.getKind() == TypeKind.ARRAY) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
820 if (type1.getKind() == TypeKind.ARRAY && type2.getKind() == TypeKind.ARRAY) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
821 return typeEquals(((ArrayType) type1).getComponentType(), ((ArrayType) type2).getComponentType());
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
822 } else {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
823 return false;
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
824 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7851
diff changeset
825 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
826 return qualified1.equals(qualified2);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
827 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
828
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
829 public static int compareByTypeHierarchy(TypeMirror t1, TypeMirror t2) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
830 if (typeEquals(t1, t2)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
831 return 0;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
832 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
833 Set<String> t1SuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(t1)));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
834 if (t1SuperSet.contains(getQualifiedName(t2))) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
835 return -1;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
836 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
837
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
838 Set<String> t2SuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(t2)));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
839 if (t2SuperSet.contains(getQualifiedName(t1))) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
840 return 1;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
841 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
842 return 0;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
843 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
844
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
845 public static boolean canThrowType(List<? extends TypeMirror> thrownTypes, TypeMirror exceptionType) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
846 if (Utils.containsType(thrownTypes, exceptionType)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
847 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
848 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
849
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
850 if (isRuntimeException(exceptionType)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
851 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
852 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
853
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
854 // search for any super types
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
855 TypeElement exceptionTypeElement = fromTypeMirror(exceptionType);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
856 List<TypeElement> superTypes = getSuperTypes(exceptionTypeElement);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
857 for (TypeElement typeElement : superTypes) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
858 if (Utils.containsType(thrownTypes, typeElement.asType())) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
859 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
860 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
861 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
862
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
863 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
864 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
865
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
866 public static Modifier getVisibility(Set<Modifier> modifier) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
867 for (Modifier mod : modifier) {
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
868 if (mod == Modifier.PUBLIC || mod == Modifier.PRIVATE || mod == Modifier.PROTECTED) {
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
869 return mod;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
870 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
871 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
872 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
873 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
874
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
875 private static boolean isRuntimeException(TypeMirror type) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
876 Set<String> typeSuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(type)));
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
877 String typeName = getQualifiedName(type);
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
878 if (!typeSuperSet.contains(Throwable.class.getCanonicalName()) && !typeName.equals(Throwable.class.getCanonicalName())) {
8251
cb70ed101b5f Added automatic generation of generic specialization which throws unsupported operation if reached.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
879 throw new IllegalArgumentException("Given type does not extend Throwable.");
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
880 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
881 return typeSuperSet.contains(RuntimeException.class.getCanonicalName()) || typeName.equals(RuntimeException.class.getCanonicalName());
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
882 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
883
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
884 private static boolean containsType(Collection<? extends TypeMirror> collection, TypeMirror type) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
885 for (TypeMirror otherTypeMirror : collection) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
886 if (typeEquals(otherTypeMirror, type)) {
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
887 return true;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
888 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
889 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
890 return false;
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
891 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
892
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
893 public static boolean isTopLevelClass(TypeMirror importType) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
894 TypeElement type = fromTypeMirror(importType);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
895 if (type != null && type.getEnclosingElement() != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
896 return !type.getEnclosingElement().getKind().isClass();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
897 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
898 return true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
899 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
900
8662
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
901 public static boolean isObject(TypeMirror actualType) {
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
902 return getQualifiedName(actualType).equals("java.lang.Object");
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
903 }
5eeade940236 Fixed user generic signature must not match generated generic signature.
Christian Humer <christian.humer@gmail.com>
parents: 8251
diff changeset
904
9220
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
905 public static boolean isFieldAccessible(Element element, VariableElement variable) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
906 TypeElement type = Utils.findNearestEnclosingType(element);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
907 TypeElement varType = Utils.findNearestEnclosingType(variable);
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
908
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
909 while (type != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
910 if (typeEquals(type.asType(), varType.asType())) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
911 return true;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
912 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
913 if (type.getSuperclass() != null) {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
914 type = Utils.fromTypeMirror(type.getSuperclass());
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
915 } else {
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
916 type = null;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
917 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
918 }
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
919 return false;
97ad6d3e7557 Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
Christian Humer <christian.humer@gmail.com>
parents: 9215
diff changeset
920 }
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
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
921 }