use of com.redhat.ceylon.model.typechecker.model.Parameter in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method appendVarsForDefaulted.
private boolean appendVarsForDefaulted(java.util.List<Parameter> declaredParams) {
boolean hasDefaulted = false;
if (!Decl.isOverloaded(getPrimaryDeclaration())) {
// append any arguments for defaulted parameters
for (Parameter param : declaredParams) {
if (bound.contains(param)) {
continue;
}
final JCExpression argExpr;
if (Strategy.hasDefaultParameterValueMethod(param)) {
// special handling for "element" optional param of java array constructors
if (getPrimaryDeclaration() instanceof Class && gen.isJavaArray(((Class) getPrimaryDeclaration()).getType())) {
// default values are hard-coded to Java default values, and are actually ignored
continue;
} else if (getQmePrimary() != null && gen.isJavaArray(getQmePrimary().getTypeModel())) {
// we support array methods with optional parameters
if (getPrimaryDeclaration() instanceof Function && getPrimaryDeclaration().getName().equals("copyTo")) {
if (param.getName().equals("sourcePosition") || param.getName().equals("destinationPosition")) {
argExpr = gen.makeInteger(0);
hasDefaulted |= true;
} else if (param.getName().equals("length")) {
argExpr = gen.makeSelect(varBaseName.suffixedBy(Suffix.$argthis$).makeIdent(), "length");
hasDefaulted |= true;
} else {
argExpr = gen.makeErroneous(this.getNode(), "compiler bug: argument to copyTo method of java array type not supported: " + param.getName());
}
} else {
argExpr = gen.makeErroneous(this.getNode(), "compiler bug: virtual method of java array type not supported: " + getPrimaryDeclaration());
}
} else {
argExpr = makeDefaultedArgumentMethodCall(param);
hasDefaulted |= true;
}
} else if (Strategy.hasEmptyDefaultArgument(param)) {
argExpr = gen.makeEmptyAsSequential(true);
} else if (gen.typeFact().isIterableType(param.getType())) {
// must be an iterable we need to fill with empty
// FIXME: deal with this erasure bug later
argExpr = gen.make().TypeCast(gen.makeJavaType(gen.typeFact().getIterableDeclaration().getType(), AbstractTransformer.JT_RAW), gen.makeEmpty());
} else {
// more expensive but worth a try
Type appliedType = gen.getTypeForParameter(param, producedReference, AbstractTransformer.TP_TO_BOUND);
if (gen.typeFact().isIterableType(appliedType)) {
argExpr = gen.make().TypeCast(gen.makeJavaType(gen.typeFact().getIterableDeclaration().getType(), AbstractTransformer.JT_RAW), gen.makeEmpty());
} else {
argExpr = gen.makeErroneous(this.getNode(), "compiler bug: missing argument, and parameter is not defaulted");
}
}
appendDefaulted(param, argExpr);
}
}
return hasDefaulted;
}
use of com.redhat.ceylon.model.typechecker.model.Parameter in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method getTransformedArgumentExpression.
@Override
protected JCExpression getTransformedArgumentExpression(int argIndex) {
Parameter param = callableParameters.get(argIndex);
// note: we don't deal with unboxing here, as that is taken care of already by CallableBuilder by unboxing the
// Callable arguments into unboxed local vars if required and if it's a value type
String paramName;
if (tempVars) {
paramName = Naming.getCallableTempVarName(param);
} else if (getPrimaryDeclaration() instanceof Class && ((Class) getPrimaryDeclaration()).hasConstructors()) {
paramName = Naming.getAliasedParameterName(param);
} else {
paramName = param.getName();
}
return gen.makeUnquotedIdent(paramName);
}
use of com.redhat.ceylon.model.typechecker.model.Parameter in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method appendVarsForSequencedArguments.
private void appendVarsForSequencedArguments(Tree.SequencedArgument sequencedArgument, java.util.List<Parameter> declaredParams) {
// FIXME: this is suspisciously similar to AbstractTransformer.makeIterable(java.util.List<Tree.PositionalArgument> list, Type seqElemType)
// and possibly needs to be merged
Parameter parameter = sequencedArgument.getParameter();
Type parameterType = parameterType(parameter, parameter.getType(), gen.TP_TO_BOUND);
// find out the individual type, we use the argument type for the value, and the param type for the temp variable
Type tupleType = AnalyzerUtil.getTupleType(sequencedArgument.getPositionalArguments(), gen.typeFact(), false);
Type argumentsType = tupleType.getSupertype(gen.typeFact().getIterableDeclaration());
Type iteratedType = gen.typeFact().getIteratedType(argumentsType);
Type absentType = gen.typeFact().getIteratedAbsentType(argumentsType);
// we can't just generate types like Foo<?> if the target type param is not raw because the bounds will
// not match, so we go raw, we also ignore primitives naturally
int flags = JT_RAW | JT_NO_PRIMITIVES;
JCTree.JCExpression sequenceValue = gen.makeLazyIterable(sequencedArgument, iteratedType, absentType, flags);
JCTree.JCExpression sequenceType = gen.makeJavaType(parameterType, flags);
Naming.SyntheticName argName = argName(parameter);
JCTree.JCVariableDecl varDecl = gen.makeVar(argName, sequenceType, sequenceValue);
gen.at(getPrimary());
bind(parameter, argName, gen.makeJavaType(parameterType, flags), List.<JCTree.JCStatement>of(varDecl));
}
use of com.redhat.ceylon.model.typechecker.model.Parameter in project ceylon-compiler by ceylon.
the class AbstractTransformer method objectVariadicToJavaArray.
private JCExpression objectVariadicToJavaArray(SimpleInvocation invocation, Type type, Type exprType, JCExpression expr, List<JCExpression> initialElements) {
// The type that the java varargs parameter erases to:
// this is the type of the array which we need to construct
java.util.List<Parameter> pl = ((Functional) invocation.getPrimaryDeclaration()).getFirstParameterList().getParameters();
Parameter varargsParameter = pl.get(pl.size() - 1);
Type arrayType = simplifyType(typeFact().getIteratedType(varargsParameter.getType()));
while (arrayType.getDeclaration() instanceof TypeParameter) {
TypeParameter tp = (TypeParameter) arrayType.getDeclaration();
if (tp.getSatisfiedTypes().isEmpty()) {
arrayType = typeFact().getObjectType();
break;
} else {
arrayType = tp.getSatisfiedTypes().get(0);
}
}
// we could have a <X>variadic(X&Object), so we need to pick a type which satisfies the bound
Type castType = simplifyType(type);
if (typeFact().isIntersection(castType)) {
for (Type t : castType.getSatisfiedTypes()) {
if (t.isSubtypeOf(arrayType)) {
castType = t;
break;
}
}
}
Naming.SyntheticName seqName = naming.temp().suffixedBy(0);
Type sequentialType = typeFact().getSequentialDeclaration().appliedType(null, Arrays.asList(type));
JCExpression seqTypeExpr1 = makeJavaType(sequentialType);
//JCExpression seqTypeExpr2 = makeJavaType(fixedSizedType);
JCExpression sizeExpr = make().Apply(List.<JCExpression>nil(), make().Select(seqName.makeIdent(), names().fromString("getSize")), List.<JCExpression>nil());
sizeExpr = utilInvocation().toInt(sizeExpr);
// add initial elements if required
if (!initialElements.isEmpty())
sizeExpr = make().Binary(JCTree.PLUS, sizeExpr, makeInteger(initialElements.size()));
JCExpression array = make().NewArray(makeJavaType(arrayType, JT_RAW | JT_NO_PRIMITIVES), List.of(sizeExpr), null);
if (!arrayType.isExactly(castType)) {
array = make().TypeCast(make().TypeArray(makeJavaType(castType, JT_CLASS_NEW | JT_NO_PRIMITIVES)), array);
}
JCExpression sequenceToArrayExpr = utilInvocation().toArray(seqName.makeIdent(), array, initialElements, makeJavaType(castType, JT_CLASS_NEW | JT_NO_PRIMITIVES));
return //make().TypeArray(makeJavaType(arrayType)),
makeLetExpr(seqName, List.<JCStatement>nil(), seqTypeExpr1, expr, sequenceToArrayExpr);
}
use of com.redhat.ceylon.model.typechecker.model.Parameter in project ceylon-compiler by ceylon.
the class AnnotationLoader method loadAnnotationInvocationArguments.
private void loadAnnotationInvocationArguments(List<AnnotationFieldName> path, LazyFunction method, AnnotationInvocation ai, AnnotationMirror annotationInvocationAnnotation, List<AnnotationMirror> annotationTree, AnnotatedMirror dpm) {
@SuppressWarnings("unchecked") List<Short> argumentCodes = (List<Short>) annotationInvocationAnnotation.getValue(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ARGUMENTS_MEMBER);
if (argumentCodes != null) {
for (int ii = 0; ii < argumentCodes.size(); ii++) {
short code = argumentCodes.get(ii);
AnnotationArgument argument = new AnnotationArgument();
Parameter classParameter = ai.getParameters().get(ii);
argument.setParameter(classParameter);
path.add(argument);
argument.setTerm(loadAnnotationArgumentTerm(path, method, ai, classParameter, annotationTree, dpm, code));
path.remove(path.size() - 1);
ai.getAnnotationArguments().add(argument);
}
}
}
Aggregations