annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java @ 22516:687bc1dda125

Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
author Christian Humer <christian.humer@oracle.com>
date Fri, 18 Dec 2015 14:41:06 +0100
parents 4a43dc00a654
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
23 package com.oracle.truffle.dsl.processor.parser;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
22516
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
25 import java.lang.annotation.Annotation;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
26 import java.util.ArrayList;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
27 import java.util.Arrays;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
28 import java.util.Collection;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
29 import java.util.Collections;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
30 import java.util.Comparator;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
31 import java.util.HashMap;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
32 import java.util.HashSet;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
33 import java.util.Iterator;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
34 import java.util.List;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
35 import java.util.ListIterator;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
36 import java.util.Map;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
37 import java.util.Objects;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
38 import java.util.Set;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
39
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
40 import javax.lang.model.element.AnnotationMirror;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
41 import javax.lang.model.element.AnnotationValue;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
42 import javax.lang.model.element.Element;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
43 import javax.lang.model.element.ElementKind;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
44 import javax.lang.model.element.ExecutableElement;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
45 import javax.lang.model.element.Modifier;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
46 import javax.lang.model.element.TypeElement;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
47 import javax.lang.model.element.VariableElement;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
48 import javax.lang.model.type.DeclaredType;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
49 import javax.lang.model.type.TypeKind;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
50 import javax.lang.model.type.TypeMirror;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
51 import javax.lang.model.util.ElementFilter;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
52 import javax.tools.Diagnostic.Kind;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
53
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
54 import com.oracle.truffle.api.Assumption;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
55 import com.oracle.truffle.api.dsl.Cached;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
56 import com.oracle.truffle.api.dsl.CreateCast;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
57 import com.oracle.truffle.api.dsl.Fallback;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
58 import com.oracle.truffle.api.dsl.GenerateNodeFactory;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
59 import com.oracle.truffle.api.dsl.GeneratedBy;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
60 import com.oracle.truffle.api.dsl.ImportStatic;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
61 import com.oracle.truffle.api.dsl.NodeChild;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
62 import com.oracle.truffle.api.dsl.NodeChildren;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
63 import com.oracle.truffle.api.dsl.NodeField;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
64 import com.oracle.truffle.api.dsl.NodeFields;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
65 import com.oracle.truffle.api.dsl.ShortCircuit;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
66 import com.oracle.truffle.api.dsl.Specialization;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
67 import com.oracle.truffle.api.dsl.TypeSystemReference;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
68 import com.oracle.truffle.api.dsl.internal.DSLOptions;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
69 import com.oracle.truffle.api.frame.Frame;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
70 import com.oracle.truffle.api.nodes.NodeInfo;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
71 import com.oracle.truffle.dsl.processor.CompileErrorException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
72 import com.oracle.truffle.dsl.processor.Log;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
73 import com.oracle.truffle.dsl.processor.expression.DSLExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
74 import com.oracle.truffle.dsl.processor.expression.DSLExpressionResolver;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
75 import com.oracle.truffle.dsl.processor.expression.InvalidExpressionException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
76 import com.oracle.truffle.dsl.processor.java.ElementUtils;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
77 import com.oracle.truffle.dsl.processor.java.compiler.CompilerFactory;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
78 import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
79 import com.oracle.truffle.dsl.processor.java.model.CodeVariableElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
80 import com.oracle.truffle.dsl.processor.model.AssumptionExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
81 import com.oracle.truffle.dsl.processor.model.CacheExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
82 import com.oracle.truffle.dsl.processor.model.ExecutableTypeData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
83 import com.oracle.truffle.dsl.processor.model.GuardExpression;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
84 import com.oracle.truffle.dsl.processor.model.MethodSpec;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
85 import com.oracle.truffle.dsl.processor.model.NodeChildData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
86 import com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
87 import com.oracle.truffle.dsl.processor.model.NodeData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
88 import com.oracle.truffle.dsl.processor.model.NodeExecutionData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
89 import com.oracle.truffle.dsl.processor.model.NodeFieldData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
90 import com.oracle.truffle.dsl.processor.model.Parameter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
91 import com.oracle.truffle.dsl.processor.model.ParameterSpec;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
92 import com.oracle.truffle.dsl.processor.model.ShortCircuitData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
93 import com.oracle.truffle.dsl.processor.model.SpecializationData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
94 import com.oracle.truffle.dsl.processor.model.SpecializationData.SpecializationKind;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
95 import com.oracle.truffle.dsl.processor.model.SpecializationThrowsData;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
96 import com.oracle.truffle.dsl.processor.model.TemplateMethod;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
97 import com.oracle.truffle.dsl.processor.model.TypeSystemData;
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
98
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
99 @DSLOptions
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
100 public class NodeParser extends AbstractParser<NodeData> {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101
16760
9f38d222fa6c Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
102 public static final List<Class<? extends Annotation>> ANNOTATIONS = Arrays.asList(Fallback.class, TypeSystemReference.class, ShortCircuit.class, Specialization.class, NodeChild.class,
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
103 NodeChildren.class);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 protected NodeData parse(Element element, AnnotationMirror mirror) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
107 NodeData node = parseRootType((TypeElement) element);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
108 if (Log.isDebug() && node != null) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
109 String dump = node.dump();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
110 log.message(Kind.ERROR, null, null, null, dump);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 return node;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116 protected NodeData filterErrorElements(NodeData model) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
117 for (Iterator<NodeData> iterator = model.getEnclosingNodes().iterator(); iterator.hasNext();) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 NodeData node = filterErrorElements(iterator.next());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 if (node == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 iterator.remove();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
123 if (model.hasErrors()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
124 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
125 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
126 return model;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
127 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
128
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 public boolean isDelegateToRootDeclaredType() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 return true;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
133
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
134 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
135 public Class<? extends Annotation> getAnnotationType() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
137 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139 @Override
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 public List<Class<? extends Annotation>> getTypeDelegatedAnnotationTypes() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 return ANNOTATIONS;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
144 private NodeData parseRootType(TypeElement rootType) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
145 List<NodeData> enclosedNodes = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
146 for (TypeElement enclosedType : ElementFilter.typesIn(rootType.getEnclosedElements())) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
147 NodeData enclosedChild = parseRootType(enclosedType);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
148 if (enclosedChild != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
149 enclosedNodes.add(enclosedChild);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 }
18781
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
152 NodeData node;
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
153 try {
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
154 node = parseNode(rootType);
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
155 } catch (CompileErrorException e) {
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
156 throw e;
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
157 } catch (Throwable e) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
158 RuntimeException e2 = new RuntimeException(String.format("Parsing of Node %s failed.", ElementUtils.getQualifiedName(rootType)));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
159 e2.addSuppressed(e);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
160 throw e2;
18781
941761f6b736 Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
161 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
162 if (node == null && !enclosedNodes.isEmpty()) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
163 node = new NodeData(context, rootType);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
166 if (node != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
167 for (NodeData enclosedNode : enclosedNodes) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
168 node.addEnclosedNode(enclosedNode);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
169 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
171 return node;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
172 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
173
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
174 private NodeData parseNode(TypeElement originalTemplateType) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
175 // reloading the type elements is needed for ecj
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
176 TypeElement templateType = ElementUtils.fromTypeMirror(context.reloadTypeElement(originalTemplateType));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
177
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
178 if (ElementUtils.findAnnotationMirror(processingEnv, originalTemplateType, GeneratedBy.class) != null) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 // generated nodes should not get called again.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
183 if (!ElementUtils.isAssignable(templateType.asType(), context.getTruffleTypes().getNode())) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
185 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
186
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
187 List<TypeElement> lookupTypes = collectSuperClasses(new ArrayList<TypeElement>(), templateType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
188 List<Element> members = loadMembers(templateType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
189 // ensure the processed element has at least one @Specialization annotation.
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
190 if (!containsSpecializations(members)) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
191 return null;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
192 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
193
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
194 NodeData node = parseNodeData(templateType, lookupTypes);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
195 if (node.hasErrors()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
196 return node;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
197 }
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
198
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
199 node.getFields().addAll(parseFields(lookupTypes, members));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
200 node.getChildren().addAll(parseChildren(lookupTypes, members));
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
201 node.getChildExecutions().addAll(parseExecutions(node.getFields(), node.getChildren(), members));
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
202 node.getExecutableTypes().addAll(parseExecutableTypeData(node, members, node.getSignatureSize(), context.getFrameTypes(), false));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
203
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
204 initializeExecutableTypes(node);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
205 initializeImportGuards(node, lookupTypes, members);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
206 initializeChildren(node);
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
207
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
208 if (node.hasErrors()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209 return node; // error sync point
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
210 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
211
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
212 if (node.hasErrors()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
213 return node; // error sync point
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
214 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
215
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
216 node.getSpecializations().addAll(new SpecializationMethodParser(context, node).parse(members));
20941
4f45e4d3361c Truffle-DSL: rename GenericParser to Fallbackparser.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
217 node.getSpecializations().addAll(new FallbackParser(context, node).parse(members));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
218 node.getCasts().addAll(new CreateCastParser(context, node).parse(members));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
219 node.getShortCircuits().addAll(new ShortCircuitParser(context, node).parse(members));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
220
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
221 if (node.hasErrors()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
222 return node; // error sync point
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
223 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
224 initializeSpecializations(members, node);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
225 initializeExecutableTypeHierarchy(node);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
226
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
227 verifySpecializationSameLength(node);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
228 initializeShortCircuits(node); // requires specializations and polymorphic specializations
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
229
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
230 verifyVisibilities(node);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
231 verifyMissingAbstractMethods(node, members);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
232 verifyConstructors(node);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
233 verifyNamingConvention(node.getShortCircuits(), "needs");
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
234 verifySpecializationThrows(node);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
235 return node;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
236 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
237
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
238 private static void initializeExecutableTypeHierarchy(NodeData node) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
239 SpecializationData polymorphic = node.getPolymorphicSpecialization();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
240 if (polymorphic != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
241 boolean polymorphicSignatureFound = false;
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
242 List<TypeMirror> dynamicTypes = polymorphic.getDynamicTypes();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
243 TypeMirror frame = null;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
244 if (polymorphic.getFrame() != null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
245 frame = dynamicTypes.remove(0);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
246 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
247
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
248 ExecutableTypeData polymorphicType = new ExecutableTypeData(node, polymorphic.getReturnType().getType(), "execute", frame, dynamicTypes);
21000
fdf55f1ffc59 Truffle-DSL: fixed name conflicts for synthetic polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20998
diff changeset
249 String genericName = ExecutableTypeData.createName(polymorphicType) + "_";
fdf55f1ffc59 Truffle-DSL: fixed name conflicts for synthetic polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20998
diff changeset
250 polymorphicType.setUniqueName(genericName);
fdf55f1ffc59 Truffle-DSL: fixed name conflicts for synthetic polymorphic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 20998
diff changeset
251
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
252 for (ExecutableTypeData type : node.getExecutableTypes()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
253 if (polymorphicType.sameSignature(type)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
254 polymorphicSignatureFound = true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
255 break;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
256 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
257 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
258
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
259 if (!polymorphicSignatureFound) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
260 node.getExecutableTypes().add(polymorphicType);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
261 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
262 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
263
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
264 List<ExecutableTypeData> rootTypes = buildExecutableHierarchy(node);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
265 List<ExecutableTypeData> additionalAbstractRootTypes = new ArrayList<>();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
266 for (int i = 1; i < rootTypes.size(); i++) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
267 ExecutableTypeData rootType = rootTypes.get(i);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
268 if (rootType.isAbstract()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
269 // cannot implemement root
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
270 additionalAbstractRootTypes.add(rootType);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
271 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
272 node.getExecutableTypes().remove(rootType);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
273 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
274 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
275 if (!additionalAbstractRootTypes.isEmpty()) {
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
276 node.addError("Incompatible abstract execute methods found %s.", additionalAbstractRootTypes);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
277 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
278
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
279 namesUnique(node.getExecutableTypes());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
280
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
281 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
282
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
283 private static List<ExecutableTypeData> buildExecutableHierarchy(NodeData node) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
284 List<ExecutableTypeData> executes = node.getExecutableTypes();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
285 if (executes.isEmpty()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
286 return Collections.emptyList();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
287 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
288 List<ExecutableTypeData> hierarchyExecutes = new ArrayList<>(executes);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
289 Collections.sort(hierarchyExecutes);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
290 ExecutableTypeData parent = hierarchyExecutes.get(0);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
291 ListIterator<ExecutableTypeData> executesIterator = hierarchyExecutes.listIterator(1);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
292 buildExecutableHierarchy(node, parent, executesIterator);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
293 return hierarchyExecutes;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
294 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
295
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
296 private static void buildExecutableHierarchy(NodeData node, ExecutableTypeData parent, ListIterator<ExecutableTypeData> executesIterator) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
297 while (executesIterator.hasNext()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
298 ExecutableTypeData other = executesIterator.next();
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
299 if (other.canDelegateTo(parent)) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
300 parent.addDelegatedFrom(other);
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
301 executesIterator.remove();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
302 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
303 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
304 for (int i = 1; i < parent.getDelegatedFrom().size(); i++) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
305 buildExecutableHierarchy(node, parent.getDelegatedFrom().get(i - 1), parent.getDelegatedFrom().listIterator(i));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
306 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
307 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
308
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
309 private List<Element> loadMembers(TypeElement templateType) {
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
310 return newElementList(CompilerFactory.getCompiler(templateType).getAllMembersInDeclarationOrder(context.getEnvironment(), templateType));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
311 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
312
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
313 private boolean containsSpecializations(List<Element> elements) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
314 boolean foundSpecialization = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
315 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
316 if (ElementUtils.findAnnotationMirror(processingEnv, method, Specialization.class) != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
317 foundSpecialization = true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
318 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
319 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
320 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
321 return foundSpecialization;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
322 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
324 private void initializeImportGuards(NodeData node, List<TypeElement> lookupTypes, List<Element> elements) {
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
325 for (TypeElement lookupType : lookupTypes) {
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
326 AnnotationMirror importAnnotation = ElementUtils.findAnnotationMirror(processingEnv, lookupType, ImportStatic.class);
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
327 if (importAnnotation == null) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
328 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
329 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
330 AnnotationValue importClassesValue = ElementUtils.getAnnotationValue(importAnnotation, "value");
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
331 List<TypeMirror> importClasses = ElementUtils.getAnnotationValueList(TypeMirror.class, importAnnotation, "value");
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
332 if (importClasses.isEmpty()) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
333 node.addError(importAnnotation, importClassesValue, "At least import guard classes must be specified.");
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
334 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
335 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
336 for (TypeMirror importGuardClass : importClasses) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
337 if (importGuardClass.getKind() != TypeKind.DECLARED) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
338 node.addError(importAnnotation, importClassesValue, "The specified import guard class '%s' is not a declared type.", ElementUtils.getQualifiedName(importGuardClass));
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
339 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
340 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
341
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
342 TypeElement typeElement = ElementUtils.fromTypeMirror(importGuardClass);
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
343 if (typeElement.getEnclosingElement().getKind().isClass() && !typeElement.getModifiers().contains(Modifier.PUBLIC)) {
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
344 node.addError(importAnnotation, importClassesValue, "The specified import guard class '%s' must be public.", ElementUtils.getQualifiedName(importGuardClass));
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
345 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
346 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
347 elements.addAll(importPublicStaticMembers(typeElement, false));
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
348 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
349 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
350 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
351
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
352 private List<? extends Element> importPublicStaticMembers(TypeElement importGuardClass, boolean includeConstructors) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
353 // hack to reload type is necessary for incremental compiling in eclipse.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
354 // otherwise methods inside of import guard types are just not found.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
355 TypeElement typeElement = ElementUtils.fromTypeMirror(context.reloadType(importGuardClass.asType()));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
356
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
357 List<Element> members = new ArrayList<>();
22516
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
358
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
359 for (Element importElement : processingEnv.getElementUtils().getAllMembers(typeElement)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
360 if (!importElement.getModifiers().contains(Modifier.PUBLIC)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
361 continue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
362 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
363
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
364 if (includeConstructors && importElement.getKind() == ElementKind.CONSTRUCTOR) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
365 members.add(importElement);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
366 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
367
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
368 if (!importElement.getModifiers().contains(Modifier.STATIC)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
369 continue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
370 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
371
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
372 ElementKind kind = importElement.getKind();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
373 if (kind.isField() || kind == ElementKind.METHOD) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
374 members.add(importElement);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
375 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
376 }
22516
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
377
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
378 /*
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
379 * Sort elements by enclosing type to ensure that duplicate static methods are used from the
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
380 * most concrete subtype.
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
381 */
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
382 Collections.sort(members, new Comparator<Element>() {
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
383 Map<TypeMirror, Set<String>> cachedQualifiedNames = new HashMap<>();
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
384
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
385 public int compare(Element o1, Element o2) {
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
386 TypeMirror e1 = o1.getEnclosingElement() != null ? o1.getEnclosingElement().asType() : null;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
387 TypeMirror e2 = o2.getEnclosingElement() != null ? o2.getEnclosingElement().asType() : null;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
388
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
389 Set<String> e1SuperTypes = getCachedSuperTypes(e1);
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
390 Set<String> e2SuperTypes = getCachedSuperTypes(e2);
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
391 return ElementUtils.compareByTypeHierarchy(e1, e1SuperTypes, e2, e2SuperTypes);
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
392 }
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
393
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
394 private Set<String> getCachedSuperTypes(TypeMirror e) {
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
395 if (e == null) {
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
396 return Collections.emptySet();
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
397 }
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
398 Set<String> superTypes = cachedQualifiedNames.get(e);
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
399 if (superTypes == null) {
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
400 superTypes = new HashSet<>(ElementUtils.getQualifiedSuperTypeNames(ElementUtils.fromTypeMirror(e)));
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
401 cachedQualifiedNames.put(e, superTypes);
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
402 }
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
403 return superTypes;
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
404 }
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
405 });
687bc1dda125 Truffle-DSL: fix wrong resolution when multiple public static methods are imported from a cached type.
Christian Humer <christian.humer@oracle.com>
parents: 22327
diff changeset
406
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
407 return members;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
408 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
409
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
410 private NodeData parseNodeData(TypeElement templateType, List<TypeElement> typeHierarchy) {
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
411 AnnotationMirror typeSystemMirror = findFirstAnnotation(typeHierarchy, TypeSystemReference.class);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
412 TypeSystemData typeSystem = null;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
413 if (typeSystemMirror != null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
414 TypeMirror typeSystemType = ElementUtils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value");
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
415 typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, true);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
416 if (typeSystem == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
417 NodeData nodeData = new NodeData(context, templateType);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
418 nodeData.addError("The used type system '%s' is invalid. Fix errors in the type system first.", ElementUtils.getQualifiedName(typeSystemType));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
419 return nodeData;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
420 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
421 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
422 // default dummy type system
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
423 typeSystem = new TypeSystemData(context, templateType, null, NodeParser.class.getAnnotation(DSLOptions.class), true);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
425 AnnotationMirror nodeInfoMirror = findFirstAnnotation(typeHierarchy, NodeInfo.class);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
426 String shortName = null;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
427 if (nodeInfoMirror != null) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
428 shortName = ElementUtils.getAnnotationValue(String.class, nodeInfoMirror, "shortName");
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
429 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
430 boolean useNodeFactory = findFirstAnnotation(typeHierarchy, GenerateNodeFactory.class) != null;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
431 return new NodeData(context, templateType, shortName, typeSystem, useNodeFactory);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
432
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
433 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
434
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
435 private List<NodeFieldData> parseFields(List<TypeElement> typeHierarchy, List<? extends Element> elements) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
436 Set<String> names = new HashSet<>();
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
437
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438 List<NodeFieldData> fields = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 for (VariableElement field : ElementFilter.fieldsIn(elements)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440 if (field.getModifiers().contains(Modifier.STATIC)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443 if (field.getModifiers().contains(Modifier.PUBLIC) || field.getModifiers().contains(Modifier.PROTECTED)) {
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
444 String name = field.getSimpleName().toString();
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
445 fields.add(new NodeFieldData(field, null, field, false));
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
446 names.add(name);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
447 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
448 }
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
449
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
450 List<TypeElement> reversedTypeHierarchy = new ArrayList<>(typeHierarchy);
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
451 Collections.reverse(reversedTypeHierarchy);
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
452 for (TypeElement typeElement : reversedTypeHierarchy) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
453 AnnotationMirror nodeChildrenMirror = ElementUtils.findAnnotationMirror(processingEnv, typeElement, NodeFields.class);
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
454 List<AnnotationMirror> children = ElementUtils.collectAnnotations(context, nodeChildrenMirror, "value", typeElement, NodeField.class);
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
455
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
456 for (AnnotationMirror mirror : children) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
457 String name = ElementUtils.firstLetterLowerCase(ElementUtils.getAnnotationValue(String.class, mirror, "name"));
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
458 TypeMirror type = ElementUtils.getAnnotationValue(TypeMirror.class, mirror, "type");
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
459
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
460 NodeFieldData field = new NodeFieldData(typeElement, mirror, new CodeVariableElement(type, name), true);
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
461 if (name.isEmpty()) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
462 field.addError(ElementUtils.getAnnotationValue(mirror, "name"), "Field name cannot be empty.");
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
463 } else if (names.contains(name)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
464 field.addError(ElementUtils.getAnnotationValue(mirror, "name"), "Duplicate field name '%s'.", name);
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
465 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
466 names.add(name);
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
467
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
468 fields.add(field);
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
469 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
470 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
471
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
472 for (NodeFieldData nodeFieldData : fields) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
473 nodeFieldData.setGetter(findGetter(elements, nodeFieldData.getName(), nodeFieldData.getType()));
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
474 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
475
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
476 return fields;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
477 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
478
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
479 private List<NodeChildData> parseChildren(final List<TypeElement> typeHierarchy, List<? extends Element> elements) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
480 Set<String> shortCircuits = new HashSet<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
481 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
482 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, method, ShortCircuit.class);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
483 if (mirror != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
484 shortCircuits.add(ElementUtils.getAnnotationValue(String.class, mirror, "value"));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
486 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
487 Map<String, TypeMirror> castNodeTypes = new HashMap<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
488 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
489 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, method, CreateCast.class);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 if (mirror != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
491 List<String> children = (ElementUtils.getAnnotationValueList(String.class, mirror, "value"));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492 if (children != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 for (String child : children) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
494 castNodeTypes.put(child, method.getReturnType());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
495 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
496 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
497 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
500 List<NodeChildData> parsedChildren = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
501 List<TypeElement> typeHierarchyReversed = new ArrayList<>(typeHierarchy);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
502 Collections.reverse(typeHierarchyReversed);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
503 for (TypeElement type : typeHierarchyReversed) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
504 AnnotationMirror nodeChildrenMirror = ElementUtils.findAnnotationMirror(processingEnv, type, NodeChildren.class);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
505
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
506 TypeMirror nodeClassType = type.getSuperclass();
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
507 if (!ElementUtils.isAssignable(nodeClassType, context.getTruffleTypes().getNode())) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
508 nodeClassType = null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
509 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
510
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
511 List<AnnotationMirror> children = ElementUtils.collectAnnotations(context, nodeChildrenMirror, "value", type, NodeChild.class);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
512 int index = 0;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
513 for (AnnotationMirror childMirror : children) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
514 String name = ElementUtils.getAnnotationValue(String.class, childMirror, "value");
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
515 if (name.equals("")) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
516 name = "child" + index;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
517 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
518
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
519 Cardinality cardinality = Cardinality.ONE;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
520
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
521 TypeMirror childType = inheritType(childMirror, "type", nodeClassType);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
522 if (childType.getKind() == TypeKind.ARRAY) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
523 cardinality = Cardinality.MANY;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
524 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
525
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
526 TypeMirror originalChildType = childType;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
527 TypeMirror castNodeType = castNodeTypes.get(name);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
528 if (castNodeType != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
529 childType = castNodeType;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
530 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
531
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
532 Element getter = findGetter(elements, name, childType);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
533 NodeChildData nodeChild = new NodeChildData(type, childMirror, name, childType, originalChildType, getter, cardinality);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
534
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
535 parsedChildren.add(nodeChild);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
536
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
537 if (nodeChild.getNodeType() == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
538 nodeChild.addError("No valid node type could be resoleved.");
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
539 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
540 if (nodeChild.hasErrors()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
541 continue;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
542 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
543
11183
0f5ff66a949d Truffle-DSL: Fixed a bug with anonymous children (GRAAL-321 #resolve)
Christian Humer <christian.humer@gmail.com>
parents: 11180
diff changeset
544 index++;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
545 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
546 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
547
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
548 List<NodeChildData> filteredChildren = new ArrayList<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
549 Set<String> encounteredNames = new HashSet<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
550 for (int i = parsedChildren.size() - 1; i >= 0; i--) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
551 NodeChildData child = parsedChildren.get(i);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
552 if (!encounteredNames.contains(child.getName())) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
553 filteredChildren.add(0, child);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
554 encounteredNames.add(child.getName());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
555 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
556 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
557
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
558 return filteredChildren;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
559 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
560
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
561 private List<NodeExecutionData> parseExecutions(List<NodeFieldData> fields, List<NodeChildData> children, List<? extends Element> elements) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
562 // pre-parse short circuits
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
563 Set<String> shortCircuits = new HashSet<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
564 List<ExecutableElement> methods = ElementFilter.methodsIn(elements);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
565 for (ExecutableElement method : methods) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
566 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, method, ShortCircuit.class);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
567 if (mirror != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
568 shortCircuits.add(ElementUtils.getAnnotationValue(String.class, mirror, "value"));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
569 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
570 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
571
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
572 boolean hasVarArgs = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
573 int maxSignatureSize = 0;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
574 if (!children.isEmpty()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
575 int lastIndex = children.size() - 1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
576 hasVarArgs = children.get(lastIndex).getCardinality() == Cardinality.MANY;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
577 if (hasVarArgs) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
578 maxSignatureSize = lastIndex;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
579 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
580 maxSignatureSize = children.size();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
581 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
582 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
583
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
584 List<NodeFieldData> nonGetterFields = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
585 for (NodeFieldData field : fields) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
586 if (field.getGetter() == null && field.isGenerated()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
587 nonGetterFields.add(field);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
588 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
589 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
590
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
591 TypeMirror cacheAnnotation = context.getType(Cached.class);
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
592 List<TypeMirror> frameTypes = context.getFrameTypes();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
593 // pre-parse specializations to find signature size
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
594 for (ExecutableElement method : methods) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
595 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, method, Specialization.class);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
596 if (mirror == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
597 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
598 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
599 int currentArgumentIndex = 0;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
600 boolean skipShortCircuit = false;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
601 parameter: for (VariableElement var : method.getParameters()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
602 if (skipShortCircuit) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
603 skipShortCircuit = false;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
604 continue parameter;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
605 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
606
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
607 TypeMirror type = var.asType();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
608 if (currentArgumentIndex == 0) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
609 // skip optionals
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
610 for (TypeMirror frameType : frameTypes) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
611 if (ElementUtils.typeEquals(type, frameType)) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
612 continue parameter;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
613 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
614 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
615 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
616
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
617 if (currentArgumentIndex < nonGetterFields.size()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
618 for (NodeFieldData field : nonGetterFields) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
619 if (ElementUtils.typeEquals(var.asType(), field.getType())) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
620 continue parameter;
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
621 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
622 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
623 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
624
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
625 if (ElementUtils.findAnnotationMirror(var.getAnnotationMirrors(), cacheAnnotation) != null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
626 continue parameter;
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
627 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
628
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
629 int childIndex = currentArgumentIndex < children.size() ? currentArgumentIndex : children.size() - 1;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
630 if (childIndex != -1) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
631 NodeChildData child = children.get(childIndex);
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
632 if (shortCircuits.contains(NodeExecutionData.createIndexedName(child, currentArgumentIndex - childIndex))) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
633 skipShortCircuit = true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
634 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
635 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
636
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
637 currentArgumentIndex++;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
638 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
639 maxSignatureSize = Math.max(maxSignatureSize, currentArgumentIndex);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
640 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
641
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
642 List<NodeExecutionData> executions = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
643 for (int i = 0; i < maxSignatureSize; i++) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
644 boolean varArgParameter = false;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
645 int childIndex = i;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
646 if (i >= children.size() - 1) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
647 if (hasVarArgs) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
648 varArgParameter = hasVarArgs;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
649 childIndex = Math.min(i, children.size() - 1);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
650 } else if (i >= children.size()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
651 childIndex = -1;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
652 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
653 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
654 int varArgsIndex = -1;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
655 boolean shortCircuit = false;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
656 NodeChildData child = null;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
657 if (childIndex != -1) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
658 varArgsIndex = varArgParameter ? Math.abs(childIndex - i) : -1;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
659 child = children.get(childIndex);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
660 shortCircuit = shortCircuits.contains(NodeExecutionData.createIndexedName(child, varArgsIndex));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
661 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
662 executions.add(new NodeExecutionData(child, i, varArgsIndex, shortCircuit));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
663 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
664 return executions;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
665 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
666
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
667 private List<ExecutableTypeData> parseExecutableTypeData(NodeData node, List<? extends Element> elements, int signatureSize, List<TypeMirror> frameTypes, boolean includeFinals) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
668 List<ExecutableTypeData> typeData = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
669 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
670 Set<Modifier> modifiers = method.getModifiers();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
671 if (modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.STATIC)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
672 continue;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
673 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
674 if (!includeFinals && modifiers.contains(Modifier.FINAL)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
675 continue;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
676 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
677
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
678 if (!method.getSimpleName().toString().startsWith("execute")) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
679 continue;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
680 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
681 if (ElementUtils.findAnnotationMirror(context.getEnvironment(), method, Specialization.class) != null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
682 continue;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
683 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
684
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
685 ExecutableTypeData executableType = new ExecutableTypeData(node, method, signatureSize, context.getFrameTypes());
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
686
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
687 if (executableType.getFrameParameter() != null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
688 boolean supportedType = false;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
689 for (TypeMirror type : frameTypes) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
690 if (ElementUtils.isAssignable(type, executableType.getFrameParameter())) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
691 supportedType = true;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
692 break;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
693 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
694 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
695 if (!supportedType) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
696 continue;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
697 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
698 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
699
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
700 typeData.add(executableType);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
701 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
702
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
703 namesUnique(typeData);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
704
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
705 return typeData;
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
706 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
707
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
708 private static void namesUnique(List<ExecutableTypeData> typeData) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
709 List<String> names = new ArrayList<>();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
710 for (ExecutableTypeData type : typeData) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
711 names.add(type.getUniqueName());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
712 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
713 while (renameDuplicateIds(names)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
714 // fix point
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
715 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
716
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
717 for (int i = 0; i < typeData.size(); i++) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
718 typeData.get(i).setUniqueName(names.get(i));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
719 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
720 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
721
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
722 private void initializeExecutableTypes(NodeData node) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
723 List<ExecutableTypeData> allExecutes = node.getExecutableTypes();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
724
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
725 Set<String> inconsistentFrameTypes = new HashSet<>();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
726 TypeMirror frameType = null;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
727 for (ExecutableTypeData execute : allExecutes) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
728
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
729 TypeMirror frame = execute.getFrameParameter();
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
730 TypeMirror resolvedFrameType;
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
731 if (frame != null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
732 resolvedFrameType = frame;
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
733 if (frameType == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
734 frameType = resolvedFrameType;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
735 } else if (!ElementUtils.typeEquals(frameType, resolvedFrameType)) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
736 // found inconsistent frame types
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
737 inconsistentFrameTypes.add(ElementUtils.getSimpleName(frameType));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
738 inconsistentFrameTypes.add(ElementUtils.getSimpleName(resolvedFrameType));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
739 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
740 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
741 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
742 if (!inconsistentFrameTypes.isEmpty()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
743 // ensure they are sorted somehow
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
744 List<String> inconsistentFrameTypesList = new ArrayList<>(inconsistentFrameTypes);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
745 Collections.sort(inconsistentFrameTypesList);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
746 node.addError("Invalid inconsistent frame types %s found for the declared execute methods. The frame type must be identical for all execute methods.", inconsistentFrameTypesList);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
747 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
748 if (frameType == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
749 frameType = context.getType(void.class);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
750 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
751
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
752 node.setFrameType(frameType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
753
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
754 boolean genericFound = false;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
755 for (ExecutableTypeData type : node.getExecutableTypes()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
756 if (!type.hasUnexpectedValue(context)) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
757 genericFound = true;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
758 break;
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
759 }
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
760 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
761
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
762 // no generic executes
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
763 if (!genericFound) {
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
764 node.addError("No accessible and overridable generic execute method found. Generic execute methods usually have the "
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
765 + "signature 'public abstract {Type} execute(VirtualFrame)' and must not throw any checked exceptions.");
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
766 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
767
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
768 int nodeChildDeclarations = 0;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
769 int nodeChildDeclarationsRequired = 0;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
770 List<NodeExecutionData> executions = node.getChildExecutions();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
771 for (NodeExecutionData execution : executions) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
772 if (execution.getChild() == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
773 nodeChildDeclarationsRequired = execution.getIndex() + 1;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
774 } else {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
775 nodeChildDeclarations++;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
776 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
777 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
778
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
779 List<String> requireNodeChildDeclarations = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
780 for (ExecutableTypeData type : allExecutes) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
781 if (type.getEvaluatedCount() < nodeChildDeclarationsRequired) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
782 requireNodeChildDeclarations.add(ElementUtils.createReferenceName(type.getMethod()));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
783 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
784 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
785
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
786 if (!requireNodeChildDeclarations.isEmpty()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
787 node.addError("Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. "
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
788 + "The following execute methods do not provide all evaluated values for the expected signature size %s: %s.", executions.size(), requireNodeChildDeclarations);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
789 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
790
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
791 if (nodeChildDeclarations > 0 && executions.size() == node.getMinimalEvaluatedParameters()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
792 for (NodeChildData child : node.getChildren()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
793 child.addError("Unnecessary @NodeChild declaration. All evaluated child values are provided as parameters in execute methods.");
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
794 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
795 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
796
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
797 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
798
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
799 private void initializeChildren(NodeData node) {
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
800 initializeExecuteWith(node);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
801
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
802 for (NodeChildData child : node.getChildren()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
803 TypeMirror nodeType = child.getNodeType();
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
804 NodeData fieldNodeData = parseChildNodeData(node, child, ElementUtils.fromTypeMirror(nodeType));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
805
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
806 child.setNode(fieldNodeData);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
807 if (fieldNodeData == null || fieldNodeData.hasErrors()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
808 child.addError("Node type '%s' is invalid or not a subclass of Node.", ElementUtils.getQualifiedName(nodeType));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
809 } else {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
810 List<ExecutableTypeData> types = child.findGenericExecutableTypes(context);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
811 if (types.isEmpty()) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
812 AnnotationValue executeWithValue = ElementUtils.getAnnotationValue(child.getMessageAnnotation(), "executeWith");
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
813 child.addError(executeWithValue, "No generic execute method found with %s evaluated arguments for node type %s and frame types %s.", child.getExecuteWith().size(),
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
814 ElementUtils.getSimpleName(nodeType), ElementUtils.getUniqueIdentifiers(createAllowedChildFrameTypes(node)));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
815 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
816 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
817 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
818 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
819
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
820 private static void initializeExecuteWith(NodeData node) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
821 for (NodeChildData child : node.getChildren()) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
822 List<String> executeWithStrings = ElementUtils.getAnnotationValueList(String.class, child.getMessageAnnotation(), "executeWith");
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
823 AnnotationValue executeWithValue = ElementUtils.getAnnotationValue(child.getMessageAnnotation(), "executeWith");
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
824 List<NodeExecutionData> executeWith = new ArrayList<>();
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
825 for (String executeWithString : executeWithStrings) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
826 if (child.getName().equals(executeWithString)) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
827 child.addError(executeWithValue, "The child node '%s' cannot be executed with itself.", executeWithString);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
828 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
829 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
830 NodeExecutionData found = null;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
831 boolean before = true;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
832 for (NodeExecutionData resolveChild : node.getChildExecutions()) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
833 if (resolveChild.getChild() == child) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
834 before = false;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
835 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
836 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
837 if (resolveChild.getIndexedName().equals(executeWithString)) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
838 found = resolveChild;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
839 break;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
840 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
841 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
842
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
843 if (found == null) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
844 child.addError(executeWithValue, "The child node '%s' cannot be executed with '%s'. The child node was not found.", child.getName(), executeWithString);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
845 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
846 } else if (!before) {
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
847 child.addError(executeWithValue, "The child node '%s' cannot be executed with '%s'. The node %s is executed after the current node.", child.getName(), executeWithString,
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
848 executeWithString);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
849 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
850 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
851 executeWith.add(found);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
852 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
853 child.setExecuteWith(executeWith);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
854 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
855 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
856
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
857 private NodeData parseChildNodeData(NodeData parentNode, NodeChildData child, TypeElement originalTemplateType) {
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
858 TypeElement templateType = ElementUtils.fromTypeMirror(context.reloadTypeElement(originalTemplateType));
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
859
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
860 if (ElementUtils.findAnnotationMirror(processingEnv, originalTemplateType, GeneratedBy.class) != null) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
861 // generated nodes should not get called again.
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
862 return null;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
863 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
864
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
865 if (!ElementUtils.isAssignable(templateType.asType(), context.getTruffleTypes().getNode())) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
866 return null;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
867 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
868
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
869 List<TypeElement> lookupTypes = collectSuperClasses(new ArrayList<TypeElement>(), templateType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
870
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
871 // Declaration order is not required for child nodes.
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
872 List<? extends Element> members = processingEnv.getElementUtils().getAllMembers(templateType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
873 NodeData node = parseNodeData(templateType, lookupTypes);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
874 if (node.hasErrors()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
875 return node;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
876 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
877 List<TypeMirror> frameTypes = Collections.emptyList();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
878 if (parentNode.getFrameType() != null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
879 frameTypes = Arrays.asList(parentNode.getFrameType());
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
880 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
881 node.getExecutableTypes().addAll(parseExecutableTypeData(node, members, child.getExecuteWith().size(), frameTypes, true));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
882 node.setFrameType(parentNode.getFrameType());
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
883 return node;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
884 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
885
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
886 private List<TypeMirror> createAllowedChildFrameTypes(NodeData parentNode) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
887 List<TypeMirror> allowedFrameTypes = new ArrayList<>();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
888 for (TypeMirror frameType : context.getFrameTypes()) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
889 if (ElementUtils.isAssignable(parentNode.getFrameType(), frameType)) {
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
890 allowedFrameTypes.add(frameType);
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
891 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
892 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
893 return allowedFrameTypes;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
894 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
895
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
896 private void initializeSpecializations(List<? extends Element> elements, final NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
897 if (node.getSpecializations().isEmpty()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
898 return;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
899 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
900
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
901 initializeExpressions(elements, node);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
902
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
903 if (node.hasErrors()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
904 return;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
905 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
906
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
907 initializeGeneric(node);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
908 initializeUninitialized(node);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
909 initializeOrder(node);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
910 initializePolymorphism(node); // requires specializations
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
911 initializeReachability(node);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
912 initializeContains(node);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
913 resolveContains(node);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
914
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
915 List<SpecializationData> specializations = node.getSpecializations();
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
916 for (SpecializationData cur : specializations) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
917 for (SpecializationData contained : cur.getContains()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
918 if (contained != cur) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
919 contained.getExcludedBy().add(cur);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
920 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
921 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
922 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
923
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
924 initializeSpecializationIdsWithMethodNames(node.getSpecializations());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
925 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
926
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
927 private static void initializeOrder(NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
928 List<SpecializationData> specializations = node.getSpecializations();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
929 Collections.sort(specializations);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
930
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
931 for (SpecializationData specialization : specializations) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
932 String searchName = specialization.getInsertBeforeName();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
933 if (searchName == null || specialization.getMethod() == null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
934 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
935 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
936 SpecializationData found = lookupSpecialization(node, searchName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
937 if (found == null || found.getMethod() == null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
938 AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "insertBefore");
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
939 specialization.addError(value, "The referenced specialization '%s' could not be found.", searchName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
940 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
941 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
942
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
943 ExecutableElement currentMethod = specialization.getMethod();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
944 ExecutableElement insertBeforeMethod = found.getMethod();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
945
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
946 TypeMirror currentEnclosedType = currentMethod.getEnclosingElement().asType();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
947 TypeMirror insertBeforeEnclosedType = insertBeforeMethod.getEnclosingElement().asType();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
948
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
949 if (ElementUtils.typeEquals(currentEnclosedType, insertBeforeEnclosedType) || !ElementUtils.isSubtype(currentEnclosedType, insertBeforeEnclosedType)) {
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
950 AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "insertBefore");
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
951 specialization.addError(value, "Specializations can only be inserted before specializations in superclasses.", searchName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
952 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
953 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
954
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
955 specialization.setInsertBefore(found);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
956 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
957
16764
f9fff060dc41 Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents: 16760
diff changeset
958 for (int i = 0; i < specializations.size(); i++) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
959 SpecializationData specialization = specializations.get(i);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
960 SpecializationData insertBefore = specialization.getInsertBefore();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
961 if (insertBefore != null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
962 int insertIndex = specializations.indexOf(insertBefore);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
963 if (insertIndex < i) {
16764
f9fff060dc41 Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents: 16760
diff changeset
964 specializations.remove(i);
f9fff060dc41 Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents: 16760
diff changeset
965 specializations.add(insertIndex, specialization);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
966 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
967 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
968 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
969
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
970 for (int i = 0; i < specializations.size(); i++) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
971 specializations.get(i).setIndex(i);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
972 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
973 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
974
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
975 private static void initializeContains(NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
976 for (SpecializationData specialization : node.getSpecializations()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
977 Set<SpecializationData> resolvedSpecializations = specialization.getContains();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
978 resolvedSpecializations.clear();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
979 Set<String> includeNames = specialization.getContainsNames();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
980 for (String includeName : includeNames) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
981 // TODO reduce complexity of this lookup.
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
982 SpecializationData foundSpecialization = lookupSpecialization(node, includeName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
983
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
984 if (foundSpecialization == null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
985 AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "contains");
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
986 specialization.addError(value, "The referenced specialization '%s' could not be found.", includeName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
987 } else {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
988 if (foundSpecialization.compareTo(specialization) > 0) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
989 AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "contains");
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
990 if (foundSpecialization.compareTo(specialization) > 0) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
991 specialization.addError(value, "The contained specialization '%s' must be declared before the containing specialization.", includeName);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
992 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
993
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
994 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
995 resolvedSpecializations.add(foundSpecialization);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
996 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
997 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
998 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
999 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1000
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1001 private void resolveContains(NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1002 // flatten transitive includes
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1003 for (SpecializationData specialization : node.getSpecializations()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1004 if (specialization.getContains().isEmpty()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1005 continue;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1006 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1007 Set<SpecializationData> foundSpecializations = new HashSet<>();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1008 collectIncludes(specialization, foundSpecializations, new HashSet<SpecializationData>());
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1009 specialization.getContains().addAll(foundSpecializations);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1010 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1011 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1012
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1013 private static SpecializationData lookupSpecialization(NodeData node, String includeName) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1014 SpecializationData foundSpecialization = null;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1015 for (SpecializationData searchSpecialization : node.getSpecializations()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1016 if (searchSpecialization.getMethodName().equals(includeName)) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1017 foundSpecialization = searchSpecialization;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1018 break;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1019 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1020 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1021 return foundSpecialization;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1022 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1023
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1024 private void collectIncludes(SpecializationData specialization, Set<SpecializationData> found, Set<SpecializationData> visited) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1025 if (visited.contains(specialization)) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1026 // circle found
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1027 specialization.addError("Circular contained specialization '%s' found.", specialization.createReferenceName());
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1028 return;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1029 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1030 visited.add(specialization);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1031
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1032 for (SpecializationData included : specialization.getContains()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1033 collectIncludes(included, found, new HashSet<>(visited));
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1034 found.add(included);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1035 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1036 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1037
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1038 private static void initializeReachability(final NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1039 List<SpecializationData> specializations = node.getSpecializations();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1040 for (int i = specializations.size() - 1; i >= 0; i--) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1041 SpecializationData current = specializations.get(i);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1042 if (current.isPolymorphic()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1043 current.setReachable(true);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1044 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1045 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1046
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1047 List<SpecializationData> shadowedBy = null;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1048 for (int j = i - 1; j >= 0; j--) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1049 SpecializationData prev = specializations.get(j);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1050 if (prev.isPolymorphic()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1051 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1052 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1053 if (!current.isReachableAfter(prev)) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1054 if (shadowedBy == null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1055 shadowedBy = new ArrayList<>();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1056 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1057 shadowedBy.add(prev);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1058 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1059 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1060
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1061 if (shadowedBy != null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1062 StringBuilder name = new StringBuilder();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1063 String sep = "";
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1064 for (SpecializationData shadowSpecialization : shadowedBy) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1065 name.append(sep);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1066 name.append(shadowSpecialization.createReferenceName());
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1067 sep = ", ";
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1068 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
1069 current.addError("%s is not reachable. It is shadowed by %s.", current.isFallback() ? "Generic" : "Specialization", name);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1070 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1071 current.setReachable(shadowedBy == null);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1072 }
10602
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
1073 }
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
1074
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1075 private static void initializeSpecializationIdsWithMethodNames(List<SpecializationData> specializations) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1076 List<String> signatures = new ArrayList<>();
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1077 for (SpecializationData specialization : specializations) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1078 if (specialization.isFallback()) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1079 signatures.add("Fallback");
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1080 } else if (specialization.isUninitialized()) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1081 signatures.add("Uninitialized");
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1082 } else if (specialization.isPolymorphic()) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1083 signatures.add("Polymorphic");
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1084 } else {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1085 String name = specialization.getMethodName();
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1086
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1087 // hack for name clashes with BaseNode.
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1088 if (name.equalsIgnoreCase("base")) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1089 name = name + "0";
18773
7382bbcac3a3 Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
1090 } else if (name.startsWith("do")) {
7382bbcac3a3 Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
1091 String filteredDo = name.substring(2, name.length());
7382bbcac3a3 Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
1092 if (!filteredDo.isEmpty() && Character.isJavaIdentifierStart(filteredDo.charAt(0))) {
7382bbcac3a3 Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
1093 name = filteredDo;
7382bbcac3a3 Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
1094 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1095 }
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1096 signatures.add(ElementUtils.firstLetterUpperCase(name));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1097 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1098 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1099
18806
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1100 while (renameDuplicateIds(signatures)) {
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1101 // fix point
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1102 }
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1103
18771
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1104 for (int i = 0; i < specializations.size(); i++) {
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1105 specializations.get(i).setId(signatures.get(i));
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1106 }
15fe16c45d64 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
1107 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1108
18806
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1109 private static boolean renameDuplicateIds(List<String> signatures) {
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1110 boolean changed = false;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1111 Map<String, Integer> counts = new HashMap<>();
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1112 for (String s1 : signatures) {
18811
d2ec5f50dcd0 Truffle-DSL: fixed name clashes were still possible on a OS with case insensitive file system.
Christian Humer <christian.humer@gmail.com>
parents: 18806
diff changeset
1113 Integer count = counts.get(s1.toLowerCase());
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1114 if (count == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1115 count = 0;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1116 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1117 count++;
18811
d2ec5f50dcd0 Truffle-DSL: fixed name clashes were still possible on a OS with case insensitive file system.
Christian Humer <christian.humer@gmail.com>
parents: 18806
diff changeset
1118 counts.put(s1.toLowerCase(), count);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1119 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1120
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1121 for (String s : counts.keySet()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1122 int count = counts.get(s);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1123 if (count > 1) {
18806
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1124 changed = true;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1125 int number = 0;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1126 for (ListIterator<String> iterator = signatures.listIterator(); iterator.hasNext();) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1127 String s2 = iterator.next();
18811
d2ec5f50dcd0 Truffle-DSL: fixed name clashes were still possible on a OS with case insensitive file system.
Christian Humer <christian.humer@gmail.com>
parents: 18806
diff changeset
1128 if (s.equalsIgnoreCase(s2)) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1129 iterator.set(s2 + number);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1130 number++;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1131 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1132 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1133 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1134 }
18806
b9cf6f3150ea Truffle-DSL: make node id renaming a fixed point algorithm; relax warning condition for multiple execute methods; fix warning condition for multiple execute methods has displayed unproblematic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18781
diff changeset
1135 return changed;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1136 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1137
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1138 private void initializeExpressions(List<? extends Element> elements, NodeData node) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1139 List<Element> members = filterNotAccessibleElements(node.getTemplateType(), elements);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1140
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1141 List<VariableElement> fields = new ArrayList<>();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1142 for (NodeFieldData field : node.getFields()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1143 fields.add(field.getVariable());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1144 }
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
1145
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1146 for (SpecializationData specialization : node.getSpecializations()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1147 if (specialization.getMethod() == null) {
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
1148 continue;
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
1149 }
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
1150
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1151 List<Element> specializationMembers = new ArrayList<>(members.size() + specialization.getParameters().size() + fields.size());
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1152 for (Parameter p : specialization.getParameters()) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1153 specializationMembers.add(p.getVariableElement());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1154 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1155 specializationMembers.addAll(fields);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1156 specializationMembers.addAll(members);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1157 DSLExpressionResolver resolver = new DSLExpressionResolver(context, specializationMembers);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1158
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1159 initializeCaches(specialization, resolver);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1160 initializeGuards(specialization, resolver);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1161 if (specialization.hasErrors()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1162 continue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1163 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1164 initializeLimit(specialization, resolver);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1165 initializeAssumptions(specialization, resolver);
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1166 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1167 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1168
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1169 private void initializeAssumptions(SpecializationData specialization, DSLExpressionResolver resolver) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1170 final DeclaredType assumptionType = context.getDeclaredType(Assumption.class);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1171 final TypeMirror assumptionArrayType = new ArrayCodeTypeMirror(assumptionType);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1172 final List<String> assumptionDefinitions = ElementUtils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "assumptions");
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1173 List<AssumptionExpression> assumptionExpressions = new ArrayList<>();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1174 int assumptionId = 0;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1175 for (String assumption : assumptionDefinitions) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1176 AssumptionExpression assumptionExpression;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1177 DSLExpression expression = null;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1178 try {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1179 expression = DSLExpression.parse(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1180 expression.accept(resolver);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1181 assumptionExpression = new AssumptionExpression(specialization, expression, "assumption" + assumptionId);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1182 if (!ElementUtils.isAssignable(expression.getResolvedType(), assumptionType) && !ElementUtils.isAssignable(expression.getResolvedType(), assumptionArrayType)) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1183 assumptionExpression.addError("Incompatible return type %s. Assumptions must be assignable to %s or %s.", ElementUtils.getSimpleName(expression.getResolvedType()),
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1184 ElementUtils.getSimpleName(assumptionType), ElementUtils.getSimpleName(assumptionArrayType));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1185 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1186 if (specialization.isDynamicParameterBound(expression)) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1187 specialization.addError("Assumption expressions must not bind dynamic parameter values.");
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1188 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1189 } catch (InvalidExpressionException e) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1190 assumptionExpression = new AssumptionExpression(specialization, null, "assumption" + assumptionId);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1191 assumptionExpression.addError("Error parsing expression '%s': %s", assumption, e.getMessage());
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1192 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1193 assumptionExpressions.add(assumptionExpression);
22300
c53c4de22c4f Truffle/DSL: fix and tests for multiple assumptions expressions
Benoit Daloze <benoit.daloze@jku.at>
parents: 22157
diff changeset
1194 assumptionId++;
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1195 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1196 specialization.setAssumptionExpressions(assumptionExpressions);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1197 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
1198
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1199 private void initializeLimit(SpecializationData specialization, DSLExpressionResolver resolver) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1200 AnnotationValue annotationValue = ElementUtils.getAnnotationValue(specialization.getMessageAnnotation(), "limit");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1201
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1202 String limitValue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1203 if (annotationValue == null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1204 limitValue = "";
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1205 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1206 limitValue = (String) annotationValue.getValue();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1207 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1208 if (limitValue.isEmpty()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1209 limitValue = "3";
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1210 } else if (!specialization.hasMultipleInstances()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1211 specialization.addWarning(annotationValue, "The limit expression has no effect. Multiple specialization instantiations are impossible for this specialization.");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1212 return;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1213 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1214
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1215 TypeMirror expectedType = context.getType(int.class);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1216 try {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1217 DSLExpression expression = DSLExpression.parse(limitValue);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1218 expression.accept(resolver);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1219 if (!ElementUtils.typeEquals(expression.getResolvedType(), expectedType)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1220 specialization.addError(annotationValue, "Incompatible return type %s. Limit expressions must return %s.", ElementUtils.getSimpleName(expression.getResolvedType()),
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1221 ElementUtils.getSimpleName(expectedType));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1222 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1223 if (specialization.isDynamicParameterBound(expression)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1224 specialization.addError(annotationValue, "Limit expressions must not bind dynamic parameter values.");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1225 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1226
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1227 specialization.setLimitExpression(expression);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1228 } catch (InvalidExpressionException e) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1229 specialization.addError(annotationValue, "Error parsing expression '%s': %s", limitValue, e.getMessage());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1230 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1231 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1232
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1233 private void initializeCaches(SpecializationData specialization, DSLExpressionResolver resolver) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1234 TypeMirror cacheMirror = context.getType(Cached.class);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1235 List<CacheExpression> expressions = new ArrayList<>();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1236 for (Parameter parameter : specialization.getParameters()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1237 AnnotationMirror annotationMirror = ElementUtils.findAnnotationMirror(parameter.getVariableElement().getAnnotationMirrors(), cacheMirror);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1238 if (annotationMirror != null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1239 String initializer = ElementUtils.getAnnotationValue(String.class, annotationMirror, "value");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1240
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1241 TypeMirror parameterType = parameter.getType();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1242
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1243 DSLExpressionResolver localResolver = resolver;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1244 if (parameterType.getKind() == TypeKind.DECLARED) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1245 localResolver = localResolver.copy(importPublicStaticMembers(ElementUtils.fromTypeMirror(parameterType), true));
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1246 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1247
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1248 CacheExpression cacheExpression;
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1249 DSLExpression expression = null;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1250 try {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1251 expression = DSLExpression.parse(initializer);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1252 expression.accept(localResolver);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1253 cacheExpression = new CacheExpression(parameter, annotationMirror, expression);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1254 if (!ElementUtils.typeEquals(expression.getResolvedType(), parameter.getType())) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1255 cacheExpression.addError("Incompatible return type %s. The expression type must be equal to the parameter type %s.", ElementUtils.getSimpleName(expression.getResolvedType()),
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1256 ElementUtils.getSimpleName(parameter.getType()));
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1257 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1258 } catch (InvalidExpressionException e) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1259 cacheExpression = new CacheExpression(parameter, annotationMirror, null);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1260 cacheExpression.addError("Error parsing expression '%s': %s", initializer, e.getMessage());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1261 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1262 expressions.add(cacheExpression);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1263 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1264 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1265 specialization.setCaches(expressions);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1266
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1267 if (specialization.hasErrors()) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1268 return;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1269 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1270
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1271 // verify that cache expressions are bound in the correct order.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1272 for (int i = 0; i < expressions.size(); i++) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1273 CacheExpression currentExpression = expressions.get(i);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1274 Set<VariableElement> boundVariables = currentExpression.getExpression().findBoundVariableElements();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1275 for (int j = i + 1; j < expressions.size(); j++) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1276 CacheExpression boundExpression = expressions.get(j);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1277 if (boundVariables.contains(boundExpression.getParameter().getVariableElement())) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1278 currentExpression.addError("The initializer expression of parameter '%s' binds unitialized parameter '%s. Reorder the parameters to resolve the problem.",
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1279 currentExpression.getParameter().getLocalName(), boundExpression.getParameter().getLocalName());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1280 break;
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1281 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1282 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1283 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1284 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1285
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1286 private void initializeGuards(SpecializationData specialization, DSLExpressionResolver resolver) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1287 final TypeMirror booleanType = context.getType(boolean.class);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1288 List<String> guardDefinitions = ElementUtils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "guards");
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1289 List<GuardExpression> guardExpressions = new ArrayList<>();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1290 for (String guard : guardDefinitions) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1291 GuardExpression guardExpression;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1292 DSLExpression expression = null;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1293 try {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1294 expression = DSLExpression.parse(guard);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1295 expression.accept(resolver);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1296 guardExpression = new GuardExpression(specialization, expression);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1297 if (!ElementUtils.typeEquals(expression.getResolvedType(), booleanType)) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1298 guardExpression.addError("Incompatible return type %s. Guards must return %s.", ElementUtils.getSimpleName(expression.getResolvedType()), ElementUtils.getSimpleName(booleanType));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1299 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1300 } catch (InvalidExpressionException e) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1301 guardExpression = new GuardExpression(specialization, null);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1302 guardExpression.addError("Error parsing expression '%s': %s", guard, e.getMessage());
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1303 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1304 guardExpressions.add(guardExpression);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1305 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1306 specialization.setGuards(guardExpressions);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1307 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1308
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1309 private static List<Element> filterNotAccessibleElements(TypeElement templateType, List<? extends Element> elements) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1310 String packageName = ElementUtils.getPackageName(templateType);
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1311 List<Element> filteredElements = newElementList(elements);
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1312 for (Element element : elements) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1313 Modifier visibility = ElementUtils.getVisibility(element.getModifiers());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1314 if (visibility == Modifier.PRIVATE) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1315 continue;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1316 } else if (visibility == null) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1317 String elementPackageName = ElementUtils.getPackageName(element.getEnclosingElement().asType());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1318 if (!Objects.equals(packageName, elementPackageName) && !elementPackageName.equals("java.lang")) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1319 continue;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1320 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1321 }
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
1322
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1323 filteredElements.add(element);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1324 }
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1325 return filteredElements;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1326 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1327
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1328 private void initializeGeneric(final NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1329 List<SpecializationData> generics = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1330 for (SpecializationData spec : node.getSpecializations()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
1331 if (spec.isFallback()) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1332 generics.add(spec);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1333 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1334 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1335
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1336 if (generics.size() == 1 && node.getSpecializations().size() == 1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1337 // TODO this limitation should be lifted
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1338 for (SpecializationData generic : generics) {
16760
9f38d222fa6c Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
1339 generic.addError("@%s defined but no @%s.", Fallback.class.getSimpleName(), Specialization.class.getSimpleName());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1340 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1341 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1342
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1343 if (generics.isEmpty()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1344 node.getSpecializations().add(createGenericSpecialization(node));
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1345 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1346 if (generics.size() > 1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1347 for (SpecializationData generic : generics) {
16760
9f38d222fa6c Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
1348 generic.addError("Only one @%s is allowed per operation.", Fallback.class.getSimpleName());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1349 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1350 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1351 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1352 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1353
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1354 private SpecializationData createGenericSpecialization(final NodeData node) {
20941
4f45e4d3361c Truffle-DSL: rename GenericParser to Fallbackparser.
Christian Humer <christian.humer@gmail.com>
parents: 20940
diff changeset
1355 FallbackParser parser = new FallbackParser(context, node);
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1356 MethodSpec specification = parser.createDefaultMethodSpec(node.getSpecializations().iterator().next().getMethod(), null, true, null);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1357
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1358 List<VariableElement> parameterTypes = new ArrayList<>();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1359 int signatureIndex = 1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1360 for (ParameterSpec spec : specification.getRequired()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1361 parameterTypes.add(new CodeVariableElement(createGenericType(node, spec), "arg" + signatureIndex));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1362 if (spec.isSignature()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1363 signatureIndex++;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1364 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1365 }
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1366
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1367 TypeMirror returnType = createGenericType(node, specification.getReturnType());
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1368 SpecializationData generic = parser.create("Generic", TemplateMethod.NO_NATURAL_ORDER, null, null, returnType, parameterTypes);
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1369 if (generic == null) {
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1370 throw new RuntimeException("Unable to create generic signature for node " + node.getNodeId() + " with " + parameterTypes + ". Specification " + specification + ".");
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1371 }
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1372
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1373 return generic;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1374 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1375
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1376 private TypeMirror createGenericType(NodeData node, ParameterSpec spec) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1377 NodeExecutionData execution = spec.getExecution();
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1378 Collection<TypeMirror> allowedTypes;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1379 if (execution == null) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1380 allowedTypes = spec.getAllowedTypes();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1381 } else {
20966
05a2b72c071f Truffle-DSL: fixed potential non generic executes in uninitialized nodes.
Christian Humer <christian.humer@gmail.com>
parents: 20960
diff changeset
1382 allowedTypes = Arrays.asList(node.getGenericType(execution));
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1383 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1384 if (allowedTypes.size() == 1) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1385 return allowedTypes.iterator().next();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1386 } else {
20952
833e088ee7d3 Truffle-DSL: fixed invalid execute delegation
Christian Humer <christian.humer@gmail.com>
parents: 20950
diff changeset
1387 return ElementUtils.getCommonSuperType(context, allowedTypes);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1388 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1389 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1390
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1391 private static void initializeUninitialized(final NodeData node) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1392 SpecializationData generic = node.getGenericSpecialization();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1393 if (generic == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1394 return;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1395 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1396 TemplateMethod uninializedMethod = new TemplateMethod("Uninitialized", -1, node, generic.getSpecification(), null, null, generic.getReturnType(), generic.getParameters());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1397 // should not use messages from generic specialization
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1398 uninializedMethod.getMessages().clear();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1399 node.getSpecializations().add(new SpecializationData(node, uninializedMethod, SpecializationKind.UNINITIALIZED));
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1400 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1401
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1402 private void initializePolymorphism(NodeData node) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1403 if (!node.needsRewrites(context)) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1404 return;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1405 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1406
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1407 SpecializationData generic = node.getGenericSpecialization();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1408 List<VariableElement> types = new ArrayList<>();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1409
20960
6fe8d8a248ba Truffle-DSL: fix generic types are not unique in javac.
Christian Humer <christian.humer@gmail.com>
parents: 20952
diff changeset
1410 Collection<TypeMirror> frameTypes = new HashSet<>();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1411 for (SpecializationData specialization : node.getSpecializations()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1412 if (specialization.getFrame() != null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1413 frameTypes.add(specialization.getFrame().getType());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1414 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1415 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1416 if (node.supportsFrame()) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1417 frameTypes.add(node.getFrameType());
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1418 }
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1419
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1420 if (!frameTypes.isEmpty()) {
20998
8e5f9310f3aa Truffle-DSL: fixed wrong order for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
1421 frameTypes = ElementUtils.uniqueSortedTypes(frameTypes, false);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1422 TypeMirror frameType;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1423 if (frameTypes.size() == 1) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1424 frameType = frameTypes.iterator().next();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1425 } else {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1426 frameType = context.getType(Frame.class);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1427 }
20942
a2e295c6cf7c Truffle-DSL: fixed frame might be added twice for polymorphic signatures.
Christian Humer <christian.humer@gmail.com>
parents: 20941
diff changeset
1428 types.add(new CodeVariableElement(frameType, TemplateMethod.FRAME_NAME));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1429 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1430
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1431 TypeMirror returnType = null;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1432 int index = 0;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1433 for (Parameter genericParameter : generic.getReturnTypeAndParameters()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1434 TypeMirror polymorphicType;
20942
a2e295c6cf7c Truffle-DSL: fixed frame might be added twice for polymorphic signatures.
Christian Humer <christian.humer@gmail.com>
parents: 20941
diff changeset
1435 if (genericParameter.getLocalName().equals(TemplateMethod.FRAME_NAME)) {
a2e295c6cf7c Truffle-DSL: fixed frame might be added twice for polymorphic signatures.
Christian Humer <christian.humer@gmail.com>
parents: 20941
diff changeset
1436 continue;
a2e295c6cf7c Truffle-DSL: fixed frame might be added twice for polymorphic signatures.
Christian Humer <christian.humer@gmail.com>
parents: 20941
diff changeset
1437 }
20950
a778fbcb8d8e Truffle-DSL: fix polymorphic return type was always object if type had implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 20942
diff changeset
1438 boolean isReturnParameter = genericParameter == generic.getReturnType();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1439 if (!genericParameter.getSpecification().isSignature()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1440 polymorphicType = genericParameter.getType();
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1441 } else {
20960
6fe8d8a248ba Truffle-DSL: fix generic types are not unique in javac.
Christian Humer <christian.humer@gmail.com>
parents: 20952
diff changeset
1442 Collection<TypeMirror> usedTypes = new HashSet<>();
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1443 for (SpecializationData specialization : node.getSpecializations()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1444 if (specialization.isUninitialized()) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1445 continue;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1446 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1447 Parameter parameter = specialization.findParameter(genericParameter.getLocalName());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1448 if (parameter == specialization.getReturnType() && specialization.isFallback() && specialization.getMethod() == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1449 continue;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1450 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1451 if (parameter == null) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1452 throw new AssertionError("Parameter existed in generic specialization but not in specialized. param = " + genericParameter.getLocalName());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1453 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1454 usedTypes.add(parameter.getType());
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1455 }
20998
8e5f9310f3aa Truffle-DSL: fixed wrong order for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 20984
diff changeset
1456 usedTypes = ElementUtils.uniqueSortedTypes(usedTypes, false);
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1457
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1458 if (usedTypes.size() == 1) {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1459 polymorphicType = usedTypes.iterator().next();
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1460 } else {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1461 polymorphicType = ElementUtils.getCommonSuperType(context, usedTypes);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1462 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1463
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1464 NodeExecutionData execution = genericParameter.getSpecification().getExecution();
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1465 if (execution != null && !ElementUtils.isSubtypeBoxed(context, polymorphicType, node.getGenericType(execution))) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1466 throw new AssertionError(String.format("Polymorphic types %s not compatible to generic type %s.", polymorphicType, node.getGenericType(execution)));
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1467 }
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1468
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1469 }
20950
a778fbcb8d8e Truffle-DSL: fix polymorphic return type was always object if type had implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 20942
diff changeset
1470 if (isReturnParameter) {
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1471 returnType = polymorphicType;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1472 } else {
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1473 types.add(new CodeVariableElement(polymorphicType, "param" + index));
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1474 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1475 index++;
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1476 }
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1477
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1478 SpecializationMethodParser parser = new SpecializationMethodParser(context, node);
20984
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1479 SpecializationData polymorphic = parser.create("Polymorphic", TemplateMethod.NO_NATURAL_ORDER, null, null, returnType, types);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1480 if (polymorphic == null) {
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1481 throw new AssertionError("Failed to parse polymorphic signature. " + parser.createDefaultMethodSpec(null, null, false, null) + " Types: " + returnType + " - " + types);
6361fa2e3321 Truffle-DSL: further fixes for polymorphic execute signatures.
Christian Humer <christian.humer@oracle.com>
parents: 20966
diff changeset
1482 }
20940
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1483
476374f3fe9a Truffle-DSL: generate better polymorphic execute signatures
Christian Humer <christian.humer@gmail.com>
parents: 20938
diff changeset
1484 polymorphic.setKind(SpecializationKind.POLYMORPHIC);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1485 node.getSpecializations().add(polymorphic);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1486 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1487
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1488 private void initializeShortCircuits(NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1489 Map<String, List<ShortCircuitData>> groupedShortCircuits = groupShortCircuits(node.getShortCircuits());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1490
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1491 boolean valid = true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1492 List<NodeExecutionData> shortCircuitExecutions = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1493 for (NodeExecutionData execution : node.getChildExecutions()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1494 if (!execution.isShortCircuit()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1495 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1496 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1497 shortCircuitExecutions.add(execution);
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1498 String valueName = execution.getIndexedName();
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1499 List<ShortCircuitData> availableCircuits = groupedShortCircuits.get(valueName);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1500
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1501 if (availableCircuits == null || availableCircuits.isEmpty()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1502 node.addError("@%s method for short cut value '%s' required.", ShortCircuit.class.getSimpleName(), valueName);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1503 valid = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1504 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1505 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1506
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1507 boolean sameMethodName = true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1508 String methodName = availableCircuits.get(0).getMethodName();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1509 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1510 if (!circuit.getMethodName().equals(methodName)) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1511 sameMethodName = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1512 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1513 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1514
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1515 if (!sameMethodName) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1516 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1517 circuit.addError("All short circuits for short cut value '%s' must have the same method name.", valueName);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1518 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1519 valid = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1520 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1521 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1522
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1523 ShortCircuitData genericCircuit = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1524 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1525 if (isGenericShortCutMethod(circuit)) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1526 genericCircuit = circuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1527 break;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1528 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1529 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1530
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1531 if (genericCircuit == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1532 node.addError("No generic @%s method available for short cut value '%s'.", ShortCircuit.class.getSimpleName(), valueName);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1533 valid = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1534 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1535 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1536
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1537 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1538 if (circuit != genericCircuit) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1539 circuit.setGenericShortCircuitMethod(genericCircuit);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1540 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1541 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1542 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1543
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1544 if (!valid) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1545 return;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1546 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1547
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1548 List<SpecializationData> specializations = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1549 specializations.addAll(node.getSpecializations());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1550 for (SpecializationData specialization : specializations) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1551 List<ShortCircuitData> assignedShortCuts = new ArrayList<>(shortCircuitExecutions.size());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1552
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1553 for (NodeExecutionData shortCircuit : shortCircuitExecutions) {
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
1554 List<ShortCircuitData> availableShortCuts = groupedShortCircuits.get(shortCircuit.getIndexedName());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1555
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1556 ShortCircuitData genericShortCircuit = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1557 ShortCircuitData compatibleShortCircuit = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1558 for (ShortCircuitData circuit : availableShortCuts) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1559 if (circuit.isGeneric()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1560 genericShortCircuit = circuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1561 } else if (circuit.isCompatibleTo(specialization)) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1562 compatibleShortCircuit = circuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1563 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1564 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1565
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1566 if (compatibleShortCircuit == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1567 compatibleShortCircuit = genericShortCircuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1568 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1569 assignedShortCuts.add(compatibleShortCircuit);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1570 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1571 specialization.setShortCircuits(assignedShortCuts);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1572 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1573 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1574
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1575 private boolean isGenericShortCutMethod(ShortCircuitData method) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1576 for (Parameter parameter : method.getParameters()) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1577 NodeExecutionData execution = parameter.getSpecification().getExecution();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1578 if (execution == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1579 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1580 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1581 ExecutableTypeData found = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1582 List<ExecutableTypeData> executableElements = execution.getChild().findGenericExecutableTypes(context);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1583 for (ExecutableTypeData executable : executableElements) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1584 if (ElementUtils.typeEquals(executable.getReturnType(), parameter.getType())) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1585 found = executable;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1586 break;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1587 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1588 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1589 if (found == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1590 return false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1591 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1592 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1593 return true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1594 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1595
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1596 private static Map<String, List<ShortCircuitData>> groupShortCircuits(List<ShortCircuitData> shortCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1597 Map<String, List<ShortCircuitData>> group = new HashMap<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1598 for (ShortCircuitData shortCircuit : shortCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1599 List<ShortCircuitData> circuits = group.get(shortCircuit.getValueName());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1600 if (circuits == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1601 circuits = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1602 group.put(shortCircuit.getValueName(), circuits);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1603 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1604 circuits.add(shortCircuit);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1605 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1606 return group;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1607 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1608
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1609 private static boolean verifySpecializationSameLength(NodeData nodeData) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1610 int lastArgs = -1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1611 for (SpecializationData specializationData : nodeData.getSpecializations()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1612 int signatureArgs = specializationData.getSignatureSize();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1613 if (lastArgs == signatureArgs) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1614 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1615 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1616 if (lastArgs != -1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1617 for (SpecializationData specialization : nodeData.getSpecializations()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1618 specialization.addError("All specializations must have the same number of arguments.");
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1619 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1620 return false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1621 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1622 lastArgs = signatureArgs;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1623 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1624 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1625 return true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1626 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1627
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1628 private static void verifyVisibilities(NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1629 if (node.getTemplateType().getModifiers().contains(Modifier.PRIVATE) && node.getSpecializations().size() > 0) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1630 node.addError("Classes containing a @%s annotation must not be private.", Specialization.class.getSimpleName());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1631 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1632 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1633
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1634 /**
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1635 * @see "https://bugs.openjdk.java.net/browse/JDK-8039214"
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1636 */
22327
4a43dc00a654 added workaround based on JDK-8075793 to allow compilation with JDK9 javac (2nd attempt)
Doug Simon <doug.simon@oracle.com>
parents: 22326
diff changeset
1637 @SuppressWarnings("unused")
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1638 private static List<Element> newElementList(List<? extends Element> src) {
22327
4a43dc00a654 added workaround based on JDK-8075793 to allow compilation with JDK9 javac (2nd attempt)
Doug Simon <doug.simon@oracle.com>
parents: 22326
diff changeset
1639 List<Element> workaround = new ArrayList<Element>(src);
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1640 return workaround;
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1641 }
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1642
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1643 private static void verifyMissingAbstractMethods(NodeData nodeData, List<? extends Element> originalElements) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1644 if (!nodeData.needsFactory()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1645 // missing abstract methods only needs to be implemented
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1646 // if we need go generate factory for it.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1647 return;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1648 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1649
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
1650 List<Element> elements = newElementList(originalElements);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1651 Set<Element> unusedElements = new HashSet<>(elements);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1652 for (ExecutableElement method : nodeData.getAllTemplateMethods()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 20130
diff changeset
1653 unusedElements.remove(method);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1654 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1655
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1656 for (NodeFieldData field : nodeData.getFields()) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1657 if (field.getGetter() != null) {
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1658 unusedElements.remove(field.getGetter());
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1659 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1660 }
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1661
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1662 for (NodeChildData child : nodeData.getChildren()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1663 if (child.getAccessElement() != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1664 unusedElements.remove(child.getAccessElement());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1665 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1666 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1667
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1668 for (ExecutableElement unusedMethod : ElementFilter.methodsIn(unusedElements)) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1669 if (unusedMethod.getModifiers().contains(Modifier.ABSTRACT)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1670 nodeData.addError("The type %s must implement the inherited abstract method %s.", ElementUtils.getSimpleName(nodeData.getTemplateType()),
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1671 ElementUtils.getReadableSignature(unusedMethod));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1672 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1673 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1674 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1675
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1676 private static void verifyNamingConvention(List<? extends TemplateMethod> methods, String prefix) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1677 for (int i = 0; i < methods.size(); i++) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1678 TemplateMethod m1 = methods.get(i);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1679 if (m1.getMethodName().length() < 3 || !m1.getMethodName().startsWith(prefix)) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1680 m1.addError("Naming convention: method name must start with '%s'.", prefix);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1681 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1682 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1683 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1684
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1685 private static void verifySpecializationThrows(NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1686 Map<String, SpecializationData> specializationMap = new HashMap<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1687 for (SpecializationData spec : node.getSpecializations()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1688 specializationMap.put(spec.getMethodName(), spec);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1689 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1690 for (SpecializationData sourceSpecialization : node.getSpecializations()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1691 if (sourceSpecialization.getExceptions() != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1692 for (SpecializationThrowsData throwsData : sourceSpecialization.getExceptions()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1693 for (SpecializationThrowsData otherThrowsData : sourceSpecialization.getExceptions()) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1694 if (otherThrowsData != throwsData && ElementUtils.typeEquals(otherThrowsData.getJavaClass(), throwsData.getJavaClass())) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1695 throwsData.addError("Duplicate exception type.");
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1696 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1697 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1698 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1699 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1700 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1701 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1702
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1703 private static void verifyConstructors(NodeData nodeData) {
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1704 List<ExecutableElement> constructors = ElementFilter.constructorsIn(nodeData.getTemplateType().getEnclosedElements());
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1705 if (constructors.isEmpty()) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1706 return;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1707 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1708
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1709 boolean oneNonPrivate = false;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1710 for (ExecutableElement constructor : constructors) {
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1711 if (ElementUtils.getVisibility(constructor.getModifiers()) != Modifier.PRIVATE) {
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1712 oneNonPrivate = true;
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1713 break;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1714 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1715 }
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1716 if (!oneNonPrivate && !nodeData.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) {
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1717 nodeData.addError("At least one constructor must be non-private.");
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1718 }
11742
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11545
diff changeset
1719 }
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11545
diff changeset
1720
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1721 private AnnotationMirror findFirstAnnotation(List<? extends Element> elements, Class<? extends Annotation> annotation) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1722 for (Element element : elements) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1723 AnnotationMirror mirror = ElementUtils.findAnnotationMirror(processingEnv, element, annotation);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1724 if (mirror != null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1725 return mirror;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1726 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1727 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1728 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1729 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1730
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1731 private TypeMirror inheritType(AnnotationMirror annotation, String valueName, TypeMirror parentType) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1732 TypeMirror inhertNodeType = context.getTruffleTypes().getNode();
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1733 TypeMirror value = ElementUtils.getAnnotationValue(TypeMirror.class, annotation, valueName);
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1734 if (ElementUtils.typeEquals(inhertNodeType, value)) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1735 return parentType;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1736 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1737 return value;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1738 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1739 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1740
11187
7a8835ec5e7d Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents: 11183
diff changeset
1741 private ExecutableElement findGetter(List<? extends Element> elements, String variableName, TypeMirror type) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1742 if (type == null) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1743 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1744 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1745 String methodName;
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1746 if (ElementUtils.typeEquals(type, context.getType(boolean.class))) {
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1747 methodName = "is" + ElementUtils.firstLetterUpperCase(variableName);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1748 } else {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1749 methodName = "get" + ElementUtils.firstLetterUpperCase(variableName);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1750 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1751
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1752 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1753 if (method.getSimpleName().toString().equals(methodName) && method.getParameters().size() == 0 && ElementUtils.isAssignable(type, method.getReturnType())) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1754 return method;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1755 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1756 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1757 return null;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1758 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1759
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1760 private static List<TypeElement> collectSuperClasses(List<TypeElement> collection, TypeElement element) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1761 if (element != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1762 collection.add(element);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1763 if (element.getSuperclass() != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1764 collectSuperClasses(collection, ElementUtils.fromTypeMirror(element.getSuperclass()));
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1765 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1766 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1767 return collection;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1768 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1769
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1770 }