use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method setTypeForElseVariable.
private void setTypeForElseVariable(Tree.Variable var, Tree.Switched switched) {
Type switchExpressionType = getSwitchedExpressionType(switched);
Tree.SwitchCaseList switchCaseList = switchCaseList();
if (switchExpressionType != null && switchCaseList != null) {
if (!isTypeUnknown(switchExpressionType)) {
Type caseUnionType = caseUnionType(switchCaseList);
if (caseUnionType != null) {
Type complementType = switchExpressionType.minus(caseUnionType);
complementType = unit.denotableType(complementType);
Value dec = var.getDeclarationModel();
if (!isCompletelyVisible(dec, complementType)) {
complementType = switchExpressionType;
}
Tree.Type local = var.getType();
local.setTypeModel(complementType);
dec.setType(complementType);
if (local instanceof Tree.LocalModifier && switchHasUncheckedNulls(switched) && caseUnionType.isSubtypeOf(unit.getObjectType())) {
handleUncheckedNulls((Tree.LocalModifier) local, complementType, // TODO!!!
switched.getExpression(), dec);
} else {
dec.setUncheckedNullType(false);
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ValueDeclarationImpl method applyInternal.
protected <Get, Set> ceylon.language.meta.model.Value<Get, Set> applyInternal(TypeDescriptor $reifiedGet, TypeDescriptor $reifiedSet, ceylon.language.meta.model.Type<?> container) {
org.eclipse.ceylon.model.typechecker.model.Value modelDecl = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
Type qType;
if (getStatic()) {
qType = ((ClassImpl) container).producedType;
} else {
qType = null;
}
org.eclipse.ceylon.model.typechecker.model.TypedReference typedReference = modelDecl.appliedTypedReference(qType, Collections.<Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type getType = typedReference.getType();
TypeDescriptor reifiedGet = Metamodel.getTypeDescriptorForProducedType(getType);
// immutable values have Set=Nothing
org.eclipse.ceylon.model.typechecker.model.Type setType = getVariable() ? getType : modelDecl.getUnit().getNothingType();
TypeDescriptor reifiedSet = getVariable() ? reifiedGet : TypeDescriptor.NothingType;
Metamodel.checkReifiedTypeArgument("apply", "Value<$1,$2>", Variance.OUT, getType, $reifiedGet, Variance.IN, setType, $reifiedSet);
return new ValueImpl<Get, Set>(reifiedGet, reifiedSet, this, typedReference, container, null);
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ForGenerator method generateForLoop.
/**
* Generates code for the beginning of a "for" loop, returning the name of the variable used for the item.
*/
private String generateForLoop(Tree.ForIterator that, boolean hasElse, Set<Value> capturedValues) {
final Tree.SpecifierExpression iterable = that.getSpecifierExpression();
final String itemVar;
boolean captured = false;
if (that instanceof Tree.ValueIterator) {
final Value val = ((Tree.ValueIterator) that).getVariable().getDeclarationModel();
captured = val.isJsCaptured();
if (captured) {
itemVar = gen.getNames().createTempVariable();
capturedValues.add(val);
} else {
itemVar = gen.getNames().name(val);
}
} else {
itemVar = gen.getNames().createTempVariable();
}
boolean isNative = iterateNative(iterable.getExpression().getTerm(), itemVar);
if (!isNative) {
final boolean checkEntered = that.getUnit().isNonemptyIterableType(iterable.getExpression().getTerm().getTypeModel());
if (hasElse || !optimize(iterable, itemVar)) {
gen.out("var ", itemVar);
if (checkEntered) {
enteredVar = gen.getNames().createTempVariable();
gen.out(",", enteredVar);
}
gen.out(";for(var ", iterVar, "=");
iterable.visit(gen);
gen.out(".iterator();(", itemVar, "=", iterVar, ".next())!==", gen.getClAlias(), "finished();)");
}
gen.beginBlock();
if (enteredVar != null) {
gen.out(enteredVar, "=true;");
}
}
if (that instanceof Tree.ValueIterator) {
if (captured) {
gen.out("var ", gen.getNames().name(((Tree.ValueIterator) that).getVariable().getDeclarationModel()), "=", itemVar, ";");
}
directAccess.add(((Tree.ValueIterator) that).getVariable().getDeclarationModel());
} else if (that instanceof Tree.PatternIterator) {
gen.out("var ");
Destructurer d = new Destructurer(((Tree.PatternIterator) that).getPattern(), gen, directAccess, itemVar, true, false);
if (d.getCapturedValues() != null) {
capturedValues.addAll(d.getCapturedValues());
}
gen.endLine(true);
}
return itemVar;
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class GenerateJsVisitor method visit.
@Override
public void visit(final Tree.ObjectDefinition that) {
if (errVisitor.hasErrors(that))
return;
if (NativeUtil.isNativeHeader(that) && ModelUtil.getNativeDeclaration(that.getDeclarationModel(), Backend.JavaScript) != null) {
// It's a native header, remember it for later when we deal with its implementation
headers.put(that.getDeclarationModel().getQualifiedNameString(), that);
return;
}
// To accept this object it is either not native or native for this backend
if (!(NativeUtil.isForBackend(that, Backend.JavaScript) || NativeUtil.isHeaderWithoutBackend(that, Backend.JavaScript))) {
return;
}
Value d = that.getDeclarationModel();
if (!(opts.isOptimize() && d.isClassOrInterfaceMember())) {
comment(that);
Singletons.objectDefinition(that, this, null);
} else {
// Don't even bother with nodes that have errors
if (errVisitor.hasErrors(that))
return;
Class c = (Class) d.getTypeDeclaration();
// Skip static objects
if (d.isStatic())
return;
comment(that);
outerSelf(d);
out(".", names.privateName(d), "=");
outerSelf(d);
out(".", names.name(c), "()");
endLine(true);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class GenerateJsVisitor method forgetCapturedValues.
void forgetCapturedValues(Set<Value> caps) {
if (caps == null) {
return;
}
for (Value v : caps) {
directAccess.remove(v);
names.forceName(v, null);
}
}
Aggregations