Mercurial > hg > graal-compiler
diff 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 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemParser.java Fri Sep 06 16:11:15 2013 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeSystemParser.java Fri Sep 06 16:16:40 2013 +0200 @@ -71,7 +71,7 @@ } typeSystem.setTypes(parseTypes(typeSystem)); - if (typeSystem.getTypes() == null) { + if (typeSystem.hasErrors()) { return typeSystem; } @@ -91,6 +91,8 @@ if (casts == null || checks == null || implicitCasts == null) { return typeSystem; } + + typeSystem.setImplicitCasts(implicitCasts); typeSystem.setCasts(casts); typeSystem.setChecks(checks); @@ -106,6 +108,7 @@ cast.getTargetType().addTypeCast(cast); } + verifyImplicitCasts(typeSystem); verifyGenericTypeChecksAndCasts(typeSystem); verifyMethodSignatures(typeSystem); verifyNamesUnique(typeSystem); @@ -113,6 +116,24 @@ return typeSystem; } + private static void verifyImplicitCasts(TypeSystemData typeSystem) { + Set<TypeData> types = new HashSet<>(); + Set<TypeData> duplicateSourceTypes = new HashSet<>(); + for (ImplicitCastData cast : typeSystem.getImplicitCasts()) { + if (types.contains(cast.getSourceType())) { + duplicateSourceTypes.add(cast.getSourceType()); + } + types.add(cast.getSourceType()); + } + for (TypeData duplicateType : duplicateSourceTypes) { + for (ImplicitCastData cast : typeSystem.getImplicitCasts()) { + if (cast.getSourceType().equals(duplicateType)) { + cast.addError("Duplicate cast source type %s.", Utils.getSimpleName(duplicateType.getPrimitiveType()), ImplicitCast.class.getSimpleName()); + } + } + } + } + private static void verifyGenericTypeChecksAndCasts(TypeSystemData typeSystem) { for (TypeData type : typeSystem.getTypes()) { if (!type.getTypeChecks().isEmpty()) {