annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java @ 20130:8dc73c226c63

Truffle: cache NodeClass lookup in Node.
author Christian Humer <christian.humer@gmail.com>
date Thu, 02 Apr 2015 01:26:31 +0200
parents 91dea7a100d2
children 18c0f02fa4d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
23 package com.oracle.truffle.dsl.processor.parser;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
79041ab43660 Truffle-DSL: 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.*;
20130
8dc73c226c63 Truffle: cache NodeClass lookup in Node.
Christian Humer <christian.humer@gmail.com>
parents: 19347
diff changeset
35 import com.oracle.truffle.api.dsl.NodeField;
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
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
48 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
49
16760
9f38d222fa6c Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
50 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
51 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
52
79041ab43660 Truffle-DSL: 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 @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
54 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
55 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
56 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
57 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
58 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
59 }
79041ab43660 Truffle-DSL: 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 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
61 }
79041ab43660 Truffle-DSL: 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 @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
64 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
65 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
66 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
67 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
68 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
69 }
79041ab43660 Truffle-DSL: 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 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
72 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
73 }
79041ab43660 Truffle-DSL: 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 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
75 }
79041ab43660 Truffle-DSL: 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 @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
78 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
79 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
80 }
79041ab43660 Truffle-DSL: 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 @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
83 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
84 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
85 }
79041ab43660 Truffle-DSL: 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 @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
88 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
89 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
90 }
79041ab43660 Truffle-DSL: 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
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
92 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
93 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
94 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
95 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
96 if (enclosedChild != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
97 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
98 }
79041ab43660 Truffle-DSL: 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 }
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
100 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
101 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
102 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
103 } 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
104 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
105 } 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
106 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
107 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
108 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
109 if (node == null && !enclosedNodes.isEmpty()) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
110 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
111 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
113 if (node != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
114 for (NodeData enclosedNode : enclosedNodes) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
115 node.addEnclosedNode(enclosedNode);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
116 }
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
117 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
118 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
119 }
79041ab43660 Truffle-DSL: 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 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
122 // 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
123 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
124
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
125 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
126 // 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
127 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
128 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
129
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
130 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
131 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
132 }
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
133
c0fb70634640 Truffle-DSL: support for frame 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 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
135 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
136 // 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
137 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
138 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
139 }
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
140
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
141 NodeData node = parseNodeData(templateType, lookupTypes);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
142 if (node.hasErrors()) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
143 return node;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
144 }
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
145
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
146 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
147 node.getChildren().addAll(parseChildren(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.getChildExecutions().addAll(parseExecutions(node.getChildren(), members));
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
149 node.setExecutableTypes(groupExecutableTypes(new ExecutableTypeMethodParser(context, node, null, context.getFrameTypes()).parse(members)));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
150
c0fb70634640 Truffle-DSL: support for frame 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 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
152 initializeImportGuards(node, lookupTypes, members);
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
153
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
154 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
155 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
156 }
79041ab43660 Truffle-DSL: 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
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
158 initializeChildren(node);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
159
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
160 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
161 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
162 }
c0fb70634640 Truffle-DSL: support for frame 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 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
165 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
166 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
167 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
168
c0fb70634640 Truffle-DSL: support for frame 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 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
170 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
171 }
c0fb70634640 Truffle-DSL: support for frame 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 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
174 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
175 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
176
c0fb70634640 Truffle-DSL: support for frame 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 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
178 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
179 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
180 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
181 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
182 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
183 }
c0fb70634640 Truffle-DSL: support for frame 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
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
185 private List<Element> loadMembers(TypeElement templateType) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
186 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
187
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
188 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
189 }
c0fb70634640 Truffle-DSL: support for frame 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 private boolean containsSpecializations(List<Element> elements) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
192 boolean foundSpecialization = false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
193 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
194 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
195 foundSpecialization = true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
196 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
197 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
198 }
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
199 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
200 }
79041ab43660 Truffle-DSL: 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
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
202 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
203 for (TypeElement lookupType : lookupTypes) {
19285
259a416388d7 Truffle-DSL: rename @ImportGuards to @ImportStatic
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
204 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
205 if (importAnnotation == null) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
206 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
207 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
208 AnnotationValue importClassesValue = ElementUtils.getAnnotationValue(importAnnotation, "value");
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
209 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
210 if (importClasses.isEmpty()) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
211 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
212 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
213 }
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
214 for (TypeMirror importGuardClass : importClasses) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
215 if (importGuardClass.getKind() != TypeKind.DECLARED) {
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
216 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
217 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
218 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
219
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
220 TypeElement typeElement = ElementUtils.fromTypeMirror(importGuardClass);
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
221 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
222 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
223 continue;
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
224 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
225 elements.addAll(importPublicStaticMembers(typeElement, false));
16832
13cf9b6b325c Truffle-DSL: implemented import guards feature.
Christian Humer <christian.humer@gmail.com>
parents: 16830
diff changeset
226 }
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
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
230 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
231 // 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
232 // 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
233 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
234
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
235 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
236 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
237 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
238 continue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
239 }
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 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
242 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
243 }
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 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
246 continue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
247 }
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 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
250 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
251 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
252 }
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 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
255 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
256
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
257 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
258 AnnotationMirror typeSystemMirror = findFirstAnnotation(typeHierarchy, TypeSystemReference.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
259 if (typeSystemMirror == null) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
260 NodeData nodeData = new NodeData(context, templateType);
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
261 nodeData.addError("No @%s annotation found in type hierarchy of %s.", TypeSystemReference.class.getSimpleName(), ElementUtils.getQualifiedName(templateType));
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
262 return nodeData;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
264
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
265 TypeMirror typeSystemType = ElementUtils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value");
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
266 final TypeSystemData typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, 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
267 if (typeSystem == null) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
268 NodeData nodeData = new NodeData(context, templateType);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
269 nodeData.addError("The used type system '%s' is invalid. Fix errors in the type system first.", ElementUtils.getQualifiedName(typeSystemType));
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
270 return nodeData;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 }
79041ab43660 Truffle-DSL: 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
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
409 private List<NodeExecutionData> parseExecutions(List<NodeChildData> children, List<? extends Element> elements) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
410 if (children == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
411 return null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
412 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
413
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
414 // pre-parse short circuits
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
415 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
416 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
417 for (ExecutableElement method : methods) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
418 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
419 if (mirror != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
420 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
421 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
422 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
423
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
424 boolean hasVarArgs = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
425 int maxSignatureSize = 0;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
426 if (!children.isEmpty()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
427 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
428 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
429 if (hasVarArgs) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
430 maxSignatureSize = lastIndex;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
431 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
432 maxSignatureSize = children.size();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
433 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
434 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
435
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
436 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
437 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
438 // 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
439 for (ExecutableElement method : methods) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
440 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
441 if (mirror == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
442 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
443 }
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
444 int currentArgumentIndex = 0;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
445 boolean skipShortCircuit = false;
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
446 outer: for (VariableElement var : method.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
447
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
448 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
449 if (currentArgumentIndex == 0) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
450 // 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
451 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
452 if (ElementUtils.typeEquals(type, 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
453 continue outer;
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
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 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
456 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
457
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
458 if (ElementUtils.findAnnotationMirror(var.getAnnotationMirrors(), cacheAnnotation) != null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
459 continue outer;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
460 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
461
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
462 int childIndex = currentArgumentIndex < children.size() ? currentArgumentIndex : children.size() - 1;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
463 if (childIndex == -1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
464 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
465 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
466 if (!skipShortCircuit) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
467 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
468 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
469 skipShortCircuit = true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
470 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
471 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
472 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
473 skipShortCircuit = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
474 }
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
475
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
476 currentArgumentIndex++;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
477 }
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
478 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
479 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
480
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
481 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
482 for (int i = 0; i < maxSignatureSize; i++) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
483 int childIndex = i;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
484 boolean varArg = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
485 if (childIndex >= children.size() - 1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
486 if (hasVarArgs) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
487 childIndex = children.size() - 1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
488 varArg = hasVarArgs;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
489 } else if (childIndex >= children.size()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
490 break;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
491 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
492 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
493 int varArgsIndex = varArg ? Math.abs(childIndex - i) : -1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
494 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
495 boolean shortCircuit = shortCircuits.contains(NodeExecutionData.createIndexedName(child, varArgsIndex));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
496 executions.add(new NodeExecutionData(child, varArgsIndex, shortCircuit));
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
497 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
498 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
499 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
500
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
501 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
502 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
503
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
504 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
505 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
506 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
507 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
508 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
509
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
510 Parameter frame = execute.getFrame();
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
511 TypeMirror resolvedFrameType;
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
512 if (frame != null) {
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
513 resolvedFrameType = frame.getType();
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
514 if (frameType == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
515 frameType = resolvedFrameType;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
516 } 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
517 // 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
518 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
519 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
520 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
521 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
522 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
523 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
524 // 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
525 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
526 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
527 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
528 }
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
529 if (frameType == null) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
530 frameType = context.getType(void.class);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
531 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
532
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
533 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
534
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
535 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
536 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
537 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
538 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
539 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
540 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
541 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
542 if (!executableTypeData.getMethod().getModifiers().contains(Modifier.FINAL)) {
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
543 if (ElementUtils.isVoid(executableTypeData.getReturnType().getType())) {
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
544 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
545 } 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
546 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
547 }
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
548 }
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
549 }
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
550 // 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
551 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
552 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
553 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
554 for (ExecutableTypeData type : 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
555 if (type.getType().isVoid()) {
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
556 methodSignatures.add(type.createReferenceName());
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
557 }
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
558 }
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
559 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
560 } 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
561 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
562 for (ExecutableTypeData type : 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
563 if (!type.getType().isVoid()) {
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
564 methodSignatures.add(type.createReferenceName());
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
565 }
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
566 }
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
567 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
568 }
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
569 }
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
570 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
571 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
572 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
573
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
574 // 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
575 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
576 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
577 + "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
578 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
579
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
580 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
581
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
582 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
583 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
584 for (ExecutableTypeData type : executableTypes) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
585 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
586
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
587 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
588 if (types == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
589 types = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
590 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
591 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
592 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
593 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
594
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
595 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
596 Collections.sort(types);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
597 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
598 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
599 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
600
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
601 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
602 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
603
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
604 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
605 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
606 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
607
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
608 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
609 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
610 child.addError("Node type '%s' is invalid or not a subclass of Node.", ElementUtils.getQualifiedName(nodeType));
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
611 } else if (!ElementUtils.typeEquals(fieldNodeData.getTypeSystem().getTemplateType().asType(), (node.getTypeSystem().getTemplateType().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
612 child.addError("The @%s of the node and the @%s of the @%s does not match. %s != %s. ", TypeSystem.class.getSimpleName(), TypeSystem.class.getSimpleName(),
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
613 NodeChild.class.getSimpleName(), ElementUtils.getSimpleName(node.getTypeSystem().getTemplateType()),
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
614 ElementUtils.getSimpleName(fieldNodeData.getTypeSystem().getTemplateType()));
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
615 } 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
616 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
617 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
618 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
619 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
620 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
621 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
622 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
623 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
624 }
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
625
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
626 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
627 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
628 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
629 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
630 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
631 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
632 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
633 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
634 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
635 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
636 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
637 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
638 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
639 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
640 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
641 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
642 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
643 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
644 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
645 break;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
646 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
647 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
648
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
649 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
650 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
651 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
652 } 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
653 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
654 executeWithString);
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
655 continue;
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
656 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
657 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
658 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
659 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
660 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
661 }
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
662
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
663 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
664 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
665
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
666 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
667 // 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
668 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
669 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
670
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
671 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
672 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
673 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
674
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
675 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
676
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
677 // 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
678 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
679 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
680 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
681 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
682 }
19292
906367e494ca Truffle-DSL: fix invalid parameter order for executeWith with non-linear execution.
Christian Humer <christian.humer@gmail.com>
parents: 19291
diff changeset
683 node.setExecutableTypes(groupExecutableTypes(new ExecutableTypeMethodParser(context, node, child, createAllowedChildFrameTypes(parentNode)).parse(members)));
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
684 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
685 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
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
c0fb70634640 Truffle-DSL: support for frame 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 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
689 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
690 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
691 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
692 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
693 }
c0fb70634640 Truffle-DSL: support for frame 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 }
c0fb70634640 Truffle-DSL: support for frame 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 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
696 }
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18775
diff changeset
697
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
698 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
699 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
700 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
701 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
702
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
703 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
704
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
705 if (node.hasErrors()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
706 return;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
707 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
708
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
709 initializeGeneric(node);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
710 initializeUninitialized(node);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
711 initializeOrder(node);
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
712 initializePolymorphism(node); // requires specializations
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
713 initializeReachability(node);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
714 initializeContains(node);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
715 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
716
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
717 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
718 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
719 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
720 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
721 contained.getExcludedBy().add(cur);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
722 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
723 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
724 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
725
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
726 initializeSpecializationIdsWithMethodNames(node.getSpecializations());
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
727 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
728
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
729 private static void initializeOrder(NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
730 List<SpecializationData> specializations = node.getSpecializations();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
731 Collections.sort(specializations);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
732
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
733 for (SpecializationData specialization : specializations) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
734 String searchName = specialization.getInsertBeforeName();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
735 if (searchName == null || specialization.getMethod() == null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
736 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
737 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
738 SpecializationData found = lookupSpecialization(node, searchName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
739 if (found == null || found.getMethod() == null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
740 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
741 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
742 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
743 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
744
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
745 ExecutableElement currentMethod = specialization.getMethod();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
746 ExecutableElement insertBeforeMethod = found.getMethod();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
747
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
748 TypeMirror currentEnclosedType = currentMethod.getEnclosingElement().asType();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
749 TypeMirror insertBeforeEnclosedType = insertBeforeMethod.getEnclosingElement().asType();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
750
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
751 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
752 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
753 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
754 continue;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
755 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
756
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
757 specialization.setInsertBefore(found);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
758 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
759
16764
f9fff060dc41 Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents: 16760
diff changeset
760 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
761 SpecializationData specialization = specializations.get(i);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
762 SpecializationData insertBefore = specialization.getInsertBefore();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
763 if (insertBefore != null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
764 int insertIndex = specializations.indexOf(insertBefore);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
765 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
766 specializations.remove(i);
f9fff060dc41 Truffle-DSL: fixed behaviour of insertBefore to be more intuitive.
Christian Humer <christian.humer@gmail.com>
parents: 16760
diff changeset
767 specializations.add(insertIndex, specialization);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
768 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
769 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
770 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
771
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
772 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
773 specializations.get(i).setIndex(i);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
774 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
775 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
776
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
777 private static void initializeContains(NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
778 for (SpecializationData specialization : node.getSpecializations()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
779 Set<SpecializationData> resolvedSpecializations = specialization.getContains();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
780 resolvedSpecializations.clear();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
781 Set<String> includeNames = specialization.getContainsNames();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
782 for (String includeName : includeNames) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
783 // TODO reduce complexity of this lookup.
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
784 SpecializationData foundSpecialization = lookupSpecialization(node, includeName);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
785
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
786 if (foundSpecialization == null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
787 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
788 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
789 } 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
790 if (foundSpecialization.compareTo(specialization) > 0) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
791 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
792 if (foundSpecialization.compareTo(specialization) > 0) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
793 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
794 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
795
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
796 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
797 resolvedSpecializations.add(foundSpecialization);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
798 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
799 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
800 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
801 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
802
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
803 private void resolveContains(NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
804 // flatten transitive includes
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
805 for (SpecializationData specialization : node.getSpecializations()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
806 if (specialization.getContains().isEmpty()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
807 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
808 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
809 Set<SpecializationData> foundSpecializations = new HashSet<>();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
810 collectIncludes(specialization, foundSpecializations, new HashSet<SpecializationData>());
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
811 specialization.getContains().addAll(foundSpecializations);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
812 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
813 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
814
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
815 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
816 SpecializationData foundSpecialization = null;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
817 for (SpecializationData searchSpecialization : node.getSpecializations()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
818 if (searchSpecialization.getMethodName().equals(includeName)) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
819 foundSpecialization = searchSpecialization;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
820 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
821 }
16755
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 return foundSpecialization;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
824 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
825
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
826 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
827 if (visited.contains(specialization)) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
828 // circle found
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
829 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
830 return;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
831 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
832 visited.add(specialization);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
833
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
834 for (SpecializationData included : specialization.getContains()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
835 collectIncludes(included, found, new HashSet<>(visited));
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
836 found.add(included);
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 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
839
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
840 private static void initializeReachability(final NodeData node) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
841 List<SpecializationData> specializations = node.getSpecializations();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
842 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
843 SpecializationData current = specializations.get(i);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
844 if (current.isPolymorphic()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
845 current.setReachable(true);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
846 continue;
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 List<SpecializationData> shadowedBy = null;
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
850 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
851 SpecializationData prev = specializations.get(j);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
852 if (prev.isPolymorphic()) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
853 continue;
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 if (!current.isReachableAfter(prev)) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
856 if (shadowedBy == null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
857 shadowedBy = new ArrayList<>();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
858 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
859 shadowedBy.add(prev);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
860 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
861 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
862
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
863 if (shadowedBy != null) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
864 StringBuilder name = new StringBuilder();
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
865 String sep = "";
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
866 for (SpecializationData shadowSpecialization : shadowedBy) {
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
867 name.append(sep);
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
868 name.append(shadowSpecialization.createReferenceName());
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
869 sep = ", ";
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
870 }
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
871 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
872 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
873 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
874 }
10602
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
875 }
b8fe1fe004ec Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents: 10600
diff changeset
876
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
877 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
878 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
879 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
880 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
881 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
882 } 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
883 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
884 } 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
885 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
886 } 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
887 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
888
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
889 // 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
890 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
891 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
892 } 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
893 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
894 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
895 name = filteredDo;
7382bbcac3a3 Truffle-DSL: better class names for specialization methods starting with do.
Christian Humer <christian.humer@gmail.com>
parents: 18771
diff changeset
896 }
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
897 }
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
898 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
899 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
900 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
901
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
902 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
903 // 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
904 }
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
905
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
906 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
907 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
908 }
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
909 }
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
910
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
911 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
912 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
913 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
914 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
915 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
916 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
917 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
918 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
919 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
920 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
921 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
922
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
923 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
924 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
925 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
926 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
927 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
928 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
929 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
930 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
931 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
932 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
933 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
934 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
935 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
936 }
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
937 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
938 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
939
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
940 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
941 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
942
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
943 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
944 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
945 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
946 }
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
947
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
948 for (SpecializationData specialization : node.getSpecializations()) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
949 if (specialization.getMethod() == null) {
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
950 continue;
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
951 }
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
952
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
953 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
954 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
955 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
956 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
957 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
958 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
959 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
960
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
961 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
962 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
963 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
964 continue;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
965 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
966 initializeLimit(specialization, resolver);
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
967 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
968 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
969 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
970
19291
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
971 private void initializeAssumptions(SpecializationData specialization, DSLExpressionResolver resolver) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
972 final DeclaredType assumptionType = context.getDeclaredType(Assumption.class);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
973 final TypeMirror assumptionArrayType = new ArrayCodeTypeMirror(assumptionType);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
974 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
975 List<AssumptionExpression> assumptionExpressions = new ArrayList<>();
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
976 int assumptionId = 0;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
977 for (String assumption : assumptionDefinitions) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
978 AssumptionExpression assumptionExpression;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
979 DSLExpression expression = null;
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
980 try {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
981 expression = DSLExpression.parse(assumption);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
982 expression.accept(resolver);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
983 assumptionExpression = new AssumptionExpression(specialization, expression, "assumption" + assumptionId);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
984 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
985 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
986 ElementUtils.getSimpleName(assumptionType), ElementUtils.getSimpleName(assumptionArrayType));
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
987 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
988 if (specialization.isDynamicParameterBound(expression)) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
989 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
990 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
991 } catch (InvalidExpressionException e) {
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
992 assumptionExpression = new AssumptionExpression(specialization, null, "assumption" + assumptionId);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
993 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
994 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
995 assumptionExpressions.add(assumptionExpression);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
996 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
997 specialization.setAssumptionExpressions(assumptionExpressions);
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
998 }
f4792a544170 Truffle-DSL: implement new assumptions semantics.
Christian Humer <christian.humer@gmail.com>
parents: 19289
diff changeset
999
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1000 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
1001 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
1002
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1003 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
1004 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
1005 limitValue = "";
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1006 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1007 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
1008 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1009 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
1010 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
1011 } 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
1012 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
1013 return;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1014 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1015
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1016 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
1017 try {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1018 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
1019 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
1020 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
1021 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
1022 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
1023 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1024 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
1025 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
1026 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1027
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1028 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
1029 } 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
1030 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
1031 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1032 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1033
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 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
1041
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1042 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
1043
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1044 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
1045 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
1046 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
1047 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1048
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1049 CacheExpression cacheExpression;
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1050 DSLExpression expression = null;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1051 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
1052 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
1053 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
1054 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
1055 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
1056 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
1057 ElementUtils.getSimpleName(parameter.getType()));
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1058 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1059 } 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
1060 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
1061 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
1062 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1063 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
1064 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1065 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1066 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
1067
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1068 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
1069 return;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1070 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1071
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1072 // 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
1073 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
1074 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
1075 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
1076 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
1077 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
1078 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
1079 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
1080 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
1081 break;
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1082 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1083 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1084 }
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1085 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1086
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1087 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
1088 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
1089 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
1090 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
1091 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
1092 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
1093 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
1094 try {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1095 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
1096 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
1097 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
1098 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
1099 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
1100 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1101 } 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
1102 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
1103 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
1104 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1105 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
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.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
1108 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1109
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1110 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
1111 String packageName = ElementUtils.getPackageName(templateType);
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1112 List<Element> filteredElements = new ArrayList<>(elements);
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1113 for (Element element : elements) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1114 Modifier visibility = ElementUtils.getVisibility(element.getModifiers());
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1115 if (visibility == Modifier.PRIVATE) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1116 continue;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1117 } else if (visibility == null) {
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1118 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
1119 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
1120 continue;
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1121 }
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1122 }
16851
2db61eddcb97 Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents: 16834
diff changeset
1123
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1124 filteredElements.add(element);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1125 }
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
1126 return filteredElements;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1127 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1128
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1129 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
1130 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
1131 for (SpecializationData spec : node.getSpecializations()) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18754
diff changeset
1132 if (spec.isFallback()) {
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1133 generics.add(spec);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1134 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1135 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1136
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1137 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
1138 // 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
1139 for (SpecializationData generic : generics) {
16760
9f38d222fa6c Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
1140 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
1141 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1142 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1143
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1144 if (generics.isEmpty()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1145 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
1146 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1147 if (generics.size() > 1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1148 for (SpecializationData generic : generics) {
16760
9f38d222fa6c Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
1149 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
1150 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1151 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1152 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1153 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1154
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1155 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
1156 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
1157 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
1158
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1159 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
1160 int signatureIndex = 1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1161 for (ParameterSpec spec : specification.getRequired()) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19285
diff changeset
1162 parameterTypes.add(new CodeVariableElement(createGenericType(spec, node.getSpecializations(), signatureIndex), "arg" + signatureIndex));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1163 if (spec.isSignature()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1164 signatureIndex++;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1165 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1166 }
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1167
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1168 TypeMirror returnType = createGenericType(specification.getReturnType(), node.getSpecializations(), 0);
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1169 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
1170 if (generic == null) {
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1171 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
1172 }
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1173
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1174 return generic;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1175 }
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
1176
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1177 private TypeMirror createGenericType(ParameterSpec spec, List<SpecializationData> specializations, int signatureIndex) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1178 NodeExecutionData execution = spec.getExecution();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1179 if (execution == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1180 if (spec.getAllowedTypes().size() == 1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1181 return spec.getAllowedTypes().get(0);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1182 } else {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1183 return ElementUtils.getCommonSuperType(context, spec.getAllowedTypes().toArray(new TypeMirror[0]));
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1184 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1185 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1186 Set<TypeData> types = new HashSet<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1187 for (SpecializationData specialization : specializations) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1188 types.add(specialization.getTypeSignature().get(signatureIndex));
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1189 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1190
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1191 NodeChildData child = execution.getChild();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1192 TypeData genericType = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1193 if (types.size() == 1) {
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1194 TypeData singleType = types.iterator().next();
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1195 ExecutableTypeData executable = child.findExecutableType(singleType);
13535
e8ef44830b50 Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents: 13528
diff changeset
1196 if (executable != null && (signatureIndex == 0 || !executable.hasUnexpectedValue(context))) {
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1197 genericType = singleType;
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1198 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1199 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1200 if (genericType == null) {
18775
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1201 ExecutableTypeData type = child.findAnyGenericExecutableType(context);
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1202 if (type == null) {
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1203 throw new AssertionError("No generic type not yet catched by parser.");
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1204 }
a069a87b9a02 Truffle-DSL: Added tests and verification of overridable generic execute methods.
Christian Humer <christian.humer@gmail.com>
parents: 18773
diff changeset
1205 genericType = type.getType();
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 return genericType.getPrimitiveType();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1208 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1209 }
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
1210
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1211 private static void initializeUninitialized(final NodeData node) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1212 SpecializationData generic = node.getGenericSpecialization();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1213 if (generic == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1214 return;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1215 }
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1216 for (Parameter parameter : generic.getReturnTypeAndParameters()) {
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1217 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
1218 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1219 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1220 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
1221 for (SpecializationData specialization : node.getSpecializations()) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1222 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
1223 if (actualParameter != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1224 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
1225 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1226 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1227 if (types.size() > 1) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1228 generic.replaceParameter(parameter.getLocalName(), new Parameter(parameter, node.getTypeSystem().getGenericTypeData()));
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 }
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1231 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
1232 // 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
1233 uninializedMethod.getMessages().clear();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1234 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
1235 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1236
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1237 private void initializePolymorphism(NodeData node) {
16755
bd28da642eea Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents: 13535
diff changeset
1238 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
1239 return;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1240 }
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
1241
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1242 SpecializationData generic = node.getGenericSpecialization();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1243
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1244 List<TypeData> polymorphicSignature = new ArrayList<>();
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1245 List<Parameter> updatePolymorphic = Arrays.asList();
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1246 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
1247 if (!genericParameter.getSpecification().isSignature()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1248 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1249 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1250
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1251 Set<TypeData> usedTypes = new HashSet<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1252 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
1253 if (!specialization.isSpecialized()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1254 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1255 }
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1256 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
1257 if (parameter == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1258 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
1259 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1260 usedTypes.add(parameter.getTypeSystemType());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1261 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1262
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1263 TypeData polymorphicType;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1264 if (usedTypes.size() == 1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1265 polymorphicType = usedTypes.iterator().next();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1266 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1267 polymorphicType = node.getTypeSystem().getGenericTypeData();
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 polymorphicSignature.add(polymorphicType);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1270 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1271
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1272 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
1273 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
1274 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
1275 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1276
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1277 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
1278 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
1279
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1280 boolean valid = true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1281 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
1282 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
1283 if (!execution.isShortCircuit()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1284 continue;
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 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
1287 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
1288 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
1289
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1290 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
1291 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
1292 valid = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1293 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1294 }
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 boolean sameMethodName = true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1297 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
1298 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1299 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
1300 sameMethodName = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1301 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1302 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1303
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1304 if (!sameMethodName) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1305 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1306 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
1307 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1308 valid = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1309 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1310 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1311
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1312 ShortCircuitData genericCircuit = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1313 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1314 if (isGenericShortCutMethod(circuit)) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1315 genericCircuit = circuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1316 break;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1317 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1318 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1319
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1320 if (genericCircuit == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1321 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
1322 valid = false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1323 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1324 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1325
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1326 for (ShortCircuitData circuit : availableCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1327 if (circuit != genericCircuit) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1328 circuit.setGenericShortCircuitMethod(genericCircuit);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1329 }
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
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1333 if (!valid) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1334 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
1335 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1336
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1337 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
1338 specializations.addAll(node.getSpecializations());
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1339 for (SpecializationData specialization : specializations) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1340 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
1341
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1342 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
1343 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
1344
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1345 ShortCircuitData genericShortCircuit = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1346 ShortCircuitData compatibleShortCircuit = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1347 for (ShortCircuitData circuit : availableShortCuts) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1348 if (circuit.isGeneric()) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1349 genericShortCircuit = circuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1350 } 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
1351 compatibleShortCircuit = circuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1352 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1353 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1354
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1355 if (compatibleShortCircuit == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1356 compatibleShortCircuit = genericShortCircuit;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1357 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1358 assignedShortCuts.add(compatibleShortCircuit);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1359 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1360 specialization.setShortCircuits(assignedShortCuts);
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 private boolean isGenericShortCutMethod(ShortCircuitData method) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1365 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
1366 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
1367 if (execution == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1368 continue;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1369 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1370 ExecutableTypeData found = null;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1371 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
1372 for (ExecutableTypeData executable : executableElements) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1373 if (executable.getType().equalsType(parameter.getTypeSystemType())) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1374 found = executable;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1375 break;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1376 }
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 if (found == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1379 return false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1380 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1381 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1382 return true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1383 }
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 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
1386 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
1387 for (ShortCircuitData shortCircuit : shortCircuits) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1388 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
1389 if (circuits == null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1390 circuits = new ArrayList<>();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1391 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
1392 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1393 circuits.add(shortCircuit);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1394 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1395 return group;
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
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1398 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
1399 int lastArgs = -1;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1400 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
1401 int signatureArgs = specializationData.getSignatureSize();
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1402 if (lastArgs == signatureArgs) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1403 continue;
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 if (lastArgs != -1) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1406 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
1407 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
1408 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1409 return false;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1410 } else {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1411 lastArgs = signatureArgs;
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 return true;
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1415 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1416
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1417 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
1418 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
1419 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
1420 }
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
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
1423 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
1424 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
1425 // 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
1426 // 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
1427 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
1428 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1429
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1430 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
1431 Set<Element> unusedElements = new HashSet<>(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
1432 for (TemplateMethod method : nodeData.getAllTemplateMethods()) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1433 unusedElements.remove(method.getMethod());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1434 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1435
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
1436 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
1437 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
1438 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
1439 }
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
1440 }
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
1441
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
1442 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
1443 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
1444 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
1445 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1446 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1447
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1448 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
1449 if (unusedMethod.getModifiers().contains(Modifier.ABSTRACT)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1450 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
1451 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
1452 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1453 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1454 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1455
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1456 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
1457 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
1458 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
1459 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
1460 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
1461 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1462 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1463 }
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 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
1466 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
1467 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
1468 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
1469 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1470 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
1471 if (sourceSpecialization.getExceptions() != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1472 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
1473 for (SpecializationThrowsData otherThrowsData : sourceSpecialization.getExceptions()) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1474 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
1475 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
1476 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1477 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1478 }
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1479 }
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
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1483 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
1484 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
1485 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
1486 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
1487 }
79041ab43660 Truffle-DSL: 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
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1489 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
1490 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
1491 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
1492 oneNonPrivate = true;
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1493 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
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 }
19282
ae81dd154fb6 Truffle-DSL: remove old DSL layout; Make new layout the default.
Christian Humer <christian.humer@gmail.com>
parents: 18811
diff changeset
1496 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
1497 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
1498 }
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
1499 }
85b846b31690 Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents: 11545
diff changeset
1500
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
1501 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
1502 for (Element element : elements) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1503 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
1504 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
1505 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
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 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
1509 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1510
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1511 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
1512 TypeMirror inhertNodeType = context.getTruffleTypes().getNode();
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1513 TypeMirror value = ElementUtils.getAnnotationValue(TypeMirror.class, annotation, valueName);
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1514 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
1515 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
1516 } 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
1517 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
1518 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1519 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1520
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
1521 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
1522 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
1523 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
1524 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1525 String methodName;
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1526 if (ElementUtils.typeEquals(type, context.getType(boolean.class))) {
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1527 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
1528 } else {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1529 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
1530 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1531
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1532 for (ExecutableElement method : ElementFilter.methodsIn(elements)) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1533 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
1534 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
1535 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1536 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1537 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
1538 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1539
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1540 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
1541 if (element != null) {
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1542 collection.add(element);
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 13527
diff changeset
1543 if (element.getSuperclass() != null) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16755
diff changeset
1544 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
1545 }
79041ab43660 Truffle-DSL: 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 }
79041ab43660 Truffle-DSL: 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 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
1548 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1549
79041ab43660 Truffle-DSL: 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 }