Skip to content

Commit

Permalink
TypeFactory #1052: Added methods to get Boolean decls from the TypeFa…
Browse files Browse the repository at this point in the history
…ctory rather than from the model loader directly
  • Loading branch information
FroMage committed May 28, 2013
1 parent 75ac6b7 commit cf1660f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
Expand Up @@ -41,7 +41,6 @@
import com.redhat.ceylon.compiler.java.loader.TypeFactory;
import com.redhat.ceylon.compiler.java.tools.CeylonLog;
import com.redhat.ceylon.compiler.loader.AbstractModelLoader;
import com.redhat.ceylon.compiler.loader.ModelLoader.DeclarationType;
import com.redhat.ceylon.compiler.typechecker.model.Annotation;
import com.redhat.ceylon.compiler.typechecker.model.Class;
import com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface;
Expand Down Expand Up @@ -440,11 +439,11 @@ private JCExpression makeLetExpr(String varBaseName, List<JCStatement> statement
*/

boolean isBooleanTrue(Declaration decl) {
return decl == loader().getDeclaration("ceylon.language.true", DeclarationType.VALUE);
return decl == typeFact.getBooleanTrueDeclaration();
}

boolean isBooleanFalse(Declaration decl) {
return decl == loader().getDeclaration("ceylon.language.false", DeclarationType.VALUE);
return decl == typeFact.getBooleanFalseDeclaration();
}

/**
Expand Down Expand Up @@ -669,7 +668,7 @@ private ProducedTypedReference getRefinedTypedReference(ProducedType qualifyingT
}

public boolean isWidening(ProducedType declType, ProducedType refinedDeclType) {
return !sameType(syms().ceylonObjectType, declType)
return !sameTypeForCeylonTypes(syms().ceylonObjectType, declType)
&& willEraseToObject(declType)
&& !willEraseToObject(refinedDeclType);
}
Expand Down Expand Up @@ -782,12 +781,12 @@ ProducedType nonWideningType(ProducedTypedReference declaration, ProducedTypedRe
return pr.getType();
}

private ProducedType toPType(com.sun.tools.javac.code.Type t) {
return loader().getType(t.tsym.packge().getQualifiedName().toString(), t.tsym.getQualifiedName().toString(), null);
private ProducedType javacCeylonTypeToProducedType(com.sun.tools.javac.code.Type t) {
return loader().getType(getLanguageModule(), t.tsym.packge().getQualifiedName().toString(), t.tsym.getQualifiedName().toString(), null);
}

private boolean sameType(Type t1, ProducedType t2) {
return t2 != null && toPType(t1).isExactly(t2);
private boolean sameTypeForCeylonTypes(Type ceylonType, ProducedType otherType) {
return otherType != null && javacCeylonTypeToProducedType(ceylonType).isExactly(otherType);
}

/**
Expand Down Expand Up @@ -822,7 +821,7 @@ boolean willEraseToPrimitive(ProducedType type) {

boolean willEraseToException(ProducedType type) {
type = simplifyType(type);
return (sameType(syms().ceylonExceptionType, type));
return (sameTypeForCeylonTypes(syms().ceylonExceptionType, type));
}

boolean willEraseToSequential(ProducedType type) {
Expand Down Expand Up @@ -971,37 +970,37 @@ private boolean isErasedUnionOrIntersection(ProducedType producedType) {
}

boolean isCeylonString(ProducedType type) {
return (sameType(syms().ceylonStringType, type));
return (sameTypeForCeylonTypes(syms().ceylonStringType, type));
}

boolean isCeylonBoolean(ProducedType type) {
TypeDeclaration declaration = type.getDeclaration();
return declaration != null
&& (sameType(syms().ceylonBooleanType, type)
&& (sameTypeForCeylonTypes(syms().ceylonBooleanType, type)
|| isBooleanTrue(declaration)
|| declaration == loader().getDeclaration("ceylon.language.true", DeclarationType.TYPE)
|| declaration == typeFact.getBooleanTrueClassDeclaration()
|| isBooleanFalse(declaration)
|| declaration == loader().getDeclaration("ceylon.language.false", DeclarationType.TYPE));
|| declaration == typeFact.getBooleanFalseClassDeclaration());
}

boolean isCeylonInteger(ProducedType type) {
return (sameType(syms().ceylonIntegerType, type));
return (sameTypeForCeylonTypes(syms().ceylonIntegerType, type));
}

boolean isCeylonFloat(ProducedType type) {
return (sameType(syms().ceylonFloatType, type));
return (sameTypeForCeylonTypes(syms().ceylonFloatType, type));
}

boolean isCeylonCharacter(ProducedType type) {
return (sameType(syms().ceylonCharacterType, type));
return (sameTypeForCeylonTypes(syms().ceylonCharacterType, type));
}

boolean isCeylonArray(ProducedType type) {
return type.getSupertype(typeFact.getArrayDeclaration()) != null;
}

boolean isCeylonObject(ProducedType type) {
return sameType(syms().ceylonObjectType, type);
return sameTypeForCeylonTypes(syms().ceylonObjectType, type);
}

boolean isCeylonBasicType(ProducedType type) {
Expand Down Expand Up @@ -1413,7 +1412,7 @@ private ListBuffer<JCExpression> makeTypeArgs(boolean isCeylonCallable,
}
JCExpression jta;

if (sameType(syms().ceylonAnythingType, ta)) {
if (sameTypeForCeylonTypes(syms().ceylonAnythingType, ta)) {
// For the root type Void:
if ((flags & (JT_SATISFIES | JT_EXTENDS)) != 0) {
// - The Ceylon type Foo<Void> appearing in an extends or satisfies
Expand Down Expand Up @@ -3039,4 +3038,8 @@ boolean isSequencedAnnotation(Class klass) {
Arrays.asList(typeFact().getAnythingDeclaration().getType(),
typeFact().getNothingDeclaration().getType())));
}

private Module getLanguageModule() {
return loader.getLanguageModule();
}
}
21 changes: 20 additions & 1 deletion src/com/redhat/ceylon/compiler/java/loader/TypeFactory.java
Expand Up @@ -29,16 +29,17 @@
import com.redhat.ceylon.compiler.typechecker.context.Context;
import com.redhat.ceylon.compiler.typechecker.model.Class;
import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.model.Interface;
import com.redhat.ceylon.compiler.typechecker.model.IntersectionType;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.Package;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;
import com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration;
import com.redhat.ceylon.compiler.typechecker.model.TypedDeclaration;
import com.redhat.ceylon.compiler.typechecker.model.UnionType;
import com.redhat.ceylon.compiler.typechecker.model.Unit;
import com.redhat.ceylon.compiler.typechecker.model.UnknownType;
import com.redhat.ceylon.compiler.typechecker.model.Util;
import com.redhat.ceylon.compiler.typechecker.model.Value;
import com.sun.tools.javac.util.List;

public class TypeFactory extends Unit {
Expand Down Expand Up @@ -183,4 +184,22 @@ public Declaration getLanguageModuleMetamodelUntypedDeclaration(String name) {
}
return null;
}

public Declaration getBooleanTrueDeclaration() {
return getLanguageModuleDeclaration("true");
}

public Declaration getBooleanFalseDeclaration() {
return getLanguageModuleDeclaration("false");
}

public TypeDeclaration getBooleanTrueClassDeclaration() {
Declaration trueDecl = getBooleanTrueDeclaration();
return trueDecl instanceof TypedDeclaration ? ((TypedDeclaration)trueDecl).getTypeDeclaration() : null;
}

public TypeDeclaration getBooleanFalseClassDeclaration() {
Declaration trueDecl = getBooleanFalseDeclaration();
return trueDecl instanceof TypedDeclaration ? ((TypedDeclaration)trueDecl).getTypeDeclaration() : null;
}
}

0 comments on commit cf1660f

Please sign in to comment.