use of com.redhat.ceylon.model.typechecker.model.Reference in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transform.
public JCExpression transform(Tree.InvocationExpression ce) {
JCExpression ret = checkForInvocationExpressionOptimisation(ce);
if (ret != null)
return ret;
Tree.Term primary = Decl.unwrapExpressionsUntilTerm(ce.getPrimary());
Declaration primaryDeclaration = null;
Reference producedReference = null;
if (primary instanceof Tree.MemberOrTypeExpression) {
producedReference = ((Tree.MemberOrTypeExpression) primary).getTarget();
primaryDeclaration = ((Tree.MemberOrTypeExpression) primary).getDeclaration();
}
Invocation invocation;
if (ce.getPositionalArgumentList() != null) {
if ((isIndirectInvocation(ce) || isWithinDefaultParameterExpression(primaryDeclaration.getContainer())) && !Decl.isJavaStaticOrInterfacePrimary(ce.getPrimary())) {
// indirect invocation
invocation = new IndirectInvocation(this, primary, primaryDeclaration, ce);
} else {
// direct invocation
java.util.List<Parameter> parameters = ((Functional) primaryDeclaration).getFirstParameterList().getParameters();
invocation = new PositionalInvocation(this, primary, primaryDeclaration, producedReference, ce, parameters);
}
} else if (ce.getNamedArgumentList() != null) {
invocation = new NamedArgumentInvocation(this, primary, primaryDeclaration, producedReference, ce);
} else {
return makeErroneous(ce, "no arguments");
}
return transformInvocation(invocation);
}
use of com.redhat.ceylon.model.typechecker.model.Reference in project ceylon-compiler by ceylon.
the class ClassTransformer method addMissingUnrefinedMembers.
/**
* Recover from members not being refined in the class hierarchy
* by generating a stub method that throws.
*/
private void addMissingUnrefinedMembers(Node def, Class classModel, ClassDefinitionBuilder classBuilder) {
for (Reference unrefined : classModel.getUnimplementedFormals()) {
//classModel.getMember(memberName, null, false);
Declaration formalMember = unrefined.getDeclaration();
String errorMessage = "formal member '" + formalMember.getName() + "' of '" + ((TypeDeclaration) formalMember.getContainer()).getName() + "' not implemented in class hierarchy";
java.util.List<Type> params = new java.util.ArrayList<Type>();
if (formalMember instanceof Generic) {
for (TypeParameter tp : ((Generic) formalMember).getTypeParameters()) {
params.add(tp.getType());
}
}
if (formalMember instanceof Value) {
addRefinedThrowerAttribute(classBuilder, errorMessage, classModel, (Value) formalMember);
} else if (formalMember instanceof Function) {
addRefinedThrowerMethod(classBuilder, errorMessage, classModel, (Function) formalMember);
} else if (formalMember instanceof Class && formalMember.isClassMember()) {
addRefinedThrowerInstantiatorMethod(classBuilder, errorMessage, classModel, (Class) formalMember, unrefined);
}
// formal member class of interface handled in
// makeDelegateToCompanion()
}
}
use of com.redhat.ceylon.model.typechecker.model.Reference in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method makeVarRefArgumentList.
// Make a list of ($arg0, $arg1, ... , $argN)
// or ($arg$this$, $arg0, $arg1, ... , $argN)
private List<JCExpression> makeVarRefArgumentList(Parameter param) {
ListBuffer<JCExpression> names = ListBuffer.<JCExpression>lb();
if (!Strategy.defaultParameterMethodStatic(getPrimaryDeclaration()) && Strategy.defaultParameterMethodTakesThis(param.getModel())) {
names.append(varBaseName.suffixedBy(Suffix.$argthis$).makeIdent());
}
// put all the required reified type args too
Reference ref = gen.resolveAliasesForReifiedTypeArguments(producedReference);
int tpCount = gen.getTypeParameters(ref).size();
for (int tpIndex = 0; tpIndex < tpCount; tpIndex++) {
names.append(reifiedTypeArgName(tpIndex).makeIdent());
}
final int parameterIndex = parameterIndex(param);
for (int ii = 0; ii < parameterIndex; ii++) {
names.append(this.argsNamesByIndex.get(ii).makeIdent());
}
return names.toList();
}
use of com.redhat.ceylon.model.typechecker.model.Reference in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method addReifiedArguments.
@Override
protected void addReifiedArguments(ListBuffer<ExpressionAndType> result) {
Reference ref = gen.resolveAliasesForReifiedTypeArguments(producedReference);
if (!gen.supportsReified(ref.getDeclaration()))
return;
int tpCount = gen.getTypeParameters(ref).size();
for (int tpIndex = 0; tpIndex < tpCount; tpIndex++) {
result.append(new ExpressionAndType(reifiedTypeArgName(tpIndex).makeIdent(), gen.makeTypeDescriptorType()));
}
}
use of com.redhat.ceylon.model.typechecker.model.Reference in project ceylon-compiler by ceylon.
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()) {
if (Decl.withinClassOrInterface(getPrimaryDeclaration())) {
// a member method
thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
defaultedParameterInstance = gen.naming.makeThis();
} else {
// a local or toplevel function
thisType = gen.naming.makeName((TypedDeclaration) getPrimaryDeclaration(), Naming.NA_WRAPPER);
defaultedParameterInstance = gen.naming.makeName((TypedDeclaration) getPrimaryDeclaration(), 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;
}
Aggregations