Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeSystemData.java @ 18605:58eb9bbb60c4
Truffle-DSL: fixed several bugs when using arrays as type. added arrays test.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 03 Dec 2014 21:02:27 +0100 |
parents | 0370880ac9ce |
children | a665483c3881 |
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 |
79041ab43660
Truffle-DSL: 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.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
|
26 |
79041ab43660
Truffle-DSL: 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 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
|
28 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
|
29 |
79041ab43660
Truffle-DSL: 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 com.oracle.truffle.dsl.processor.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
31 import com.oracle.truffle.dsl.processor.java.*; |
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
|
32 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 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
|
34 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 private List<TypeData> types; |
79041ab43660
Truffle-DSL: 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 private List<TypeMirror> primitiveTypeMirrors = 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
|
37 private List<TypeMirror> boxedTypeMirrors = new ArrayList<>(); |
16816
b8470fcec3a3
Truffle-DSL: refined type system type caching
Christian Humer <christian.humer@gmail.com>
parents:
16814
diff
changeset
|
38 private Map<String, TypeData> cachedTypes = new HashMap<>(); |
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
|
39 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
40 private List<ImplicitCastData> implicitCasts; |
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
|
41 private List<TypeCastData> 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
|
42 private List<TypeCheckData> 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
|
43 |
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
|
44 private TypeMirror genericType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 private TypeData voidType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
47 public TypeSystemData(ProcessorContext context, TypeElement templateType, AnnotationMirror annotation) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
48 super(context, templateType, null, 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
|
49 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 @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
|
52 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
|
53 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
|
54 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
56 public void setTypes(List<TypeData> 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
|
57 this.types = types; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 if (types != 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
|
59 for (TypeData typeData : types) { |
79041ab43660
Truffle-DSL: 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 primitiveTypeMirrors.add(typeData.getPrimitiveType()); |
79041ab43660
Truffle-DSL: 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 boxedTypeMirrors.add(typeData.getBoxedType()); |
16818
8169deda04bb
Truffle-DSL: introduced identifiers for type matching.
Christian Humer <christian.humer@gmail.com>
parents:
16816
diff
changeset
|
62 cachedTypes.put(ElementUtils.getUniqueIdentifier(typeData.getPrimitiveType()), typeData); |
16820
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16818
diff
changeset
|
63 cachedTypes.put(ElementUtils.getUniqueIdentifier(typeData.getBoxedType()), typeData); |
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
|
64 } |
79041ab43660
Truffle-DSL: 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 } |
79041ab43660
Truffle-DSL: 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 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
68 public void setImplicitCasts(List<ImplicitCastData> implicitCasts) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
69 this.implicitCasts = implicitCasts; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
70 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
71 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
72 public List<ImplicitCastData> getImplicitCasts() { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
73 return implicitCasts; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
74 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
75 |
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
|
76 public void setCasts(List<TypeCastData> 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
|
77 this.casts = 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
|
78 } |
43eab069ca9b
Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
79 |
43eab069ca9b
Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
80 public void setChecks(List<TypeCheckData> 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
|
81 this.checks = 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
|
82 } |
43eab069ca9b
Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
83 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
84 public void setGenericType(TypeMirror genericType) { |
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
|
85 this.genericType = genericType; |
79041ab43660
Truffle-DSL: 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 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
88 public void setVoidType(TypeData voidType) { |
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
|
89 this.voidType = voidType; |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 @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
|
93 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
|
94 List<MessageContainer> sinks = 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
|
95 if (types != 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
|
96 sinks.addAll(types); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 } |
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
|
98 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
|
99 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
|
100 } |
43eab069ca9b
Truffle-DSL: improved error recovery of type systems and improved error testability infrastructure.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
101 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
|
102 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
|
103 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
104 if (implicitCasts != null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
105 sinks.addAll(implicitCasts); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
106 } |
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
|
107 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
|
108 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 public TypeData getVoidType() { |
79041ab43660
Truffle-DSL: 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 return voidType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 |
79041ab43660
Truffle-DSL: 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 public List<TypeMirror> getBoxedTypeMirrors() { |
79041ab43660
Truffle-DSL: 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 return boxedTypeMirrors; |
79041ab43660
Truffle-DSL: 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 } |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 public List<TypeMirror> getPrimitiveTypeMirrors() { |
79041ab43660
Truffle-DSL: 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 return primitiveTypeMirrors; |
79041ab43660
Truffle-DSL: 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 |
16820
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16818
diff
changeset
|
122 public Set<String> getTypeIdentifiers() { |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16818
diff
changeset
|
123 return cachedTypes.keySet(); |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16818
diff
changeset
|
124 } |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16818
diff
changeset
|
125 |
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 public List<TypeData> getTypes() { |
79041ab43660
Truffle-DSL: 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 types; |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 public TypeMirror getGenericType() { |
79041ab43660
Truffle-DSL: 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 genericType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
133 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
134 public TypeData getGenericTypeData() { |
16820
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16818
diff
changeset
|
135 TypeData result = types.get(types.size() - 2); |
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
|
136 assert result.getBoxedType() == genericType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 return result; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 public TypeData findType(String simpleName) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 for (TypeData type : types) { |
18605
58eb9bbb60c4
Truffle-DSL: fixed several bugs when using arrays as type. added arrays test.
Christian Humer <christian.humer@gmail.com>
parents:
16820
diff
changeset
|
142 if (ElementUtils.getTypeId(type.getBoxedType()).equals(simpleName)) { |
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
|
143 return 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
|
144 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 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
|
147 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 public TypeData findTypeData(TypeMirror type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
150 if (ElementUtils.typeEquals(voidType.getPrimitiveType(), 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
|
151 return voidType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 |
79041ab43660
Truffle-DSL: 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 int index = findType(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
|
155 if (index == -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
|
156 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
|
157 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 return types.get(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
|
159 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 public int findType(TypeMirror type) { |
16818
8169deda04bb
Truffle-DSL: introduced identifiers for type matching.
Christian Humer <christian.humer@gmail.com>
parents:
16816
diff
changeset
|
162 TypeData data = cachedTypes.get(ElementUtils.getUniqueIdentifier(type)); |
16814
e8d9b3827d4b
Truffle-DSL: added hashing for type lookups.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
163 if (data != null) { |
e8d9b3827d4b
Truffle-DSL: added hashing for type lookups.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
164 return data.getIndex(); |
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
|
165 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 return -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
|
167 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
169 @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
|
170 public String toString() { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
171 return getClass().getSimpleName() + "[template = " + ElementUtils.getSimpleName(getTemplateType()) + ", types = " + types + "]"; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
172 } |
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 public List<ImplicitCastData> lookupByTargetType(TypeData targetType) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
175 if (getImplicitCasts() == null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
176 return Collections.emptyList(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
177 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
178 List<ImplicitCastData> foundCasts = new ArrayList<>(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
179 for (ImplicitCastData cast : getImplicitCasts()) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
180 if (cast.getTargetType().equals(targetType)) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
181 foundCasts.add(cast); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
182 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
183 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
184 return foundCasts; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
185 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
186 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
187 public ImplicitCastData lookupCast(TypeData sourceType, TypeData targetType) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
188 if (getImplicitCasts() == null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
189 return null; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
190 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
191 for (ImplicitCastData cast : getImplicitCasts()) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
192 if (cast.getSourceType().equals(sourceType) && cast.getTargetType().equals(targetType)) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
193 return cast; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
194 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
195 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
196 return null; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
197 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
198 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
199 public List<TypeData> lookupSourceTypes(TypeData type) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
200 List<TypeData> sourceTypes = new ArrayList<>(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
201 sourceTypes.add(type); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
202 if (getImplicitCasts() != null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
203 for (ImplicitCastData cast : getImplicitCasts()) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
204 if (cast.getTargetType() == type) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
205 sourceTypes.add(cast.getSourceType()); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
206 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
207 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
208 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
209 Collections.sort(sourceTypes); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
210 return sourceTypes; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
211 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11467
diff
changeset
|
212 |
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
|
213 } |