Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemParser.java @ 11545:2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 16:16:40 +0200 |
parents | 43eab069ca9b |
children | e08a9328ce92 |
comparison
equal
deleted
inserted
replaced
11544:e5b5a5cb0ac7 | 11545:2fb276f5e3e9 |
---|---|
69 if (typeSystem.hasErrors()) { | 69 if (typeSystem.hasErrors()) { |
70 return typeSystem; | 70 return typeSystem; |
71 } | 71 } |
72 | 72 |
73 typeSystem.setTypes(parseTypes(typeSystem)); | 73 typeSystem.setTypes(parseTypes(typeSystem)); |
74 if (typeSystem.getTypes() == null) { | 74 if (typeSystem.hasErrors()) { |
75 return typeSystem; | 75 return typeSystem; |
76 } | 76 } |
77 | 77 |
78 TypeMirror genericType = context.getType(Object.class); | 78 TypeMirror genericType = context.getType(Object.class); |
79 TypeData voidType = new TypeData(typeSystem, typeSystem.getTypes().size(), null, context.getType(void.class), context.getType(Void.class)); | 79 TypeData voidType = new TypeData(typeSystem, typeSystem.getTypes().size(), null, context.getType(void.class), context.getType(Void.class)); |
89 List<TypeCheckData> checks = new TypeCheckParser(context, typeSystem).parse(elements); | 89 List<TypeCheckData> checks = new TypeCheckParser(context, typeSystem).parse(elements); |
90 | 90 |
91 if (casts == null || checks == null || implicitCasts == null) { | 91 if (casts == null || checks == null || implicitCasts == null) { |
92 return typeSystem; | 92 return typeSystem; |
93 } | 93 } |
94 | |
95 typeSystem.setImplicitCasts(implicitCasts); | |
94 typeSystem.setCasts(casts); | 96 typeSystem.setCasts(casts); |
95 typeSystem.setChecks(checks); | 97 typeSystem.setChecks(checks); |
96 | 98 |
97 if (typeSystem.hasErrors()) { | 99 if (typeSystem.hasErrors()) { |
98 return typeSystem; | 100 return typeSystem; |
104 | 106 |
105 for (TypeCastData cast : casts) { | 107 for (TypeCastData cast : casts) { |
106 cast.getTargetType().addTypeCast(cast); | 108 cast.getTargetType().addTypeCast(cast); |
107 } | 109 } |
108 | 110 |
111 verifyImplicitCasts(typeSystem); | |
109 verifyGenericTypeChecksAndCasts(typeSystem); | 112 verifyGenericTypeChecksAndCasts(typeSystem); |
110 verifyMethodSignatures(typeSystem); | 113 verifyMethodSignatures(typeSystem); |
111 verifyNamesUnique(typeSystem); | 114 verifyNamesUnique(typeSystem); |
112 | 115 |
113 return typeSystem; | 116 return typeSystem; |
117 } | |
118 | |
119 private static void verifyImplicitCasts(TypeSystemData typeSystem) { | |
120 Set<TypeData> types = new HashSet<>(); | |
121 Set<TypeData> duplicateSourceTypes = new HashSet<>(); | |
122 for (ImplicitCastData cast : typeSystem.getImplicitCasts()) { | |
123 if (types.contains(cast.getSourceType())) { | |
124 duplicateSourceTypes.add(cast.getSourceType()); | |
125 } | |
126 types.add(cast.getSourceType()); | |
127 } | |
128 for (TypeData duplicateType : duplicateSourceTypes) { | |
129 for (ImplicitCastData cast : typeSystem.getImplicitCasts()) { | |
130 if (cast.getSourceType().equals(duplicateType)) { | |
131 cast.addError("Duplicate cast source type %s.", Utils.getSimpleName(duplicateType.getPrimitiveType()), ImplicitCast.class.getSimpleName()); | |
132 } | |
133 } | |
134 } | |
114 } | 135 } |
115 | 136 |
116 private static void verifyGenericTypeChecksAndCasts(TypeSystemData typeSystem) { | 137 private static void verifyGenericTypeChecksAndCasts(TypeSystemData typeSystem) { |
117 for (TypeData type : typeSystem.getTypes()) { | 138 for (TypeData type : typeSystem.getTypes()) { |
118 if (!type.getTypeChecks().isEmpty()) { | 139 if (!type.getTypeChecks().isEmpty()) { |