use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Attr method visitTypeTest.
public void visitTypeTest(JCInstanceOf tree) {
Type exprtype = chk.checkNullOrRefType(tree.expr.pos(), attribExpr(tree.expr, env));
Type clazztype = chk.checkReifiableReferenceType(tree.clazz.pos(), attribType(tree.clazz, env));
chk.validate(tree.clazz, env, false);
chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
result = check(tree, syms.booleanType, VAL, pkind, pt);
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Attr method getSyntheticScopeMapping.
/** Creates a synthetic scope containing fake generic constructors.
* Assuming that the original scope contains a constructor of the kind:
* Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
* the synthetic scope is added a generic constructor of the kind:
* <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
* inference. The inferred return type of the synthetic constructor IS
* the inferred type for the diamond operator.
*/
private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
if (ctype.tag != CLASS) {
return erroneousMapping;
}
Pair<Scope, Scope> mapping = new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
//declared, and insert it into the new scope.
for (Scope.Entry e = mapping.fst.lookup(names.init); e.scope != null; e = e.next()) {
Type synthRestype = new ClassType(ctype.getEnclosingType(), ctype.tsym.type.getTypeArguments(), ctype.tsym);
MethodSymbol synhConstr = new MethodSymbol(e.sym.flags(), names.init, types.createMethodTypeWithReturn(e.sym.type, synthRestype), e.sym.owner);
mapping.snd.enter(synhConstr);
}
return mapping;
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Attr method visitTry.
public void visitTry(JCTry tree) {
// Create a new local environment with a local
Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
boolean isTryWithResource = tree.resources.nonEmpty();
// Create a nested environment for attributing the try block if needed
Env<AttrContext> tryEnv = isTryWithResource ? env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : localEnv;
// Attribute resource declarations
for (JCTree resource : tree.resources) {
if (resource.getTag() == JCTree.VARDEF) {
attribStat(resource, tryEnv);
chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type");
//check that resource type cannot throw InterruptedException
checkAutoCloseable(resource.pos(), localEnv, resource.type);
VarSymbol var = (VarSymbol) TreeInfo.symbolFor(resource);
var.setData(ElementKind.RESOURCE_VARIABLE);
} else {
attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type");
}
}
// Attribute body
attribStat(tree.body, tryEnv);
if (isTryWithResource)
tryEnv.info.scope.leave();
// Attribute catch clauses
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
JCCatch c = l.head;
Env<AttrContext> catchEnv = localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
Type ctype = attribStat(c.param, catchEnv);
if (TreeInfo.isMultiCatch(c)) {
//multi-catch parameter is implicitly marked as final
c.param.sym.flags_field |= FINAL | UNION;
}
if (c.param.sym.kind == Kinds.VAR) {
c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
}
chk.checkType(c.param.vartype.pos(), chk.checkClassType(c.param.vartype.pos(), ctype), syms.throwableType);
attribStat(c.body, catchEnv);
catchEnv.info.scope.leave();
}
// Attribute finalizer
if (tree.finalizer != null)
attribStat(tree.finalizer, localEnv);
localEnv.info.scope.leave();
result = null;
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Check method checkNonCyclicInternal.
/** Check for cyclic references. Issue an error if the
* symbol of the type referred to has a LOCKED flag set.
*
* @param pos Position to be used for error reporting.
* @param t The type referred to.
* @returns True if the check completed on all attributed classes
*/
private boolean checkNonCyclicInternal(DiagnosticPosition pos, Type t) {
// was the check complete?
boolean complete = true;
//- System.err.println("checkNonCyclicInternal("+t+");");//DEBUG
Symbol c = t.tsym;
if ((c.flags_field & ACYCLIC) != 0)
return true;
if ((c.flags_field & LOCKED) != 0) {
noteCyclic(pos, (ClassSymbol) c);
} else if (!c.type.isErroneous()) {
try {
c.flags_field |= LOCKED;
if (c.type.tag == CLASS) {
ClassType clazz = (ClassType) c.type;
if (clazz.interfaces_field != null)
for (List<Type> l = clazz.interfaces_field; l.nonEmpty(); l = l.tail) complete &= checkNonCyclicInternal(pos, l.head);
if (clazz.supertype_field != null) {
Type st = clazz.supertype_field;
if (st != null && st.tag == CLASS)
complete &= checkNonCyclicInternal(pos, st);
}
if (c.owner.kind == TYP)
complete &= checkNonCyclicInternal(pos, c.owner.type);
}
} finally {
c.flags_field &= ~LOCKED;
}
}
if (complete)
complete = ((c.flags_field & UNATTRIBUTED) == 0) && c.completer == null;
if (complete)
c.flags_field |= ACYCLIC;
return complete;
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Check method firstIncompatibility.
/** Return the first method which is defined with same args
* but different return types in two given interfaces, or null if none
* exists.
* @param t1 The first type.
* @param t2 The second type.
* @param site The most derived type.
* @returns symbol from t2 that conflicts with one in t1.
*/
private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
Map<TypeSymbol, Type> interfaces1 = new HashMap<TypeSymbol, Type>();
closure(t1, interfaces1);
Map<TypeSymbol, Type> interfaces2;
if (t1 == t2)
interfaces2 = interfaces1;
else
closure(t2, interfaces1, interfaces2 = new HashMap<TypeSymbol, Type>());
for (Type t3 : interfaces1.values()) {
for (Type t4 : interfaces2.values()) {
Symbol s = firstDirectIncompatibility(pos, t3, t4, site);
if (s != null)
return s;
}
}
return null;
}
Aggregations