use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method visitThrow.
public void visitThrow(JCThrow tree) {
Type owntype = attribExpr(tree.expr, env, allowPoly ? Type.noType : syms.throwableType);
if (allowPoly) {
chk.checkType(tree, owntype, syms.throwableType);
}
result = null;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method selectSym.
/*
// Added by Ceylon
private Symbol resolveIndyCall(JCTree tree,
JCExpression indyReturnTypeExpression, List<JCExpression> indyParameterTypeExpressions,
Name indyName,
JCExpression bsmType, Name bsmName, List<Object> bsmStatic,
List<Type> parameterTypes){
// build the list of static bsm arguments
List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
syms.stringType,
syms.methodTypeType).appendList(bsmStaticArgToTypes(bsmStatic));
// find the type of the bootstrap method class
Type bsmSite = attribTree(bsmType, env, TYP, Infer.anyPoly);
// find the bsm method
Symbol bsm = rs.resolveInternalMethod(tree.pos(), env, bsmSite,
bsmName, bsm_staticArgs, List.<Type>nil());
if(!bsm.isStatic())
log.error(tree.pos(), "ceylon", "Bootstrap method must be static: " + bsmName.toString());
// find the type of the indy call
Type indyReturnType = attribTree(indyReturnTypeExpression, env, TYP, Infer.anyPoly);
ListBuffer<Type> indyParameterTypes = new ListBuffer<Type>();
int c=0;
List<Type> givenParameterTypes = parameterTypes;
for(JCExpression expectedParamTypeExpr : indyParameterTypeExpressions){
// also check that the parameter types we are passing to the method are compatible with the declared type
Type givenParameterType = givenParameterTypes.head;
if(givenParameterType == null) {
log.error(tree.pos(), "ceylon", "Indy declared method expects more parameters than given. Expecting " + indyParameterTypeExpressions.size()
+ ", but given " + c);
return syms.errSymbol;
}
Type paramType = attribTree(expectedParamTypeExpr, env, TYP, Infer.anyPoly);
if(!types.isAssignable(givenParameterType, paramType)) {
log.error(tree.pos(), "ceylon", "Indy given method parameter "+c+" not compatible with expected parameter type: " + paramType
+ ", but given " + givenParameterType);
return syms.errSymbol;
}
indyParameterTypes.append(paramType);
c++;
givenParameterTypes = givenParameterTypes.tail;
}
if(!givenParameterTypes.isEmpty()) {
log.error(tree.pos(), "ceylon", "Indy declared method expects less parameters than given. Expecting " + indyParameterTypeExpressions.size()
+ ", but given " + parameterTypes.size());
return syms.errSymbol;
}
MethodType indyType = new MethodType(indyParameterTypes.toList(), indyReturnType, List.<Type>nil(), syms.methodClass);
// make an indy symbol for it
DynamicMethodSymbol dynSym =
new DynamicMethodSymbol(indyName,
syms.noSymbol,
bsm.isStatic() ?
ClassFile.REF_invokeStatic :
ClassFile.REF_invokeVirtual,
(MethodSymbol)bsm,
indyType,
bsmStatic.toArray());
return dynSym;
}
*/
// where
/**
* Determine symbol referenced by a Select expression,
*
* @param tree The select tree.
* @param site The type of the selected expression,
* @param env The current environment.
* @param resultInfo The current result.
*/
private Symbol selectSym(JCFieldAccess tree, Symbol location, Type site, Env<AttrContext> env, ResultInfo resultInfo) {
DiagnosticPosition pos = tree.pos();
Name name = tree.name;
switch(site.getTag()) {
case PACKAGE:
return rs.accessBase(rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind), pos, location, site, name, true);
case ARRAY:
case CLASS:
if (resultInfo.pt.hasTag(METHOD) || resultInfo.pt.hasTag(FORALL)) {
return rs.resolveQualifiedMethod(pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments());
} else if (name == names._this || name == names._super) {
return rs.resolveSelf(pos, env, site.tsym, name);
} else if (name == names._class) {
// In this case, we have already made sure in
// visitSelect that qualifier expression is a type.
Type t = syms.classType;
List<Type> typeargs = allowGenerics ? List.of(types.erasure(site)) : List.<Type>nil();
t = new ClassType(t.getEnclosingType(), typeargs, t.tsym);
return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
} else {
// We are seeing a plain identifier as selector.
Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind);
if ((resultInfo.pkind & Kinds.ERRONEOUS) == 0)
sym = rs.accessBase(sym, pos, location, site, name, true);
return sym;
}
case WILDCARD:
throw new AssertionError(tree);
case TYPEVAR:
// Normally, site.getUpperBound() shouldn't be null.
// It should only happen during memberEnter/attribBase
// when determining the super type which *must* beac
// done before attributing the type variables. In
// other words, we are seeing this illegal program:
// class B<T> extends A<T.foo> {}
Symbol sym = (site.getUpperBound() != null) ? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo) : null;
if (sym == null) {
log.error(pos, "type.var.cant.be.deref");
return syms.errSymbol;
} else {
// Ceylon: relax the rules for private methods in wildcards, damnit, we want the private
// method to be called, not any subtype's method we can't possibly know about, this is really
// a lame Java decision.
Symbol sym2 = (!sourceLanguage.isCeylon() && (sym.flags() & Flags.PRIVATE) != 0) ? rs.new AccessError(env, site, sym) : sym;
rs.accessBase(sym2, pos, location, site, name, true);
return sym;
}
case ERROR:
// preserve identifier names through errors
return types.createErrorType(name, site.tsym, site).tsym;
default:
// .class is allowed for these.
if (name == names._class) {
// In this case, we have already made sure in Select that
// qualifier expression is a type.
Type t = syms.classType;
Type arg = types.boxedClass(site).type;
t = new ClassType(t.getEnclosingType(), List.of(arg), t.tsym);
return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
} else {
log.error(pos, "cant.deref", site);
return syms.errSymbol;
}
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method checkMethodIdInternal.
Type checkMethodIdInternal(JCTree tree, Type site, Symbol sym, Env<AttrContext> env, ResultInfo resultInfo) {
if ((resultInfo.pkind & POLY) != 0) {
Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase));
Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo);
resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase));
return owntype;
} else {
return checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo);
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method visitBinary.
public void visitBinary(JCBinary tree) {
// Attribute arguments.
Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env));
Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env));
// Find operator.
Symbol operator = tree.operator = rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right);
Type owntype = types.createErrorType(tree.type);
if (operator.kind == MTH && !left.isErroneous() && !right.isErroneous()) {
owntype = operator.type.getReturnType();
// This will figure out when unboxing can happen and
// choose the right comparison operator.
int opc = chk.checkOperator(tree.lhs.pos(), (OperatorSymbol) operator, tree.getTag(), left, right);
// If both arguments are constants, fold them.
if (left.constValue() != null && right.constValue() != null) {
Type ctype = cfolder.fold2(opc, left, right);
if (ctype != null) {
owntype = cfolder.coerce(ctype, owntype);
}
}
// comparisons will not have an acmp* opc at this point.
if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) {
if (!types.isEqualityComparable(left, right, new Warner(tree.pos()))) {
log.error(tree.pos(), "incomparable.types", left, right);
}
}
chk.checkDivZero(tree.rhs.pos(), operator, right);
}
result = check(tree, owntype, VAL, resultInfo);
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Attr method isBooleanOrNumeric.
// where
private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) {
switch(tree.getTag()) {
case LITERAL:
return ((JCLiteral) tree).typetag.isSubRangeOf(DOUBLE) || ((JCLiteral) tree).typetag == BOOLEAN || ((JCLiteral) tree).typetag == BOT;
case LAMBDA:
case REFERENCE:
return false;
case PARENS:
return isBooleanOrNumeric(env, ((JCParens) tree).expr);
case CONDEXPR:
JCConditional condTree = (JCConditional) tree;
return isBooleanOrNumeric(env, condTree.truepart) && isBooleanOrNumeric(env, condTree.falsepart);
case APPLY:
JCMethodInvocation speculativeMethodTree = (JCMethodInvocation) deferredAttr.attribSpeculative(tree, env, unknownExprInfo);
Type owntype = TreeInfo.symbol(speculativeMethodTree.meth).type.getReturnType();
return types.unboxedTypeOrType(owntype).isPrimitive();
case NEWCLASS:
JCExpression className = removeClassParams.translate(((JCNewClass) tree).clazz);
JCExpression speculativeNewClassTree = (JCExpression) deferredAttr.attribSpeculative(className, env, unknownTypeInfo);
return types.unboxedTypeOrType(speculativeNewClassTree.type).isPrimitive();
default:
Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type;
speculativeType = types.unboxedTypeOrType(speculativeType);
return speculativeType.isPrimitive();
}
}
Aggregations