[Nice-commit] Nice/src/bossa/syntax NewArrayExp.java,1.19,1.20
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-04-15 14:42:15
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31726/src/bossa/syntax Modified Files: NewArrayExp.java Log Message: Simpler and more flexible typing for 'new T[x]': that expression now has type ?T, unless T is already known to be a complete, non-raw type. Index: NewArrayExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NewArrayExp.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** NewArrayExp.java 25 Feb 2004 11:23:29 -0000 1.19 --- NewArrayExp.java 15 Apr 2004 14:42:01 -0000 1.20 *************** *** 59,63 **** { Monotype monotype; ! Constraint cst; TypeConstructor[] nullVars; --- 59,63 ---- { Monotype monotype; ! Constraint cst = Constraint.True; TypeConstructor[] nullVars; *************** *** 79,124 **** else nullVars = null; ! if (resolvedType instanceof MonotypeVar) { MonotypeVar res = (MonotypeVar) resolvedType; - TypeConstructor tc = new TypeConstructor("nullness", PrimitiveType.maybeTC.variance, false, false); - MonotypeVar raw = new MonotypeVar(res.getName()+"raw"); - MonotypeConstructor eq = MonotypeConstructor.apply(tc, raw); - TypeSymbol[] vars; - if (nullVars == null) - vars = new TypeSymbol[]{tc, raw}; - else - { - vars = new TypeSymbol[nullVars.length + 2]; - System.arraycopy(nullVars, 0, vars, 2, nullVars.length); - vars[0] = tc; - vars[1] = raw; - } - cst = new Constraint(vars, new AtomicConstraint[]{ - new TypeConstructorLeqCst(tc, PrimitiveType.maybeTC), - new MonotypeLeqCst(eq, res), - new MonotypeLeqCst(res, eq)}); ! if (nullVars != null) ! monotype = MonotypeConstructor.apply(nullVars[nullVars.length - 1], ! raw); ! else ! monotype = bossa.syntax.Monotype.maybe(raw); } else if (resolvedType == mlsub.typing.TopMonotype.instance) { monotype = mlsub.typing.TopMonotype.instance; - if (nullVars != null) - { - monotype = MonotypeConstructor.apply(nullVars[nullVars.length - 1], - monotype); - cst = new Constraint(nullVars, null); - } - else - { - monotype = bossa.syntax.Monotype.maybe(monotype); - cst = Constraint.True; - } } else --- 79,124 ---- else nullVars = null; ! ! // Whether the element are surely not null ! boolean sure = false; ! if (resolvedType instanceof MonotypeVar) { MonotypeVar res = (MonotypeVar) resolvedType; ! if (res.getKind() == mlsub.typing.NullnessKind.instance) ! monotype = Types.rawType(res.equivalent()); ! else ! monotype = res; ! /* ! TypeConstructor tc = new TypeConstructor("nullness", PrimitiveType.maybeTC.variance, false, false); ! MonotypeVar raw = new MonotypeVar(res.getName()+"raw"); ! MonotypeConstructor eq = MonotypeConstructor.apply(tc, raw); ! TypeSymbol[] vars; ! if (nullVars == null) ! vars = new TypeSymbol[]{tc, raw}; ! else ! { ! vars = new TypeSymbol[nullVars.length + 2]; ! System.arraycopy(nullVars, 0, vars, 2, nullVars.length); ! vars[0] = tc; ! vars[1] = raw; ! } ! cst = new Constraint(vars, new AtomicConstraint[]{ ! new TypeConstructorLeqCst(tc, PrimitiveType.maybeTC), ! new MonotypeLeqCst(eq, res), ! new MonotypeLeqCst(res, eq)}); ! ! if (nullVars != null) ! monotype = MonotypeConstructor.apply(nullVars[nullVars.length - 1], ! raw); ! else ! monotype = bossa.syntax.Monotype.maybe(raw); ! */ ! } } else if (resolvedType == mlsub.typing.TopMonotype.instance) { monotype = mlsub.typing.TopMonotype.instance; } else *************** *** 126,146 **** if (!(resolvedType instanceof TypeConstructor)) User.error(ident, ident + " should be a class"); - - cst = Constraint.True; TypeConstructor tc = (TypeConstructor) resolvedType; monotype = new MonotypeConstructor(tc, MonotypeVar.news(tc.arity())); if (Types.isPrimitive(tc)) ! monotype = bossa.syntax.Monotype.sure(monotype); ! else if (nullVars != null) ! { ! monotype = MonotypeConstructor.apply(nullVars[nullVars.length - 1], ! monotype); ! cst = new Constraint(nullVars, null); ! } ! else ! monotype = bossa.syntax.Monotype.maybe(monotype); } ! for (int i = 0; i < unknownDimensions; i++) { --- 126,149 ---- if (!(resolvedType instanceof TypeConstructor)) User.error(ident, ident + " should be a class"); TypeConstructor tc = (TypeConstructor) resolvedType; monotype = new MonotypeConstructor(tc, MonotypeVar.news(tc.arity())); + if (Types.isPrimitive(tc)) ! sure = true; } ! ! // Add the nullness marker to the element type. ! if (sure) ! monotype = bossa.syntax.Monotype.sure(monotype); ! else if (nullVars == null) ! monotype = bossa.syntax.Monotype.maybe(monotype); ! else ! { ! monotype = MonotypeConstructor.apply ! (nullVars[nullVars.length - 1], monotype); ! cst = new Constraint(nullVars, null); ! } ! for (int i = 0; i < unknownDimensions; i++) { |