Metaclass.st
changeset 2039 6a03b5a9d4e2
parent 2035 5b79c170d6a3
child 2047 8150a3ae6fa0
--- a/Metaclass.st	Fri Jan 03 16:35:28 1997 +0100
+++ b/Metaclass.st	Fri Jan 03 16:38:26 1997 +0100
@@ -475,7 +475,8 @@
      changeSet1 changeSet2 addedNames
      anyChange oldInstVars newInstVars oldClassVars newClassVars superFlags newFlags
      pkg idx spec nClassInstVars superInstVars
-     realNewName thisIsPrivate oldCIVNames newCIVNames msg nsName namespace|
+     realNewName thisIsPrivate oldCIVNames newCIVNames msg nsName namespace
+     oldSuperClass newSuperClass|
 
     "NOTICE:
      this method is too complex and should be splitted into managable pieces ...
@@ -490,7 +491,7 @@
 
     Behavior flushSubclassInfo.
 
-    newName = aClass name ifTrue:[
+    (aClass notNil and:[newName = aClass name]) ifTrue:[
         self error:'trying to create circular class definition'.
         ^ nil
     ].
@@ -506,9 +507,11 @@
     ].
 
     "check for invalid subclassing of UndefinedObject and SmallInteger"
-    aClass canBeSubclassed ifFalse:[
-        self error:('it is not possible to subclass ' , aClass name).
-        ^ nil
+    aClass notNil ifTrue:[
+        aClass canBeSubclassed ifFalse:[
+            self error:('it is not possible to subclass ' , aClass name).
+            ^ nil
+        ]
     ].
 
     nInstVars := stringOfInstVarNames countWords.
@@ -596,12 +599,14 @@
                 ]
             ].
 
-            aClass superclass notNil ifTrue:[
-                aClass allSuperclasses do:[:cls |
-                    cls name = realNewName ifTrue:[
-                        self error:'trying to create circular class definition'.
-                        ^ nil
-                    ]
+            aClass notNil ifTrue:[
+                aClass superclass notNil ifTrue:[
+                    aClass allSuperclasses do:[:cls |
+                        cls name = realNewName ifTrue:[
+                            self error:'trying to create circular class definition'.
+                            ^ nil
+                        ]
+                    ].
                 ].
             ].
 
@@ -716,15 +721,24 @@
     ] ifFalse:[
         newMetaclass := Metaclass new.
     ].
-    newMetaclass setSuperclass:(aClass class).
-    newMetaclass instSize:(aClass class instSize + nClassInstVars).
+    aClass isNil ifTrue:[
+        newMetaclass setSuperclass:Class.
+        newMetaclass instSize:(Class instSize + nClassInstVars).
+    ] ifFalse:[
+        newMetaclass setSuperclass:(aClass class).
+        newMetaclass instSize:(aClass class instSize + nClassInstVars).
+    ].
     newMetaclass classVariableString:''.
     newMetaclass setInstanceVariableString:stringOfClassInstVarNames.
 
     "then let the new meta create the class"
     newClass := newMetaclass new.
     newClass setSuperclass:aClass.
-    newClass instSize:(aClass instSize + nInstVars).
+    aClass isNil ifTrue:[
+        newClass instSize:nInstVars.
+    ] ifFalse:[
+        newClass instSize:(aClass instSize + nInstVars).
+    ].
 
     thisIsPrivate ifTrue:[
         "/ some private class
@@ -795,7 +809,12 @@
         "/ false or symbol.
         newFlags := Behavior flagForSymbolic:variableBoolean.
     ].
-    superFlags := aClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits"
+    aClass isNil ifTrue:[
+        superFlags := 0
+    ] ifFalse:[
+        superFlags := aClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits"
+    ].
+
     oldClass notNil ifTrue:[
         oldClass isBuiltInClass ifTrue:[
             "
@@ -872,7 +891,9 @@
     oldClassVars := oldClass classVariableString asCollectionOfWords.
     newClassVars := newClass classVariableString asCollectionOfWords.
 
-    superClassChange := oldClass superclass ~~ newClass superclass.
+    oldSuperClass := oldClass superclass.
+    newSuperClass := newClass superclass.
+    superClassChange := oldSuperClass ~~ newSuperClass.
 
     "
      we are on the bright side of life, if the instance layout and
@@ -953,12 +974,22 @@
               changeSet1 := Set new.
               oldClassVars do:[:nm |
                   (newClassVars includes:nm) ifFalse:[
+                      "/ a removed classVar;
+                      "/ must recompile methods accessing that one:
+                      "/ access was: classVar; now: global.
                       changeSet1 add:nm
                   ]
               ].
               newClassVars do:[:nm |
                   (oldClassVars includes:nm) ifFalse:[
-                      changeSet1 add:nm
+                      "/ an added classVar;
+                      "/ must recompile methods accessing that one:
+                      "/ access was: global; now: classVar.
+                      "/ but only, if such a global existed in the first
+                      "/ place. (otherwise, it is a brand-new name)
+                      (Smalltalk includesKey:nm asSymbol) ifTrue:[
+                          changeSet1 add:nm
+                      ]  
                   ]
               ].
 
@@ -1017,7 +1048,7 @@
     "
     changed ifTrue:[
         (superClassChange 
-         and:[(oldClass superclass isNil or:[oldClass superclass name = newClass superclass name])
+         and:[(oldSuperClass isNil or:[oldSuperClass name = newSuperClass name])
          and:[(oldClassVars = newClassVars) 
          and:[(oldInstVars = newInstVars)
          and:[newComment = oldClass comment]]]]) ifFalse:[
@@ -1033,9 +1064,11 @@
     classVarChange := false.
 
     superClassChange ifTrue:[
-        (oldClass superclass allClassVarNames = newClass superclass allClassVarNames
-        and:[oldClass superclass name = newClass superclass name
-        and:[oldClassVars = newClassVars]])
+        (oldSuperClass notNil
+        and:[newSuperClass notNil
+        and:[oldSuperClass allClassVarNames = newSuperClass allClassVarNames
+        and:[oldSuperClass name = newSuperClass name
+        and:[oldClassVars = newClassVars]]]])
         ifTrue:[
 " "
             Transcript showCR:'keep class methods (same classvars)'.
@@ -1285,7 +1318,7 @@
 
     "Created: 26.5.1996 / 11:55:26 / cg"
     "Modified: 18.6.1996 / 14:19:39 / stefan"
-    "Modified: 3.1.1997 / 13:17:35 / cg"
+    "Modified: 3.1.1997 / 16:22:40 / cg"
 !
 
 name:newName inEnvironment:aSystemDictionary
@@ -1665,5 +1698,5 @@
 !Metaclass class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Metaclass.st,v 1.95 1997-01-03 12:28:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Metaclass.st,v 1.96 1997-01-03 15:38:26 cg Exp $'
 ! !