SnapShotImageMemory.st
changeset 1419 f808d17ff6f5
parent 1417 28d6026fe30c
child 1420 9a649c1bb8cf
equal deleted inserted replaced
1418:7466259d8bb5 1419:f808d17ff6f5
     1 'From Smalltalk/X, Version:4.1.1 on 24-Okt-2000 at 12:50:47'                    !
       
     2 
       
     3 "{ Package: 'cg:private' }"
     1 "{ Package: 'cg:private' }"
     4 
     2 
     5 Object subclass:#SnapShotImageMemory
     3 Object subclass:#SnapShotImageMemory
     6 	instanceVariableNames:'image stream msb ptrSize intSize intTag spaceInfos symbolEntries
     4 	instanceVariableNames:'image stream msb ptrSize intSize intTag spaceInfos symbolEntries
     7 		globalEntries addrToObjectMapping'
     5 		globalEntries addrToObjectMapping'
    15 	classVariableNames:''
    13 	classVariableNames:''
    16 	poolDictionaries:''
    14 	poolDictionaries:''
    17 	privateIn:SnapShotImageMemory
    15 	privateIn:SnapShotImageMemory
    18 !
    16 !
    19 
    17 
       
    18 SnapShotImageMemory::ImageHeader variableByteSubclass:#ImageByteObject
       
    19 	instanceVariableNames:''
       
    20 	classVariableNames:''
       
    21 	poolDictionaries:''
       
    22 	privateIn:SnapShotImageMemory
       
    23 !
       
    24 
    20 Object subclass:#SpaceInfo
    25 Object subclass:#SpaceInfo
    21 	instanceVariableNames:'start end size flags imageBase'
    26 	instanceVariableNames:'start end size flags imageBase'
    22 	classVariableNames:''
    27 	classVariableNames:''
    23 	poolDictionaries:''
    28 	poolDictionaries:''
    24 	privateIn:SnapShotImageMemory
    29 	privateIn:SnapShotImageMemory
    25 !
    30 !
    26 
    31 
    27 SnapShotImageMemory::ImageHeader variableSubclass:#ImageObject
    32 SnapShotImageMemory::ImageHeader variableSubclass:#ImageObject
    28 	instanceVariableNames:''
    33 	instanceVariableNames:'cachedContents'
    29 	classVariableNames:''
    34 	classVariableNames:''
    30 	poolDictionaries:''
    35 	poolDictionaries:''
    31 	privateIn:SnapShotImageMemory
    36 	privateIn:SnapShotImageMemory
    32 !
    37 !
    33 
    38 
    34 SnapShotImageMemory::ImageObject variableSubclass:#ImageClassObject
    39 SnapShotImageMemory::ImageObject variableSubclass:#ImageClassObject
    35 	instanceVariableNames:''
       
    36 	classVariableNames:''
       
    37 	poolDictionaries:''
       
    38 	privateIn:SnapShotImageMemory
       
    39 !
       
    40 
       
    41 SnapShotImageMemory::ImageHeader variableByteSubclass:#ImageByteObject
       
    42 	instanceVariableNames:''
    40 	instanceVariableNames:''
    43 	classVariableNames:''
    41 	classVariableNames:''
    44 	poolDictionaries:''
    42 	poolDictionaries:''
    45 	privateIn:SnapShotImageMemory
    43 	privateIn:SnapShotImageMemory
    46 !
    44 !
   280     globalEntries isNil ifTrue:[
   278     globalEntries isNil ifTrue:[
   281         self readHeader.
   279         self readHeader.
   282         self readGlobals.
   280         self readGlobals.
   283     ].
   281     ].
   284 !
   282 !
       
   283 
       
   284 fetchByteArrayFor:aByteArrayRef
       
   285     |nBytes|
       
   286 
       
   287     (aByteArrayRef isImageBytes) ifFalse:[self halt].
       
   288 
       
   289     nBytes := aByteArrayRef byteSize - (intSize * 3).
       
   290     ^ ((ByteArray new:nBytes) replaceFrom:1 to:nBytes-1 with:aByteArrayRef startingAt:1).!
   285 
   291 
   286 fetchStringFor:aStringRef
   292 fetchStringFor:aStringRef
   287     |nBytes|
   293     |nBytes|
   288 
   294 
   289     (aStringRef isImageBytes) ifFalse:[self halt].
   295     (aStringRef isImageBytes) ifFalse:[self halt].
   727         ^ category
   733         ^ category
   728     ].
   734     ].
   729 self halt.
   735 self halt.
   730 !
   736 !
   731 
   737 
       
   738 isBehavior
       
   739     ^ self isImageBehavior!
       
   740 
   732 isImageBehavior
   741 isImageBehavior
   733     |flags|
   742     |flags|
   734 
   743 
   735     flags := classRef flags.
   744     flags := classRef flags.
   736     ^ flags bitTest:Behavior flagBehavior  
   745     ^ flags bitTest:Behavior flagBehavior  
   754     |flags|
   763     |flags|
   755 
   764 
   756     flags := classRef flags.
   765     flags := classRef flags.
   757     ^ flags bitTest:Behavior flagSymbol 
   766     ^ flags bitTest:Behavior flagSymbol 
   758 !
   767 !
       
   768 
       
   769 isLazyMethod                               
       
   770     ^ classRef name = 'LazyMethod'!
   759 
   771 
   760 isMeta
   772 isMeta
   761     ^ false
   773     ^ false
   762 !
   774 !
   763 
   775 
   776 
   788 
   777 isString                               
   789 isString                               
   778     ^ classRef name = 'String'
   790     ^ classRef name = 'String'
   779 ! !
   791 ! !
   780 
   792 
       
   793 !SnapShotImageMemory::ImageByteObject methodsFor:'queries'!
       
   794 
       
   795 size
       
   796     ^ byteSize
       
   797 ! !
       
   798 
   781 !SnapShotImageMemory::SpaceInfo methodsFor:'accessing'!
   799 !SnapShotImageMemory::SpaceInfo methodsFor:'accessing'!
   782 
   800 
   783 end
   801 end
   784     "return the value of the instance variable 'end' (automatically generated)"
   802     "return the value of the instance variable 'end' (automatically generated)"
   785 
   803 
   828 start:something
   846 start:something
   829     "set the value of the instance variable 'start' (automatically generated)"
   847     "set the value of the instance variable 'start' (automatically generated)"
   830 
   848 
   831     start := something.! !
   849     start := something.! !
   832 
   850 
   833 !SnapShotImageMemory::ImageObject methodsFor:'object protocol'!
   851 !SnapShotImageMemory::ImageObject methodsFor:'method protocol'!
   834 
   852 
   835 at:aSelector ifAbsent:exceptionValue
   853 byteCode
   836     |symPtr symRef mthdPtr mthdRef s|
   854     |byteCodeSlotOffset byteCodePtr byteCodeRef byteCode|
   837 
   855 
   838     self isMethodDictionary ifTrue:[
   856     self isMethod ifTrue:[
   839         1 to:self size by:2 do:[:idx |
   857         byteCodeSlotOffset := Method instVarOffsetOf:'byteCode'.
   840             symPtr := self at:idx.
   858     ].
   841             symRef := memory fetchObjectAt:symPtr.
   859     byteCodeSlotOffset notNil ifTrue:[
   842             symRef isImageSymbol ifFalse:[self halt].
   860         byteCodePtr := self at:byteCodeSlotOffset.
   843             s := memory fetchStringFor:symRef.
   861         byteCodeRef := memory fetchObjectAt:byteCodePtr.
   844             mthdPtr := self at:idx + 1.
   862         byteCodeRef isNil ifTrue:[^ nil].
   845             mthdRef := memory fetchObjectAt:mthdPtr.
   863 
   846             ^ mthdRef.
   864         byteCode := memory fetchByteArrayFor:byteCodeRef.
   847         ].
   865         ^ byteCode
   848     ].
   866     ].
   849     ^ exceptionValue value
   867 
   850 !
   868     self halt.
   851 
   869 !
   852 do:aBlock
   870 
   853     |mthdPtr mthdRef|
   871 comment
   854 
   872     |src comment comments parser|
   855     self isMethodDictionary ifTrue:[
   873 
   856         2 to:self size by:2 do:[:idx |
   874     self isMethod ifTrue:[
   857             mthdPtr := self at:idx.
   875         src := self source.
   858             mthdRef := memory fetchObjectAt:mthdPtr.
   876         src isNil ifTrue:[^ nil].
   859             aBlock value:mthdRef.
   877 
   860         ].
   878         parser := Parser for:src in:nil.
   861     ].
   879         parser ignoreErrors; ignoreWarnings; saveComments:true.
   862 !
   880         parser parseMethodSpec.
       
   881         comments := parser comments.
       
   882         comments size ~~ 0 ifTrue:[
       
   883             comment := comments first string.
       
   884             (comment withoutSpaces endsWith:'}') ifTrue:[
       
   885                 "if first comment is a pragma, take next comment"
       
   886                 comment := comments at:2 ifAbsent:nil.
       
   887                 comment notNil ifTrue:[
       
   888                     comment := comment string.
       
   889                 ].
       
   890             ].
       
   891         ].
       
   892         ^ comment.
       
   893     ].
       
   894     self isLazyMethod ifTrue:[
       
   895         ^ ''
       
   896     ].
       
   897 
       
   898     self halt.
       
   899 !
       
   900 
       
   901 containingClass
       
   902     self isMethodOrLazyMethod ifTrue:[
       
   903         ^ self mclass
       
   904     ].
       
   905     self halt.!
       
   906 
       
   907 hasCode
       
   908     ^ false!
       
   909 
       
   910 isBreakpointed
       
   911     ^ false!
       
   912 
       
   913 isCounting
       
   914     ^ false!
       
   915 
       
   916 isCountingMemoryUsage
       
   917     ^ false!
       
   918 
       
   919 isDynamic
       
   920     ^ false!
       
   921 
       
   922 isExecutable
       
   923     self isMethod ifTrue:[
       
   924         ^ false
       
   925     ].
       
   926     self halt.!
       
   927 
       
   928 isIgnored
       
   929     ^ false!
       
   930 
       
   931 isJavaMethod
       
   932     ^ self class name = 'JavaMethod'!
       
   933 
       
   934 isPrivate
       
   935     ^ false!
       
   936 
       
   937 isProtected
       
   938     ^ false!
       
   939 
       
   940 isPublic
       
   941     ^ true!
       
   942 
       
   943 isTimed
       
   944     ^ false!
       
   945 
       
   946 isTraced
       
   947     ^ false!
   863 
   948 
   864 isWrapped
   949 isWrapped
   865     ^ false
   950     ^ false
   866 !
   951 !
   867 
   952 
   868 keysAndValuesDo:aBlock
   953 mclass
   869     |symPtr symRef mthdPtr mthdRef s|
   954     |mclassSlotOffset mclassPtr mclass|
   870 
   955 
   871     self isMethodDictionary ifTrue:[
   956     self isMethod ifTrue:[
   872         1 to:self size by:2 do:[:idx |
   957         mclassSlotOffset := Method instVarOffsetOf:'mclass'.
   873             symPtr := self at:idx.
   958         mclassPtr := self at:mclassSlotOffset.
   874             symRef := memory fetchObjectAt:symPtr.
   959         mclassPtr ~~ 0 ifTrue:[
   875             symRef isImageSymbol ifFalse:[self halt].
   960             mclass := memory fetchObjectAt:mclassPtr.
   876             s := memory fetchStringFor:symRef.
   961             mclass isImageBehavior ifFalse:[
   877             mthdPtr := self at:idx + 1.
   962                 self halt
   878             mthdRef := memory fetchObjectAt:mthdPtr.
   963             ].
   879             aBlock value:s asSymbol value:mthdRef.
   964             ^ mclass
   880         ].
   965         ].
   881     ].
   966 
   882 !
   967         "/ search my class ...
       
   968         memory image allClassesDo:[:eachClass |
       
   969             eachClass theNonMetaclass methodDictionary keysAndValuesDo:[:sel :mthdRef |
       
   970                 mthdRef == self ifTrue:[
       
   971                     self at:mclassSlotOffset put:eachClass theNonMetaclass.    
       
   972                     ^ eachClass theNonMetaclass
       
   973                 ].
       
   974             ].
       
   975             eachClass theMetaclass methodDictionary keysAndValuesDo:[:sel :mthdRef |
       
   976                 mthdRef == self ifTrue:[
       
   977                     self at:mclassSlotOffset put:eachClass theMetaclass.    
       
   978                     ^ eachClass theMetaclass
       
   979                 ].
       
   980             ]
       
   981         ].
       
   982         self halt.
       
   983     ].
       
   984     self halt.
       
   985 !
       
   986 
       
   987 numArgs
       
   988     |flagsSlotOffset flagsPtr flags|
       
   989 
       
   990     self isMethod ifTrue:[
       
   991         flagsSlotOffset := Method instVarOffsetOf:'flags'.
       
   992     ].
       
   993     flagsSlotOffset notNil ifTrue:[
       
   994         flagsPtr := self at:flagsSlotOffset.
       
   995         flags := memory fetchObjectAt:flagsPtr.
       
   996         ^ (flags bitAnd:(Method numArgsMaskInFlags)) bitShift:(Method numArgsShiftInFlags negated)   
       
   997     ].
       
   998 
       
   999     self halt.
       
  1000 !
       
  1001 
       
  1002 package
       
  1003     |packageSlotOffset packagePtr packageRef package|
       
  1004 
       
  1005     self isImageBehavior ifTrue:[
       
  1006         self isMeta ifTrue:[
       
  1007             ^ self theNonMetaclass package
       
  1008         ].
       
  1009         packageSlotOffset := Class instVarOffsetOf:'package'.
       
  1010     ].
       
  1011     self isMethod ifTrue:[
       
  1012         packageSlotOffset := Method instVarOffsetOf:'package'.
       
  1013     ].
       
  1014     packageSlotOffset notNil ifTrue:[
       
  1015         packagePtr := self at:packageSlotOffset.
       
  1016         packageRef := memory fetchObjectAt:packagePtr.
       
  1017         packageRef isNil ifTrue:[^ nil].
       
  1018 
       
  1019         packageRef isImageSymbol ifFalse:[
       
  1020             self halt.
       
  1021         ].
       
  1022         package := memory fetchStringFor:packageRef.
       
  1023         ^ package asSymbol
       
  1024     ].
       
  1025     self isMeta ifTrue:[
       
  1026         self halt
       
  1027     ].
       
  1028 
       
  1029     self halt.
       
  1030 !
       
  1031 
       
  1032 previousVersion
       
  1033     ^ nil!
   883 
  1034 
   884 printStringForBrowserWithSelector:selector
  1035 printStringForBrowserWithSelector:selector
   885     ^ selector
  1036     ^ selector
   886 !
  1037 !
   887 
  1038 
       
  1039 privacy
       
  1040     ^ #public!
       
  1041 
   888 resources
  1042 resources
   889     ^ nil
  1043     ^ nil
   890 !
  1044 !
   891 
  1045 
   892 source
  1046 source
   893     |sourcePosition source aStream junk|
  1047     |sourcePosition sourcePositionPtr sourcePtr sourceRef source aStream junk|
   894 
  1048 
   895     self isMethod ifTrue:[
  1049     self isMethodOrLazyMethod ifTrue:[
   896         sourcePosition := self at:(Method instVarOffsetOf:'sourcePosition').
  1050         sourcePositionPtr := self at:(Method instVarOffsetOf:'sourcePosition').
   897         source := self at:(Method instVarOffsetOf:'source').
  1051         sourcePtr := self at:(Method instVarOffsetOf:'source').
   898         source := memory fetchObjectAt:source.
  1052         sourceRef := memory fetchObjectAt:sourcePtr.
   899         source isString ifFalse:[
  1053         sourceRef isString ifFalse:[
   900             self halt.
  1054             self halt.
   901         ].
  1055         ].
   902         source := memory printStringOfString:source.
  1056         source := memory printStringOfString:sourceRef.
       
  1057         sourcePosition := memory fetchObjectAt:sourcePositionPtr.
   903         sourcePosition isNil ifTrue:[
  1058         sourcePosition isNil ifTrue:[
   904             self halt.
       
   905             ^ source
  1059             ^ source
   906         ].
  1060         ].
   907         sourcePosition := memory fetchObjectAt:sourcePosition.
       
   908 
  1061 
   909         aStream := self sourceStream.
  1062         aStream := self sourceStream.
   910         aStream notNil ifTrue:[
  1063         aStream notNil ifTrue:[
   911             Stream positionErrorSignal handle:[:ex |
  1064             Stream positionErrorSignal handle:[:ex |
   912                 ^ nil
  1065                 ^ nil
   919             ^ junk
  1072             ^ junk
   920         ].
  1073         ].
   921     ].
  1074     ].
   922     self halt.
  1075     self halt.
   923 !
  1076 !
       
  1077 
       
  1078 sourceFilename
       
  1079     "return the sourcefilename if source is extern; nil otherwise"
       
  1080 
       
  1081     self isMethodOrLazyMethod ifTrue:[
       
  1082         self sourcePosition notNil ifTrue:[^ self source].
       
  1083         ^ nil
       
  1084     ].
       
  1085     self halt.!
       
  1086 
       
  1087 sourceLineNumber
       
  1088     self isMethodOrLazyMethod ifTrue:[
       
  1089         ^ 1
       
  1090     ].
       
  1091     self halt.
       
  1092 !
       
  1093 
       
  1094 sourcePosition
       
  1095     |sourcePosition|
       
  1096 
       
  1097     self isMethodOrLazyMethod ifTrue:[
       
  1098         sourcePosition := self sourcePositionValue.
       
  1099         sourcePosition isNil ifTrue:[^ sourcePosition].
       
  1100         ^ sourcePosition abs
       
  1101     ].
       
  1102     self halt.!
       
  1103 
       
  1104 sourcePositionValue
       
  1105     |sourcePosition sourcePositionPtr|
       
  1106 
       
  1107     self isMethodOrLazyMethod ifTrue:[
       
  1108         sourcePositionPtr := self at:(Method instVarOffsetOf:'sourcePosition').
       
  1109         sourcePosition := memory fetchObjectAt:sourcePositionPtr.
       
  1110         ^ sourcePosition 
       
  1111     ].
       
  1112     self halt.!
   924 
  1113 
   925 sourceStream
  1114 sourceStream
   926     |sourcePosition source aStream fileName junk who 
  1115     |sourcePosition source aStream fileName junk who 
   927      myClass mgr className sep dir mod package|
  1116      myClass mgr className sep dir mod package|
   928 
  1117 
  1035         ^ nil
  1224         ^ nil
  1036     ].
  1225     ].
  1037     self halt.
  1226     self halt.
  1038 ! !
  1227 ! !
  1039 
  1228 
       
  1229 !SnapShotImageMemory::ImageObject methodsFor:'methodDictionary protocol'!
       
  1230 
       
  1231 at:aSelector ifAbsent:exceptionValue
       
  1232     self isMethodDictionary ifTrue:[
       
  1233         cachedContents isNil ifTrue:[
       
  1234             self cacheMethodDictionary.
       
  1235         ].
       
  1236         ^ cachedContents at:aSelector ifAbsent:exceptionValue
       
  1237     ].
       
  1238     self halt.!
       
  1239 
       
  1240 cacheMethodDictionary
       
  1241     |symPtr symRef mthdPtr mthdRef s|
       
  1242 
       
  1243     cachedContents isNil ifTrue:[
       
  1244         cachedContents := IdentityDictionary new.
       
  1245 
       
  1246         1 to:self size by:2 do:[:idx |
       
  1247             symPtr := self at:idx.
       
  1248             symRef := memory fetchObjectAt:symPtr.
       
  1249             symRef isImageSymbol ifFalse:[self halt].
       
  1250             s := memory fetchStringFor:symRef.
       
  1251             mthdPtr := self at:idx + 1.
       
  1252             mthdRef := memory fetchObjectAt:mthdPtr.
       
  1253             cachedContents at:s asSymbol put:mthdRef.
       
  1254         ].
       
  1255     ].!
       
  1256 
       
  1257 do:aBlock
       
  1258     self isMethodDictionary ifTrue:[
       
  1259         cachedContents isNil ifTrue:[
       
  1260             self cacheMethodDictionary.
       
  1261         ].
       
  1262         cachedContents do:aBlock.
       
  1263         ^ self.
       
  1264     ].
       
  1265     self halt.
       
  1266 !
       
  1267 
       
  1268 includesKey:aSelector
       
  1269     self isMethodDictionary ifTrue:[
       
  1270         cachedContents isNil ifTrue:[
       
  1271             self cacheMethodDictionary.
       
  1272         ].
       
  1273         ^ cachedContents includesKey:aSelector
       
  1274     ].
       
  1275     self halt.!
       
  1276 
       
  1277 keyAtValue:aMethod ifAbsent:exceptionValue
       
  1278     self isMethodDictionary ifTrue:[
       
  1279         cachedContents isNil ifTrue:[
       
  1280             self cacheMethodDictionary.
       
  1281         ].
       
  1282         ^ cachedContents keyAtValue:aMethod ifAbsent:exceptionValue
       
  1283     ].
       
  1284     self halt.!
       
  1285 
       
  1286 keysAndValuesDo:aBlock
       
  1287     self isMethodDictionary ifTrue:[
       
  1288         cachedContents isNil ifTrue:[
       
  1289             self cacheMethodDictionary.
       
  1290         ].
       
  1291 
       
  1292         cachedContents keysAndValuesDo:[:sel :mthdRef |
       
  1293             aBlock value:sel value:mthdRef.
       
  1294         ].
       
  1295         ^ self
       
  1296     ].
       
  1297     self halt.
       
  1298 ! !
       
  1299 
  1040 !SnapShotImageMemory::ImageClassObject methodsFor:'accessing - slots'!
  1300 !SnapShotImageMemory::ImageClassObject methodsFor:'accessing - slots'!
  1041 
  1301 
  1042 category
  1302 category
  1043     |categoryRef category|
  1303     |categoryRef category|
  1044 
  1304 
  1051     ].
  1311     ].
  1052     ^ category
  1312     ^ category
  1053 !
  1313 !
  1054 
  1314 
  1055 categorySlot
  1315 categorySlot
  1056     ^ self at:8
  1316     ^ self at:(Class instVarOffsetOf:'category')!
  1057 !
  1317 
       
  1318 classFilename
       
  1319     |classFilenameRef classFilename|
       
  1320 
       
  1321     classFilenameRef := self classFilenameSlot.
       
  1322     classFilenameRef isInteger ifTrue:[
       
  1323         classFilenameRef := memory fetchObjectAt:classFilenameRef.
       
  1324     ].
       
  1325     classFilenameRef notNil ifTrue:[
       
  1326         classFilename := memory fetchStringFor:classFilenameRef.
       
  1327     ].
       
  1328     ^ classFilename!
  1058 
  1329 
  1059 classFilenameSlot
  1330 classFilenameSlot
  1060     ^ self at:12
  1331     ^ self at:(Class instVarOffsetOf:'classFilename')!
  1061 !
       
  1062 
  1332 
  1063 classVarNames
  1333 classVarNames
  1064     |classVarNamesRef classVarNames s|
  1334     |classVarNamesRef classVarNames s|
  1065 
  1335 
  1066     classVarNamesRef := self classVarsSlot.
  1336     classVarNamesRef := self classVarsSlot.
  1084         ].
  1354         ].
  1085     ].
  1355     ].
  1086     ^ classVarNames
  1356     ^ classVarNames
  1087 !
  1357 !
  1088 
  1358 
       
  1359 classVariableString
       
  1360     |classVarsPtr classVarsRef classVars|
       
  1361 
       
  1362     (classVarsPtr := self classVarsSlot) == 0 ifTrue:[^ ''].
       
  1363     classVarsRef := memory fetchObjectAt:classVarsPtr.
       
  1364     classVarsRef isImageBytes ifTrue:[
       
  1365         "/ a string
       
  1366         classVars := memory fetchStringFor:classVarsRef.
       
  1367         ^ classVars
       
  1368     ].
       
  1369     ^ self classVarNames asStringWith:(Character space)
       
  1370 !
       
  1371 
  1089 classVarsSlot
  1372 classVarsSlot
  1090     ^ self at:9
  1373     ^ self at:9
  1091 !
  1374 !
  1092 
  1375 
  1093 comment
  1376 comment
  1102     ].
  1385     ].
  1103     ^ comment
  1386     ^ comment
  1104 !
  1387 !
  1105 
  1388 
  1106 commentSlot
  1389 commentSlot
  1107     ^ self at:10
  1390     ^ self at:(Class instVarOffsetOf:'comment')!
  1108 !
       
  1109 
  1391 
  1110 flags
  1392 flags
  1111     |flags|
  1393     |flags|
  1112 
  1394 
  1113     flags := self flagsSlot.
  1395     flags := self flagsSlot.
  1117     ].
  1399     ].
  1118     ^ flags bitShift:-1.
  1400     ^ flags bitShift:-1.
  1119 !
  1401 !
  1120 
  1402 
  1121 flagsSlot
  1403 flagsSlot
  1122     ^ self at:2
  1404     ^ self at:(Class instVarOffsetOf:'flags')!
  1123 !
  1405 
       
  1406 instSize
       
  1407     |instSizeRef|
       
  1408 
       
  1409     instSizeRef := self instSizeSlot.
       
  1410     ^ memory fetchObjectAt:instSizeRef.!
  1124 
  1411 
  1125 instSizeSlot
  1412 instSizeSlot
  1126     ^ self at:5
  1413     ^ self at:(Class instVarOffsetOf:'instSize')!
  1127 !
       
  1128 
  1414 
  1129 instVarNames
  1415 instVarNames
  1130     |instVarNamesRef instVarNames s|
  1416     |instVarNamesRef instVarNames s|
  1131 
  1417 
  1132     instVarNamesRef := self instVarsSlot.
  1418     instVarNamesRef := self instVarsSlot.
  1147                 s := memory fetchStringFor:s.
  1433                 s := memory fetchStringFor:s.
  1148                 instVarNames at:idx put:s.
  1434                 instVarNames at:idx put:s.
  1149             ].
  1435             ].
  1150         ].
  1436         ].
  1151     ].
  1437     ].
  1152     ^ instVarNames
  1438     ^ instVarNames ? #()!
  1153 !
       
  1154 
  1439 
  1155 instVarsSlot
  1440 instVarsSlot
  1156     ^ self at:6
  1441     ^ self at:6
  1157 !
  1442 !
  1158 
  1443 
  1166     ].
  1451     ].
  1167     ^ methodDictionary
  1452     ^ methodDictionary
  1168 !
  1453 !
  1169 
  1454 
  1170 methodDictionarySlot
  1455 methodDictionarySlot
  1171     ^ self at:3
  1456     ^ self at:(Class instVarOffsetOf:'methodDictionary')!
  1172 !
       
  1173 
  1457 
  1174 name
  1458 name
  1175     |nameRef name|
  1459     |nameRef name|
       
  1460 
       
  1461     self isMeta ifTrue:[
       
  1462         ^ self theNonMetaclass name , ' class'
       
  1463     ].
  1176 
  1464 
  1177     nameRef := self nameSlot.
  1465     nameRef := self nameSlot.
  1178     nameRef isInteger ifTrue:[
  1466     nameRef isInteger ifTrue:[
  1179         nameRef := memory fetchObjectAt:nameRef.
  1467         nameRef := memory fetchObjectAt:nameRef.
  1180     ].
  1468     ].
  1186     ].
  1474     ].
  1187     ^ name
  1475     ^ name
  1188 !
  1476 !
  1189 
  1477 
  1190 nameSlot
  1478 nameSlot
  1191     ^ self at:7
  1479     ^ self at:(Class instVarOffsetOf:'name')!
  1192 !
       
  1193 
  1480 
  1194 packageSlot
  1481 packageSlot
  1195     ^ self at:13
  1482     ^ self at:(Class instVarOffsetOf:'package')!
  1196 !
  1483 
       
  1484 primitiveSpec
       
  1485     |primitiveSpecRef primitiveSpec|
       
  1486 
       
  1487     primitiveSpecRef := self primitiveSpecSlot.
       
  1488     primitiveSpecRef isInteger ifTrue:[
       
  1489         primitiveSpecRef := memory fetchObjectAt:primitiveSpecRef.
       
  1490     ].
       
  1491     primitiveSpecRef notNil ifTrue:[
       
  1492         primitiveSpec := memory fetchStringFor:primitiveSpecRef.
       
  1493     ].
       
  1494     ^ primitiveSpec
       
  1495 !
       
  1496 
       
  1497 primitiveSpecSlot
       
  1498     ^ self at:(Class instVarOffsetOf:'primitiveSpec')!
       
  1499 
       
  1500 revision
       
  1501     |revisionRef revision|
       
  1502 
       
  1503     revisionRef := self revisionSlot.
       
  1504     revisionRef isInteger ifTrue:[
       
  1505         revisionRef := memory fetchObjectAt:revisionRef.
       
  1506     ].
       
  1507     revisionRef notNil ifTrue:[
       
  1508         revision := memory fetchStringFor:revisionRef.
       
  1509     ].
       
  1510     ^ revision!
  1197 
  1511 
  1198 revisionSlot
  1512 revisionSlot
  1199     ^ self at:14
  1513     ^ self at:14
  1200 !
  1514 !
  1201 
  1515 
  1213     ^ self at:1
  1527     ^ self at:1
  1214 ! !
  1528 ! !
  1215 
  1529 
  1216 !SnapShotImageMemory::ImageClassObject methodsFor:'class protocol'!
  1530 !SnapShotImageMemory::ImageClassObject methodsFor:'class protocol'!
  1217 
  1531 
       
  1532 addAllClassVarNamesTo:aCollection
       
  1533     "helper - add the name-strings of the class variables and of the class-vars
       
  1534      of all superclasses to the argument, aCollection. Return aCollection"
       
  1535 
       
  1536     |classvars superclass|
       
  1537 
       
  1538     (superclass := self superclass) notNil ifTrue:[
       
  1539         superclass addAllClassVarNamesTo:aCollection
       
  1540     ].
       
  1541     (classvars := self classVariableString) notNil ifTrue:[
       
  1542         aCollection addAll:(classvars asCollectionOfWords).
       
  1543     ].
       
  1544     ^ aCollection!
       
  1545 
       
  1546 addAllInstVarNamesTo:aCollection
       
  1547     |superInsts instvars superclass|
       
  1548 
       
  1549     (superclass := self superclass) notNil ifTrue:[
       
  1550         self superclass addAllInstVarNamesTo:aCollection
       
  1551     ].
       
  1552     aCollection addAll:self instVarNames.
       
  1553     ^ aCollection!
       
  1554 
       
  1555 addChangeRecordForClassFileOut:aClass!
       
  1556 
       
  1557 allClassVarNames
       
  1558     "return a collection of all the class variable name-strings
       
  1559      this includes all superclass-class variables"
       
  1560 
       
  1561     ^ self addAllClassVarNamesTo:(OrderedCollection new)!
       
  1562 
       
  1563 allInstVarNames
       
  1564     self superclass isNil ifTrue:[^ self instVarNames].
       
  1565     ^ self addAllInstVarNamesTo:(OrderedCollection new)!
       
  1566 
       
  1567 allSubclassesDo:aBlock
       
  1568     "evaluate aBlock for all of my subclasses.
       
  1569      There is no specific order, in which the entries are enumerated.
       
  1570      Warning:
       
  1571         This will only enumerate globally known classes - for anonymous
       
  1572         behaviors, you have to walk over all instances of Behavior."
       
  1573 
       
  1574     self isMeta ifTrue:[
       
  1575         "/ metaclasses are not found via Smalltalk allClassesDo:
       
  1576         "/ here, walk over classes and enumerate corresponding metas.
       
  1577         self soleInstance allSubclassesDo:[:aSubClass |
       
  1578             aBlock value:(aSubClass class)
       
  1579         ].
       
  1580     ] ifFalse:[
       
  1581         Smalltalk allClassesDo:[:aClass |
       
  1582             (aClass isSubclassOf:self) ifTrue:[
       
  1583                 aBlock value:aClass
       
  1584             ]
       
  1585         ]
       
  1586     ]
       
  1587 
       
  1588     "
       
  1589      Collection allSubclassesDo:[:c | Transcript showCR:(c name)]
       
  1590      Collection class allSubclassesDo:[:c | Transcript showCR:(c name)]
       
  1591     "
       
  1592 
       
  1593     "Modified: / 25.10.1997 / 21:17:13 / cg"
       
  1594 !
       
  1595 
       
  1596 allSuperclasses
       
  1597     "return a collection of the receivers accumulated superclasses"
       
  1598 
       
  1599     |aCollection theSuperClass|
       
  1600 
       
  1601     theSuperClass := self superclass.
       
  1602     theSuperClass isNil ifTrue:[
       
  1603         ^ #()
       
  1604     ].
       
  1605     aCollection := OrderedCollection new.
       
  1606     [theSuperClass notNil] whileTrue:[
       
  1607         aCollection add:theSuperClass.
       
  1608         theSuperClass := theSuperClass superclass
       
  1609     ].
       
  1610     ^ aCollection
       
  1611 
       
  1612     "
       
  1613      String allSuperclasses 
       
  1614     "!
       
  1615 
       
  1616 allSuperclassesDo:aBlock
       
  1617     "evaluate aBlock for all of my superclasses"
       
  1618 
       
  1619     |theClass|
       
  1620 
       
  1621     theClass := self superclass.
       
  1622     [theClass notNil] whileTrue:[
       
  1623         aBlock value:theClass.
       
  1624         theClass := theClass superclass
       
  1625     ]
       
  1626 
       
  1627     "
       
  1628      String allSuperclassesDo:[:c | Transcript showCR:(c name)]
       
  1629     "
       
  1630 !
       
  1631 
       
  1632 basicFileOutDefinitionOn:aStream withNameSpace:forceNameSpace
       
  1633     "append an expression on aStream, which defines myself."
       
  1634 
       
  1635     self
       
  1636         basicFileOutDefinitionOn:aStream 
       
  1637         withNameSpace:forceNameSpace 
       
  1638         withPackage:true!
       
  1639 
  1218 basicFileOutDefinitionOn:aStream withNameSpace:forceNameSpace withPackage:showPackage
  1640 basicFileOutDefinitionOn:aStream withNameSpace:forceNameSpace withPackage:showPackage
  1219     "append an expression on aStream, which defines myself."
  1641     "append an expression on aStream, which defines myself."
  1220 
  1642 
  1221     |s owner ns nsName fullName superName cls topOwner
  1643     |s owner ns nsName fullName superName cls topOwner
  1222      syntaxHilighting superclass category|
  1644      syntaxHilighting superclass category|
  1223 
       
  1224     superclass := self superclass.
       
  1225     category := self category.
       
  1226 
  1645 
  1227     UserPreferences isNil ifTrue:[
  1646     UserPreferences isNil ifTrue:[
  1228         syntaxHilighting := false
  1647         syntaxHilighting := false
  1229     ] ifFalse:[
  1648     ] ifFalse:[
  1230         syntaxHilighting := UserPreferences current syntaxColoring.
  1649         syntaxHilighting := UserPreferences current syntaxColoring.
  1258             aStream nextPutAll:nsName.
  1677             aStream nextPutAll:nsName.
  1259             syntaxHilighting ifTrue:[aStream normal].
  1678             syntaxHilighting ifTrue:[aStream normal].
  1260             aStream nextPutAll:' }"'; cr; cr.
  1679             aStream nextPutAll:' }"'; cr; cr.
  1261         ]
  1680         ]
  1262     ].
  1681     ].
       
  1682 
       
  1683     superclass := self superclass.
       
  1684     category := self category.
  1263 
  1685 
  1264     "take care of nil-superclass"
  1686     "take care of nil-superclass"
  1265     superclass isNil ifTrue:[
  1687     superclass isNil ifTrue:[
  1266         s := 'nil'
  1688         s := 'nil'
  1267     ] ifFalse:[
  1689     ] ifFalse:[
  1382     ].
  1804     ].
  1383     aStream cr
  1805     aStream cr
  1384 
  1806 
  1385     "Created: / 4.1.1997 / 20:38:16 / cg"
  1807     "Created: / 4.1.1997 / 20:38:16 / cg"
  1386     "Modified: / 8.8.1997 / 10:59:50 / cg"
  1808     "Modified: / 8.8.1997 / 10:59:50 / cg"
  1387     "Modified: / 18.3.1999 / 18:15:46 / stefan"
  1809     "Modified: / 18.3.1999 / 18:15:46 / stefan"!
  1388 !
       
  1389 
  1810 
  1390 basicFileOutInstvarTypeKeywordOn:aStream
  1811 basicFileOutInstvarTypeKeywordOn:aStream
  1391     "a helper for fileOutDefinition"
  1812     "a helper for fileOutDefinition"
  1392 
  1813 
  1393     |isVar s superclass|
  1814     |isVar s superclass|
  1403     aStream nextPutAll:(self firstDefinitionSelectorPart).
  1824     aStream nextPutAll:(self firstDefinitionSelectorPart).
  1404 
  1825 
  1405     "Created: 11.10.1996 / 18:57:29 / cg"
  1826     "Created: 11.10.1996 / 18:57:29 / cg"
  1406 !
  1827 !
  1407 
  1828 
       
  1829 binaryRevision
       
  1830     "return the revision-ID from which the class was stc-compiled;
       
  1831      nil if its an autoloaded or filedIn class.
       
  1832      If a classes binary is up-to-date w.r.t. the source repository,
       
  1833      the returned string is the same as the one returned by #revision."
       
  1834 
       
  1835     |owner info c revision|
       
  1836 
       
  1837     revision := self revision.
       
  1838 
       
  1839     (owner := self owningClass) notNil ifTrue:[^ owner binaryRevision].
       
  1840     revision notNil ifTrue:[
       
  1841         c := revision first.
       
  1842         c == $$ ifTrue:[
       
  1843             info := Class revisionInfoFromString:revision.
       
  1844             info isNil ifTrue:[^ '0'].
       
  1845             ^ info at:#revision ifAbsent:'0'.
       
  1846         ].
       
  1847         c isDigit ifFalse:[
       
  1848             ^ '0'
       
  1849         ].
       
  1850     ].
       
  1851 
       
  1852     ^ revision
       
  1853 
       
  1854     "
       
  1855      Object binaryRevision
       
  1856      Object class binaryRevision
       
  1857     "
       
  1858 
       
  1859     "
       
  1860      to find all classes which are not up-to-date:
       
  1861 
       
  1862      |classes|
       
  1863 
       
  1864      classes := Smalltalk allClasses 
       
  1865                     select:[:cls | cls binaryRevision notNil and:[cls binaryRevision ~= cls revision]].
       
  1866      SystemBrowser browseClasses:classes title:'classes which are not up-to-date'
       
  1867     "
       
  1868 
       
  1869     "Created: 7.12.1995 / 10:58:47 / cg"
       
  1870     "Modified: 1.4.1997 / 23:33:01 / stefan"
       
  1871     "Modified: 9.9.1997 / 12:05:41 / cg"!
       
  1872 
  1408 compiledMethodAt:aSelector
  1873 compiledMethodAt:aSelector
  1409 
  1874 
  1410     ^ self compiledMethodAt:aSelector ifAbsent:nil
  1875     ^ self compiledMethodAt:aSelector ifAbsent:nil
  1411 !
  1876 !
  1412 
  1877 
  1424 
  1889 
  1425 evaluatorClass
  1890 evaluatorClass
  1426     ^ Object evaluatorClass
  1891     ^ Object evaluatorClass
  1427 !
  1892 !
  1428 
  1893 
       
  1894 fileOut
       
  1895     |baseName dirName nm fileName|
       
  1896 
       
  1897     baseName := (Smalltalk fileNameForClass:self name).
       
  1898     nm := baseName asFilename withSuffix:'st'.
       
  1899 
       
  1900     "
       
  1901      this test allows a smalltalk to be built without Projects/ChangeSets
       
  1902     "
       
  1903     Project notNil ifTrue:[
       
  1904         dirName := Project currentProjectDirectory
       
  1905     ] ifFalse:[
       
  1906         dirName := Filename currentDirectory
       
  1907     ].
       
  1908     fileName := (dirName asFilename construct:nm).
       
  1909     fileName makeLegalFilename.
       
  1910 
       
  1911     self fileOutAs:fileName name.
       
  1912 
       
  1913 "/    "
       
  1914 "/     add a change record; that way, administration is much easier,
       
  1915 "/     since we can see in that changeBrowser, which changes have 
       
  1916 "/     already found their way into a sourceFile and which must be
       
  1917 "/     applied again
       
  1918 "/    "
       
  1919 "/    self addChangeRecordForClassFileOut:self
       
  1920 
       
  1921     "Modified: / 7.6.1996 / 09:14:43 / stefan"
       
  1922     "Modified: / 27.8.1998 / 02:02:57 / cg"!
       
  1923 
       
  1924 fileOutAllDefinitionsOn:aStream
       
  1925     "append expressions on aStream, which defines myself and all of my private classes."
       
  1926 
       
  1927     self fileOutDefinitionOn:aStream.
       
  1928     aStream nextPutChunkSeparator. 
       
  1929     aStream cr; cr.
       
  1930 
       
  1931     "/
       
  1932     "/ optional classInstanceVariables
       
  1933     "/
       
  1934     self classRef instanceVariableString isBlank ifFalse:[
       
  1935         self fileOutClassInstVarDefinitionOn:aStream.
       
  1936         aStream nextPutChunkSeparator. 
       
  1937         aStream cr; cr
       
  1938     ].
       
  1939 
       
  1940     "/ here, the full nameSpace prefixes are output,
       
  1941     "/ to avoid confusing stc 
       
  1942     "/ (which otherwise could not find the correct superclass)
       
  1943     "/
       
  1944     Class fileOutNameSpaceQuerySignal answer:true do:[
       
  1945         self privateClassesSorted do:[:aClass |
       
  1946             aClass fileOutAllDefinitionsOn:aStream
       
  1947         ]
       
  1948     ].
       
  1949 
       
  1950     "Created: 15.10.1996 / 11:15:19 / cg"
       
  1951     "Modified: 22.3.1997 / 16:11:56 / cg"!
       
  1952 
       
  1953 fileOutAs:fileNameString
       
  1954     "create a file consisting of all methods in myself in
       
  1955      sourceForm, from which the class can be reconstructed (by filing in).
       
  1956      The given fileName should be a full path, including suffix.
       
  1957      Care is taken, to not clobber any existing file in
       
  1958      case of errors (for example: disk full). 
       
  1959      Also, since the classes methods need a valid sourcefile, the current 
       
  1960      sourceFile may not be rewritten."
       
  1961 
       
  1962     |aStream fileName newFileName savFilename needRename
       
  1963      mySourceFileName sameFile s mySourceFileID anySourceRef|
       
  1964 
       
  1965     self isLoaded ifFalse:[
       
  1966         ^ Class fileOutErrorSignal 
       
  1967             raiseRequestWith:self
       
  1968                  errorString:'will not fileOut unloaded classes'
       
  1969     ].
       
  1970 
       
  1971     fileName := fileNameString asFilename.
       
  1972 
       
  1973     "
       
  1974      if file exists, copy the existing to a .sav-file,
       
  1975      create the new file as XXX.new-file,
       
  1976      and, if that worked rename afterwards ...
       
  1977     "
       
  1978     (fileName exists) ifTrue:[
       
  1979         sameFile := false.
       
  1980 
       
  1981         "/ check carefully - maybe, my source does not really come from that
       
  1982         "/ file (i.e. all of my methods have their source as string)
       
  1983 
       
  1984         anySourceRef := false.
       
  1985         self methodDictionary do:[:m|
       
  1986             m sourcePosition notNil ifTrue:[
       
  1987                 anySourceRef := true
       
  1988             ]
       
  1989         ].
       
  1990         self classRef methodDictionary do:[:m|
       
  1991             m sourcePosition notNil ifTrue:[
       
  1992                 anySourceRef := true
       
  1993             ]
       
  1994         ].
       
  1995 
       
  1996         anySourceRef ifTrue:[
       
  1997             s := self sourceStream.
       
  1998             s notNil ifTrue:[
       
  1999                 mySourceFileID := s pathName asFilename info id.
       
  2000                 sameFile := (fileName info id) == mySourceFileID.
       
  2001                 s close.
       
  2002             ] ifFalse:[
       
  2003                 self classFilename notNil ifTrue:[
       
  2004                     "
       
  2005                      check for overwriting my current source file
       
  2006                      this is not allowed, since it would clobber my methods source
       
  2007                      file ... you have to save it to some other place.
       
  2008                      This happens if you ask for a fileOut into the source-directory
       
  2009                      (from which my methods get their source)
       
  2010                     "
       
  2011                     mySourceFileName := Smalltalk getSourceFileName:self classFilename. 
       
  2012                     sameFile := (fileNameString = mySourceFileName).
       
  2013                     sameFile ifFalse:[
       
  2014                         mySourceFileName notNil ifTrue:[
       
  2015                             sameFile := (fileName info id) == (mySourceFileName asFilename info id)
       
  2016                         ]
       
  2017                     ].
       
  2018                 ]
       
  2019             ].
       
  2020         ].
       
  2021 
       
  2022         sameFile ifTrue:[
       
  2023             ^ Class fileOutErrorSignal 
       
  2024                 raiseRequestWith:fileNameString
       
  2025                 errorString:('may not overwrite sourcefile:', fileNameString)
       
  2026         ].
       
  2027 
       
  2028         savFilename := Filename newTemporary.
       
  2029         fileName copyTo:savFilename.
       
  2030         newFileName := fileName withSuffix:'new'.
       
  2031         needRename := true
       
  2032     ] ifFalse:[
       
  2033         "/ another possible trap: if my sourceFileName is
       
  2034         "/ the same as the written one AND the new files directory
       
  2035         "/ is along the sourcePath, we also need a temporary file
       
  2036         "/ first, to avoid accessing the newly written file.
       
  2037 
       
  2038         anySourceRef := false.
       
  2039         self methodDictionary do:[:m|
       
  2040             |mSrc|
       
  2041 
       
  2042             (mSrc := m sourceFilename) notNil ifTrue:[
       
  2043                 mSrc asFilename baseName = fileName baseName ifTrue:[
       
  2044                     anySourceRef := true
       
  2045                 ]
       
  2046             ]
       
  2047         ].
       
  2048         self classRef methodDictionary do:[:m|
       
  2049             |mSrc|
       
  2050 
       
  2051             (mSrc := m sourceFilename) notNil ifTrue:[
       
  2052                 mSrc asFilename baseName = fileName baseName ifTrue:[
       
  2053                     anySourceRef := true
       
  2054                 ]
       
  2055             ]
       
  2056         ].
       
  2057         anySourceRef ifTrue:[
       
  2058             newFileName := fileName withSuffix:'new'.
       
  2059             needRename := true
       
  2060         ] ifFalse:[
       
  2061             newFileName := fileName.
       
  2062             needRename := false
       
  2063         ]
       
  2064     ].
       
  2065 
       
  2066     aStream := newFileName writeStream.
       
  2067     aStream isNil ifTrue:[
       
  2068         savFilename notNil ifTrue:[
       
  2069             savFilename delete
       
  2070         ].
       
  2071         ^ Class fileOutErrorSignal 
       
  2072                 raiseRequestWith:newFileName
       
  2073                 errorString:('cannot create file:', newFileName name)
       
  2074     ].
       
  2075     self fileOutOn:aStream.
       
  2076     aStream close.
       
  2077 
       
  2078     "
       
  2079      finally, replace the old-file
       
  2080      be careful, if the old one is a symbolic link; in this case,
       
  2081      we have to do a copy ...
       
  2082     "
       
  2083     needRename ifTrue:[
       
  2084         newFileName copyTo:fileName.
       
  2085         newFileName delete
       
  2086     ].
       
  2087     savFilename notNil ifTrue:[
       
  2088         savFilename delete
       
  2089     ].
       
  2090 
       
  2091     "
       
  2092      add a change record; that way, administration is much easier,
       
  2093      since we can see in that changeBrowser, which changes have 
       
  2094      already found their way into a sourceFile and which must be
       
  2095      applied again
       
  2096     "
       
  2097     self addChangeRecordForClassFileOut:self
       
  2098 
       
  2099     "Modified: / 7.6.1996 / 09:14:43 / stefan"
       
  2100     "Created: / 16.4.1997 / 20:44:05 / cg"
       
  2101     "Modified: / 12.8.1998 / 11:14:56 / cg"!
       
  2102 
       
  2103 fileOutCategory:aCategory
       
  2104     "create a file 'class-category.st' consisting of all methods in aCategory.
       
  2105      If the current project is not nil, create the file in the projects
       
  2106      directory."
       
  2107 
       
  2108     |aStream fileName|
       
  2109 
       
  2110     fileName := (self name , '-' , aCategory , '.st') asFilename.
       
  2111     fileName makeLegalFilename.
       
  2112 
       
  2113     "/
       
  2114     "/ this test allows a smalltalk to be built without Projects/ChangeSets
       
  2115     "/
       
  2116     Project notNil ifTrue:[
       
  2117         fileName := Project currentProjectDirectory asFilename construct:(fileName name).
       
  2118     ].
       
  2119 
       
  2120     "/
       
  2121     "/ if the file exists, save original in a .sav file
       
  2122     "/
       
  2123     fileName exists ifTrue:[
       
  2124         fileName copyTo:(fileName withSuffix:'sav')
       
  2125     ].
       
  2126     aStream := FileStream newFileNamed:fileName.
       
  2127     aStream isNil ifTrue:[
       
  2128         ^ Class fileOutErrorSignal 
       
  2129                 raiseRequestWith:fileName
       
  2130                 errorString:('cannot create file:', fileName pathName)
       
  2131     ].
       
  2132 
       
  2133     self fileOutCategory:aCategory on:aStream.
       
  2134     aStream close
       
  2135 
       
  2136     "Modified: / 1.4.1997 / 16:00:24 / stefan"
       
  2137     "Created: / 1.4.1997 / 16:04:18 / stefan"
       
  2138     "Modified: / 28.10.1997 / 14:40:28 / cg"!
       
  2139 
       
  2140 fileOutCategory:aCategory except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream
       
  2141     |dict source sortedSelectors first privacy interestingMethods cat|
       
  2142 
       
  2143     dict := self methodDictionary.
       
  2144     dict notNil ifTrue:[
       
  2145         interestingMethods := OrderedCollection new.
       
  2146         dict do:[:aMethod |
       
  2147             |wanted|
       
  2148 
       
  2149             (methodFilter isNil
       
  2150             or:[methodFilter value:aMethod]) ifTrue:[
       
  2151                 (aCategory = aMethod category) ifTrue:[
       
  2152                     skippedMethods notNil ifTrue:[
       
  2153                         wanted := (skippedMethods includesIdentical:aMethod) not
       
  2154                     ] ifFalse:[
       
  2155                         savedMethods notNil ifTrue:[
       
  2156                             wanted := (savedMethods includesIdentical:aMethod).
       
  2157                         ] ifFalse:[
       
  2158                             wanted := true
       
  2159                         ]
       
  2160                     ].
       
  2161                     wanted ifTrue:[interestingMethods add:aMethod].
       
  2162                 ]
       
  2163             ]
       
  2164         ].
       
  2165         interestingMethods notEmpty ifTrue:[
       
  2166             first := true.
       
  2167             privacy := nil.
       
  2168 
       
  2169             "/
       
  2170             "/ sort by selector
       
  2171             "/
       
  2172             sortedSelectors := interestingMethods collect:[:m | self selectorAtMethod:m].
       
  2173             sortedSelectors sortWith:interestingMethods.
       
  2174 
       
  2175             interestingMethods do:[:aMethod |
       
  2176                 first ifFalse:[
       
  2177                     privacy ~~ aMethod privacy ifTrue:[
       
  2178                         first := true.
       
  2179                         aStream space.
       
  2180                         aStream nextPutChunkSeparator.
       
  2181                     ].
       
  2182                     aStream cr; cr
       
  2183                 ].
       
  2184 
       
  2185                 privacy := aMethod privacy.
       
  2186 
       
  2187                 first ifTrue:[
       
  2188                     aStream nextPutChunkSeparator.
       
  2189                     self printClassNameOn:aStream.
       
  2190                     privacy ~~ #public ifTrue:[
       
  2191                         aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'.
       
  2192                     ] ifFalse:[
       
  2193                         aStream nextPutAll:' methodsFor:'.
       
  2194                     ].
       
  2195                     cat := aCategory.
       
  2196                     cat isNil ifTrue:[ cat := '' ].
       
  2197                     aStream nextPutAll:aCategory asString storeString.
       
  2198                     aStream nextPutChunkSeparator; cr; cr.
       
  2199                     first := false.
       
  2200                 ].
       
  2201                 source := aMethod source.
       
  2202                 source isNil ifTrue:[
       
  2203                     Class fileOutErrorSignal 
       
  2204                         raiseRequestWith:self
       
  2205                         errorString:'no source for method: ', (aMethod displayString)
       
  2206                 ] ifFalse:[
       
  2207                     aStream nextChunkPut:source.
       
  2208                 ].
       
  2209             ].
       
  2210             aStream space.
       
  2211             aStream nextPutChunkSeparator.
       
  2212             aStream cr
       
  2213         ]
       
  2214     ]
       
  2215 
       
  2216     "Modified: 28.8.1995 / 14:30:41 / claus"
       
  2217     "Modified: 12.6.1996 / 11:37:33 / stefan"
       
  2218     "Modified: 15.11.1996 / 11:32:21 / cg"
       
  2219     "Created: 1.4.1997 / 16:04:33 / stefan"!
       
  2220 
       
  2221 fileOutCategory:aCategory methodFilter:methodFilter on:aStream
       
  2222     "file out all methods belonging to aCategory, aString onto aStream"
       
  2223 
       
  2224     self fileOutCategory:aCategory except:nil only:nil methodFilter:methodFilter on:aStream!
       
  2225 
       
  2226 fileOutCategory:aCategory on:aStream
       
  2227     Class fileOutNameSpaceQuerySignal answer:true do:[
       
  2228         self fileOutCategory:aCategory except:nil only:nil methodFilter:nil on:aStream
       
  2229     ]!
       
  2230 
       
  2231 fileOutClassInstVarDefinitionOn:aStream withNameSpace:withNameSpace
       
  2232     "append an expression to define my classInstanceVariables on aStream"
       
  2233 
       
  2234     |anySuperClassInstVar|
       
  2235 
       
  2236     self isLoaded ifFalse:[
       
  2237         ^ self basicFileOutDefinitionOn:aStream withNameSpace:withNameSpace
       
  2238     ].
       
  2239 
       
  2240     withNameSpace ifTrue:[
       
  2241         self name printOn:aStream.
       
  2242     ] ifFalse:[
       
  2243         self printClassNameOn:aStream.
       
  2244     ].
       
  2245     aStream nextPutAll:' class instanceVariableNames:'''.
       
  2246     self class printInstVarNamesOn:aStream indent:8.
       
  2247     aStream nextPutAll:''''.
       
  2248 
       
  2249     "mhmh - good idea; saw this in SmallDraw sourcecode ..."
       
  2250 
       
  2251     anySuperClassInstVar := false.
       
  2252     self allSuperclassesDo:[:aSuperClass |
       
  2253         aSuperClass class instVarNames do:[:ignored | anySuperClassInstVar := true].
       
  2254     ].
       
  2255 
       
  2256     aStream cr; cr; nextPut:(Character doubleQuote); cr; space.
       
  2257     anySuperClassInstVar ifFalse:[
       
  2258         aStream  
       
  2259             nextPutLine:'No other class instance variables are inherited by this class.'.
       
  2260     ] ifTrue:[
       
  2261         aStream  
       
  2262             nextPutLine:'The following class instance variables are inherited by this class:'.
       
  2263         aStream cr.
       
  2264         self allSuperclassesDo:[:aSuperClass |
       
  2265             aStream tab; nextPutAll:aSuperClass name; nextPutAll:' - '.
       
  2266             aStream nextPutLine:(aSuperClass class instanceVariableString).
       
  2267         ].
       
  2268 
       
  2269     ].
       
  2270     aStream nextPut:(Character doubleQuote); cr.
       
  2271 
       
  2272     "Created: / 10.12.1995 / 16:31:25 / cg"
       
  2273     "Modified: / 1.4.1997 / 16:00:33 / stefan"
       
  2274     "Modified: / 3.2.2000 / 23:05:28 / cg"
       
  2275 !
       
  2276 
       
  2277 fileOutDefinitionOn:aStream
       
  2278     "append an expression on aStream, which defines myself."
       
  2279 
       
  2280     ^ self basicFileOutDefinitionOn:aStream withNameSpace:false!
       
  2281 
       
  2282 fileOutMethod:aMethod
       
  2283     |aStream fileName selector|
       
  2284 
       
  2285     selector := self selectorAtMethod:aMethod.
       
  2286     selector notNil ifTrue:[
       
  2287         fileName := (self name , '-' , selector, '.st') asFilename.
       
  2288         fileName makeLegalFilename.
       
  2289 
       
  2290         "
       
  2291          this test allows a smalltalk to be built without Projects/ChangeSets
       
  2292         "
       
  2293         Project notNil ifTrue:[
       
  2294             fileName := Project currentProjectDirectory asFilename construct:fileName name.
       
  2295         ].
       
  2296 
       
  2297         "
       
  2298          if file exists, save original in a .sav file
       
  2299         "
       
  2300         fileName exists ifTrue:[
       
  2301             fileName copyTo:(fileName withSuffix: 'sav')
       
  2302         ].
       
  2303 
       
  2304         fileName := fileName name.
       
  2305 
       
  2306         aStream := FileStream newFileNamed:fileName.
       
  2307         aStream isNil ifTrue:[
       
  2308             ^ Class fileOutErrorSignal 
       
  2309                 raiseRequestWith:fileName
       
  2310                 errorString:('cannot create file:', fileName)
       
  2311         ].
       
  2312         self fileOutMethod:aMethod on:aStream.
       
  2313         aStream close
       
  2314     ]
       
  2315 
       
  2316     "Modified: / 1.4.1997 / 16:00:57 / stefan"
       
  2317     "Created: / 2.4.1997 / 00:24:28 / stefan"
       
  2318     "Modified: / 28.10.1997 / 14:40:34 / cg"!
       
  2319 
       
  2320 fileOutMethod:aMethod on:aStream
       
  2321     |dict cat source privacy|
       
  2322 
       
  2323     dict := self methodDictionary.
       
  2324     dict notNil ifTrue:[
       
  2325         aStream nextPutChunkSeparator.
       
  2326         self name printOn:aStream.
       
  2327 "/        self printClassNameOn:aStream.
       
  2328 
       
  2329         (privacy := aMethod privacy) ~~ #public ifTrue:[
       
  2330             aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'.
       
  2331         ] ifFalse:[
       
  2332             aStream nextPutAll:' methodsFor:'.
       
  2333         ].
       
  2334         cat := aMethod category.
       
  2335         cat isNil ifTrue:[
       
  2336             cat := ''
       
  2337         ].
       
  2338         aStream nextPutAll:cat asString storeString.
       
  2339         aStream nextPutChunkSeparator; cr; cr.
       
  2340         source := aMethod source.
       
  2341         source isNil ifTrue:[
       
  2342             Class fileOutErrorSignal 
       
  2343                 raiseRequestWith:self
       
  2344                 errorString:('no source for method: ' ,
       
  2345                              self name , '>>' ,
       
  2346                              (self selectorAtMethod:aMethod))
       
  2347         ] ifFalse:[
       
  2348             aStream nextChunkPut:source.
       
  2349         ].
       
  2350         aStream space.
       
  2351         aStream nextPutChunkSeparator.
       
  2352         aStream cr
       
  2353     ]
       
  2354 
       
  2355     "Modified: 27.8.1995 / 01:23:19 / claus"
       
  2356     "Modified: 12.6.1996 / 11:44:41 / stefan"
       
  2357     "Modified: 15.11.1996 / 11:32:43 / cg"
       
  2358     "Created: 2.4.1997 / 00:24:33 / stefan"!
       
  2359 
       
  2360 fileOutOn:aStream
       
  2361 
       
  2362     ^ self fileOutOn:aStream withTimeStamp:true!
       
  2363 
       
  2364 fileOutOn:aStream withTimeStamp:stampIt
       
  2365     "file out my definition and all methods onto aStream.
       
  2366      If stampIt is true, a timeStamp comment is prepended."
       
  2367 
       
  2368     self fileOutOn:aStream withTimeStamp:stampIt withInitialize:true!
       
  2369 
       
  2370 fileOutOn:aStream withTimeStamp:stampIt withInitialize:initIt
       
  2371     "file out my definition and all methods onto aStream.
       
  2372      If stampIt is true, a timeStamp comment is prepended.
       
  2373      If initIt is true, and the class implements a class-initialize method,
       
  2374      append a corresponding doIt expression for initialization."
       
  2375 
       
  2376     self 
       
  2377         fileOutOn:aStream 
       
  2378         withTimeStamp:stampIt 
       
  2379         withInitialize:initIt 
       
  2380         withDefinition:true
       
  2381         methodFilter:nil!
       
  2382 
       
  2383 fileOutOn:aStream withTimeStamp:stampIt withInitialize:initIt withDefinition:withDefinition methodFilter:methodFilter
       
  2384     "file out my definition and all methods onto aStream.
       
  2385      If stampIt is true, a timeStamp comment is prepended.
       
  2386      If initIt is true, and the class implements a class-initialize method,
       
  2387      append a corresponding doIt expression for initialization.
       
  2388      The order by which the fileOut is done is used to put the version string at the end.
       
  2389      Thus, if the version string is expanded (by CVS), the characterPositions of methods should not move"
       
  2390 
       
  2391     |collectionOfCategories copyrightMethod copyrightText comment versionMethod skippedMethods
       
  2392      meta|
       
  2393 
       
  2394     self isLoaded ifFalse:[
       
  2395         ^ Class fileOutErrorSignal 
       
  2396             raiseRequestWith:self
       
  2397                  errorString:'will not fileOut unloaded classes'
       
  2398     ].
       
  2399 
       
  2400     meta := self classRef.
       
  2401 
       
  2402     "
       
  2403      if there is a copyright method, add a copyright comment
       
  2404      at the beginning, taking the string from the copyright method.
       
  2405      We cannot do this unconditionally - that would lead to my copyrights
       
  2406      being put on your code ;-).
       
  2407      On the other hand: I want every file created by myself to have the
       
  2408      copyright string at the beginning be preserved .... even if the
       
  2409      code was edited in the browser and filedOut.
       
  2410     "
       
  2411     (copyrightMethod := meta compiledMethodAt:#copyright) notNil ifTrue:[
       
  2412         "
       
  2413          get the copyright methods source,
       
  2414          and insert at beginning.
       
  2415         "
       
  2416         copyrightText := copyrightMethod source.
       
  2417         copyrightText isNil ifTrue:[
       
  2418             "
       
  2419              no source available - trigger an error
       
  2420             "
       
  2421             Class fileOutErrorSignal
       
  2422                 raiseRequestWith:'no source for class ' , self name , ' available. Cannot fileOut'.
       
  2423             ^ self
       
  2424         ].
       
  2425         "
       
  2426          strip off the selector-line
       
  2427         "
       
  2428         copyrightText := copyrightText asCollectionOfLines asStringCollection.
       
  2429         copyrightText := copyrightText copyFrom:2 to:(copyrightText size).
       
  2430 "/        copyrightText do:[:line | aStream nextPutAll:line. aStream cr.].
       
  2431         copyrightText := copyrightText asString.
       
  2432         aStream nextPutAllAsChunk:copyrightText.
       
  2433     ].
       
  2434 
       
  2435     stampIt ifTrue:[
       
  2436         "/
       
  2437         "/ first, a timestamp
       
  2438         "/
       
  2439         aStream nextPutAll:(Smalltalk timeStamp).
       
  2440         aStream nextPutChunkSeparator. 
       
  2441         aStream cr; cr.
       
  2442     ].
       
  2443 
       
  2444     withDefinition ifTrue:[
       
  2445         "/
       
  2446         "/ then the definition
       
  2447         "/
       
  2448         self fileOutAllDefinitionsOn:aStream.
       
  2449         "/
       
  2450         "/ a comment - if any
       
  2451         "/
       
  2452         (comment := self comment) notNil ifTrue:[
       
  2453             self fileOutCommentOn:aStream.
       
  2454             aStream cr.
       
  2455         ].
       
  2456         "/
       
  2457         "/ primitive definitions - if any
       
  2458         "/
       
  2459         self fileOutPrimitiveSpecsOn:aStream.
       
  2460     ].
       
  2461 
       
  2462     "/
       
  2463     "/ methods from all categories in metaclass (i.e. class methods)
       
  2464     "/ EXCEPT: the version method is placed at the very end, to
       
  2465     "/         avoid sourcePosition-shifts when checked out later.
       
  2466     "/         (RCS expands this string, so its size is not constant)
       
  2467     "/
       
  2468     collectionOfCategories := meta categories asSortedCollection.
       
  2469     collectionOfCategories notNil ifTrue:[
       
  2470         "/
       
  2471         "/ documentation first (if any), but not the version method
       
  2472         "/
       
  2473         (collectionOfCategories includes:'documentation') ifTrue:[
       
  2474             versionMethod := meta compiledMethodAt:#version.
       
  2475             versionMethod notNil ifTrue:[
       
  2476                 skippedMethods := Array with:versionMethod
       
  2477             ].
       
  2478             meta fileOutCategory:'documentation' except:skippedMethods only:nil methodFilter:methodFilter on:aStream.
       
  2479             aStream cr.
       
  2480         ].
       
  2481 
       
  2482         "/
       
  2483         "/ initialization next (if any)
       
  2484         "/
       
  2485         (collectionOfCategories includes:'initialization') ifTrue:[
       
  2486             meta fileOutCategory:'initialization' methodFilter:methodFilter on:aStream.
       
  2487             aStream cr.
       
  2488         ].
       
  2489 
       
  2490         "/
       
  2491         "/ instance creation next (if any)
       
  2492         "/
       
  2493         (collectionOfCategories includes:'instance creation') ifTrue:[
       
  2494             meta fileOutCategory:'instance creation' methodFilter:methodFilter on:aStream.
       
  2495             aStream cr.
       
  2496         ].
       
  2497         collectionOfCategories do:[:aCategory |
       
  2498             ((aCategory ~= 'documentation')
       
  2499             and:[(aCategory ~= 'initialization')
       
  2500             and:[aCategory ~= 'instance creation']]) ifTrue:[
       
  2501                 meta fileOutCategory:aCategory methodFilter:methodFilter on:aStream.
       
  2502                 aStream cr
       
  2503             ]
       
  2504         ]
       
  2505     ].
       
  2506 
       
  2507     "/
       
  2508     "/ methods from all categories in myself
       
  2509     "/
       
  2510     collectionOfCategories := self categories asSortedCollection.
       
  2511     collectionOfCategories notNil ifTrue:[
       
  2512         collectionOfCategories do:[:aCategory |
       
  2513             self fileOutCategory:aCategory methodFilter:methodFilter on:aStream.
       
  2514             aStream cr
       
  2515         ]
       
  2516     ].
       
  2517 
       
  2518     "/
       
  2519     "/ any private classes' methods
       
  2520     "/
       
  2521     self privateClassesSorted do:[:aClass |
       
  2522         aClass fileOutAllMethodsOn:aStream methodFilter:methodFilter
       
  2523     ].
       
  2524 
       
  2525 
       
  2526     "/
       
  2527     "/ finally, the previously skipped version method
       
  2528     "/
       
  2529     versionMethod notNil ifTrue:[
       
  2530         meta fileOutCategory:'documentation' except:nil only:skippedMethods methodFilter:methodFilter on:aStream.
       
  2531     ].
       
  2532 
       
  2533     initIt ifTrue:[
       
  2534         "/
       
  2535         "/ optionally an initialize message
       
  2536         "/
       
  2537         (meta implements:#initialize) ifTrue:[
       
  2538             self printClassNameOn:aStream. aStream nextPutAll:' initialize'.
       
  2539             aStream nextPutChunkSeparator.
       
  2540             aStream cr
       
  2541         ]
       
  2542     ]
       
  2543 
       
  2544     "Created: / 15.11.1995 / 12:53:06 / cg"
       
  2545     "Modified: / 1.4.1997 / 16:01:05 / stefan"
       
  2546     "Modified: / 13.3.1998 / 12:23:59 / cg"!
       
  2547 
       
  2548 fileOutPrimitiveDefinitionsOn:aStream
       
  2549     "append primitive defs (if any) to aStream."
       
  2550 
       
  2551     |s|
       
  2552 
       
  2553     "
       
  2554      primitive definitions - if any
       
  2555     "
       
  2556     (s := self primitiveDefinitionsString) notNil ifTrue:[
       
  2557         aStream nextPutChunkSeparator.
       
  2558         self printClassNameOn:aStream.
       
  2559         aStream nextPutAll:' primitiveDefinitions';
       
  2560                 nextPutChunkSeparator;
       
  2561                 cr.
       
  2562         aStream nextPutAll:s.
       
  2563         aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr
       
  2564     ].
       
  2565     (s := self primitiveVariablesString) notNil ifTrue:[
       
  2566         aStream nextPutChunkSeparator.
       
  2567         self printClassNameOn:aStream.
       
  2568         aStream nextPutAll:' primitiveVariables';
       
  2569                 nextPutChunkSeparator;
       
  2570                 cr.
       
  2571         aStream nextPutAll:s.
       
  2572         aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr
       
  2573     ].
       
  2574 
       
  2575     "Modified: 8.1.1997 / 17:45:40 / cg"!
       
  2576 
       
  2577 fileOutPrimitiveSpecsOn:aStream
       
  2578     "append primitive defs (if any) to aStream."
       
  2579 
       
  2580     |s|
       
  2581 
       
  2582     "
       
  2583      primitive definitions - if any
       
  2584     "
       
  2585     self fileOutPrimitiveDefinitionsOn:aStream.
       
  2586     "
       
  2587      primitive functions - if any
       
  2588     "
       
  2589     (s := self primitiveFunctionsString) notNil ifTrue:[
       
  2590         aStream nextPutChunkSeparator.
       
  2591         self printClassNameOn:aStream.
       
  2592         aStream nextPutAll:' primitiveFunctions';
       
  2593                 nextPutChunkSeparator;
       
  2594                 cr.
       
  2595         aStream nextPutAll:s.
       
  2596         aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr
       
  2597     ].
       
  2598 
       
  2599     "Modified: 8.1.1997 / 17:45:51 / cg"!
       
  2600 
  1429 firstDefinitionSelectorPart
  2601 firstDefinitionSelectorPart
  1430     "return the first part of the selector with which I was (can be) defined in my superclass"
  2602     "return the first part of the selector with which I was (can be) defined in my superclass"
  1431 
  2603 
  1432     self isVariable ifFalse:[
  2604     self isVariable ifFalse:[
  1433         ^ #'subclass:'
  2605         ^ #'subclass:'
  1458     ].
  2630     ].
  1459     self isLongLongs ifTrue:[
  2631     self isLongLongs ifTrue:[
  1460         ^ #'variableLongLongSubclass:'
  2632         ^ #'variableLongLongSubclass:'
  1461     ].
  2633     ].
  1462     ^ #'variableSubclass:'
  2634     ^ #'variableSubclass:'
       
  2635 !
       
  2636 
       
  2637 getPrimitiveSpecsAt:index
       
  2638     "{ Pragma: +optSpace }"
       
  2639 
       
  2640     "return a primitiveSpecification component as string or nil"
       
  2641 
       
  2642     |owner pos stream string primitiveSpec classFilename|
       
  2643 
       
  2644     (owner := self owningClass) notNil ifTrue:[^ owner getPrimitiveSpecsAt:index].
       
  2645 
       
  2646     primitiveSpec := self primitiveSpec.
       
  2647 
       
  2648     primitiveSpec isNil ifTrue:[^ nil].
       
  2649     pos := primitiveSpec at:index.
       
  2650     pos isNil ifTrue:[^ nil].
       
  2651 
       
  2652     "the primitiveSpec is either a string, or an integer specifying the
       
  2653      position within the classes sourcefile ...
       
  2654     "
       
  2655     pos isNumber ifTrue:[
       
  2656         classFilename := self classFilename.
       
  2657         classFilename notNil ifTrue:[
       
  2658             stream := self sourceStream. 
       
  2659             stream notNil ifTrue:[
       
  2660                 stream position:pos+1.
       
  2661                 string := stream nextChunk.
       
  2662                 stream close.
       
  2663                 ^ string
       
  2664             ]
       
  2665         ].
       
  2666         ^ nil
       
  2667     ].
       
  2668     ^ pos
       
  2669 
       
  2670     "Modified: 15.1.1997 / 15:29:30 / stefan"!
       
  2671 
       
  2672 hasMethods
       
  2673     "return true, if there are any (local) methods in this class"
       
  2674 
       
  2675     ^ (self methodDictionary size ~~ 0)!
       
  2676 
       
  2677 implements:aSelector
       
  2678     ^ self includesSelector:aSelector!
       
  2679 
       
  2680 includesSelector:aSelector
       
  2681     ^ self methodDictionary includesKey:aSelector!
       
  2682 
       
  2683 instanceVariableString
       
  2684     "return a string of the instance variable names"
       
  2685 
       
  2686     |instvars|
       
  2687 
       
  2688     instvars := self instVarNames.
       
  2689     instvars isNil ifTrue:[^ ''].
       
  2690     instvars isString ifTrue:[
       
  2691         ^ instvars
       
  2692     ].
       
  2693 
       
  2694     ^ instvars asStringWith:(Character space)
       
  2695 
       
  2696     "
       
  2697      Point instanceVariableString   
       
  2698     "
       
  2699 
       
  2700     "Modified: 22.8.1997 / 14:59:14 / cg"
       
  2701 !
       
  2702 
       
  2703 isObsolete
       
  2704     ^ false
       
  2705 !
       
  2706 
       
  2707 isSubclassOf:aClass
       
  2708     "return true, if I am a subclass of the argument, aClass"
       
  2709 
       
  2710     |theClass|
       
  2711 
       
  2712     theClass := self superclass.
       
  2713     [theClass notNil] whileTrue:[
       
  2714         (theClass == aClass) ifTrue:[^ true].
       
  2715         theClass := theClass superclass.
       
  2716     ].
       
  2717     ^ false
  1463 !
  2718 !
  1464 
  2719 
  1465 nameWithoutNameSpacePrefix
  2720 nameWithoutNameSpacePrefix
  1466     |nm owner|
  2721     |nm owner|
  1467 
  2722 
  1481     idx == 0 ifTrue:[
  2736     idx == 0 ifTrue:[
  1482         ^ nm
  2737         ^ nm
  1483     ].
  2738     ].
  1484     ^ nm copyFrom:idx+1.
  2739     ^ nm copyFrom:idx+1.
  1485 !
  2740 !
       
  2741 
       
  2742 packageSourceCodeInfo
       
  2743     "{ Pragma: +optSpace }"
       
  2744 
       
  2745     "return the sourceCodeInfo, which defines the module and the subdirectory
       
  2746      in which the receiver class was built. 
       
  2747      This info is extracted from the package id (which is added to stc-compiled classes).
       
  2748      This method is to be obsoleted soon, since the same info is now found
       
  2749      in the versionString.
       
  2750 
       
  2751      The info returned consists of a dictionary
       
  2752      filled with (at least) values at: #module, #directory and #library.
       
  2753      If no such info is present in the class, nil is returned.
       
  2754      (this happens with autoloaded and filed-in classes)
       
  2755      Auotloaded classes set their package from the revisionInfo, if present.
       
  2756 
       
  2757      By convention, this info is encoded in the classes package
       
  2758      string (which is given as argument to stc) as the last word in parenthesis. 
       
  2759      The info consists of 1 to 3 subcomponents, separated by colons.
       
  2760      The first defines the classes module (i.e. some application identifier), 
       
  2761      the second defines the subdirectory within that module, the third
       
  2762      defines the name of the class library. 
       
  2763      If left blank, the module info defaults to 'stx',
       
  2764      the directory info defaults to library name.
       
  2765      The library name may not be left blank.
       
  2766      (this is done for backward compatibility,)
       
  2767 
       
  2768      For example: 
       
  2769         '....(libbasic)'                         -> module: stx directory: libbasic library: libbasic
       
  2770         '....(stx:libbasic)'                     -> module: stx directory: libbasic library: libbasic
       
  2771         '....(stx:foo:libbfoo)'                  -> module: stx directory: foo library: libfoo
       
  2772         '....(aeg:libIECInterface)'              -> module: aeg directory: libIECInterface library:libIECInterface
       
  2773         '....(stx:goodies/persistency:libdbase)' -> module: stx directory: goodies/persistency library:libdbase 
       
  2774 
       
  2775      The way how the sourceCodeManager uses this to find the source location
       
  2776      depends on the scheme used. For CVS, the module is taken as the -d arg,
       
  2777      while the directory is prepended to the file name.
       
  2778      Other schemes may do things differently - these are not yet specified.
       
  2779 
       
  2780      Caveat:
       
  2781         Encoding this info in the package string seems somewhat kludgy.
       
  2782     "
       
  2783 
       
  2784     |owner sourceInfo packageString idx1 idx2 
       
  2785      moduleString directoryString libraryString components component1 component2 dirComponents mgr
       
  2786      package|
       
  2787 
       
  2788     (owner := self owningClass) notNil ifTrue:[^ owner packageSourceCodeInfo].
       
  2789 
       
  2790     package := self package.
       
  2791     package isNil ifTrue:[^ nil].
       
  2792 
       
  2793     packageString := package asString.
       
  2794     idx1 := packageString lastIndexOf:$(.
       
  2795     idx1 ~~ 0 ifTrue:[
       
  2796         idx2 := packageString indexOf:$) startingAt:idx1+1.
       
  2797         idx2 ~~ 0 ifTrue:[
       
  2798             sourceInfo := packageString copyFrom:idx1 + 1 to:idx2 - 1
       
  2799         ]
       
  2800     ] ifFalse:[
       
  2801         sourceInfo := packageString
       
  2802     ].
       
  2803 
       
  2804     sourceInfo isNil ifTrue:[^ nil].
       
  2805     components := sourceInfo asCollectionOfSubstringsSeparatedBy:$:.
       
  2806     components size == 0 ifTrue:[
       
  2807 "/        moduleString := 'stx'.
       
  2808 "/        directoryString := libraryString := ''.
       
  2809         ^ nil
       
  2810     ].
       
  2811 
       
  2812     component1 := components at:1.
       
  2813     components size == 1 ifTrue:[
       
  2814         "/ a single name given - the module becomes 'stx' or
       
  2815         "/ the very first directory component (if such a module exists).
       
  2816         "/ If the component includes slashes, its the directory
       
  2817         "/ otherwise the library.
       
  2818         "/ 
       
  2819         dirComponents := Filename concreteClass components:component1.     
       
  2820         (dirComponents size > 1
       
  2821         and:[(mgr := self sourceCodeManager) notNil
       
  2822         and:[mgr checkForExistingModule:dirComponents first]]) ifTrue:[
       
  2823             moduleString := dirComponents first.
       
  2824             directoryString := libraryString := (Filename fromComponents:(dirComponents copyFrom:2)) asString.
       
  2825         ] ifFalse:[
       
  2826             "/ non-existing; assume directory under the stx package.
       
  2827             moduleString := 'stx'.
       
  2828             (component1 startsWith:'stx/') ifTrue:[
       
  2829                 component1 := component1 copyFrom:5
       
  2830             ].
       
  2831             directoryString := libraryString := component1.
       
  2832         ].
       
  2833 
       
  2834         (libraryString includes:$/) ifTrue:[
       
  2835             libraryString := libraryString asFilename baseName
       
  2836         ]
       
  2837     ] ifFalse:[
       
  2838         component2 := components at:2.
       
  2839         components size == 2 ifTrue:[
       
  2840             "/ two components - assume its the module and the directory; 
       
  2841             "/ the library is assumed to be named after the directory
       
  2842             "/ except, if slashes are in the name; then the libraryname
       
  2843             "/ is the last component.
       
  2844             "/
       
  2845             moduleString := component1.
       
  2846             directoryString := libraryString := component2.
       
  2847             (libraryString includes:$/) ifTrue:[
       
  2848                 libraryString := libraryString asFilename baseName
       
  2849             ]
       
  2850         ] ifFalse:[
       
  2851             "/ all components given
       
  2852             moduleString := component1.
       
  2853             directoryString := component2.
       
  2854             libraryString := components at:3.
       
  2855         ]
       
  2856     ].
       
  2857 
       
  2858     libraryString isEmpty ifTrue:[
       
  2859         directoryString notEmpty ifTrue:[
       
  2860             libraryString := directoryString asFilename baseName
       
  2861         ].
       
  2862         libraryString isEmpty ifTrue:[
       
  2863             "/ lets extract the library from the liblist file ...
       
  2864             libraryString := Smalltalk libraryFileNameOfClass:self.
       
  2865             libraryString isNil ifTrue:[^ nil].
       
  2866         ]
       
  2867     ].
       
  2868 
       
  2869     moduleString isEmpty ifTrue:[
       
  2870         moduleString := 'stx'.
       
  2871     ].
       
  2872     directoryString isEmpty ifTrue:[
       
  2873         directoryString := libraryString.
       
  2874     ].
       
  2875 
       
  2876     ^ IdentityDictionary
       
  2877         with:(#module->moduleString)
       
  2878         with:(#directory->directoryString)
       
  2879         with:(#library->libraryString)
       
  2880 
       
  2881     "
       
  2882      Object packageSourceCodeInfo     
       
  2883      View packageSourceCodeInfo    
       
  2884      Model packageSourceCodeInfo  
       
  2885      BinaryObjectStorage packageSourceCodeInfo  
       
  2886      MemoryMonitor packageSourceCodeInfo  
       
  2887      ClockView packageSourceCodeInfo  
       
  2888     "
       
  2889 
       
  2890     "Created: 4.11.1995 / 20:36:53 / cg"
       
  2891     "Modified: 19.9.1997 / 10:42:25 / cg"!
       
  2892 
       
  2893 primitiveDefinitionsString
       
  2894     "{ Pragma: +optSpace }"
       
  2895 
       
  2896     "return the primitiveDefinition string or nil"
       
  2897 
       
  2898     ^ self getPrimitiveSpecsAt:1
       
  2899 
       
  2900     "
       
  2901      Object primitiveDefinitionsString 
       
  2902      String primitiveDefinitionsString
       
  2903     "!
       
  2904 
       
  2905 primitiveFunctionsString
       
  2906     "{ Pragma: +optSpace }"
       
  2907 
       
  2908     "return the primitiveFunctions string or nil"
       
  2909 
       
  2910     ^ self getPrimitiveSpecsAt:3!
       
  2911 
       
  2912 primitiveVariablesString
       
  2913     "{ Pragma: +optSpace }"
       
  2914 
       
  2915     "return the primitiveVariables string or nil"
       
  2916 
       
  2917     ^ self getPrimitiveSpecsAt:2!
       
  2918 
       
  2919 printClassNameOn:aStream
       
  2920     |nm|
       
  2921 
       
  2922     Class fileOutNameSpaceQuerySignal query == false ifTrue:[
       
  2923         nm := self nameWithoutNameSpacePrefix
       
  2924     ] ifFalse:[
       
  2925         nm := self name.
       
  2926     ].
       
  2927 
       
  2928     aStream nextPutAll:nm.!
  1486 
  2929 
  1487 printClassVarNamesOn:aStream indent:indent
  2930 printClassVarNamesOn:aStream indent:indent
  1488     "print the class variable names indented and breaking at line end"
  2931     "print the class variable names indented and breaking at line end"
  1489 
  2932 
  1490     self printNameArray:(self classVarNames) on:aStream indent:indent
  2933     self printNameArray:(self classVarNames) on:aStream indent:indent
  1569 
  3012 
  1570 printNameInHierarchy
  3013 printNameInHierarchy
  1571     ^ self name
  3014     ^ self name
  1572 !
  3015 !
  1573 
  3016 
       
  3017 privateClasses
       
  3018     "{ Pragma: +optSpace }"
       
  3019 
       
  3020     "return a collection of my private classes (if any).
       
  3021      The classes are in any order."
       
  3022 
       
  3023     ^ self privateClassesOrAll:false!
       
  3024 
  1574 privateClassesAt:aClassNameStringOrSymbol
  3025 privateClassesAt:aClassNameStringOrSymbol
  1575     |nmSym|
  3026     |nmSym|
  1576 
  3027 
  1577     nmSym := (self name , '::' , aClassNameStringOrSymbol) asSymbolIfInterned.
  3028     nmSym := (self name , '::' , aClassNameStringOrSymbol) asSymbolIfInterned.
  1578     nmSym isNil ifTrue:[
  3029     nmSym isNil ifTrue:[
  1581     ].
  3032     ].
  1582 
  3033 
  1583     ^ memory at:nmSym.
  3034     ^ memory at:nmSym.
  1584 !
  3035 !
  1585 
  3036 
       
  3037 privateClassesOrAll:allOfThem
       
  3038     "{ Pragma: +optSpace }"
       
  3039 
       
  3040     "return a collection of my direct private classes (if any)
       
  3041      or direct plus indirect private classes (if allOfThem).
       
  3042      An empty collection if there are none.
       
  3043      The classes are in any order."
       
  3044 
       
  3045     |classes myName myNamePrefix myNamePrefixLen|
       
  3046 
       
  3047     myName := self name.
       
  3048     myNamePrefix := myName , '::'.
       
  3049     myNamePrefixLen := myNamePrefix size.
       
  3050 
       
  3051     Smalltalk keysDo:[:nm |
       
  3052         |cls|
       
  3053 
       
  3054         (nm startsWith:myNamePrefix) ifTrue:[
       
  3055             (allOfThem
       
  3056             or:[(nm indexOf:$: startingAt:myNamePrefixLen + 1) == 0]) ifTrue:[
       
  3057                 cls := Smalltalk at:nm.
       
  3058 
       
  3059                 (cls isBehavior and:[cls isMeta not]) ifTrue:[
       
  3060                     classes isNil ifTrue:[
       
  3061                         classes := IdentitySet new:10.
       
  3062                     ].
       
  3063                     classes add:cls.
       
  3064                 ]
       
  3065             ]
       
  3066         ]
       
  3067     ].
       
  3068 
       
  3069     ^ classes ? #()
       
  3070 
       
  3071     "
       
  3072      UILayoutTool privateClassesOrAll:true 
       
  3073      UILayoutTool privateClassesOrAll:false 
       
  3074     "
       
  3075 
       
  3076     "Modified: / 29.5.1998 / 23:23:18 / cg"!
       
  3077 
       
  3078 privateClassesSorted
       
  3079     "{ Pragma: +optSpace }"
       
  3080 
       
  3081     "return a collection of my private classes (if any).
       
  3082      The classes are sorted by inheritance."
       
  3083 
       
  3084     |classes|
       
  3085 
       
  3086     classes := self privateClasses.
       
  3087     (classes size > 0) ifTrue:[
       
  3088         classes := classes asOrderedCollection topologicalSort:[:a :b | b isSubclassOf:a].
       
  3089     ].
       
  3090     ^ classes.
       
  3091 
       
  3092     "
       
  3093      Object privateClassesSorted
       
  3094     "
       
  3095 
       
  3096     "Created: 22.3.1997 / 16:10:42 / cg"
       
  3097     "Modified: 22.3.1997 / 16:11:20 / cg"!
       
  3098 
       
  3099 revisionInfo
       
  3100     "return a dictionary filled with revision info.
       
  3101      This extracts the relevant info from the revisionString.
       
  3102      The revisionInfo contains all or a subset of:
       
  3103         #binaryRevision - the revision upon which the binary of this class is based
       
  3104         #revision       - the revision upon which the class is based logically
       
  3105                           (different, if a changed class was checked in, but not yet recompiled)
       
  3106         #user           - the user who checked in the logical revision
       
  3107         #date           - the date when the logical revision was checked in
       
  3108         #time           - the time when the logical revision was checked in
       
  3109         #fileName       - the classes source file name
       
  3110         #repositoryPath - the classes source container
       
  3111     "
       
  3112 
       
  3113     |vsnString info mgr|
       
  3114 
       
  3115     vsnString := self revisionString.
       
  3116     vsnString notNil ifTrue:[
       
  3117         mgr := self sourceCodeManager.
       
  3118         mgr notNil ifTrue:[
       
  3119             info := mgr revisionInfoFromString:vsnString
       
  3120         ] ifFalse:[
       
  3121             info := Class revisionInfoFromString:vsnString.
       
  3122         ].
       
  3123         info notNil ifTrue:[
       
  3124             info at:#binaryRevision put:self binaryRevision.
       
  3125         ]
       
  3126     ].
       
  3127     ^ info!
       
  3128 
       
  3129 revisionString
       
  3130     "{ Pragma: +optSpace }"
       
  3131 
       
  3132     "return my revision string; that one is extracted from the
       
  3133      classes #version method. Either this is a method returning that string,
       
  3134      or its a comment-only method and the comment defines the version.
       
  3135      If the source is not accessable or no such method exists,
       
  3136      nil is returned."
       
  3137 
       
  3138     |owner cls meta m src val|
       
  3139 
       
  3140     (owner := self owningClass) notNil ifTrue:[^ owner revisionString].
       
  3141 
       
  3142     thisContext isRecursive ifTrue:[^ nil ].
       
  3143 
       
  3144     self isMeta ifTrue:[
       
  3145         meta := self. cls := self soleInstance
       
  3146     ] ifFalse:[
       
  3147         cls := self. meta := self classRef
       
  3148     ].
       
  3149 
       
  3150     m := meta compiledMethodAt:#version.
       
  3151     m isNil ifTrue:[
       
  3152         m := cls compiledMethodAt:#version.
       
  3153         m isNil ifTrue:[^ nil].
       
  3154     ].
       
  3155 
       
  3156     m isExecutable ifTrue:[
       
  3157         "/
       
  3158         "/ if its a method returning the string,
       
  3159         "/ thats the returned value
       
  3160         "/
       
  3161         val := cls version.
       
  3162         val isString ifTrue:[^ val].
       
  3163     ].
       
  3164 
       
  3165     "/
       
  3166     "/ if its a method consisting of a comment only
       
  3167     "/ extract it - this may lead to a recursive call
       
  3168     "/ to myself (thats what the #isRecursive is for)
       
  3169     "/ in case we need to access the source code manager
       
  3170     "/ for the source ...
       
  3171     "/
       
  3172     src := m source.
       
  3173     src isNil ifTrue:[^ nil].
       
  3174     ^ Class revisionStringFromSource:src 
       
  3175 
       
  3176     "
       
  3177      Smalltalk allClassesDo:[:cls |
       
  3178         Transcript showCR:cls revisionString
       
  3179      ].
       
  3180 
       
  3181      Number revisionString  
       
  3182      FileDirectory revisionString
       
  3183      Metaclass revisionString
       
  3184     "
       
  3185 
       
  3186     "Created: 29.10.1995 / 19:28:03 / cg"
       
  3187     "Modified: 23.10.1996 / 18:23:56 / cg"
       
  3188     "Modified: 1.4.1997 / 23:37:25 / stefan"!
       
  3189 
       
  3190 selectorAtMethod:aMethod
       
  3191     ^ self selectorAtMethod:aMethod ifAbsent:[nil]!
       
  3192 
       
  3193 selectorAtMethod:aMethod ifAbsent:failBlock
       
  3194     |md|
       
  3195 
       
  3196     md := self methodDictionary.
       
  3197     md isNil ifTrue:[
       
  3198         'OOPS - nil methodDictionary' errorPrintCR.
       
  3199         ^ nil
       
  3200     ].
       
  3201     ^ md keyAtValue:aMethod ifAbsent:failBlock.!
       
  3202 
       
  3203 soleInstance
       
  3204     self isMeta ifFalse:[self halt].
       
  3205     ^ self theNonMetaclass.
       
  3206 !
       
  3207 
  1586 sourceCodeManager
  3208 sourceCodeManager
  1587     ^ SourceCodeManager
  3209     ^ SourceCodeManager
  1588 !
  3210 !
  1589 
  3211 
       
  3212 sourceStreamFor:source
       
  3213     "return an open stream on a sourcefile, nil if that is not available"
       
  3214 
       
  3215     |owner fileName aStream mgr validated guessedFileName sep mod dir classFilename package name|
       
  3216 
       
  3217     self isMeta ifTrue:[
       
  3218         ^ self theNonMetaclass sourceStreamFor:source
       
  3219     ].
       
  3220 
       
  3221     (owner := self owningClass) notNil ifTrue:[^ owner sourceStreamFor:source].
       
  3222     validated := false.
       
  3223 
       
  3224     classFilename := self classFilename.
       
  3225     package := self package.
       
  3226     name := self name.
       
  3227 
       
  3228     "/
       
  3229     "/ if there is no SourceCodeManager, 
       
  3230     "/ or TryLocalSourceFirst is true,
       
  3231     "/ look in standard places first
       
  3232     "/
       
  3233     ((mgr := self sourceCodeManager) isNil 
       
  3234     or:[Class tryLocalSourceFirst == true]) ifTrue:[
       
  3235         aStream := self localSourceStreamFor:source.
       
  3236     ].
       
  3237 
       
  3238     aStream isNil ifTrue:[
       
  3239         "/ mhmh - still no source file.
       
  3240         "/ If there is a SourceCodeManager, ask it to aquire the
       
  3241         "/ the source for my class, and return an open stream on it. 
       
  3242         "/ if that one does not know about the source, look in
       
  3243         "/ standard places
       
  3244 
       
  3245         mgr notNil ifTrue:[
       
  3246             self classFilename ~= source ifTrue:[
       
  3247                 sep := self package indexOfAny:'/\:'.
       
  3248                 sep ~~ 0 ifTrue:[
       
  3249                     mod := package copyTo:sep - 1.
       
  3250                     dir := package copyFrom:sep + 1.
       
  3251                     aStream := mgr streamForClass:nil fileName:source revision:nil directory:dir module:mod cache:true.
       
  3252                 ].
       
  3253             ].
       
  3254             aStream isNil ifTrue:[
       
  3255                 classFilename isNil ifTrue:[
       
  3256                     classFilename := guessedFileName := (Smalltalk fileNameForClass:self) , '.st'.
       
  3257                 ].
       
  3258                 source asFilename baseName = classFilename asFilename baseName ifTrue:[
       
  3259                     aStream := mgr getSourceStreamFor:self.
       
  3260                 ]
       
  3261             ].
       
  3262             aStream notNil ifTrue:[
       
  3263                 (self validateSourceStream:aStream) ifFalse:[
       
  3264                     ('Class [info]: repositories source for `' 
       
  3265                      , (self isMeta ifTrue:[self soleInstance name]
       
  3266                                     ifFalse:[name])
       
  3267                      , ''' is invalid.') infoPrintCR.
       
  3268                     aStream close.
       
  3269                     aStream := nil
       
  3270                 ] ifTrue:[
       
  3271                     validated := true.
       
  3272                 ].
       
  3273             ].
       
  3274         ]
       
  3275     ].
       
  3276 
       
  3277     aStream isNil ifTrue:[
       
  3278         "/      
       
  3279         "/ hard case - there is no source file for this class
       
  3280         "/ (in the source-dir-path).
       
  3281         "/      
       
  3282 
       
  3283         "/      
       
  3284         "/ look if my binary is from a dynamically loaded module,
       
  3285         "/ and, if so, look in the modules directory for the
       
  3286         "/ source file.
       
  3287         "/      
       
  3288         ObjectFileLoader notNil ifTrue:[
       
  3289             ObjectFileLoader loadedObjectHandlesDo:[:h |
       
  3290                 |f classes|
       
  3291 
       
  3292                 aStream isNil ifTrue:[
       
  3293                     (classes := h classes) size > 0 ifTrue:[
       
  3294                         (classes includes:self) ifTrue:[
       
  3295                             f := h pathName.
       
  3296                             f := f asFilename directory.
       
  3297                             f := f construct:source.
       
  3298                             f exists ifTrue:[
       
  3299                                 aStream := f readStream.
       
  3300                             ].
       
  3301                         ].
       
  3302                     ].
       
  3303                 ]
       
  3304             ].
       
  3305         ].
       
  3306     ].
       
  3307 
       
  3308     "/
       
  3309     "/ try along sourcePath
       
  3310     "/
       
  3311     aStream isNil ifTrue:[
       
  3312         aStream := self localSourceStreamFor:source.
       
  3313     ].
       
  3314 
       
  3315     "/
       
  3316     "/ final chance: try current directory
       
  3317     "/
       
  3318     aStream isNil ifTrue:[
       
  3319         aStream := source asFilename readStream.
       
  3320     ].
       
  3321 
       
  3322     (aStream notNil and:[validated not]) ifTrue:[
       
  3323         (self validateSourceStream:aStream) ifFalse:[
       
  3324             (Smalltalk releaseIdentification = 'ST/X_free_demo_vsn') ifTrue:[
       
  3325 "/                ('Class [info]: source for ''' , self name , ''' is not available in the demo version.') infoPrintCR
       
  3326             ] ifFalse:[
       
  3327                 ('Class [warning]: source for ''' , self name , ''' is invalid or stripped. Take care.') errorPrintCR
       
  3328             ]
       
  3329         ].
       
  3330     ].
       
  3331     (aStream notNil and:[aStream isFileStream]) ifTrue:[
       
  3332         guessedFileName notNil ifTrue:[
       
  3333             classFilename := aStream pathName asFilename baseName.
       
  3334         ]
       
  3335     ].
       
  3336     ^ aStream
       
  3337 
       
  3338     "
       
  3339      Object sourceStream
       
  3340      Clock sourceStream
       
  3341      Autoload sourceStream
       
  3342     "
       
  3343 
       
  3344     "Created: / 10.11.1995 / 21:05:13 / cg"
       
  3345     "Modified: / 22.4.1998 / 19:20:50 / ca"
       
  3346     "Modified: / 23.4.1998 / 15:53:54 / cg"
       
  3347 !
       
  3348 
       
  3349 subclasses
       
  3350     "return a collection of the direct subclasses of the receiver"
       
  3351 
       
  3352     |newColl|
       
  3353 
       
  3354 "/    "/ use cached information (avoid class hierarchy search)
       
  3355 "/    "/ if possible
       
  3356 "/
       
  3357 "/    SubclassInfo notNil ifTrue:[
       
  3358 "/        newColl := SubclassInfo at:self ifAbsent:nil.
       
  3359 "/        newColl notNil ifTrue:[^ newColl asOrderedCollection]
       
  3360 "/    ].
       
  3361 
       
  3362     newColl := OrderedCollection new.
       
  3363     self subclassesDo:[:aClass |
       
  3364         newColl add:aClass
       
  3365     ].
       
  3366 "/    SubclassInfo notNil ifTrue:[
       
  3367 "/        SubclassInfo at:self put:newColl.
       
  3368 "/    ].
       
  3369     ^ newColl
       
  3370 !
       
  3371 
       
  3372 subclassesDo:aBlock
       
  3373     "evaluate the argument, aBlock for all immediate subclasses.
       
  3374      This will only enumerate globally known classes - for anonymous
       
  3375      behaviors, you have to walk over all instances of Behavior."
       
  3376 
       
  3377     |coll|
       
  3378 
       
  3379     self isMeta ifTrue:[
       
  3380         self halt.
       
  3381         "/ metaclasses are not found via Smalltalk allClassesDo:
       
  3382         "/ here, walk over classes and enumerate corresponding metas.
       
  3383         self soleInstance subclassesDo:[:aSubClass |
       
  3384             aBlock value:(aSubClass class)
       
  3385         ].
       
  3386         ^ self
       
  3387     ].
       
  3388 
       
  3389     "/ use cached information (avoid class hierarchy search)
       
  3390     "/ if possible
       
  3391 
       
  3392 "/    SubclassInfo isNil ifTrue:[
       
  3393 "/        Behavior subclassInfo
       
  3394 "/    ].
       
  3395 "/    SubclassInfo notNil ifTrue:[
       
  3396 "/        coll := SubclassInfo at:self ifAbsent:nil.
       
  3397 "/        coll notNil ifTrue:[
       
  3398 "/            coll do:aBlock.
       
  3399 "/        ].
       
  3400 "/        ^ self
       
  3401 "/    ].
       
  3402 
       
  3403     Smalltalk allClassesDo:[:aClass |
       
  3404         (aClass superclass == self) ifTrue:[
       
  3405             aBlock value:aClass
       
  3406         ]
       
  3407     ]
       
  3408 
       
  3409     "
       
  3410      Collection subclassesDo:[:c | Transcript showCR:(c name)]
       
  3411     "
       
  3412 
       
  3413     "Modified: 22.1.1997 / 18:44:01 / cg"
       
  3414 !
       
  3415 
  1590 syntaxHighlighterClass
  3416 syntaxHighlighterClass
  1591     ^ Object syntaxHighlighterClass
  3417     ^ Object syntaxHighlighterClass
  1592 !
  3418 !
       
  3419 
       
  3420 theMetaclass
       
  3421     self isMeta ifTrue:[^ self].
       
  3422     ^ self classRef.!
       
  3423 
       
  3424 theNonMetaclass
       
  3425     |instSlotOffs clsPtr|
       
  3426 
       
  3427     self isMeta ifFalse:[^ self].
       
  3428     instSlotOffs := Metaclass instVarOffsetOf:'myClass'.
       
  3429     clsPtr := self at:instSlotOffs.
       
  3430     ^ memory fetchObjectAt:clsPtr.
       
  3431 !
       
  3432 
       
  3433 validateSourceStream:aStream
       
  3434     "check if aStream really contains my source.
       
  3435      This is done by checking the version methods return value
       
  3436      against the version string as contained in the version method"
       
  3437 
       
  3438     ^ true!
       
  3439 
       
  3440 withAllSuperclasses
       
  3441     "return a collection containing the receiver and all
       
  3442      of the receivers accumulated superclasses"
       
  3443 
       
  3444     |aCollection theSuperClass|
       
  3445 
       
  3446     aCollection := OrderedCollection with:self.
       
  3447     theSuperClass := self superclass.
       
  3448     [theSuperClass notNil] whileTrue:[
       
  3449         aCollection add:theSuperClass.
       
  3450         theSuperClass := theSuperClass superclass
       
  3451     ].
       
  3452     ^ aCollection
       
  3453 
       
  3454     "
       
  3455      String withAllSuperclasses 
       
  3456     "!
  1593 
  3457 
  1594 withAllSuperclassesDo:aBlock
  3458 withAllSuperclassesDo:aBlock
  1595     |sc|
  3459     |sc|
  1596 
  3460 
  1597     aBlock value:self.
  3461     aBlock value:self.
  1642 isLongs
  3506 isLongs
  1643     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagLongs.
  3507     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagLongs.
  1644 !
  3508 !
  1645 
  3509 
  1646 isMeta
  3510 isMeta
  1647     ^ self size == (Metaclass instSize * memory ptrSize).
  3511     ^ self size == (Metaclass instSize).
  1648 "/    ^ classRef classRef name = 'Metaclass'
  3512 "/    ^ classRef classRef name = 'Metaclass'!
  1649 !
       
  1650 
  3513 
  1651 isPrivate
  3514 isPrivate
  1652     ^ classRef isPrivateMeta 
  3515     ^ classRef isPrivateMeta 
  1653 !
  3516 !
  1654 
  3517 
  1678 
  3541 
  1679 nameSpace
  3542 nameSpace
  1680     |env name idx nsName|
  3543     |env name idx nsName|
  1681 
  3544 
  1682 "/    (env := self environment) notNil ifTrue:[^ env].
  3545 "/    (env := self environment) notNil ifTrue:[^ env].
       
  3546     env := Smalltalk. "/ default
  1683     name := self name.
  3547     name := self name.
  1684     idx := name lastIndexOf:$:.
  3548     idx := name lastIndexOf:$:.
  1685     idx ~~ 0 ifTrue:[
  3549     idx ~~ 0 ifTrue:[
  1686         (name at:idx-1) == $: ifTrue:[
  3550         (name at:idx-1) == $: ifTrue:[
  1687             nsName := name copyTo:(idx - 2).
  3551             nsName := name copyTo:(idx - 2).
  1721 
  3585 
  1722 wasAutoloaded
  3586 wasAutoloaded
  1723     ^ false 
  3587     ^ false 
  1724 ! !
  3588 ! !
  1725 
  3589 
  1726 !SnapShotImageMemory::ImageByteObject methodsFor:'queries'!
       
  1727 
       
  1728 size
       
  1729     ^ byteSize
       
  1730 ! !
       
  1731 
       
  1732 !SnapShotImageMemory class methodsFor:'documentation'!
  3590 !SnapShotImageMemory class methodsFor:'documentation'!
  1733 
  3591 
  1734 version
  3592 version
  1735     ^ '$Header$'
  3593     ^ '$Header$'
  1736 ! !
  3594 ! !