use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class StatementTransformer method closeInnerSubstituionsForSpecifiedValues.
/**
* Removes the "inner substitutions" for any deferred values specified
* in the given control block
*/
private void closeInnerSubstituionsForSpecifiedValues(Tree.ControlClause contolClause) {
if (contolClause != null) {
ControlBlock controlBlock = contolClause.getControlBlock();
java.util.Set<Value> assigned = controlBlock.getSpecifiedValues();
if (assigned != null) {
for (Value value : assigned) {
DeferredSpecification ds = statementGen().getDeferredSpecification(value);
if (ds != null) {
ds.closeInnerSubstitution();
}
}
}
}
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class LocalTypeVisitor method visit.
@Override
public void visit(Tree.AttributeGetterDefinition that) {
Value model = that.getDeclarationModel();
collect(that, model);
// stop at locals, who get a type generated for them
if (model.isMember())
super.visit(that);
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class MethodDefinitionBuilder method getNonWideningParam.
public NonWideningParam getNonWideningParam(TypedReference typedRef, WideningRules wideningRules) {
TypedDeclaration nonWideningDecl = null;
int flags = 0;
Type nonWideningType;
FunctionOrValue mov = (FunctionOrValue) typedRef.getDeclaration();
if (Decl.isValue(mov)) {
TypedReference nonWideningTypedRef = gen.nonWideningTypeDecl(typedRef);
nonWideningType = gen.nonWideningType(typedRef, nonWideningTypedRef);
nonWideningDecl = nonWideningTypedRef.getDeclaration();
} else {
// Stef: So here's the thing. I know this is wrong for Function where we should do getFullType(), BUT
// lots of methods call this and then feed the output into AT.makeJavaType(TypedDeclaration typeDecl, Type type, int flags)
// which adds the Callable type, so if we fix it here we have to remove it from there and there's lots of callers of that
// function which rely on its behaviour and frankly I've had enough of this refactoring, so a few callers of this function
// have to add the Callable back. It sucks, yeah, but so far it works, which is amazing enough that I don't want to touch it
// any more. More ambitious/courageous people are welcome to fix this properly.
nonWideningType = typedRef.getType();
nonWideningDecl = mov;
}
if (!CodegenUtil.isUnBoxed(nonWideningDecl))
flags |= AbstractTransformer.JT_NO_PRIMITIVES;
// make sure we don't accidentally narrow value parameters that would be erased in the topmost declaration
if (wideningRules != WideningRules.NONE && mov instanceof Value) {
TypedDeclaration refinedParameter = (TypedDeclaration) CodegenUtil.getTopmostRefinedDeclaration(mov);
// mixin bridge methods have the same rules as when refining stuff except they are their own refined decl
if (wideningRules == WideningRules.FOR_MIXIN || !Decl.equal(refinedParameter, mov)) {
Type refinedParameterType;
// in the refined parameter type
if (refinedParameter instanceof Function)
refinedParameterType = refinedParameter.appliedTypedReference(null, Collections.<Type>emptyList()).getFullType();
else
refinedParameterType = refinedParameter.getType();
// if the supertype method itself got erased to Object, we can't do better than this
if (gen.willEraseToObject(refinedParameterType) && !gen.willEraseToBestBounds(mov))
nonWideningType = gen.typeFact().getObjectType();
else if (CodegenUtil.isRaw(refinedParameter)) {
flags |= AbstractTransformer.JT_RAW;
} else {
flags |= AbstractTransformer.JT_NARROWED;
}
}
}
// keep in sync with gen.willEraseToBestBounds()
if (wideningRules != WideningRules.NONE && (gen.typeFact().isUnion(nonWideningType) || gen.typeFact().isIntersection(nonWideningType))) {
final Type refinedType = ((TypedDeclaration) CodegenUtil.getTopmostRefinedDeclaration(nonWideningDecl)).getType();
if (refinedType.isTypeParameter() && !refinedType.getSatisfiedTypes().isEmpty()) {
nonWideningType = refinedType.getSatisfiedTypes().get(0);
// Could be parameterized, and type param won't be in scope, so have to go raw
flags |= AbstractTransformer.JT_RAW;
}
}
// this is to be done on the parameter's containing method, to see if that method must have raw parameters
if (mov.isParameter() && mov.getContainer() instanceof Declaration && gen.rawParameters((Declaration) mov.getContainer())) {
flags |= AbstractTransformer.JT_RAW;
}
return new NonWideningParam(flags, nonWideningType, nonWideningDecl);
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class DeclarationErrorVisitor method planAccordingToErrors.
/**
* Update the plan according to the errors on the node
*/
private void planAccordingToErrors(Node that) {
List<Message> errors = that.getErrors();
for (Message message : errors) {
if (isError(that, message)) {
TransformationPlan plan;
/*if (message.getCode() == MEMBER_HAS_WRONG_NUMBER_OF_PARAMETERS
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else if (message.getCode() == TYPE_OF_PARAMETER_IS_DIFFERENT_TO_CORRESPONDING_PARAMETER
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else if (message.getCode() == COULD_NOT_DETERMINE_PARAMETER_TYPE_SAME_AS_CORRESPONDING_PARAMETER
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else if ((message.getCode() == REFINED_MEMBER_WRONG_NUM_PL
|| message.getCode() == MISSING_PL_FUNCTION_DECL)
&& model.isActual()
&& model.isClassMember()) {
plan = new ThrowerMethod(that, message);
} else*/
if (message.getCode() == FORMAL_MEMBER_UNIMPLEMENTED_IN_CLASS_HIERARCHY && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
plan = new ThrowerMethod(that, message);
} else if (message.getCode() == PL_AND_CONSTRUCTORS && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
plan = new ThrowerCatchallConstructor(that, message);
} else {
plan = new Drop(that, message);
}
newplan(plan);
}
}
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class MethodOrValueReferenceVisitor method capture.
private void capture(Tree.Primary that, boolean methodSpecifier) {
if (that instanceof Tree.MemberOrTypeExpression) {
final Declaration decl = ((Tree.MemberOrTypeExpression) that).getDeclaration();
if (!(decl instanceof TypedDeclaration)) {
return;
}
TypedDeclaration d = (TypedDeclaration) decl;
if (Decl.equal(d, declaration) || (d.isNativeHeader() && d.getOverloads().contains(declaration))) {
d = declaration;
if (Decl.isParameter(d)) {
// a reference from a default argument
// expression of the same parameter
// list does not capture a parameter
Scope s = that.getScope();
boolean sameScope = d.getContainer().equals(s) || (s instanceof Declaration && (Decl.isParameter((Declaration) s) || (s instanceof Value && !((Value) s).isTransient())) && d.getContainer().equals(s.getScope()));
if (!sameScope || methodSpecifier || inLazySpecifierExpression) {
((FunctionOrValue) d).setCaptured(true);
}
// Accessing another instance's member passed to a class initializer
if (that instanceof Tree.QualifiedMemberExpression) {
if (d instanceof TypedDeclaration && ((TypedDeclaration) d).getOtherInstanceAccess()) {
((FunctionOrValue) d).setCaptured(true);
}
}
if (isCapturableMplParameter(d)) {
((FunctionOrValue) d).setCaptured(true);
}
} else if (Decl.isValue(d) || Decl.isGetter(d)) {
Value v = (Value) d;
v.setCaptured(true);
if (Decl.isObjectValue(d)) {
v.setSelfCaptured(isSelfCaptured(that, d));
}
if (v.getSetter() != null) {
v.getSetter().setCaptured(true);
}
} else if (d instanceof Function) {
((Function) d).setCaptured(true);
}
/*if (d.isVariable() && !d.isClassMember() && !d.isToplevel()) {
that.addError("access to variable local from capturing scope: " + declaration.getName());
}*/
}
}
}
Aggregations