use of org.eclipse.ceylon.model.typechecker.model.ConditionScope in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Resource that) {
ConditionScope cb = new ConditionScope();
cb.setId(id++);
that.setScope(cb);
visitElement(that, cb);
enterScope(cb);
super.visit(that);
}
use of org.eclipse.ceylon.model.typechecker.model.ConditionScope in project ceylon by eclipse.
the class StatementTransformer method transform.
public JCTree transform(CustomTree.GuardedVariable that) {
BoxingStrategy boxingStrategy = CodegenUtil.getBoxingStrategy(that.getDeclarationModel());
Tree.Expression expr = that.getSpecifierExpression().getExpression();
Type fromType = expr.getTypeModel();
Value newValue = that.getDeclarationModel();
Type toType = newValue.getType();
Tree.ConditionList conditionList = that.getConditionList();
Tree.Condition condition = conditionList.getConditions().get(0);
JCExpression val = expressionGen().transformExpression(expr, newValue.hasUncheckedNullType() ? ExpressionTransformer.EXPR_TARGET_ACCEPTS_NULL : 0);
at(that);
if (condition instanceof Tree.IsCondition) {
if (!willEraseToObject(toType)) {
// Want raw type for instanceof since it can't be used with generic types
JCExpression rawToTypeExpr = makeJavaType(toType, JT_NO_PRIMITIVES | JT_RAW);
// Substitute variable with the correct type to use in the rest of the code block
val = make().TypeCast(rawToTypeExpr, val);
if (CodegenUtil.isUnBoxed(newValue) && canUnbox(toType)) {
val = unboxType(val, toType);
}
}
} else if (condition instanceof Tree.ExistsCondition) {
Type exprType = fromType;
if (isOptional(exprType)) {
exprType = typeFact().getDefiniteType(exprType);
}
val = expressionGen().applyErasureAndBoxing(val, exprType, CodegenUtil.hasTypeErased(expr), true, CodegenUtil.hasUntrustedType(expr), boxingStrategy, toType, 0);
} else if (condition instanceof Tree.NonemptyCondition) {
Type exprType = fromType;
if (isOptional(exprType)) {
exprType = typeFact().getDefiniteType(exprType);
}
val = expressionGen().applyErasureAndBoxing(val, exprType, false, true, BoxingStrategy.BOXED, toType, ExpressionTransformer.EXPR_DOWN_CAST);
}
SyntheticName alias = naming.alias(that.getIdentifier().getText());
Substitution subst = naming.addVariableSubst(newValue, alias.getName());
// FIXME: this is rubbish, but the same rubbish from assert. it's most likely wrong there too
Scope scope = that.getScope().getScope();
while (scope instanceof ConditionScope) {
scope = scope.getScope();
}
subst.scopeClose(scope);
JCExpression varType = makeJavaType(toType);
return make().VarDef(make().Modifiers(FINAL), alias.asName(), varType, val);
}
use of org.eclipse.ceylon.model.typechecker.model.ConditionScope in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Condition that) {
ConditionScope cb = new ConditionScope();
cb.setId(id++);
that.setScope(cb);
visitElement(that, cb);
enterScope(cb);
super.visit(that);
}
use of org.eclipse.ceylon.model.typechecker.model.ConditionScope in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Variable that) {
if (that instanceof CustomTree.GuardedVariable) {
ConditionScope cb = new ConditionScope();
cb.setId(id++);
that.setScope(cb);
visitElement(that, cb);
enterScope(cb);
}
Tree.SpecifierExpression se = that.getSpecifierExpression();
if (se != null) {
Scope s = scope;
if (scope instanceof ControlBlock) {
ControlBlock block = (ControlBlock) scope;
if (!block.isLet()) {
scope = scope.getContainer();
}
}
se.visit(this);
scope = s;
}
Tree.Type type = that.getType();
Value v = new Value();
that.setDeclarationModel(v);
visitDeclaration(that, v, !(type instanceof Tree.SyntheticVariable));
ModelUtil.setVisibleScope(v);
if (type != null) {
type.visit(this);
}
Tree.Identifier identifier = that.getIdentifier();
if (identifier != null) {
identifier.visit(this);
}
// TODO: scope should be the variable, not the
// containing control structure:
Tree.AnnotationList al = that.getAnnotationList();
if (al != null) {
al.visit(this);
}
List<Tree.ParameterList> pls = that.getParameterLists();
for (Tree.ParameterList pl : pls) {
pl.visit(this);
}
if (pls.isEmpty()) {
if (type instanceof Tree.FunctionModifier) {
type.addError("variables with no parameters may not be declared using the keyword 'function'");
}
if (type instanceof Tree.VoidModifier) {
type.addError("variables with no parameters may not be declared using the keyword 'void'");
}
} else {
Tree.ParameterList pl = pls.get(0);
pl.addUnsupportedError("variables with parameter lists are not yet supported");
if (type instanceof Tree.ValueModifier) {
type.addError("variables with parameters may not be declared using the keyword 'value'");
}
}
that.setScope(scope);
that.setUnit(unit);
}
use of org.eclipse.ceylon.model.typechecker.model.ConditionScope in project ceylon by eclipse.
the class StatementTransformer method transformBlock.
public List<JCStatement> transformBlock(Tree.Block block, boolean revertRet) {
if (block == null) {
return List.<JCStatement>nil();
}
at(block);
CeylonVisitor v = gen().visitor;
final ListBuffer<JCTree> prevDefs = v.defs;
final boolean prevInInitializer = v.inInitializer;
final ClassDefinitionBuilder prevClassBuilder = v.classBuilder;
Tree.Block oldBlock = block;
currentBlock = block;
List<JCStatement> result;
try {
v.defs = new ListBuffer<JCTree>();
v.inInitializer = false;
v.classBuilder = current();
pushBlockImports(block);
java.util.Iterator<Statement> statements = block.getStatements().iterator();
while (statements.hasNext()) {
Tree.Statement stmt = statements.next();
Transformer<JCStatement, Return> returnTransformer;
if (revertRet && stmt instanceof Tree.Declaration) {
returnTransformer = returnTransformer(defaultReturnTransformer);
} else {
returnTransformer = this.returnTransformer;
}
try {
HasErrorException error = errors().getFirstErrorBlock(stmt);
if (error == null) {
stmt.visit(v);
} else {
v.append(this.makeThrowUnresolvedCompilationError(error));
break;
}
} finally {
returnTransformer(returnTransformer);
}
}
popBlockImports(block);
result = (List<JCStatement>) v.getResult().toList();
Runnable r = onEndBlock.get(block);
if (r != null) {
r.run();
}
} finally {
v.classBuilder = prevClassBuilder;
v.inInitializer = prevInInitializer;
v.defs = prevDefs;
// Close Substitutions which were scoped to this block
Scope scope = block.getScope();
while (scope instanceof ConditionScope) {
scope = scope.getScope();
}
naming.closeScopedSubstitutions(scope);
currentBlock = oldBlock;
}
return result;
}
Aggregations