Mercurial > hg > truffle
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemData.java @ 10597:79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Jul 2013 20:58:32 +0200 |
parents | |
children | 43eab069ca9b |
comparison
equal
deleted
inserted
replaced
10596:f43eb2f1bbbc | 10597:79041ab43660 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.dsl.processor.typesystem; | |
24 | |
25 import java.util.*; | |
26 | |
27 import javax.lang.model.element.*; | |
28 import javax.lang.model.type.*; | |
29 | |
30 import com.oracle.truffle.dsl.processor.*; | |
31 import com.oracle.truffle.dsl.processor.template.*; | |
32 | |
33 public class TypeSystemData extends Template { | |
34 | |
35 private List<TypeData> types; | |
36 private List<TypeMirror> primitiveTypeMirrors = new ArrayList<>(); | |
37 private List<TypeMirror> boxedTypeMirrors = new ArrayList<>(); | |
38 | |
39 private TypeMirror genericType; | |
40 private TypeData voidType; | |
41 | |
42 public TypeSystemData(TypeElement templateType, AnnotationMirror annotation) { | |
43 super(templateType, null, annotation); | |
44 } | |
45 | |
46 @Override | |
47 public TypeSystemData getTypeSystem() { | |
48 return this; | |
49 } | |
50 | |
51 void setTypes(List<TypeData> types) { | |
52 this.types = types; | |
53 if (types != null) { | |
54 for (TypeData typeData : types) { | |
55 primitiveTypeMirrors.add(typeData.getPrimitiveType()); | |
56 boxedTypeMirrors.add(typeData.getBoxedType()); | |
57 } | |
58 } | |
59 } | |
60 | |
61 void setGenericType(TypeMirror genericType) { | |
62 this.genericType = genericType; | |
63 } | |
64 | |
65 void setVoidType(TypeData voidType) { | |
66 this.voidType = voidType; | |
67 } | |
68 | |
69 @Override | |
70 protected List<MessageContainer> findChildContainers() { | |
71 List<MessageContainer> sinks = new ArrayList<>(); | |
72 if (types != null) { | |
73 sinks.addAll(types); | |
74 } | |
75 return sinks; | |
76 } | |
77 | |
78 public boolean isGeneric(TypeMirror type) { | |
79 return Utils.typeEquals(getGenericType(), type); | |
80 } | |
81 | |
82 public TypeData getVoidType() { | |
83 return voidType; | |
84 } | |
85 | |
86 public List<TypeMirror> getBoxedTypeMirrors() { | |
87 return boxedTypeMirrors; | |
88 } | |
89 | |
90 public List<TypeMirror> getPrimitiveTypeMirrors() { | |
91 return primitiveTypeMirrors; | |
92 } | |
93 | |
94 public List<TypeData> getTypes() { | |
95 return types; | |
96 } | |
97 | |
98 public TypeMirror getGenericType() { | |
99 return genericType; | |
100 } | |
101 | |
102 public TypeData getGenericTypeData() { | |
103 TypeData result = types.get(types.size() - 1); | |
104 assert result.getBoxedType() == genericType; | |
105 return result; | |
106 } | |
107 | |
108 public TypeData findType(String simpleName) { | |
109 for (TypeData type : types) { | |
110 if (Utils.getSimpleName(type.getBoxedType()).equals(simpleName)) { | |
111 return type; | |
112 } | |
113 } | |
114 return null; | |
115 } | |
116 | |
117 public TypeData findTypeData(TypeMirror type) { | |
118 if (Utils.typeEquals(voidType.getPrimitiveType(), type)) { | |
119 return voidType; | |
120 } | |
121 | |
122 int index = findType(type); | |
123 if (index == -1) { | |
124 return null; | |
125 } | |
126 return types.get(index); | |
127 } | |
128 | |
129 public int findType(TypeData typeData) { | |
130 return findType(typeData.getPrimitiveType()); | |
131 } | |
132 | |
133 public int findType(TypeMirror type) { | |
134 for (int i = 0; i < types.size(); i++) { | |
135 if (Utils.typeEquals(types.get(i).getPrimitiveType(), type)) { | |
136 return i; | |
137 } | |
138 } | |
139 return -1; | |
140 } | |
141 | |
142 @Override | |
143 public String toString() { | |
144 return getClass().getSimpleName() + "[template = " + Utils.getSimpleName(getTemplateType()) + ", types = " + types + "]"; | |
145 } | |
146 | |
147 } |