[Nice-commit] Nice/src/bossa/syntax NiceClass.java,1.81,1.82 ClassDefinition.java,1.104,1.105 Abstra
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-06-11 15:53:44
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28516/src/bossa/syntax Modified Files: NiceClass.java ClassDefinition.java AbstractInterfaceImplementation.java Log Message: Is is now possible to make a class of an imported package implement an interface defined in the current package (fixes #904327). Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** NiceClass.java 20 Mar 2004 15:49:24 -0000 1.81 --- NiceClass.java 11 Jun 2004 15:53:35 -0000 1.82 *************** *** 894,897 **** --- 894,902 ---- for (int i = 0; i < constructorMethod.length; i++) constructorMethod[i].getCode(); + + // Take into account external interface implementations, which + // can add new interfaces to implement in the bytecode. + classe.supers = computeSupers(); + classe.recomputeInterfaces(); } Index: ClassDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ClassDefinition.java,v retrieving revision 1.104 retrieving revision 1.105 diff -C2 -d -r1.104 -r1.105 *** ClassDefinition.java 16 Apr 2004 13:16:59 -0000 1.104 --- ClassDefinition.java 11 Jun 2004 15:53:35 -0000 1.105 *************** *** 72,91 **** TypeConstructor getSuperClass() { return null; } - mlsub.typing.Interface[] getInterfaces() { return extendedInterfaces; } - void resolveClass() { ! extendedInterfaces = this.resolveInterfaces(extensions); extensions = null; - // Resolve the super-interfaces first. - if (extendedInterfaces != null) - for (int i = 0; i < extendedInterfaces.length; i++) - { - ClassDefinition d = ClassDefinition.get(extendedInterfaces[i].associatedTC()); - if (d != null) - d.resolve(); - } - createAssociatedInterface(); --- 72,80 ---- TypeConstructor getSuperClass() { return null; } void resolveClass() { ! this.resolveInterfaces(extensions); extensions = null; createAssociatedInterface(); *************** *** 96,124 **** { try{ - if (extendedInterfaces != null) - try{ - Typing.assertImp(tc, extendedInterfaces, true); - } - catch(KindingEx e){ - User.error(name, - "Interface " + name + " cannot extend " + e.t2 + - ": they do not have the same number or kind of type parameters"); - } - - if (javaInterfaces != null) - for (int i = 0; i < javaInterfaces.length; i++) - try { - Typing.initialLeq(tc, javaInterfaces[i]); - } - catch(KindingEx e){ - User.error(name, - "Interface " + name + " cannot extend " + e.t2 + - ": they do not have the same number or kind of type parameters"); - } - Typing.assertImp(tc, associatedInterface, true); } catch(TypingEx e){ ! User.error(name, "Error in interface " + name + " : " + e.getMessage()); } --- 85,92 ---- { try{ Typing.assertImp(tc, associatedInterface, true); } catch(TypingEx e){ ! User.error(name, "Error in interface " + name, e.getMessage()); } *************** *** 132,176 **** s.print(getSimpleName()); s.print(this.printTypeParameters()); ! s.print(printInterfaces(" extends ", extendedInterfaces)); implementation.printInterface(s); } ! /**************************************************************** ! * Associated interface ! ****************************************************************/ ! private mlsub.typing.Interface associatedInterface; - /** - * Returns the abstract interface associated to this class, or null. - * - * An associated abstract interface in created - * for each "interface" class. - */ - public mlsub.typing.Interface getAssociatedInterface() - { return associatedInterface; } - private void createAssociatedInterface() { // the associated interface extends the associated interfaces // of the classes we extend ! if (extendedInterfaces != null) ! for(int i = 0; i < extendedInterfaces.length; i++) ! { ! mlsub.typing.Interface ai = extendedInterfaces[i]; ! ! try{ ! Typing.assertLeq(associatedInterface, ai); ! } ! catch(KindingEx e){ ! User.error(this, "Cannot extend interface " + ai + ! " which has a different variance"); ! } ! } } ! protected List /* of TypeConstructor */ extensions; - mlsub.typing.Interface[] extendedInterfaces; } --- 100,142 ---- s.print(getSimpleName()); s.print(this.printTypeParameters()); ! s.print(printInterfaces(" extends ", interfaces)); implementation.printInterface(s); } ! /**************************************************************** ! * Associated interface ! ****************************************************************/ ! private mlsub.typing.Interface associatedInterface; ! ! /** ! * Returns the abstract interface associated to this class, or null. ! * ! * An associated abstract interface in created ! * for each "interface" class. ! */ ! public mlsub.typing.Interface getAssociatedInterface() ! { return associatedInterface; } private void createAssociatedInterface() { // the associated interface extends the associated interfaces // of the classes we extend ! for (Iterator i = interfaces.iterator(); i.hasNext();) ! { ! mlsub.typing.Interface ai = (mlsub.typing.Interface) i.next(); ! ! try{ ! Typing.assertLeq(associatedInterface, ai); ! } ! catch(KindingEx e){ ! User.error(this, "Cannot extend interface " + ai + ! " which has a different variance"); ! } ! } } ! protected List /* of TypeConstructor */ extensions; } *************** *** 252,265 **** } - mlsub.typing.Interface[] getInterfaces() { return impl; } - public ClassDefinition.Interface[] getImplementedInterfaces() { ! if (impl == null) return null; List res = new LinkedList(); ! for (int i = 0; i < impl.length; i++) ! { ! Object itf = ClassDefinition.get(impl[i].associatedTC()); if (itf != null) res.add(itf); --- 218,231 ---- } public ClassDefinition.Interface[] getImplementedInterfaces() { ! if (interfaces.size() == 0) return null; List res = new LinkedList(); ! for (Iterator i = interfaces.iterator(); i.hasNext();) ! { ! mlsub.typing.Interface ai = (mlsub.typing.Interface) i.next(); ! ! ClassDefinition itf = ClassDefinition.get(ai.associatedTC()); if (itf != null) res.add(itf); *************** *** 312,327 **** } - if (javaInterfaces != null) - for (int i = 0; i < javaInterfaces.length; i++) - if (tc.arity() == 0 || - ! JavaClasses.excludedInterface(javaInterfaces[i])) - try { - Typing.initialLeq(tc, javaInterfaces[i]); - } - catch(KindingEx e){ - User.error(name, - "Class " + name + " cannot implement " + e.t2 + - ": they do not have the same number or kind of type parameters"); - } } catch(TypingEx e){ --- 278,281 ---- *************** *** 342,346 **** if (superClass != null) s.print(" extends " + superClass); ! s.print(printInterfaces(" implements ", impl)); s.print(Util.map(" finally implements ",", ","",abs)); implementation.printInterface(s); --- 296,300 ---- if (superClass != null) s.print(" extends " + superClass); ! s.print(printInterfaces(" implements ", interfaces)); s.print(Util.map(" finally implements ",", ","",abs)); implementation.printInterface(s); *************** *** 354,357 **** --- 308,315 ---- } + /**************************************************************** + * Generic definition, common to classes and interfaces + ****************************************************************/ + /** * Creates a class definition. *************** *** 375,379 **** /* of Interface */ implementations, /* of Interface */ abstractions; ! mlsub.typing.Interface[] impl, abs; void createTC() --- 333,340 ---- /* of Interface */ implementations, /* of Interface */ abstractions; ! ! mlsub.typing.Interface[] abs; ! ! List interfaces = new ArrayList(5); void createTC() *************** *** 528,532 **** void resolveClass() { ! impl = this.resolveInterfaces(implementations); abs = TypeIdent.resolveToItf(typeScope, abstractions); --- 489,493 ---- void resolveClass() { ! this.resolveInterfaces(implementations); abs = TypeIdent.resolveToItf(typeScope, abstractions); *************** *** 534,544 **** // Resolve the super-interfaces first. ! if (impl != null) ! for (int i = 0; i < impl.length; i++) ! { ! ClassDefinition d = ClassDefinition.get(impl[i].associatedTC()); ! if (d != null) ! d.resolve(); ! } createContext(); --- 495,505 ---- // Resolve the super-interfaces first. ! for (Iterator i = interfaces.iterator(); i.hasNext();) ! { ! mlsub.typing.Interface itf = (mlsub.typing.Interface) i.next(); ! ClassDefinition d = ClassDefinition.get(itf.associatedTC()); ! if (d != null) ! d.resolve(); ! } createContext(); *************** *** 549,559 **** TypeConstructor[] javaInterfaces; ! mlsub.typing.Interface[] resolveInterfaces(List names) { if (names == null) ! return null; - mlsub.typing.Interface[] res = new mlsub.typing.Interface[names.size()]; - int n = 0; ArrayList javaInterfaces = null; --- 510,518 ---- TypeConstructor[] javaInterfaces; ! void resolveInterfaces(List names) { if (names == null) ! return; ArrayList javaInterfaces = null; *************** *** 564,568 **** if (s instanceof mlsub.typing.Interface) ! res[n++] = (mlsub.typing.Interface) s; else { --- 523,527 ---- if (s instanceof mlsub.typing.Interface) ! interfaces.add(s); else { *************** *** 578,591 **** } ! if (n < res.length) // The array is too long ! { ! mlsub.typing.Interface[] tmp = new mlsub.typing.Interface[n]; ! System.arraycopy(res, 0, tmp, 0, n); ! res = tmp; ! this.javaInterfaces = (TypeConstructor[]) ! javaInterfaces.toArray(new TypeConstructor[javaInterfaces.size()]); ! } ! ! return res; } --- 537,543 ---- } ! if (javaInterfaces != null) ! this.javaInterfaces = (TypeConstructor[]) ! javaInterfaces.toArray(new TypeConstructor[javaInterfaces.size()]); } *************** *** 631,637 **** { try { ! if (impl != null) try{ ! Typing.assertImp(tc, impl, true); } catch(KindingEx e){ --- 583,590 ---- { try { ! for (Iterator i = interfaces.iterator(); i.hasNext();) try{ ! mlsub.typing.Interface itf = (mlsub.typing.Interface) i.next(); ! Typing.assertImp(tc, itf, true); } catch(KindingEx e){ *************** *** 646,649 **** --- 599,615 ---- Typing.assertAbs(tc, abs); } + + if (javaInterfaces != null) + for (int i = 0; i < javaInterfaces.length; i++) + if (tc.arity() == 0 || + ! JavaClasses.excludedInterface(javaInterfaces[i])) + try { + Typing.initialLeq(tc, javaInterfaces[i]); + } + catch(KindingEx e){ + User.error(name, + "Class " + name + " cannot implement " + e.t2 + + ": they do not have the same number or kind of type parameters"); + } } catch(TypingEx e){ *************** *** 661,666 **** abstract TypeConstructor getSuperClass(); ! abstract mlsub.typing.Interface[] getInterfaces(); ! private Type javaType; --- 627,641 ---- abstract TypeConstructor getSuperClass(); ! mlsub.typing.Interface[] getInterfaces() ! { ! return (mlsub.typing.Interface[]) ! interfaces.toArray(new mlsub.typing.Interface[interfaces.size()]); ! } ! ! void addInterfaceImplementation(mlsub.typing.Interface itf) ! { ! interfaces.add(itf); ! } ! private Type javaType; *************** *** 685,692 **** } ! String printInterfaces(String keyword, mlsub.typing.Interface[] interfaces) { StringBuffer res = new StringBuffer(); ! if (interfaces != null || javaInterfaces != null) { res.append(keyword); --- 660,667 ---- } ! String printInterfaces(String keyword, List interfaces) { StringBuffer res = new StringBuffer(); ! if (interfaces.size() != 0 || javaInterfaces != null) { res.append(keyword); Index: AbstractInterfaceImplementation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/AbstractInterfaceImplementation.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractInterfaceImplementation.java 11 Jun 2004 10:56:55 -0000 1.5 --- AbstractInterfaceImplementation.java 11 Jun 2004 15:53:35 -0000 1.6 *************** *** 65,68 **** --- 65,72 ---- interfaceITF = ident.resolveToItf(typeScope); + ClassDefinition def = ClassDefinition.get(classTC); + if (def != null) + def.addInterfaceImplementation(interfaceITF); + createContext(); } |