Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeData.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 | e93efe3ba5f4 |
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 TypeData extends MessageContainer { | |
34 | |
35 private final TypeSystemData typeSystem; | |
36 private final AnnotationValue annotationValue; | |
37 private final TypeMirror primitiveType; | |
38 private final TypeMirror boxedType; | |
39 | |
40 private final List<TypeCastData> typeCasts = new ArrayList<>(); | |
41 private final List<TypeCheckData> typeChecks = new ArrayList<>(); | |
42 | |
43 public TypeData(TypeSystemData typeSystem, AnnotationValue value, TypeMirror primitiveType, TypeMirror boxedType) { | |
44 this.typeSystem = typeSystem; | |
45 this.annotationValue = value; | |
46 this.primitiveType = primitiveType; | |
47 this.boxedType = boxedType; | |
48 } | |
49 | |
50 @Override | |
51 public Element getMessageElement() { | |
52 return typeSystem.getMessageElement(); | |
53 } | |
54 | |
55 @Override | |
56 public AnnotationMirror getMessageAnnotation() { | |
57 return typeSystem.getMessageAnnotation(); | |
58 } | |
59 | |
60 @Override | |
61 public AnnotationValue getMessageAnnotationValue() { | |
62 return annotationValue; | |
63 } | |
64 | |
65 void addTypeCast(TypeCastData typeCast) { | |
66 this.typeCasts.add(typeCast); | |
67 } | |
68 | |
69 void addTypeCheck(TypeCheckData typeCheck) { | |
70 this.typeChecks.add(typeCheck); | |
71 } | |
72 | |
73 public List<TypeCastData> getTypeCasts() { | |
74 return typeCasts; | |
75 } | |
76 | |
77 public List<TypeCheckData> getTypeChecks() { | |
78 return typeChecks; | |
79 } | |
80 | |
81 public TypeSystemData getTypeSystem() { | |
82 return typeSystem; | |
83 } | |
84 | |
85 public TypeMirror getPrimitiveType() { | |
86 return primitiveType; | |
87 } | |
88 | |
89 public TypeMirror getBoxedType() { | |
90 return boxedType; | |
91 } | |
92 | |
93 public boolean isGeneric() { | |
94 return Utils.typeEquals(boxedType, getTypeSystem().getGenericType()); | |
95 } | |
96 | |
97 public boolean isVoid() { | |
98 if (getTypeSystem().getVoidType() == null) { | |
99 return false; | |
100 } | |
101 return Utils.typeEquals(boxedType, getTypeSystem().getVoidType().getBoxedType()); | |
102 } | |
103 | |
104 @Override | |
105 public String toString() { | |
106 return getClass().getSimpleName() + "[" + Utils.getSimpleName(primitiveType) + "]"; | |
107 } | |
108 | |
109 public boolean equalsType(TypeData actualTypeData) { | |
110 return Utils.typeEquals(boxedType, actualTypeData.boxedType); | |
111 } | |
112 | |
113 public boolean needsCastTo(ProcessorContext context, TypeData targetType) { | |
114 if (this.equals(targetType)) { | |
115 return false; | |
116 } else if (targetType.isGeneric()) { | |
117 return false; | |
118 } else if (targetType.isVoid()) { | |
119 return false; | |
120 } else if (Utils.isAssignable(context, getPrimitiveType(), targetType.getPrimitiveType())) { | |
121 return false; | |
122 } | |
123 return true; | |
124 } | |
125 | |
126 public boolean isPrimitive() { | |
127 return Utils.isPrimitive(getPrimitiveType()); | |
128 } | |
129 | |
130 } |