--- a/Behavior.st Thu Sep 14 10:59:29 2006 +0200
+++ b/Behavior.st Thu Sep 14 11:30:30 2006 +0200
@@ -753,6 +753,65 @@
!Behavior class methodsFor:'helpers'!
+classesSortedByLoadOrder:someClasses
+ "return a copy of the given collection of classes, which is sorted
+ by inheritance and superclass-of-any-private class.
+ This is the optimal order for loading, and the required order for compilation"
+
+ |remaining classesInLoadOrder|
+
+ remaining := OrderedCollection withAll:someClasses.
+
+ classesInLoadOrder := OrderedCollection new:(someClasses size).
+ [remaining notEmpty] whileTrue:[
+ |thoseWithOtherSuperclasses thoseWhichCanBeLoadedNow|
+
+ "/ all those, which have superclasses NOT in the remaining set
+ thoseWithOtherSuperclasses :=
+ remaining
+ select:[:eachClass | (remaining includesIdentical:eachClass superclass) not].
+
+ "/ all those with privateClasses, which have superclasses NOT in the remaining set
+ thoseWhichCanBeLoadedNow :=
+ thoseWithOtherSuperclasses
+ select:[:eachClass |
+ |anyPrivateClassWithSuperClassInPackage|
+
+ anyPrivateClassWithSuperClassInPackage := false.
+ eachClass privateClasses do:[:eachPrivateClass |
+ eachPrivateClass superclass ~~ eachClass ifTrue:[
+ (remaining includesIdentical:eachPrivateClass superclass) ifTrue:[
+ anyPrivateClassWithSuperClassInPackage := true
+ ]
+ ]
+ ].
+ anyPrivateClassWithSuperClassInPackage ifTrue:[
+ Transcript showCR:('later load of ' , eachClass name , ' due to a private classes superclass').
+ ].
+ anyPrivateClassWithSuperClassInPackage not.
+ ].
+
+ thoseWhichCanBeLoadedNow size == 0 ifTrue:[
+ self error:'load order is cyclic (care for private classes)' mayProceed:true.
+ thoseWhichCanBeLoadedNow := thoseWithOtherSuperclasses.
+ thoseWhichCanBeLoadedNow size == 0 ifTrue:[
+ self error:'load order is cyclic'.
+ ]
+ ].
+ thoseWhichCanBeLoadedNow := thoseWhichCanBeLoadedNow asOrderedCollection sort:[:a :b | a name < b name].
+ classesInLoadOrder addAll:thoseWhichCanBeLoadedNow.
+ remaining removeAllFoundIn:thoseWhichCanBeLoadedNow.
+ ].
+ ^ classesInLoadOrder
+
+ "
+ Class
+ classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libbasic3')
+ "
+
+ "Created: / 14-09-2006 / 11:21:25 / cg"
+!
+
commonSuperclassOf:listOfClassesOrClassNames
|common|
@@ -4305,5 +4364,5 @@
!Behavior class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.261 2006-08-24 09:25:47 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.262 2006-09-14 09:30:30 cg Exp $'
! !