Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java @ 20938:18c0f02fa4d2
Truffle-DSL: make type systems optional.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 15:12:48 +0200 |
parents | 8dc73c226c63 |
children | 476374f3fe9a |
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 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.lang.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
|
26 import java.util.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import javax.lang.model.element.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import javax.lang.model.type.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import javax.lang.model.util.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import javax.tools.Diagnostic.Kind; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
33 import com.oracle.truffle.api.*; |
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
|
34 import com.oracle.truffle.api.dsl.*; |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
35 import com.oracle.truffle.api.dsl.internal.*; |
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
|
36 import com.oracle.truffle.api.nodes.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 import com.oracle.truffle.dsl.processor.*; |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
38 import com.oracle.truffle.dsl.processor.expression.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
39 import com.oracle.truffle.dsl.processor.java.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
40 import com.oracle.truffle.dsl.processor.java.compiler.*; |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
41 import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror; |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
42 import com.oracle.truffle.dsl.processor.java.model.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
43 import com.oracle.truffle.dsl.processor.model.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
44 import com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
45 import com.oracle.truffle.dsl.processor.model.SpecializationData.SpecializationKind; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
46 import com.oracle.truffle.dsl.processor.model.TemplateMethod.TypeSignature; |
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
|
47 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
48 @DSLOptions |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
49 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
|
50 |
16760
9f38d222fa6c
Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
51 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
|
52 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
|
53 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 @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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 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
|
62 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 @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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 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
|
73 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
|
74 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 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
|
76 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 @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
|
79 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
|
80 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
|
81 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 @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
|
84 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
|
85 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
|
86 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 @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
|
89 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
|
90 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
|
91 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 |
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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 if (enclosedChild != null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
98 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
|
99 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 } |
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
|
101 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
|
102 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
|
103 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
|
104 } 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
|
105 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
|
106 } catch (Throwable 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
|
107 e.addSuppressed(new RuntimeException(String.format("Parsing of Node %s failed.", ElementUtils.getQualifiedName(rootType)), e)); |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
108 throw e; |
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
|
109 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
110 if (node == null && !enclosedNodes.isEmpty()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
111 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
|
112 } |
79041ab43660
Truffle-DSL: 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 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
114 if (node != null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
115 for (NodeData enclosedNode : enclosedNodes) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
116 node.addEnclosedNode(enclosedNode); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
117 } |
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 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
119 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
|
120 } |
79041ab43660
Truffle-DSL: 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 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
|
123 // 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
|
124 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
|
125 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
126 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
|
127 // 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
|
128 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
|
129 } |
79041ab43660
Truffle-DSL: 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 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
131 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
|
132 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
|
133 } |
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
|
134 |
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
|
135 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
|
136 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
|
137 // 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
|
138 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
|
139 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
|
140 } |
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
|
141 |
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
|
142 NodeData node = parseNodeData(templateType, lookupTypes); |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
143 if (node.hasErrors()) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
144 return node; |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
145 } |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
146 |
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 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
|
148 node.getChildren().addAll(parseChildren(lookupTypes, members)); |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
149 node.getChildExecutions().addAll(parseExecutions(node.getFields(), node.getChildren(), members)); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
150 node.setExecutableTypes(groupExecutableTypes(parseExecutableTypeData(members, node.getChildExecutions().size(), context.getFrameTypes()))); |
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
|
151 |
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
|
152 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
|
153 initializeImportGuards(node, lookupTypes, members); |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
154 |
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
|
155 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
|
156 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
|
157 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
159 initializeChildren(node); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
160 |
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
|
161 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
|
162 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
|
163 } |
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
|
164 |
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
|
165 node.getSpecializations().addAll(new SpecializationMethodParser(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
|
166 node.getSpecializations().addAll(new GenericParser(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
|
167 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
|
168 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
|
169 |
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
|
170 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
|
171 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
|
172 } |
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
|
173 |
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
|
174 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
|
175 initializeSpecializations(members, 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
|
176 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
|
177 |
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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 } |
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
|
185 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
186 private List<Element> loadMembers(TypeElement templateType) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
187 List<Element> members = new ArrayList<>(CompilerFactory.getCompiler(templateType).getAllMembersInDeclarationOrder(context.getEnvironment(), templateType)); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
188 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
189 return 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
|
190 } |
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 |
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 private boolean containsSpecializations(List<Element> elements) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
193 boolean foundSpecialization = false; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
194 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
195 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
|
196 foundSpecialization = true; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
197 break; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
198 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
199 } |
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
|
200 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
|
201 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
202 |
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 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
|
204 for (TypeElement lookupType : lookupTypes) { |
19285
259a416388d7
Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
205 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
|
206 if (importAnnotation == null) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
207 continue; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
208 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
209 AnnotationValue importClassesValue = ElementUtils.getAnnotationValue(importAnnotation, "value"); |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
210 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
|
211 if (importClasses.isEmpty()) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
212 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
|
213 continue; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
214 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
215 for (TypeMirror importGuardClass : importClasses) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
216 if (importGuardClass.getKind() != TypeKind.DECLARED) { |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
217 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
|
218 continue; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
219 } |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
220 |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
221 TypeElement typeElement = ElementUtils.fromTypeMirror(importGuardClass); |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16834
diff
changeset
|
222 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
|
223 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
|
224 continue; |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
225 } |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
226 elements.addAll(importPublicStaticMembers(typeElement, false)); |
16832
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
227 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
228 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
229 } |
13cf9b6b325c
Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents:
16830
diff
changeset
|
230 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
231 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
|
232 // 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
|
233 // 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
|
234 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
|
235 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
236 List<Element> members = 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
|
237 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
|
238 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
|
239 continue; |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
240 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
241 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
242 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
|
243 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
|
244 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
245 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
246 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
|
247 continue; |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
248 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
249 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
254 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
255 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
|
256 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
257 |
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
|
258 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
|
259 AnnotationMirror typeSystemMirror = findFirstAnnotation(typeHierarchy, TypeSystemReference.class); |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
260 TypeSystemData typeSystem = null; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
261 if (typeSystemMirror != null) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
262 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
|
263 typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, true); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
264 if (typeSystem == null) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
265 NodeData nodeData = new NodeData(context, templateType); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
266 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
|
267 return nodeData; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
268 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
269 } else { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
270 // default dummy type system |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
271 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
|
272 } |
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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 } |
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
|
278 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
|
279 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
|
280 |
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
|
281 } |
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
|
282 |
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
|
283 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
|
284 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
|
285 |
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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
296 } |
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
|
297 |
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
|
298 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
|
299 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
|
300 for (TypeElement typeElement : reversedTypeHierarchy) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
301 AnnotationMirror nodeChildrenMirror = ElementUtils.findAnnotationMirror(processingEnv, typeElement, NodeFields.class); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
302 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
|
303 |
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
|
304 for (AnnotationMirror mirror : children) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
305 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
|
306 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
|
307 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
308 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
|
309 if (name.isEmpty()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
310 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
|
311 } else if (names.contains(name)) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
312 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
|
313 } |
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
|
314 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
|
315 |
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
|
316 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
|
317 } |
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
|
318 } |
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
|
319 |
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
|
320 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
|
321 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
|
322 } |
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
|
323 |
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
|
324 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
|
325 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
326 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
327 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
|
328 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
|
329 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
330 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
|
331 if (mirror != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
332 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
|
333 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
334 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
335 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
|
336 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
337 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
|
338 if (mirror != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
344 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
345 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
346 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
347 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 for (TypeElement type : typeHierarchyReversed) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
352 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
|
353 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
354 TypeMirror nodeClassType = type.getSuperclass(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
355 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
|
356 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
|
357 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
358 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
359 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
|
360 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
|
361 for (AnnotationMirror childMirror : children) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
366 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
367 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
|
368 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
373 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 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
|
378 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
379 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
380 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
|
381 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
|
382 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
383 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
|
384 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
385 if (nodeChild.getNodeType() == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
386 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
|
387 } |
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
|
388 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
|
389 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
|
390 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
391 |
11183
0f5ff66a949d
Truffle-DSL: Fixed a bug with anonymous children (GRAAL-321 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11180
diff
changeset
|
392 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
|
393 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
394 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
395 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
404 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
405 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
406 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
|
407 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
408 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
409 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
|
410 // pre-parse short circuits |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
411 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
|
412 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
|
413 for (ExecutableElement method : methods) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
414 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
|
415 if (mirror != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
416 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
|
417 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
418 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
419 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
420 boolean hasVarArgs = false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
421 int maxSignatureSize = 0; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
422 if (!children.isEmpty()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
423 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
|
424 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
|
425 if (hasVarArgs) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
426 maxSignatureSize = lastIndex; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
427 } else { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
428 maxSignatureSize = children.size(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
429 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
430 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
431 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
432 List<NodeFieldData> nonGetterFields = new ArrayList<>(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
433 for (NodeFieldData field : fields) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
434 if (field.getGetter() == null && field.isGenerated()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
435 nonGetterFields.add(field); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
436 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
437 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
438 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
439 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
|
440 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
|
441 // 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
|
442 for (ExecutableElement method : methods) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
443 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
|
444 if (mirror == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
445 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
446 } |
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
|
447 int currentArgumentIndex = 0; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
448 boolean skipShortCircuit = false; |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
449 parameter: for (VariableElement var : method.getParameters()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
450 if (skipShortCircuit) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
451 skipShortCircuit = false; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
452 continue parameter; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
453 } |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
454 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
455 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
|
456 if (currentArgumentIndex == 0) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
457 // 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
|
458 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
|
459 if (ElementUtils.typeEquals(type, frameType)) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
460 continue parameter; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
461 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
462 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
463 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
464 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
465 if (currentArgumentIndex < nonGetterFields.size()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
466 for (NodeFieldData field : nonGetterFields) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
467 if (ElementUtils.typeEquals(var.asType(), field.getType())) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
468 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
|
469 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
470 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
471 } |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
472 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
473 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
|
474 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
|
475 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
476 |
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
|
477 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
|
478 if (childIndex != -1) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
479 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
|
480 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
|
481 skipShortCircuit = true; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
482 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
483 } |
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
|
484 |
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
|
485 currentArgumentIndex++; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
486 } |
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
|
487 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
|
488 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
489 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
490 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
|
491 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
|
492 boolean varArgParameter = false; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
493 int childIndex = i; |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
494 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
|
495 if (hasVarArgs) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
496 varArgParameter = hasVarArgs; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
497 childIndex = Math.min(i, children.size() - 1); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
498 } else if (i >= children.size()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
499 childIndex = -1; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
500 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
501 } |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
502 int varArgsIndex = -1; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
503 boolean shortCircuit = false; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
504 NodeChildData child = null; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
505 if (childIndex != -1) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
506 varArgsIndex = varArgParameter ? Math.abs(childIndex - i) : -1; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
507 child = children.get(childIndex); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
508 shortCircuit = shortCircuits.contains(NodeExecutionData.createIndexedName(child, varArgsIndex)); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
509 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
510 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
|
511 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
512 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
|
513 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
514 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
515 private List<ExecutableTypeData> parseExecutableTypeData(List<? extends Element> elements, int signatureSize, List<TypeMirror> frameTypes) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
516 List<ExecutableTypeData> typeData = new ArrayList<>(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
517 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
518 Set<Modifier> modifiers = method.getModifiers(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
519 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
|
520 continue; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
521 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
522 if (!method.getSimpleName().toString().startsWith("execute")) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
523 continue; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
524 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
525 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
|
526 continue; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
527 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
528 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
529 ExecutableTypeData executableType = new ExecutableTypeData(method, signatureSize, context.getFrameTypes()); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
530 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
531 if (executableType.getFrameParameter() != null) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
532 boolean supportedType = false; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
533 for (TypeMirror type : frameTypes) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
534 if (ElementUtils.isAssignable(type, executableType.getFrameParameter())) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
535 supportedType = true; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
536 break; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
537 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
538 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
539 if (!supportedType) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
540 continue; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
541 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
542 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
543 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
544 typeData.add(executableType); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
545 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
546 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
547 Collections.sort(typeData); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
548 return typeData; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
549 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
550 |
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
|
551 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
|
552 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
|
553 |
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
|
554 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
|
555 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
|
556 Set<Integer> evaluatedCounts = 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
|
557 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
|
558 evaluatedCounts.add(execute.getEvaluatedCount()); |
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
|
559 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
560 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
|
561 TypeMirror resolvedFrameType; |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
562 if (frame != null) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
563 resolvedFrameType = frame; |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
564 if (frameType == null) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
565 frameType = resolvedFrameType; |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
566 } 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
|
567 // 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
|
568 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
|
569 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
|
570 } |
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
|
571 } |
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
|
572 } |
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
|
573 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
|
574 // 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
|
575 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
|
576 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
|
577 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
|
578 } |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
579 if (frameType == null) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
580 frameType = context.getType(void.class); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
581 } |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
582 |
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
|
583 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
|
584 |
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
|
585 int totalGenericCount = 0; |
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
|
586 int totalVoidCount = 0; |
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
|
587 for (Integer evaluatedCount : evaluatedCounts) { |
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
|
588 List<ExecutableTypeData> genericExecutes = node.findGenericExecutableTypes(context, evaluatedCount); |
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
|
589 int genericCount = 0; |
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
|
590 int voidCount = 0; |
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
|
591 for (ExecutableTypeData executableTypeData : genericExecutes) { |
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
|
592 if (!executableTypeData.getMethod().getModifiers().contains(Modifier.FINAL)) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
593 if (ElementUtils.isVoid(executableTypeData.getReturnType())) { |
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
|
594 voidCount++; |
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
|
595 } else { |
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
|
596 genericCount++; |
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
|
597 } |
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
|
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 } |
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
|
600 // multiple generic execute |
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
|
601 if (evaluatedCount == 0) { |
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
|
602 if (voidCount > 1) { |
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
|
603 List<String> methodSignatures = new ArrayList<>(); |
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
|
604 for (ExecutableTypeData type : genericExecutes) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
605 if (context.isType(type.getReturnType(), void.class)) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
606 methodSignatures.add(ElementUtils.createReferenceName(type.getMethod())); |
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
|
607 } |
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
|
608 } |
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
|
609 node.addWarning("Multiple accessible and overridable generic execute methods found %s. Remove all but one or mark all but one as final.", methodSignatures); |
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
|
610 } else if (genericCount > 1) { |
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
|
611 List<String> methodSignatures = new ArrayList<>(); |
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
|
612 for (ExecutableTypeData type : genericExecutes) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
613 if (!context.isType(type.getReturnType(), void.class)) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
614 methodSignatures.add(ElementUtils.createReferenceName(type.getMethod())); |
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
|
615 } |
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
|
616 } |
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
|
617 node.addWarning("Multiple accessible and overridable generic execute methods found %s. Remove all but one or mark all but one as final.", methodSignatures); |
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
|
618 } |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
619 } |
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
|
620 totalGenericCount += genericCount; |
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
|
621 totalVoidCount += voidCount; |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
622 } |
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
623 |
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
|
624 // no generic executes |
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
|
625 if (totalGenericCount + totalVoidCount == 0) { |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
626 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
|
627 + "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
|
628 } |
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
629 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
630 int nodeChildDeclarations = 0; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
631 int nodeChildDeclarationsRequired = 0; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
632 List<NodeExecutionData> executions = node.getChildExecutions(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
633 for (NodeExecutionData execution : executions) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
634 if (execution.getChild() == null) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
635 nodeChildDeclarationsRequired = execution.getIndex() + 1; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
636 } else { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
637 nodeChildDeclarations++; |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
638 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
639 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
640 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
641 List<String> requireNodeChildDeclarations = new ArrayList<>(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
642 for (ExecutableTypeData type : allExecutes) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
643 if (type.getEvaluatedCount() < nodeChildDeclarationsRequired) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
644 requireNodeChildDeclarations.add(ElementUtils.createReferenceName(type.getMethod())); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
645 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
646 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
647 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
648 if (!requireNodeChildDeclarations.isEmpty()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
649 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
|
650 + "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
|
651 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
652 |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
653 if (nodeChildDeclarations > 0 && executions.size() == node.getMinimalEvaluatedParameters()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
654 for (NodeChildData child : node.getChildren()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
655 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
|
656 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
657 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
658 |
18775
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
659 } |
a069a87b9a02
Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
18773
diff
changeset
|
660 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
661 private static Map<Integer, List<ExecutableTypeData>> groupExecutableTypes(List<ExecutableTypeData> executableTypes) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
662 Map<Integer, List<ExecutableTypeData>> groupedTypes = new TreeMap<>(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
663 for (ExecutableTypeData type : executableTypes) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
664 int evaluatedCount = type.getEvaluatedCount(); |
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 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
666 List<ExecutableTypeData> types = groupedTypes.get(evaluatedCount); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
667 if (types == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
668 types = new ArrayList<>(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
669 groupedTypes.put(evaluatedCount, types); |
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
|
670 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
671 types.add(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
|
672 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
673 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
674 for (List<ExecutableTypeData> types : groupedTypes.values()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
675 Collections.sort(types); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
676 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
677 return groupedTypes; |
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
|
678 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
679 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
680 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
|
681 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
|
682 |
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
|
683 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
|
684 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
|
685 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
|
686 |
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
|
687 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
|
688 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
|
689 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
|
690 } 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
697 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
698 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
699 } |
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
|
700 |
19292
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 continue; |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
710 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
711 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 continue; |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
717 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
718 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
|
719 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
|
720 break; |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
721 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
722 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
723 |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
724 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
|
725 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
|
726 continue; |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
727 } 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
|
728 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
|
729 executeWithString); |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
730 continue; |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
731 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
732 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
|
733 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
734 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
|
735 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
736 } |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
737 |
906367e494ca
Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents:
19291
diff
changeset
|
738 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
|
739 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
|
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 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
|
742 // 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
|
743 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
|
744 } |
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 |
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 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
|
747 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
|
748 } |
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
|
749 |
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
|
750 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
|
751 |
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 // 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
|
753 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
|
754 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
|
755 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
|
756 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
|
757 } |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
758 List<TypeMirror> frameTypes = Collections.emptyList(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
759 if (parentNode.getFrameType() != null) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
760 frameTypes = Arrays.asList(parentNode.getFrameType()); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
761 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
762 node.setExecutableTypes(groupExecutableTypes(parseExecutableTypeData(members, child.getExecuteWith().size(), frameTypes))); |
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
|
763 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
|
764 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
|
765 } |
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
|
766 |
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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 } |
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
|
773 } |
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
|
774 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
|
775 } |
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
|
776 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
777 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
|
778 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
|
779 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
|
780 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
781 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
782 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
|
783 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
784 if (node.hasErrors()) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
785 return; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
786 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
787 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
788 initializeGeneric(node); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
789 initializeUninitialized(node); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
790 initializeOrder(node); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
791 initializePolymorphism(node); // requires specializations |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
792 initializeReachability(node); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
793 initializeContains(node); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
794 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
|
795 |
19282
ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents:
18811
diff
changeset
|
796 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
|
797 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
|
798 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
|
799 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
|
800 contained.getExcludedBy().add(cur); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
801 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
802 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
803 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
804 |
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
|
805 initializeSpecializationIdsWithMethodNames(node.getSpecializations()); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
806 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
807 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
808 private static void initializeOrder(NodeData node) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
809 List<SpecializationData> specializations = node.getSpecializations(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
810 Collections.sort(specializations); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
811 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
812 for (SpecializationData specialization : specializations) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
813 String searchName = specialization.getInsertBeforeName(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
814 if (searchName == null || specialization.getMethod() == null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
815 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
816 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
817 SpecializationData found = lookupSpecialization(node, searchName); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
818 if (found == null || found.getMethod() == null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
819 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
|
820 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
|
821 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
822 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
823 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
824 ExecutableElement currentMethod = specialization.getMethod(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
825 ExecutableElement insertBeforeMethod = found.getMethod(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
826 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
827 TypeMirror currentEnclosedType = currentMethod.getEnclosingElement().asType(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
828 TypeMirror insertBeforeEnclosedType = insertBeforeMethod.getEnclosingElement().asType(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
829 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
830 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
|
831 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
|
832 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
|
833 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
834 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
835 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
836 specialization.setInsertBefore(found); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
837 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
838 |
16764
f9fff060dc41
Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents:
16760
diff
changeset
|
839 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
|
840 SpecializationData specialization = specializations.get(i); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
841 SpecializationData insertBefore = specialization.getInsertBefore(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
842 if (insertBefore != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
843 int insertIndex = specializations.indexOf(insertBefore); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
844 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
|
845 specializations.remove(i); |
f9fff060dc41
Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents:
16760
diff
changeset
|
846 specializations.add(insertIndex, specialization); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
847 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
848 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
849 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
850 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
851 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
|
852 specializations.get(i).setIndex(i); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
853 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
854 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
855 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
856 private static void initializeContains(NodeData node) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
857 for (SpecializationData specialization : node.getSpecializations()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
858 Set<SpecializationData> resolvedSpecializations = specialization.getContains(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
859 resolvedSpecializations.clear(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
860 Set<String> includeNames = specialization.getContainsNames(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
861 for (String includeName : includeNames) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
862 // TODO reduce complexity of this lookup. |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
863 SpecializationData foundSpecialization = lookupSpecialization(node, includeName); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
864 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
865 if (foundSpecialization == null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
866 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
|
867 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
|
868 } 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
|
869 if (foundSpecialization.compareTo(specialization) > 0) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
870 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
|
871 if (foundSpecialization.compareTo(specialization) > 0) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
872 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
|
873 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
874 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
875 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
876 resolvedSpecializations.add(foundSpecialization); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
877 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
878 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
879 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
880 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
881 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
882 private void resolveContains(NodeData node) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
883 // flatten transitive includes |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
884 for (SpecializationData specialization : node.getSpecializations()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
885 if (specialization.getContains().isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
886 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
|
887 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
888 Set<SpecializationData> foundSpecializations = new HashSet<>(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
889 collectIncludes(specialization, foundSpecializations, new HashSet<SpecializationData>()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
890 specialization.getContains().addAll(foundSpecializations); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
891 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
892 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
893 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
894 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
|
895 SpecializationData foundSpecialization = null; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
896 for (SpecializationData searchSpecialization : node.getSpecializations()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
897 if (searchSpecialization.getMethodName().equals(includeName)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
898 foundSpecialization = searchSpecialization; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
899 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
|
900 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
901 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
902 return foundSpecialization; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
903 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
904 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
905 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
|
906 if (visited.contains(specialization)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
907 // circle found |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
908 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
|
909 return; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
910 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
911 visited.add(specialization); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
912 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
913 for (SpecializationData included : specialization.getContains()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
914 collectIncludes(included, found, new HashSet<>(visited)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
915 found.add(included); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
916 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
917 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
918 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
919 private static void initializeReachability(final NodeData node) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
920 List<SpecializationData> specializations = node.getSpecializations(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
921 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
|
922 SpecializationData current = specializations.get(i); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
923 if (current.isPolymorphic()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
924 current.setReachable(true); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
925 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
926 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
927 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
928 List<SpecializationData> shadowedBy = null; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
929 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
|
930 SpecializationData prev = specializations.get(j); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
931 if (prev.isPolymorphic()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
932 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
933 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
934 if (!current.isReachableAfter(prev)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
935 if (shadowedBy == null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
936 shadowedBy = new ArrayList<>(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
937 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
938 shadowedBy.add(prev); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
939 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
940 } |
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 if (shadowedBy != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
943 StringBuilder name = new StringBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
944 String sep = ""; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
945 for (SpecializationData shadowSpecialization : shadowedBy) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
946 name.append(sep); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
947 name.append(shadowSpecialization.createReferenceName()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
948 sep = ", "; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
949 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
950 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
|
951 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
952 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
|
953 } |
10602
b8fe1fe004ec
Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10600
diff
changeset
|
954 } |
b8fe1fe004ec
Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10600
diff
changeset
|
955 |
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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 } 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
|
962 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
|
963 } 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
|
964 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
|
965 } 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
|
966 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
|
967 |
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
|
968 // 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
|
969 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
|
970 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
|
971 } 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
|
972 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
|
973 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
|
974 name = filteredDo; |
7382bbcac3a3
Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents:
18771
diff
changeset
|
975 } |
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
|
976 } |
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
|
977 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
|
978 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
979 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
980 |
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
|
981 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
|
982 // 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
|
983 } |
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
|
984 |
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
|
985 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
|
986 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
|
987 } |
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
|
988 } |
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
|
989 |
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
|
990 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
|
991 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
|
992 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
998 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
|
999 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
|
1000 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1001 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 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
|
1012 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1013 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1014 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1015 } |
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
|
1016 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
|
1017 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1018 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1019 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
|
1020 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
|
1021 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1022 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
|
1023 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
|
1024 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
|
1025 } |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16834
diff
changeset
|
1026 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1027 for (SpecializationData specialization : node.getSpecializations()) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1028 if (specialization.getMethod() == null) { |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16834
diff
changeset
|
1029 continue; |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16834
diff
changeset
|
1030 } |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16834
diff
changeset
|
1031 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1032 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
|
1033 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
|
1034 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
|
1035 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1036 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
|
1037 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
|
1038 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
|
1039 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1040 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
|
1041 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
|
1042 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
|
1043 continue; |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1044 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1045 initializeLimit(specialization, resolver); |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1046 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
|
1047 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1048 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1049 |
19291
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1050 private void initializeAssumptions(SpecializationData specialization, DSLExpressionResolver resolver) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1051 final DeclaredType assumptionType = context.getDeclaredType(Assumption.class); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1052 final TypeMirror assumptionArrayType = new ArrayCodeTypeMirror(assumptionType); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1053 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
|
1054 List<AssumptionExpression> assumptionExpressions = new ArrayList<>(); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1055 int assumptionId = 0; |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1056 for (String assumption : assumptionDefinitions) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1057 AssumptionExpression assumptionExpression; |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1058 DSLExpression expression = null; |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1059 try { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1060 expression = DSLExpression.parse(assumption); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1061 expression.accept(resolver); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1062 assumptionExpression = new AssumptionExpression(specialization, expression, "assumption" + assumptionId); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1063 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
|
1064 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
|
1065 ElementUtils.getSimpleName(assumptionType), ElementUtils.getSimpleName(assumptionArrayType)); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1066 } |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1067 if (specialization.isDynamicParameterBound(expression)) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1068 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
|
1069 } |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1070 } catch (InvalidExpressionException e) { |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1071 assumptionExpression = new AssumptionExpression(specialization, null, "assumption" + assumptionId); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1072 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
|
1073 } |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1074 assumptionExpressions.add(assumptionExpression); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1075 } |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1076 specialization.setAssumptionExpressions(assumptionExpressions); |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1077 } |
f4792a544170
Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents:
19289
diff
changeset
|
1078 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1079 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
|
1080 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
|
1081 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1082 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
|
1083 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
|
1084 limitValue = ""; |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1085 } else { |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1086 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
|
1087 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1088 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
|
1089 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
|
1090 } 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
|
1091 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
|
1092 return; |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1093 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1094 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1095 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
|
1096 try { |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1097 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
|
1098 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
|
1099 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
|
1100 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
|
1101 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
|
1102 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1103 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
|
1104 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
|
1105 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1106 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1107 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
|
1108 } 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
|
1109 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
|
1110 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1111 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1112 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 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
|
1118 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
|
1119 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
|
1120 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1121 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
|
1122 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1123 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
|
1124 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
|
1125 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
|
1126 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1127 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1128 CacheExpression cacheExpression; |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1129 DSLExpression expression = null; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1130 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
|
1131 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
|
1132 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
|
1133 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
|
1134 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
|
1135 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
|
1136 ElementUtils.getSimpleName(parameter.getType())); |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1137 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1138 } 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
|
1139 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
|
1140 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
|
1141 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1142 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
|
1143 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1144 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1145 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
|
1146 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1147 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
|
1148 return; |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1149 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1150 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1151 // 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 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
|
1157 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
|
1158 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
|
1159 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
|
1160 break; |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1161 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1162 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1163 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1164 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1165 |
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 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
|
1167 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
|
1168 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
|
1169 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
|
1170 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
|
1171 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
|
1172 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
|
1173 try { |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1180 } 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
|
1181 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
|
1182 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
|
1183 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1184 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
|
1185 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1186 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
|
1187 } |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1188 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1189 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
|
1190 String packageName = ElementUtils.getPackageName(templateType); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1191 List<Element> filteredElements = new ArrayList<>(elements); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1192 for (Element element : elements) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1193 Modifier visibility = ElementUtils.getVisibility(element.getModifiers()); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1194 if (visibility == Modifier.PRIVATE) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1195 continue; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1196 } else if (visibility == null) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1197 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
|
1198 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
|
1199 continue; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1200 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1201 } |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16834
diff
changeset
|
1202 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1203 filteredElements.add(element); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1204 } |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
1205 return filteredElements; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1206 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1207 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1208 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
|
1209 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
|
1210 for (SpecializationData spec : node.getSpecializations()) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18754
diff
changeset
|
1211 if (spec.isFallback()) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1212 generics.add(spec); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1213 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1214 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1215 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1216 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
|
1217 // 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
|
1218 for (SpecializationData generic : generics) { |
16760
9f38d222fa6c
Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
1219 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
|
1220 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1221 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1222 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1223 if (generics.isEmpty()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1224 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
|
1225 } else { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1226 if (generics.size() > 1) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1227 for (SpecializationData generic : generics) { |
16760
9f38d222fa6c
Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
1228 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
|
1229 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1230 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1231 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1232 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1233 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1234 private SpecializationData createGenericSpecialization(final NodeData node) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1235 GenericParser parser = new GenericParser(context, node); |
13535
e8ef44830b50
Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
1236 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
|
1237 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19285
diff
changeset
|
1238 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
|
1239 int signatureIndex = 1; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1240 for (ParameterSpec spec : specification.getRequired()) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1241 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
|
1242 if (spec.isSignature()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1243 signatureIndex++; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1244 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1245 } |
13535
e8ef44830b50
Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
1246 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1247 TypeMirror returnType = createGenericType(node, specification.getReturnType()); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1248 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
|
1249 if (generic == null) { |
e8ef44830b50
Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
1250 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
|
1251 } |
e8ef44830b50
Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
1252 |
e8ef44830b50
Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
1253 return generic; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1254 } |
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
|
1255 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1256 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
|
1257 NodeExecutionData execution = spec.getExecution(); |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1258 Collection<TypeMirror> allowedTypes; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1259 if (execution == null) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1260 allowedTypes = spec.getAllowedTypes(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1261 } else { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1262 allowedTypes = node.getPossibleTypes(execution); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1263 } |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1264 if (allowedTypes.size() == 1) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1265 return allowedTypes.iterator().next(); |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1266 } else { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1267 return ElementUtils.getCommonSuperType(context, allowedTypes.toArray(new TypeMirror[allowedTypes.size()])); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1268 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1269 } |
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
|
1270 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1271 private 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
|
1272 SpecializationData generic = node.getGenericSpecialization(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1273 if (generic == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1274 return; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1275 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1276 for (Parameter parameter : generic.getReturnTypeAndParameters()) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1277 if (ElementUtils.isObject(parameter.getType())) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1278 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1279 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1280 Set<String> types = new HashSet<>(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1281 for (SpecializationData specialization : node.getSpecializations()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1282 Parameter actualParameter = specialization.findParameter(parameter.getLocalName()); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1283 if (actualParameter != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1284 types.add(ElementUtils.getQualifiedName(actualParameter.getType())); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1285 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1286 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1287 if (types.size() > 1) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1288 generic.replaceParameter(parameter.getLocalName(), new Parameter(parameter, context.getType(Object.class))); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1289 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1290 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1291 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
|
1292 // 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
|
1293 uninializedMethod.getMessages().clear(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1294 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
|
1295 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1296 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1297 private void initializePolymorphism(NodeData node) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1298 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
|
1299 return; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1300 } |
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
|
1301 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1302 SpecializationData generic = node.getGenericSpecialization(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1303 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1304 List<TypeMirror> polymorphicSignature = new ArrayList<>(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1305 List<Parameter> updatePolymorphic = Arrays.asList(); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1306 for (Parameter genericParameter : updatePolymorphic) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1307 if (!genericParameter.getSpecification().isSignature()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1308 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1309 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1310 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1311 Set<TypeMirror> usedTypes = new HashSet<>(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1312 for (SpecializationData specialization : node.getSpecializations()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1313 if (!specialization.isSpecialized()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1314 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1315 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1316 Parameter parameter = specialization.findParameter(genericParameter.getLocalName()); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1317 if (parameter == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1318 throw new AssertionError("Parameter existed in generic specialization but not in specialized. param = " + genericParameter.getLocalName()); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1319 } |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1320 usedTypes.add(parameter.getType()); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1321 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1322 |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1323 TypeMirror polymorphicType; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1324 if (usedTypes.size() == 1) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1325 polymorphicType = usedTypes.iterator().next(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1326 } else { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1327 polymorphicType = context.getType(Object.class); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1328 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1329 polymorphicSignature.add(polymorphicType); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1330 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1331 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1332 SpecializationData polymorphic = new SpecializationData(node, generic, SpecializationKind.POLYMORPHIC); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1333 polymorphic.updateSignature(new TypeSignature(polymorphicSignature)); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1334 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
|
1335 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1336 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1337 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
|
1338 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
|
1339 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1340 boolean valid = true; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1341 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
|
1342 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
|
1343 if (!execution.isShortCircuit()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1344 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1345 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1346 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
|
1347 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
|
1348 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
|
1349 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1350 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
|
1351 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
|
1352 valid = false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1353 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1354 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1355 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1356 boolean sameMethodName = true; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1357 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
|
1358 for (ShortCircuitData circuit : availableCircuits) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1359 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
|
1360 sameMethodName = false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1361 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1362 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1363 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1364 if (!sameMethodName) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1365 for (ShortCircuitData circuit : availableCircuits) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1366 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
|
1367 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1368 valid = false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1369 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1370 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1371 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1372 ShortCircuitData genericCircuit = null; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1373 for (ShortCircuitData circuit : availableCircuits) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1374 if (isGenericShortCutMethod(circuit)) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1375 genericCircuit = circuit; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1376 break; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1377 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1378 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1379 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1380 if (genericCircuit == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1381 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
|
1382 valid = false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1383 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1384 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1385 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1386 for (ShortCircuitData circuit : availableCircuits) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1387 if (circuit != genericCircuit) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1388 circuit.setGenericShortCircuitMethod(genericCircuit); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1389 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1390 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1391 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1392 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1393 if (!valid) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1394 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
|
1395 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1396 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1397 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
|
1398 specializations.addAll(node.getSpecializations()); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1399 for (SpecializationData specialization : specializations) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1400 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
|
1401 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1402 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
|
1403 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
|
1404 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1405 ShortCircuitData genericShortCircuit = null; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1406 ShortCircuitData compatibleShortCircuit = null; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1407 for (ShortCircuitData circuit : availableShortCuts) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1408 if (circuit.isGeneric()) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1409 genericShortCircuit = circuit; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1410 } 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
|
1411 compatibleShortCircuit = circuit; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1412 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1413 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1414 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1415 if (compatibleShortCircuit == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1416 compatibleShortCircuit = genericShortCircuit; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1417 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1418 assignedShortCuts.add(compatibleShortCircuit); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1419 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1420 specialization.setShortCircuits(assignedShortCuts); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1421 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1422 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1423 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1424 private boolean isGenericShortCutMethod(ShortCircuitData method) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1425 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
|
1426 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
|
1427 if (execution == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1428 continue; |
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 ExecutableTypeData found = null; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1431 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
|
1432 for (ExecutableTypeData executable : executableElements) { |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1433 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
|
1434 found = executable; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1435 break; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1436 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1437 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1438 if (found == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1439 return false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1440 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1441 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1442 return true; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1443 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1444 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1445 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
|
1446 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
|
1447 for (ShortCircuitData shortCircuit : shortCircuits) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1448 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
|
1449 if (circuits == null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1450 circuits = new ArrayList<>(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1451 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
|
1452 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1453 circuits.add(shortCircuit); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1454 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1455 return group; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1456 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1457 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1458 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
|
1459 int lastArgs = -1; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1460 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
|
1461 int signatureArgs = specializationData.getSignatureSize(); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1462 if (lastArgs == signatureArgs) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1463 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1464 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1465 if (lastArgs != -1) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1466 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
|
1467 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
|
1468 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1469 return false; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1470 } else { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1471 lastArgs = signatureArgs; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1472 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1473 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1474 return true; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1475 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1476 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1477 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
|
1478 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
|
1479 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
|
1480 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1481 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1482 |
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
|
1483 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
|
1484 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
|
1485 // 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
|
1486 // 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
|
1487 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
|
1488 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1489 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1490 List<Element> elements = new ArrayList<>(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
|
1491 Set<Element> unusedElements = new HashSet<>(elements); |
20938
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1492 for (ExecutableElement method : nodeData.getAllTemplateMethods()) { |
18c0f02fa4d2
Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents:
20130
diff
changeset
|
1493 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
|
1494 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1495 |
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
|
1496 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
|
1497 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
|
1498 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
|
1499 } |
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
|
1500 } |
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
|
1501 |
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
|
1502 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
|
1503 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
|
1504 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
|
1505 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1506 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1507 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1508 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
|
1509 if (unusedMethod.getModifiers().contains(Modifier.ABSTRACT)) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1510 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
|
1511 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
|
1512 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1513 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1514 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1515 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1516 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
|
1517 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
|
1518 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
|
1519 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
|
1520 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
|
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 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1524 |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1525 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
|
1526 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
|
1527 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
|
1528 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
|
1529 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1530 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
|
1531 if (sourceSpecialization.getExceptions() != null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1532 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
|
1533 for (SpecializationThrowsData otherThrowsData : sourceSpecialization.getExceptions()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1534 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
|
1535 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
|
1536 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1537 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1538 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1539 } |
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 |
19282
ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents:
18811
diff
changeset
|
1543 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
|
1544 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
|
1545 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
|
1546 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
|
1547 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1548 |
19282
ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents:
18811
diff
changeset
|
1549 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
|
1550 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
|
1551 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
|
1552 oneNonPrivate = true; |
ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents:
18811
diff
changeset
|
1553 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
|
1554 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1555 } |
19282
ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents:
18811
diff
changeset
|
1556 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
|
1557 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
|
1558 } |
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
|
1559 } |
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11545
diff
changeset
|
1560 |
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
|
1561 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
|
1562 for (Element element : elements) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1563 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
|
1564 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
|
1565 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
|
1566 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1567 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1568 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
|
1569 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1570 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1571 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
|
1572 TypeMirror inhertNodeType = context.getTruffleTypes().getNode(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1573 TypeMirror value = ElementUtils.getAnnotationValue(TypeMirror.class, annotation, valueName); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1574 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
|
1575 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
|
1576 } 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
|
1577 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
|
1578 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1579 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1580 |
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
|
1581 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
|
1582 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
|
1583 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
|
1584 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1585 String methodName; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1586 if (ElementUtils.typeEquals(type, context.getType(boolean.class))) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1587 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
|
1588 } else { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1589 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
|
1590 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1591 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1592 for (ExecutableElement method : ElementFilter.methodsIn(elements)) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1593 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
|
1594 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
|
1595 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1596 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1597 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
|
1598 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1599 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1600 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
|
1601 if (element != null) { |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1602 collection.add(element); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1603 if (element.getSuperclass() != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1604 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
|
1605 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1606 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1607 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
|
1608 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1609 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1610 } |