annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeSystemData.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 9c8c0937da41
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 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.model;
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
25 import com.oracle.truffle.api.dsl.internal.DSLOptions;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
26 import com.oracle.truffle.dsl.processor.ProcessorContext;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
27 import com.oracle.truffle.dsl.processor.java.ElementUtils;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
28 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
29 import java.util.Collections;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
30 import java.util.HashSet;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
31 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
32 import java.util.Set;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
33 import javax.lang.model.element.AnnotationMirror;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
34 import javax.lang.model.element.TypeElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
35 import javax.lang.model.type.TypeMirror;
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
79041ab43660 Truffle-DSL: 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 public class TypeSystemData extends Template {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
39 private final List<ImplicitCastData> implicitCasts = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
40 private final List<TypeCastData> casts = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
41 private final List<TypeCheckData> checks = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
42 private final List<TypeMirror> legacyTypes = new ArrayList<>();
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
43
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
44 private Set<String> legacyTypeIds;
11467
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
45
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
46 private final boolean isDefault;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
47 private final DSLOptions options;
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
48
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
49 public TypeSystemData(ProcessorContext context, TypeElement templateType, AnnotationMirror annotation, DSLOptions options, boolean isDefault) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
50 super(context, templateType, annotation);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
51 this.options = options;
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
52 this.isDefault = isDefault;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
53 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
54
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
55 public boolean isDefault() {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
56 return isDefault;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
57 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
58
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
59 public DSLOptions getOptions() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
60 return options;
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
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 public TypeSystemData getTypeSystem() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 return this;
79041ab43660 Truffle-DSL: 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 }
79041ab43660 Truffle-DSL: 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
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
68 public List<TypeMirror> getLegacyTypes() {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
69 return legacyTypes;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
70 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
71
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
72 public TypeCastData getCast(TypeMirror targetType) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
73 for (TypeCastData cast : casts) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
74 if (ElementUtils.typeEquals(cast.getTargetType(), targetType)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
75 return cast;
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
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 }
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
78 return 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
79 }
79041ab43660 Truffle-DSL: 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
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
81 public TypeCheckData getCheck(TypeMirror type) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
82 for (TypeCheckData check : checks) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
83 if (ElementUtils.typeEquals(check.getCheckedType(), type)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
84 return check;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
85 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
86 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
87 return null;
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
88 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
89
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
90 public List<ImplicitCastData> getImplicitCasts() {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
91 return implicitCasts;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
92 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
93
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
94 public List<TypeCastData> getCasts() {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
95 return casts;
11467
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
96 }
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
97
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
98 public List<TypeCheckData> getChecks() {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
99 return checks;
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
100 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 @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
103 protected List<MessageContainer> findChildContainers() {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 List<MessageContainer> sinks = new ArrayList<>();
11467
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
105 if (checks != null) {
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
106 sinks.addAll(checks);
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
107 }
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
108 if (casts != null) {
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
109 sinks.addAll(casts);
43eab069ca9b Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
110 }
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
111 if (implicitCasts != null) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
112 sinks.addAll(implicitCasts);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
113 }
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
114 return sinks;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
117 @Override
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
118 public String toString() {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
119 return getClass().getSimpleName() + "[template = " + ElementUtils.getSimpleName(getTemplateType()) + "]";
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
122 public List<ImplicitCastData> lookupByTargetType(TypeMirror targetType) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
123 if (getImplicitCasts() == null) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
124 return Collections.emptyList();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
125 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
126 List<ImplicitCastData> foundCasts = new ArrayList<>();
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
127 for (ImplicitCastData cast : getImplicitCasts()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
128 if (ElementUtils.typeEquals(cast.getTargetType(), targetType)) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
129 foundCasts.add(cast);
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
130 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
131 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
132 return foundCasts;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
133 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
134
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
135 public ImplicitCastData lookupCast(TypeMirror sourceType, TypeMirror targetType) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
136 if (getImplicitCasts() == null) {
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
137 return null;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
138 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
139 for (ImplicitCastData cast : getImplicitCasts()) {
20990
e6b59c7b3991 Truffle-DSL: fixed invalid types compares. they do not work in javac.
Christian Humer <christian.humer@oracle.com>
parents: 20938
diff changeset
140 if (ElementUtils.typeEquals(cast.getSourceType(), sourceType) && ElementUtils.typeEquals(cast.getTargetType(), targetType)) {
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
141 return cast;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
142 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
143 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
144 return null;
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
145 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
146
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
147 public boolean hasImplicitSourceTypes(TypeMirror targetType) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
148 if (getImplicitCasts() == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
149 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
150 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
151 for (ImplicitCastData cast : getImplicitCasts()) {
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
152 if (ElementUtils.typeEquals(cast.getTargetType(), targetType)) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
153 return true;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
154 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
155 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
156 return false;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
157 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
158
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
159 public List<TypeMirror> lookupTargetTypes() {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
160 List<TypeMirror> sourceTypes = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
161 for (ImplicitCastData cast : getImplicitCasts()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
162 sourceTypes.add(cast.getTargetType());
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
163 }
20998
8e5f9310f3aa Truffle-DSL: fixed wrong order for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 20990
diff changeset
164 return ElementUtils.uniqueSortedTypes(sourceTypes, true);
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
165 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
166
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
167 public List<TypeMirror> lookupSourceTypes(TypeMirror targetType) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
168 List<TypeMirror> sourceTypes = new ArrayList<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
169 sourceTypes.add(targetType);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
170 for (ImplicitCastData cast : getImplicitCasts()) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
171 if (ElementUtils.typeEquals(cast.getTargetType(), targetType)) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
172 sourceTypes.add(cast.getSourceType());
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
173 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
174 }
20998
8e5f9310f3aa Truffle-DSL: fixed wrong order for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 20990
diff changeset
175 return ElementUtils.uniqueSortedTypes(sourceTypes, true);
11545
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
176 }
2fb276f5e3e9 Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents: 11467
diff changeset
177
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
178 public boolean isImplicitSubtypeOf(TypeMirror source, TypeMirror target) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
179 List<ImplicitCastData> targetCasts = lookupByTargetType(target);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
180 for (ImplicitCastData cast : targetCasts) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
181 if (ElementUtils.isSubtype(boxType(source), boxType(cast.getSourceType()))) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
182 return true;
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
183 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
184 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
185 return ElementUtils.isSubtype(boxType(source), boxType(target));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
186 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
187
20938
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
188 public TypeMirror boxType(TypeMirror type) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
189 return ElementUtils.boxType(getContext(), type);
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
190 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
191
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
192 public boolean hasType(TypeMirror type) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
193 if (legacyTypeIds == null) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
194 legacyTypeIds = new HashSet<>();
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
195 for (TypeMirror legacyType : legacyTypes) {
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
196 legacyTypeIds.add(ElementUtils.getTypeId(legacyType));
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
197 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
198 }
18c0f02fa4d2 Truffle-DSL: make type systems optional.
Christian Humer <christian.humer@gmail.com>
parents: 19282
diff changeset
199 return legacyTypeIds.contains(ElementUtils.getTypeId(type));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
200 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents: 18605
diff changeset
201
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
202 }