use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Check method isDeprecatedOverrideIgnorable.
// where
private boolean isDeprecatedOverrideIgnorable(MethodSymbol m, ClassSymbol origin) {
// If the method, m, is defined in an interface, then ignore the issue if the method
// is only inherited via a supertype and also implemented in the supertype,
// because in that case, we will rediscover the issue when examining the method
// in the supertype.
// If the method, m, is not defined in an interface, then the only time we need to
// address the issue is when the method is the supertype implemementation: any other
// case, we will have dealt with when examining the supertype classes
ClassSymbol mc = m.enclClass();
Type st = types.supertype(origin.type);
if (st.tag != CLASS)
return true;
MethodSymbol stimpl = m.implementation((ClassSymbol) st.tsym, types, false);
if (mc != null && ((mc.flags() & INTERFACE) != 0)) {
List<Type> intfs = types.interfaces(origin.type);
return (intfs.contains(mc.type) ? false : (stimpl != null));
} else
return (stimpl != m);
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Check method checkClassBounds.
//where
/** Enter all interfaces of type `type' into the hash table `seensofar'
* with their class symbol as key and their type as value. Make
* sure no class is entered with two different types.
*/
void checkClassBounds(DiagnosticPosition pos, Map<TypeSymbol, Type> seensofar, Type type) {
if (type.isErroneous())
return;
for (List<Type> l = types.interfaces(type); l.nonEmpty(); l = l.tail) {
Type it = l.head;
Type oldit = seensofar.put(it.tsym, it);
if (oldit != null) {
List<Type> oldparams = oldit.allparams();
List<Type> newparams = it.allparams();
if (!sourceLanguage.isCeylon() && !types.containsTypeEquivalent(oldparams, newparams))
log.error(pos, "cant.inherit.diff.arg", it.tsym, Type.toString(oldparams), Type.toString(newparams));
}
checkClassBounds(pos, seensofar, it);
}
Type st = types.supertype(type);
if (st != null)
checkClassBounds(pos, seensofar, st);
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Lower method accessSymbol.
/** Return access symbol for a private or protected symbol from an inner class.
* @param sym The accessed private symbol.
* @param tree The accessing tree.
* @param enclOp The closest enclosing operation node of tree,
* null if tree is not a subtree of an operation.
* @param protAccess Is access to a protected symbol in another
* package?
* @param refSuper Is access via a (qualified) C.super?
*/
MethodSymbol accessSymbol(Symbol sym, JCTree tree, JCTree enclOp, boolean protAccess, boolean refSuper) {
ClassSymbol accOwner = refSuper && protAccess ? // access symbol on T.
(ClassSymbol) ((JCFieldAccess) tree).selected.type.tsym : // class which is a subclass of the symbol's owner.
accessClass(sym, protAccess, tree);
Symbol vsym = sym;
if (sym.owner != accOwner) {
vsym = sym.clone(accOwner);
actualSymbols.put(vsym, sym);
}
// The access number of the access method.
Integer anum = accessNums.get(vsym);
if (anum == null) {
anum = accessed.length();
accessNums.put(vsym, anum);
accessSyms.put(vsym, new MethodSymbol[NCODES]);
accessed.append(vsym);
// System.out.println("accessing " + vsym + " in " + vsym.location());
}
// The access code of the access method.
int acode;
// The argument types of the access method.
List<Type> argtypes;
// The result type of the access method.
Type restype;
// The thrown exceptions of the access method.
List<Type> thrown;
switch(vsym.kind) {
case VAR:
acode = accessCode(tree, enclOp);
if (acode >= FIRSTASGOPcode) {
OperatorSymbol operator = binaryAccessOperator(acode);
if (operator.opcode == string_add)
argtypes = List.of(syms.objectType);
else
argtypes = operator.type.getParameterTypes().tail;
} else if (acode == ASSIGNcode)
argtypes = List.of(vsym.erasure(types));
else
argtypes = List.nil();
restype = vsym.erasure(types);
thrown = List.nil();
break;
case MTH:
acode = DEREFcode;
argtypes = vsym.erasure(types).getParameterTypes();
restype = vsym.erasure(types).getReturnType();
thrown = vsym.type.getThrownTypes();
break;
default:
throw new AssertionError();
}
// making it odd.
if (protAccess && refSuper)
acode++;
// containing the access method.
if ((vsym.flags() & STATIC) == 0) {
argtypes = argtypes.prepend(vsym.owner.erasure(types));
}
MethodSymbol[] accessors = accessSyms.get(vsym);
MethodSymbol accessor = accessors[acode];
if (accessor == null) {
accessor = new MethodSymbol(STATIC | SYNTHETIC, accessName(anum.intValue(), acode), new MethodType(argtypes, restype, thrown, syms.methodClass), accOwner);
enterSynthetic(tree.pos(), accessor, accOwner.members());
accessors[acode] = accessor;
}
return accessor;
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Lower method visitMethodDef.
public void visitMethodDef(JCMethodDecl tree) {
if (tree.name == names.init && (currentClass.flags_field & ENUM) != 0) {
// Add "String $enum$name, int $enum$ordinal" to the beginning of the
// argument list for each constructor of an enum.
JCVariableDecl nameParam = make_at(tree.pos()).Param(names.fromString(target.syntheticNameChar() + "enum" + target.syntheticNameChar() + "name"), syms.stringType, tree.sym);
nameParam.mods.flags |= SYNTHETIC;
nameParam.sym.flags_field |= SYNTHETIC;
JCVariableDecl ordParam = make.Param(names.fromString(target.syntheticNameChar() + "enum" + target.syntheticNameChar() + "ordinal"), syms.intType, tree.sym);
ordParam.mods.flags |= SYNTHETIC;
ordParam.sym.flags_field |= SYNTHETIC;
tree.params = tree.params.prepend(ordParam).prepend(nameParam);
MethodSymbol m = tree.sym;
Type olderasure = m.erasure(types);
m.erasure_field = new MethodType(olderasure.getParameterTypes().prepend(syms.intType).prepend(syms.stringType), olderasure.getReturnType(), olderasure.getThrownTypes(), syms.methodClass);
if (target.compilerBootstrap(m.owner)) {
// Initialize synthetic name field
Symbol nameVarSym = lookupSynthetic(names.fromString("$name"), tree.sym.owner.members());
JCIdent nameIdent = make.Ident(nameParam.sym);
JCIdent id1 = make.Ident(nameVarSym);
JCAssign newAssign = make.Assign(id1, nameIdent);
newAssign.type = id1.type;
JCExpressionStatement nameAssign = make.Exec(newAssign);
nameAssign.type = id1.type;
tree.body.stats = tree.body.stats.prepend(nameAssign);
// Initialize synthetic ordinal field
Symbol ordinalVarSym = lookupSynthetic(names.fromString("$ordinal"), tree.sym.owner.members());
JCIdent ordIdent = make.Ident(ordParam.sym);
id1 = make.Ident(ordinalVarSym);
newAssign = make.Assign(id1, ordIdent);
newAssign.type = id1.type;
JCExpressionStatement ordinalAssign = make.Exec(newAssign);
ordinalAssign.type = id1.type;
tree.body.stats = tree.body.stats.prepend(ordinalAssign);
}
}
JCMethodDecl prevMethodDef = currentMethodDef;
MethodSymbol prevMethodSym = currentMethodSym;
try {
currentMethodDef = tree;
currentMethodSym = tree.sym;
visitMethodDefInternal(tree);
} finally {
currentMethodDef = prevMethodDef;
currentMethodSym = prevMethodSym;
}
}
use of com.sun.tools.javac.code.Type in project ceylon-compiler by ceylon.
the class Attr method visitTypeApply.
/** Visitor method for parameterized types.
* Bound checking is left until later, since types are attributed
* before supertype structure is completely known
*/
public void visitTypeApply(JCTypeApply tree) {
Type owntype = types.createErrorType(tree.type);
// Attribute functor part of application and make sure it's a class.
Type clazztype = chk.checkClassType(tree.clazz.pos(), attribType(tree.clazz, env));
// Attribute type parameters
List<Type> actuals = attribTypes(tree.arguments, env);
if (clazztype.tag == CLASS) {
List<Type> formals = clazztype.tsym.type.getTypeArguments();
if (actuals.length() == formals.length() || actuals.length() == 0) {
List<Type> a = actuals;
List<Type> f = formals;
while (a.nonEmpty()) {
a.head = a.head.withTypeVar(f.head);
a = a.tail;
f = f.tail;
}
// Compute the proper generic outer
Type clazzOuter = clazztype.getEnclosingType();
if (clazzOuter.tag == CLASS) {
Type site;
JCExpression clazz = TreeInfo.typeIn(tree.clazz);
if (clazz.getTag() == JCTree.IDENT) {
site = env.enclClass.sym.type;
} else if (clazz.getTag() == JCTree.SELECT) {
site = ((JCFieldAccess) clazz).selected.type;
} else
throw new AssertionError("" + tree);
if (clazzOuter.tag == CLASS && site != clazzOuter) {
if (site.tag == CLASS)
site = types.asOuterSuper(site, clazzOuter.tsym);
if (site == null)
site = types.erasure(clazzOuter);
clazzOuter = site;
}
}
owntype = new ClassType(clazzOuter, actuals, clazztype.tsym);
} else {
if (formals.length() != 0) {
log.error(tree.pos(), "wrong.number.type.args", Integer.toString(formals.length()));
} else {
log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym);
}
owntype = types.createErrorType(tree.type);
}
}
result = check(tree, owntype, TYP, pkind, pt);
}
Aggregations