use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression in project ceylon by eclipse.
the class BoxingVisitor method visit.
@Override
public void visit(InvocationExpression that) {
super.visit(that);
if (isIndirectInvocation(that, true) && !Decl.isJavaStaticOrInterfacePrimary(that.getPrimary())) {
// if the Callable is raw the invocation will be erased
if (that.getPrimary().getTypeModel() != null && isRaw(that.getPrimary().getTypeModel()))
CodegenUtil.markTypeErased(that);
// These are always boxed
return;
}
if (isByteLiteral(that))
CodegenUtil.markUnBoxed(that);
else
propagateFromTerm(that, that.getPrimary());
// then we mark the expression itself as erased as well
if (that.getPrimary() instanceof StaticMemberOrTypeExpression) {
StaticMemberOrTypeExpression expr = (StaticMemberOrTypeExpression) that.getPrimary();
if (expr.getDeclaration() instanceof Function) {
Function mth = (Function) expr.getDeclaration();
if (isTypeParameter(mth.getType()) && (hasErasedTypeParameter(expr.getTarget(), expr.getTypeArguments()) || CodegenUtil.isRaw(that))) {
CodegenUtil.markTypeErased(that);
CodegenUtil.markUntrustedType(that);
}
}
}
if (that.getPrimary() instanceof Tree.MemberOrTypeExpression && Decl.isConstructor(((Tree.MemberOrTypeExpression) that.getPrimary()).getDeclaration())) {
Constructor ctor = ModelUtil.getConstructor(((Tree.MemberOrTypeExpression) that.getPrimary()).getDeclaration());
if (Decl.isJavaObjectArrayWith(ctor)) {
CodegenUtil.markTypeErased(that);
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression in project ceylon by eclipse.
the class NamedArgumentInvocation method makeThis.
private final JCVariableDecl makeThis() {
// first append $this
JCExpression defaultedParameterInstance;
// TODO Fix how we figure out the thisType, because it's doesn't
// handle type parameters correctly
// we used to use thisType = gen.getThisType(getPrimaryDeclaration());
final JCExpression thisType;
Reference target = ((Tree.MemberOrTypeExpression) getPrimary()).getTarget();
if (getPrimary() instanceof Tree.BaseMemberExpression && !gen.expressionGen().isWithinSyntheticClassBody()) {
Declaration primaryDec = getPrimaryDeclaration();
if (primaryDec.isClassOrInterfaceMember()) {
// a member method
thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES | (primaryDec.isInterfaceMember() && !primaryDec.isShared() ? JT_COMPANION : 0));
TypeDeclaration outer = Decl.getOuterScopeOfMemberInvocation((StaticMemberOrTypeExpression) getPrimary(), primaryDec);
if (outer instanceof Interface && primaryDec.isShared()) {
defaultedParameterInstance = gen.naming.makeQuotedThis();
} else {
defaultedParameterInstance = gen.naming.makeQualifiedThis(gen.makeJavaType(((TypeDeclaration) outer).getType(), JT_NO_PRIMITIVES | (primaryDec.isInterfaceMember() && !primaryDec.isShared() ? JT_COMPANION : 0)));
}
} else {
// a local or toplevel function
thisType = gen.naming.makeName((TypedDeclaration) primaryDec, Naming.NA_WRAPPER);
defaultedParameterInstance = gen.naming.makeName((TypedDeclaration) primaryDec, Naming.NA_MEMBER);
}
} else if (getPrimary() instanceof Tree.BaseTypeExpression || getPrimary() instanceof Tree.QualifiedTypeExpression) {
TypeDeclaration declaration = (TypeDeclaration) ((Tree.MemberOrTypeExpression) getPrimary()).getDeclaration();
thisType = gen.makeJavaType(declaration.getType(), JT_COMPANION);
defaultedParameterInstance = gen.make().NewClass(null, null, gen.makeJavaType(declaration.getType(), JT_COMPANION), List.<JCExpression>nil(), null);
} else {
if (isOnValueType()) {
thisType = gen.makeJavaType(target.getQualifyingType());
} else {
thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
}
defaultedParameterInstance = callVarName.makeIdent();
}
JCVariableDecl thisDecl = gen.makeVar(varBaseName.suffixedBy(Suffix.$argthis$), thisType, defaultedParameterInstance);
return thisDecl;
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression in project ceylon by eclipse.
the class GenerateJsVisitor method visit.
@Override
public void visit(final Tree.AssignOp that) {
if (errVisitor.hasErrors(that))
return;
String returnValue = null;
StaticMemberOrTypeExpression lhsExpr = null;
final boolean leftDynamic = isInDynamicBlock() && ModelUtil.isTypeUnknown(that.getLeftTerm().getTypeModel());
if (that.getLeftTerm() instanceof Tree.IndexExpression) {
Tree.IndexExpression iex = (Tree.IndexExpression) that.getLeftTerm();
if (leftDynamic) {
iex.getPrimary().visit(this);
out("[");
((Tree.Element) iex.getElementOrRange()).getExpression().visit(this);
out("]=");
that.getRightTerm().visit(this);
} else {
final String tv = createRetainedTempVar();
out("(", tv, "=");
that.getRightTerm().visit(this);
out(",");
iex.getPrimary().visit(this);
TypeDeclaration td = iex.getPrimary().getTypeModel().getDeclaration();
if (td != null && td.inherits(iex.getUnit().getKeyedCorrespondenceMutatorDeclaration())) {
out(".put(");
} else {
out(".set(");
}
((Tree.Element) iex.getElementOrRange()).getExpression().visit(this);
out(",", tv, "), ", tv, ")");
}
return;
}
if (leftDynamic) {
that.getLeftTerm().visit(this);
out("=");
int box = boxUnboxStart(that.getRightTerm(), that.getLeftTerm());
that.getRightTerm().visit(this);
if (box == 4)
out("/*TODO: callable targs 6.2*/");
boxUnboxEnd(box);
return;
}
out("(");
if (that.getLeftTerm() instanceof BaseMemberExpression) {
BaseMemberExpression bme = (BaseMemberExpression) that.getLeftTerm();
lhsExpr = bme;
Declaration bmeDecl = bme.getDeclaration();
boolean simpleSetter = hasSimpleGetterSetter(bmeDecl);
if (!simpleSetter) {
returnValue = memberAccess(bme, null);
}
} else if (that.getLeftTerm() instanceof QualifiedMemberExpression) {
QualifiedMemberExpression qme = (QualifiedMemberExpression) that.getLeftTerm();
lhsExpr = qme;
boolean simpleSetter = hasSimpleGetterSetter(qme.getDeclaration());
String lhsVar = null;
if (!simpleSetter) {
lhsVar = createRetainedTempVar();
out(lhsVar, "=");
super.visit(qme);
out(",", lhsVar, ".");
returnValue = memberAccess(qme, lhsVar);
} else if (qme.getPrimary() instanceof Tree.Package == false) {
super.visit(qme);
out(".");
if (qme.getDeclaration() != null && qme.getDeclaration().isStatic()) {
out("$st$.");
}
}
}
BmeGenerator.generateMemberAccess(lhsExpr, new GenerateCallback() {
@Override
public void generateValue() {
if (!isNaturalLiteral(that.getRightTerm())) {
int boxType = boxUnboxStart(that.getRightTerm(), that.getLeftTerm());
that.getRightTerm().visit(GenerateJsVisitor.this);
if (boxType == 4)
out("/*TODO: callable targs 7*/");
boxUnboxEnd(boxType);
}
}
}, null, this);
if (returnValue != null) {
out(",", returnValue);
}
out(")");
}
Aggregations