annotate graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/TemplateMethodParser.java @ 8314:2be3865d9ea0

Fixed minor bug for implicit parameters in sourcegen.
author Christian Humer <christian.humer@gmail.com>
date Sat, 16 Mar 2013 15:53:04 +0100
parents 89006c76f737
children 8a1115c92271
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.template;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 static com.oracle.truffle.codegen.processor.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
26
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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.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
28 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
29
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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.*;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
32 import javax.lang.model.util.*;
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
33
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
34 import com.oracle.truffle.api.codegen.*;
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
35 import 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
36 import com.oracle.truffle.codegen.processor.template.ParameterSpec.Cardinality;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
38 public abstract class TemplateMethodParser<T extends Template, E extends TemplateMethod> {
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
39
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 private final ProcessorContext context;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
42 protected final T template;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
43
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
44 private boolean emitErrors = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
45 private boolean parseNullOnError = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
46
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
47 public TemplateMethodParser(ProcessorContext context, T template) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
48 this.template = template;
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
49 this.context = context;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
52 public boolean isEmitErrors() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
53 return emitErrors;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
54 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
55
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
56 public void setParseNullOnError(boolean nullOnError) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
57 this.parseNullOnError = nullOnError;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
58 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
59
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
60 public boolean isParseNullOnError() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
61 return parseNullOnError;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
62 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
63
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
64 public void setEmitErrors(boolean emitErrors) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
65 this.emitErrors = emitErrors;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
66 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
67
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
68 public ProcessorContext getContext() {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 return context;
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 public abstract MethodSpec createSpecification(ExecutableElement method, AnnotationMirror 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
73
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 public abstract E create(TemplateMethod 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
75
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
76 public abstract boolean isParsable(ExecutableElement method);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
77
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
78 public Class<? extends Annotation> getAnnotationType() {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
79 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
80 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
81
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
82 public final List<E> parse(List<? extends Element> elements) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
83 List<ExecutableElement> methods = new ArrayList<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
84 methods.addAll(ElementFilter.methodsIn(elements));
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
85
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
86 List<E> parsedMethods = new ArrayList<>();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
87 boolean valid = true;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
88 for (ExecutableElement method : methods) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
89 if (!isParsable(method)) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
90 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
91 }
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
92
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
93 Class<? extends Annotation> annotationType = getAnnotationType();
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
94 AnnotationMirror mirror = null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
95 if (annotationType != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
96 mirror = Utils.findAnnotationMirror(getContext().getEnvironment(), method, annotationType);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
97 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
98
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
99 E parsedMethod = parse(method, mirror);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
100
8248
c4c3f50fa9c2 Fixes for codegen builtins support.
Christian Humer <christian.humer@gmail.com>
parents: 8245
diff changeset
101 if (method.getModifiers().contains(Modifier.PRIVATE) && emitErrors) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
102 parsedMethod.addError("Method must not be private.");
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
103 valid = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
104 continue;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
105 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
106
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
107 if (parsedMethod != null) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
108 parsedMethods.add(parsedMethod);
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
109 } else {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
110 valid = false;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
111 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
112 }
8278
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
113 Collections.sort(parsedMethods, new Comparator<TemplateMethod>() {
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
114
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
115 @Override
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
116 public int compare(TemplateMethod o1, TemplateMethod o2) {
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
117 return o1.getMethodName().compareTo(o2.getMethodName());
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
118 }
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
119 });
a219e2a5a92f Fixed element ordering of methods which were inconsistent from javac to ecj.
Christian Humer <christian.humer@gmail.com>
parents: 8252
diff changeset
120
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
121 if (!valid && parseNullOnError) {
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
122 return null;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
123 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
124 return parsedMethods;
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
125 }
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
126
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
127 private E parse(ExecutableElement method, AnnotationMirror annotation) {
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
128 MethodSpec methodSpecification = createSpecification(method, 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
129 if (methodSpecification == 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
130 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
131 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
133 String id = method.getSimpleName().toString();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
134 AnnotationMirror idAnnotation = Utils.findAnnotationMirror(context.getEnvironment(), method, NodeId.class);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
135 if (idAnnotation != null) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
136 id = Utils.getAnnotationValue(String.class, idAnnotation, "value");
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
137 }
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
138
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
139 List<TypeDef> typeDefs = createTypeDefinitions(methodSpecification.getReturnType(), methodSpecification.getParameters());
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
140
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
141 ParameterSpec returnTypeSpec = methodSpecification.getReturnType();
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 List<ParameterSpec> parameterSpecs = 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
143 parameterSpecs.addAll(methodSpecification.getParameters());
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
145 ActualParameter returnTypeMirror = matchParameter(returnTypeSpec, method.getReturnType(), template, 0, false);
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
146 if (returnTypeMirror == null) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
147 if (emitErrors) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
148 E invalidMethod = create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<ActualParameter> emptyList()));
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
149 String expectedReturnType = createTypeSignature(returnTypeSpec, typeDefs, true);
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
150 String actualReturnType = Utils.getSimpleName(method.getReturnType());
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
151
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
152 String message = String.format("The provided return type \"%s\" does not match expected return type \"%s\".\nExpected signature: \n %s", actualReturnType, expectedReturnType,
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
153 createExpectedSignature(method.getSimpleName().toString(), returnTypeSpec, parameterSpecs, typeDefs));
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
154 invalidMethod.addError(message);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
155 return invalidMethod;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
156 } else {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
157 return null;
7502
6343a09b2ec1 Codegen operation generation is inferred from the node type hierarchy.
Christian Humer <christian.humer@gmail.com>
parents: 7291
diff changeset
158 }
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
159 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
161 List<TypeMirror> parameterTypes = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
162 for (VariableElement var : method.getParameters()) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
163 parameterTypes.add(var.asType());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
164 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
165
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
166 List<ActualParameter> parameters = parseParameters(parameterTypes, methodSpecification.getImplicitTypes(), parameterSpecs);
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
167 if (parameters == null) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
168 if (isEmitErrors()) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
169 E invalidMethod = create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, Collections.<ActualParameter> emptyList()));
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
170 String message = String.format("Method signature %s does not match to the expected signature: \n%s", createActualSignature(methodSpecification, method),
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
171 createExpectedSignature(method.getSimpleName().toString(), returnTypeSpec, parameterSpecs, typeDefs));
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
172 invalidMethod.addError(message);
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
173 return invalidMethod;
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
174 } else {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
175 return null;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
176 }
8242
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
177 }
ac4e8c16ffdf Added new codegen api classes NodeId, NodeClass to codegen along with some refactorings.
Christian Humer <christian.humer@gmail.com>
parents: 8237
diff changeset
178
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
179 return create(new TemplateMethod(id, template, methodSpecification, method, annotation, returnTypeMirror, parameters));
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
180 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
181
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
182 private static String createActualSignature(MethodSpec spec, ExecutableElement method) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
183 List<String> types = new ArrayList<>();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
184 for (TypeMirror implicitType : spec.getImplicitTypes()) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
185 types.add("implicit " + Utils.getSimpleName(implicitType));
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
186 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
187 for (VariableElement var : method.getParameters()) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
188 types.add(Utils.getSimpleName(var.asType()));
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
189 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
190
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
191 StringBuilder b = new StringBuilder("(");
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
192 for (Iterator<String> iterator = types.iterator(); iterator.hasNext();) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
193 b.append(iterator.next());
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
194 if (iterator.hasNext()) {
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
195 b.append(", ");
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
196 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
197 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
198 b.append(")");
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
199 return b.toString();
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
200 }
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
201
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
202 private List<ActualParameter> parseParameters(List<TypeMirror> types, List<TypeMirror> implicitTypes, List<ParameterSpec> parameterSpecs) {
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
203 Iterator<? extends TypeMirror> parameterIterator = types.iterator();
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
204 Iterator<? extends TypeMirror> implicitParametersIterator = implicitTypes.iterator();
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7502
diff changeset
205 Iterator<? extends ParameterSpec> specificationIterator = parameterSpecs.iterator();
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
206
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
207 TypeMirror parameter = parameterIterator.hasNext() ? parameterIterator.next() : null;
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
208 TypeMirror implicitParameter = implicitParametersIterator.hasNext() ? implicitParametersIterator.next() : null;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
209 ParameterSpec specification = specificationIterator.hasNext() ? specificationIterator.next() : 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
210
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
211 int specificationParameterIndex = 0;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
212 List<ActualParameter> resolvedParameters = new ArrayList<>();
8314
2be3865d9ea0 Fixed minor bug for implicit parameters in sourcegen.
Christian Humer <christian.humer@gmail.com>
parents: 8310
diff changeset
213 while (parameter != null || specification != null || implicitParameter != null) {
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
214 if (parameter == null || specification == null) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
215 if (specification != null && (specification.isOptional() || specification.getCardinality() == Cardinality.MULTIPLE)) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
216 specification = specificationIterator.hasNext() ? specificationIterator.next() : null;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
217 specificationParameterIndex = 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
218 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
219 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
220 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
221 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
222
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
223 ActualParameter resolvedParameter = null;
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
224
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
225 boolean implicit = false;
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
226 if (implicitParameter != null) {
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
227 resolvedParameter = matchParameter(specification, implicitParameter, template, specificationParameterIndex, true);
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
228 if (resolvedParameter != null) {
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
229 implicit = true;
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
230 }
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
231 }
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
232
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
233 if (resolvedParameter == null) {
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
234 resolvedParameter = matchParameter(specification, parameter, template, specificationParameterIndex, false);
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
235 }
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
236
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
237 if (resolvedParameter == null) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
238 // mismatch
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
239 if (specification.isOptional()) {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
240 specification = specificationIterator.hasNext() ? specificationIterator.next() : null;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
241 specificationParameterIndex = 0;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
242 } else {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
243 return null;
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
244 }
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
245 } else {
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
246 resolvedParameters.add(resolvedParameter);
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
247
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
248 // match
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
249 if (implicit) {
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
250 implicitParameter = implicitParametersIterator.hasNext() ? implicitParametersIterator.next() : null;
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
251 } else {
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
252 parameter = parameterIterator.hasNext() ? parameterIterator.next() : null;
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
253 }
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
254
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
255 if (specification.getCardinality() == Cardinality.ONE) {
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
256 specification = specificationIterator.hasNext() ? specificationIterator.next() : null;
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
257 specificationParameterIndex = 0;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
258 } else if (specification.getCardinality() == Cardinality.MULTIPLE) {
8245
703c09f8640c Implemented support for @NodeClass annotation to support builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8242
diff changeset
259 specificationParameterIndex++;
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
260 }
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
261 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 }
8237
6b74ffe38183 Implemented support for executing nodes in @Children fields.
Christian Humer <christian.humer@gmail.com>
parents: 7753
diff changeset
263 return resolvedParameters;
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
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
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
266 private ActualParameter matchParameter(ParameterSpec specification, TypeMirror mirror, Template typeSystem, int index, boolean implicit) {
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
267 TypeMirror resolvedType = 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
268 if (hasError(resolvedType)) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
269 resolvedType = context.resolveNotYetCompiledType(mirror, typeSystem);
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
270 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 if (!specification.matches(resolvedType)) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273 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
274 }
8310
89006c76f737 Final fields of base node can be optionally passed to builtin specialization method. And a few fixes.
Christian Humer <christian.humer@gmail.com>
parents: 8278
diff changeset
275 return new ActualParameter(specification, resolvedType, index, implicit);
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
276 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277
7753
c17ee8823d72 Fixed bug in method parsing error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7679
diff changeset
278 protected List<TypeDef> createTypeDefinitions(ParameterSpec returnType, List<? extends ParameterSpec> parameters) {
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
279 List<TypeDef> typeDefs = new ArrayList<>();
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
280
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
281 List<ParameterSpec> allParams = new ArrayList<>();
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
282 allParams.add(returnType);
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
283 allParams.addAll(parameters);
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
284
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
285 int defIndex = 0;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
286 for (ParameterSpec spec : allParams) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
287 List<TypeMirror> allowedTypes = spec.getAllowedTypes();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
288 List<TypeMirror> types = spec.getAllowedTypes();
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
289 if (types != null && allowedTypes.size() > 1) {
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
290 TypeDef foundDef = null;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
291 for (TypeDef def : typeDefs) {
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
292 if (allowedTypes.equals(def.getTypes())) {
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
293 foundDef = def;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
294 break;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
295 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
296 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
297 if (foundDef == null) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
298 foundDef = new TypeDef(types, "Types" + defIndex);
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
299 typeDefs.add(foundDef);
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
300 defIndex++;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
301 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
302
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
303 foundDef.getParameters().add(spec);
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
304 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
305 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
306
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
307 return typeDefs;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
308 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
309
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
310 protected static class TypeDef {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
311
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
312 private final List<TypeMirror> types;
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
313 private final String name;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
314 private final List<ParameterSpec> parameters = new ArrayList<>();
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
315
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
316 public TypeDef(List<TypeMirror> types, String name) {
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
317 this.types = types;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
318 this.name = name;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
319 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
320
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
321 public List<ParameterSpec> getParameters() {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
322 return parameters;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
323 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
324
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
325 public List<TypeMirror> getTypes() {
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
326 return types;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
327 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
328
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
329 public String getName() {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
330 return name;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
331 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
332 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
333
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
334 public static String createExpectedSignature(String methodName, ParameterSpec returnType, List<? extends ParameterSpec> parameters, List<TypeDef> typeDefs) {
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 StringBuilder b = new StringBuilder();
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 b.append(" ");
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
338 b.append(createTypeSignature(returnType, typeDefs, true));
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
339
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
340 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
341 b.append(methodName);
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
342 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
343
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
344 for (int i = 0; i < parameters.size(); 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
345 ParameterSpec specification = parameters.get(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
346 if (specification.isOptional()) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 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
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 if (specification.getCardinality() == Cardinality.MULTIPLE) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
350 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
351 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
352
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
353 b.append(createTypeSignature(specification, typeDefs, false));
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
354
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
355 if (specification.isOptional()) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
356 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
357 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
358
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 if (specification.getCardinality() == Cardinality.MULTIPLE) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
360 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
361 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
362
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
363 if (i < parameters.size() - 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
364 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
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 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
369 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
370
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
371 if (!typeDefs.isEmpty()) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
372 b.append("\n\n");
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
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
374 String lineSep = "";
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
375 for (TypeDef def : typeDefs) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
376 b.append(lineSep);
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
377 b.append(" <").append(def.getName()).append(">");
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
378 b.append(" = {");
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
379 String separator = "";
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
380 for (TypeMirror type : def.getTypes()) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
381 b.append(separator).append(Utils.getSimpleName(type));
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
382 separator = ", ";
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
383 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
384 b.append("}");
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
385 lineSep = "\n";
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
386
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
387 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 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
390 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
392 private static String createTypeSignature(ParameterSpec spec, List<TypeDef> typeDefs, boolean typeOnly) {
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
393 StringBuilder builder = new StringBuilder();
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
394 if (spec.getAllowedTypes().size() > 1) {
7679
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
395 TypeDef foundTypeDef = null;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
396 for (TypeDef typeDef : typeDefs) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
397 if (typeDef.getParameters().contains(spec)) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
398 foundTypeDef = typeDef;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
399 break;
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
400 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
401 }
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
402 if (foundTypeDef != null) {
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
403 builder.append("<" + foundTypeDef.getName() + ">");
5f3cba05c2fa Cleanup and improved error messages.
Christian Humer <christian.humer@gmail.com>
parents: 7530
diff changeset
404 }
8252
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
405 } else if (spec.getAllowedTypes().size() == 1) {
0905d796944a Refactored codegen error model to make error redirection a lot easier.
Christian Humer <christian.humer@gmail.com>
parents: 8248
diff changeset
406 builder.append(Utils.getSimpleName(spec.getAllowedTypes().get(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
407 } 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
408 builder.append("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 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 if (!typeOnly) {
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
411 builder.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
412 builder.append(spec.getName());
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
413 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation processor for automatic code generation of the type-specialized Node classes during the build process
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
414 return builder.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
415 }
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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
a748e4d44694 Truffle API to specify type-specalized Node classes; annotation 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 }