39 Class adds more functionality to classes; minimum stuff has already |
39 Class adds more functionality to classes; minimum stuff has already |
40 been defined in Behavior and ClassDescription; this adds naming, categories etc. |
40 been defined in Behavior and ClassDescription; this adds naming, categories etc. |
41 |
41 |
42 [Instance variables:] |
42 [Instance variables:] |
43 |
43 |
44 name <Symbol> the classes name |
44 name <Symbol> the classes name |
45 |
45 |
46 category <Symbol> the classes category |
46 category <Symbol> the classes category |
47 |
47 |
48 classvars <String> the names of the class variables |
48 classvars <String> the names of the class variables |
49 |
49 |
50 comment <String> the classes comment; either a string, |
50 comment <String> the classes comment; either a string, |
51 a number specifying the offset in classFilename, or nil |
51 a number specifying the offset in classFilename, or nil |
52 |
52 |
53 subclasses <Collection> cached collection of subclasses |
53 subclasses <Collection> cached collection of subclasses |
54 (currently unused - but will be soon) |
54 (currently unused - but will be soon) |
55 |
55 |
56 classFilename <String> the file (or nil) where the classes |
56 classFilename <String> the file (or nil) where the classes |
57 sources are found |
57 sources are found |
58 |
58 |
59 package <Symbol> the package, in which the class was defined |
59 package <Symbol> the package, in which the class was defined |
60 (inserted by compilers) |
60 (inserted by compilers) |
61 |
61 |
62 revision <String> revision string - inserted by stc |
62 revision <String> revision string - inserted by stc |
63 |
63 |
64 primitiveSpec <Array | nil> describes primitiveIncludes, primitiveFunctions etc. |
64 primitiveSpec <Array | nil> describes primitiveIncludes, primitiveFunctions etc. |
65 |
65 |
66 environment <Symbol | nil> cached environment (i.e. Smalltalk or a namespace) |
66 environment <Symbol | nil> cached environment (i.e. Smalltalk or a namespace) |
67 of class |
67 of class |
68 |
68 |
69 signature <SmallInteger> the classes signature (used to detect obsolete |
69 signature <SmallInteger> the classes signature (used to detect obsolete |
70 or changed classes with binaryStorage) |
70 or changed classes with binaryStorage) |
71 This is filled in lazy - i.e. upon the first signature query. |
71 This is filled in lazy - i.e. upon the first signature query. |
72 |
72 |
73 hook <any> reserved: a place to add additional attributes, |
73 hook <any> reserved: a place to add additional attributes, |
74 without a need to recompile all classes. |
74 without a need to recompile all classes. |
75 Currently unused. |
75 Currently unused. |
76 |
76 |
77 [Class variables:] |
77 [Class variables:] |
78 |
78 |
79 OldMethods if nonNil, this must be an IdentityDictionary, |
79 OldMethods if nonNil, this must be an IdentityDictionary, |
80 which is filled with method->previousversionMethod |
80 which is filled with method->previousversionMethod |
81 associations. Can be used for undo-last-method-change |
81 associations. Can be used for undo-last-method-change |
82 Notice: this may fillup your memory over time. |
82 Notice: this may fillup your memory over time. |
83 |
83 |
84 |
84 |
85 WARNING: layout known by compiler and runtime system |
85 WARNING: layout known by compiler and runtime system |
86 |
86 |
87 [author:] |
87 [author:] |
88 Claus Gittinger |
88 Claus Gittinger |
89 |
89 |
90 [see also:] |
90 [see also:] |
91 Behavior ClassDescription Metaclass |
91 Behavior ClassDescription Metaclass |
92 " |
92 " |
93 ! ! |
93 ! ! |
94 |
94 |
95 !Class class methodsFor:'Signal constants'! |
95 !Class class methodsFor:'Signal constants'! |
96 |
96 |
288 |
288 |
289 "/ |
289 "/ |
290 "/ mhmh - ask the default manager |
290 "/ mhmh - ask the default manager |
291 "/ |
291 "/ |
292 (mgr := Smalltalk at:#SourceCodeManager) notNil ifTrue:[ |
292 (mgr := Smalltalk at:#SourceCodeManager) notNil ifTrue:[ |
293 info := mgr revisionInfoFromString:aString. |
293 info := mgr revisionInfoFromString:aString. |
294 info notNil ifTrue:[ |
294 info notNil ifTrue:[ |
295 ^ info |
295 ^ info |
296 ] |
296 ] |
297 ]. |
297 ]. |
298 |
298 |
299 "/ |
299 "/ |
300 "/ fallBack - handles some RCS headers only |
300 "/ fallBack - handles some RCS headers only |
301 "/ is this really needed ? |
301 "/ is this really needed ? |
302 "/ |
302 "/ |
303 info := IdentityDictionary new. |
303 info := IdentityDictionary new. |
304 words := aString asCollectionOfWords. |
304 words := aString asCollectionOfWords. |
305 |
305 |
306 words notEmpty ifTrue:[ |
306 words notEmpty ifTrue:[ |
307 "/ |
307 "/ |
308 "/ supported formats: |
308 "/ supported formats: |
309 "/ |
309 "/ |
310 "/ $-Header: pathName rev date time user state $ |
310 "/ $-Header: pathName rev date time user state $ |
311 "/ $-Revision: rev $ |
311 "/ $-Revision: rev $ |
312 "/ $-Id: fileName rev date time user state $ |
312 "/ $-Id: fileName rev date time user state $ |
313 "/ |
313 "/ |
314 |
314 |
315 ((words at:1) = '$Header:') ifTrue:[ |
315 ((words at:1) = '$Header:') ifTrue:[ |
316 nm := words at:2. |
316 nm := words at:2. |
317 info at:#repositoryPathName put:nm. |
317 info at:#repositoryPathName put:nm. |
318 (nm endsWith:',v') ifTrue:[ |
318 (nm endsWith:',v') ifTrue:[ |
319 nm := nm copyWithoutLast:2 |
319 nm := nm copyWithoutLast:2 |
320 ]. |
320 ]. |
321 info at:#fileName put:nm asFilename baseName. |
321 info at:#fileName put:nm asFilename baseName. |
322 words size > 2 ifTrue:[ |
322 words size > 2 ifTrue:[ |
323 (words at:3) = '$' ifFalse:[ |
323 (words at:3) = '$' ifFalse:[ |
324 info at:#revision put:(words at:3). |
324 info at:#revision put:(words at:3). |
325 (words at:4) = '$' ifFalse:[ |
325 (words at:4) = '$' ifFalse:[ |
326 info at:#date put:(words at:4). |
326 info at:#date put:(words at:4). |
327 info at:#time put:(words at:5). |
327 info at:#time put:(words at:5). |
328 info at:#user put:(words at:6). |
328 info at:#user put:(words at:6). |
329 info at:#state put:(words at:7). |
329 info at:#state put:(words at:7). |
330 ] |
330 ] |
331 ]. |
331 ]. |
332 ]. |
332 ]. |
333 ^ info |
333 ^ info |
334 ]. |
334 ]. |
335 ((words at:1) = '$Revision:') ifTrue:[ |
335 ((words at:1) = '$Revision:') ifTrue:[ |
336 info at:#revision put:(words at:2). |
336 info at:#revision put:(words at:2). |
337 ^ info |
337 ^ info |
338 ]. |
338 ]. |
339 ((words at:1) = '$Id:') ifTrue:[ |
339 ((words at:1) = '$Id:') ifTrue:[ |
340 info at:#fileName put:(words at:2). |
340 info at:#fileName put:(words at:2). |
341 info at:#revision put:(words at:3). |
341 info at:#revision put:(words at:3). |
342 info at:#date put:(words at:4). |
342 info at:#date put:(words at:4). |
343 info at:#time put:(words at:5). |
343 info at:#time put:(words at:5). |
344 info at:#user put:(words at:6). |
344 info at:#user put:(words at:6). |
345 info at:#state put:(words at:7). |
345 info at:#state put:(words at:7). |
346 ^ info |
346 ^ info |
347 ]. |
347 ]. |
348 ]. |
348 ]. |
349 |
349 |
350 ^ nil |
350 ^ nil |
351 |
351 |
352 "Created: 15.11.1995 / 14:58:35 / cg" |
352 "Created: 15.11.1995 / 14:58:35 / cg" |
604 No change record is written and no classes are recompiled." |
604 No change record is written and no classes are recompiled." |
605 |
605 |
606 |prevVarNames varNames any| |
606 |prevVarNames varNames any| |
607 |
607 |
608 (classvars = aString) ifFalse:[ |
608 (classvars = aString) ifFalse:[ |
609 prevVarNames := self classVarNames. |
609 prevVarNames := self classVarNames. |
610 classvars := aString. |
610 classvars := aString. |
611 varNames := self classVarNames. |
611 varNames := self classVarNames. |
612 |
612 |
613 "new ones get initialized to nil; |
613 "new ones get initialized to nil; |
614 - old ones are nilled and removed from Smalltalk" |
614 - old ones are nilled and removed from Smalltalk" |
615 any := false. |
615 any := false. |
616 |
616 |
617 varNames do:[:aName | |
617 varNames do:[:aName | |
618 (prevVarNames includes:aName) ifFalse:[ |
618 (prevVarNames includes:aName) ifFalse:[ |
619 "a new one" |
619 "a new one" |
620 self classVarAt:aName put:nil. |
620 self classVarAt:aName put:nil. |
621 any := true. |
621 any := true. |
622 ] ifTrue:[ |
622 ] ifTrue:[ |
623 prevVarNames remove:aName |
623 prevVarNames remove:aName |
624 ] |
624 ] |
625 ]. |
625 ]. |
626 "left overs are gone" |
626 "left overs are gone" |
627 prevVarNames do:[:aName | |
627 prevVarNames do:[:aName | |
628 self classVarAt:aName put:nil. |
628 self classVarAt:aName put:nil. |
629 Smalltalk removeKey:(self name , ':' , aName) asSymbol. |
629 Smalltalk removeKey:(self name , ':' , aName) asSymbol. |
630 ]. |
630 ]. |
631 any ifTrue:[ |
631 any ifTrue:[ |
632 Smalltalk changed:#classVariables with:self |
632 Smalltalk changed:#classVariables with:self |
633 ]. |
633 ]. |
634 ] |
634 ] |
635 |
635 |
636 "Modified: 2.4.1997 / 00:16:05 / stefan" |
636 "Modified: 2.4.1997 / 00:16:05 / stefan" |
637 ! |
637 ! |
638 |
638 |
725 "/ due to the implementation, extract this from my name |
725 "/ due to the implementation, extract this from my name |
726 "/ (physically, all classes are found in Smalltalk) |
726 "/ (physically, all classes are found in Smalltalk) |
727 |
727 |
728 idx := name lastIndexOf:$:. |
728 idx := name lastIndexOf:$:. |
729 idx == 0 ifTrue:[ |
729 idx == 0 ifTrue:[ |
730 environment := Smalltalk. |
730 environment := Smalltalk. |
731 ^ Smalltalk |
731 ^ Smalltalk |
732 ]. |
732 ]. |
733 |
733 |
734 (name at:idx-1) ~~ $: ifTrue:[ |
734 (name at:idx-1) ~~ $: ifTrue:[ |
735 environment := Smalltalk. |
735 environment := Smalltalk. |
736 ^ Smalltalk |
736 ^ Smalltalk |
737 ]. |
737 ]. |
738 nsName := name copyTo:(idx - 2). |
738 nsName := name copyTo:(idx - 2). |
739 environment := Smalltalk at:nsName asSymbol. |
739 environment := Smalltalk at:nsName asSymbol. |
740 ^ environment |
740 ^ environment |
741 |
741 |
742 "Modified: 24.3.1997 / 11:12:09 / cg" |
742 "Modified: 24.3.1997 / 11:12:09 / cg" |
743 ! |
743 ! |
744 |
744 |
745 package |
745 package |
746 "return the package of the class" |
746 "return the package-id of the class" |
747 |
747 |
748 |owner| |
748 |owner| |
749 |
749 |
750 (owner := self owningClass) notNil ifTrue:[^ owner package]. |
750 (owner := self owningClass) notNil ifTrue:[^ owner package]. |
751 ^ package |
751 ^ package |
852 classes := IdentitySet new. |
852 classes := IdentitySet new. |
853 myName := self name. |
853 myName := self name. |
854 myNamePrefix := myName , '::'. |
854 myNamePrefix := myName , '::'. |
855 |
855 |
856 Smalltalk allBehaviorsDo:[:aClass | |
856 Smalltalk allBehaviorsDo:[:aClass | |
857 |nm owner| |
857 |nm owner| |
858 |
858 |
859 aClass isBehavior ifTrue:[ |
859 aClass isBehavior ifTrue:[ |
860 (owner := aClass owningClass) notNil ifTrue:[ |
860 (owner := aClass owningClass) notNil ifTrue:[ |
861 "/ owner == self ifTrue:[ |
861 "/ owner == self ifTrue:[ |
862 "/ classes add:aClass. |
862 "/ classes add:aClass. |
863 "/ ]. |
863 "/ ]. |
864 |
864 |
865 nm := aClass name. |
865 nm := aClass name. |
866 (nm startsWith:myNamePrefix) ifTrue:[ |
866 (nm startsWith:myNamePrefix) ifTrue:[ |
867 "/ care for private-privateClasses |
867 "/ care for private-privateClasses |
868 (nm indexOf:$: startingAt:myName size + 3) == 0 ifTrue:[ |
868 (nm indexOf:$: startingAt:myName size + 3) == 0 ifTrue:[ |
869 classes add:aClass. |
869 classes add:aClass. |
870 ] |
870 ] |
871 ] |
871 ] |
872 ] |
872 ] |
873 ] |
873 ] |
874 ]. |
874 ]. |
875 ^ classes asSortedCollection:[:a :b | a name < b name]. |
875 ^ classes asSortedCollection:[:a :b | a name < b name]. |
876 |
876 |
877 " |
877 " |
878 Object privateClasses |
878 Object privateClasses |
1166 "/ number of private classes |
1166 "/ number of private classes |
1167 "/ private classes, if any |
1167 "/ private classes, if any |
1168 |
1168 |
1169 formatID := manager nextObject. |
1169 formatID := manager nextObject. |
1170 formatID isInteger ifFalse:[ "/ backward compatibilty |
1170 formatID isInteger ifFalse:[ "/ backward compatibilty |
1171 formatID := nil. |
1171 formatID := nil. |
1172 superclassName := formatID |
1172 superclassName := formatID |
1173 ] ifTrue:[ |
1173 ] ifTrue:[ |
1174 superclassName := manager nextObject. |
1174 superclassName := manager nextObject. |
1175 ]. |
1175 ]. |
1176 superclassSig := manager nextObject. |
1176 superclassSig := manager nextObject. |
1177 |
1177 |
1178 superclassName notNil ifTrue:[ |
1178 superclassName notNil ifTrue:[ |
1179 superClass := Smalltalk at:superclassName ifAbsent:nil. |
1179 superClass := Smalltalk at:superclassName ifAbsent:nil. |
1180 |
1180 |
1181 superClass isNil ifTrue:[ |
1181 superClass isNil ifTrue:[ |
1182 BinaryIOManager nonexistingClassSignal |
1182 BinaryIOManager nonexistingClassSignal |
1183 raiseRequestWith:'non existent superclass (in binaryLoad)'. |
1183 raiseRequestWith:'non existent superclass (in binaryLoad)'. |
1184 ^ nil |
1184 ^ nil |
1185 ]. |
1185 ]. |
1186 |
1186 |
1187 "/ ('loading superclass: ' , superclassName ) printNL. |
1187 "/ ('loading superclass: ' , superclassName ) printNL. |
1188 superClass autoload. |
1188 superClass autoload. |
1189 superClass := Smalltalk at:superclassName. |
1189 superClass := Smalltalk at:superclassName. |
1190 |
1190 |
1191 superclassSig ~= superClass signature ifTrue:[ |
1191 superclassSig ~= superClass signature ifTrue:[ |
1192 BinaryIOManager changedInstLayoutSignal |
1192 BinaryIOManager changedInstLayoutSignal |
1193 raiseRequestWith:'incompatible superclass (in binaryLoad)'. |
1193 raiseRequestWith:'incompatible superclass (in binaryLoad)'. |
1194 ^ nil |
1194 ^ nil |
1195 ] |
1195 ] |
1196 ]. |
1196 ]. |
1197 |
1197 |
1198 name := manager nextObject. |
1198 name := manager nextObject. |
1199 flags := manager nextObject. |
1199 flags := manager nextObject. |
1200 instvars := manager nextObject. |
1200 instvars := manager nextObject. |
1205 classInstVars := manager nextObject. |
1205 classInstVars := manager nextObject. |
1206 classInstVars isNil ifTrue:[classInstVars := '']. |
1206 classInstVars isNil ifTrue:[classInstVars := '']. |
1207 comment := manager nextObject. |
1207 comment := manager nextObject. |
1208 package := manager nextObject. |
1208 package := manager nextObject. |
1209 formatID == 1 ifTrue:[ |
1209 formatID == 1 ifTrue:[ |
1210 rev := manager nextObject. |
1210 rev := manager nextObject. |
1211 ownerName := manager nextObject. |
1211 ownerName := manager nextObject. |
1212 ownerName notNil ifTrue:[ |
1212 ownerName notNil ifTrue:[ |
1213 name := name copyFrom:(ownerName size + 2 + 1). |
1213 name := name copyFrom:(ownerName size + 2 + 1). |
1214 owner := Smalltalk at:ownerName. |
1214 owner := Smalltalk at:ownerName. |
1215 ] |
1215 ] |
1216 ]. |
1216 ]. |
1217 |
1217 |
1218 "/ 'got superName:' print. superclassName printNL. |
1218 "/ 'got superName:' print. superclassName printNL. |
1219 "/ 'got name:' print. name printNL. |
1219 "/ 'got name:' print. name printNL. |
1220 "/ 'got flags: ' print. flags printNL. |
1220 "/ 'got flags: ' print. flags printNL. |
1224 "/ 'got classInstvars: ' print. classInstVars printNL. |
1224 "/ 'got classInstvars: ' print. classInstVars printNL. |
1225 |
1225 |
1226 "/ ('create class: ' , name ) printNL. |
1226 "/ ('create class: ' , name ) printNL. |
1227 |
1227 |
1228 owner notNil ifTrue:[ |
1228 owner notNil ifTrue:[ |
1229 environment := owner |
1229 environment := owner |
1230 ] ifFalse:[ |
1230 ] ifFalse:[ |
1231 environment := Class nameSpaceQuerySignal raise. |
1231 environment := Class nameSpaceQuerySignal raise. |
1232 ]. |
1232 ]. |
1233 |
1233 |
1234 cls := superClass. |
1234 cls := superClass. |
1235 superClass isNil ifTrue:[ |
1235 superClass isNil ifTrue:[ |
1236 cls := Object |
1236 cls := Object |
1237 ]. |
1237 ]. |
1238 |
1238 |
1239 newClass := cls class |
1239 newClass := cls class |
1240 name:name asSymbol |
1240 name:name asSymbol |
1241 in:environment |
1241 in:environment |
1242 subclassOf:cls |
1242 subclassOf:cls |
1243 instanceVariableNames:instvars |
1243 instanceVariableNames:instvars |
1244 variable:false |
1244 variable:false |
1245 words:false |
1245 words:false |
1246 pointers:true |
1246 pointers:true |
1247 classVariableNames:classvars |
1247 classVariableNames:classvars |
1248 poolDictionaries:'' |
1248 poolDictionaries:'' |
1249 category:category |
1249 category:category |
1250 comment:comment |
1250 comment:comment |
1251 changed:false |
1251 changed:false |
1252 classInstanceVariableNames:classInstVars. |
1252 classInstanceVariableNames:classInstVars. |
1253 |
1253 |
1254 newClass isNil ifTrue:[ |
1254 newClass isNil ifTrue:[ |
1255 ^ nil. |
1255 ^ nil. |
1256 ]. |
1256 ]. |
1257 |
1257 |
1258 superClass isNil ifTrue:[ |
1258 superClass isNil ifTrue:[ |
1259 newClass setSuperclass:nil. |
1259 newClass setSuperclass:nil. |
1260 newClass class setSuperclass:Class. |
1260 newClass class setSuperclass:Class. |
1261 ]. |
1261 ]. |
1262 |
1262 |
1263 "/ Transcript showCR:'loaded ' , name , ' in ' , environment name. |
1263 "/ Transcript showCR:'loaded ' , name , ' in ' , environment name. |
1264 |
1264 |
1265 newClass flags:flags. |
1265 newClass flags:flags. |
1268 cmethods := MethodDictionary binaryFullDefinitionFrom:stream manager:manager. |
1268 cmethods := MethodDictionary binaryFullDefinitionFrom:stream manager:manager. |
1269 "/ retrieve inst methods |
1269 "/ retrieve inst methods |
1270 methods := MethodDictionary binaryFullDefinitionFrom:stream manager:manager. |
1270 methods := MethodDictionary binaryFullDefinitionFrom:stream manager:manager. |
1271 |
1271 |
1272 formatID == 1 ifTrue:[ |
1272 formatID == 1 ifTrue:[ |
1273 "/ privateClasses |
1273 "/ privateClasses |
1274 nPrivate := manager nextObject. |
1274 nPrivate := manager nextObject. |
1275 nPrivate timesRepeat:[ |
1275 nPrivate timesRepeat:[ |
1276 Class nameSpaceQuerySignal |
1276 Class nameSpaceQuerySignal |
1277 answer:newClass |
1277 answer:newClass |
1278 do:[ |
1278 do:[ |
1279 privateClass := manager nextObject |
1279 privateClass := manager nextObject |
1280 ] |
1280 ] |
1281 ] |
1281 ] |
1282 ]. |
1282 ]. |
1283 |
1283 |
1284 (superClass isNil and:[superclassName notNil]) ifTrue:[^ nil]. |
1284 (superClass isNil and:[superclassName notNil]) ifTrue:[^ nil]. |
1285 newClass isNil ifTrue:[ |
1285 newClass isNil ifTrue:[ |
1286 ^ nil |
1286 ^ nil |
1287 ]. |
1287 ]. |
1288 |
1288 |
1289 owner notNil ifTrue:[ |
1289 owner notNil ifTrue:[ |
1290 newClass category:nil. |
1290 newClass category:nil. |
1291 ] ifFalse:[ |
1291 ] ifFalse:[ |
1292 newClass package:package. |
1292 newClass package:package. |
1293 ]. |
1293 ]. |
1294 |
1294 |
1295 newClass methodDictionary:methods. |
1295 newClass methodDictionary:methods. |
1296 newClass class methodDictionary:cmethods. |
1296 newClass class methodDictionary:cmethods. |
1297 ^ newClass |
1297 ^ newClass |
1335 1 storeBinaryOn:stream manager:manager. "/ formatID |
1335 1 storeBinaryOn:stream manager:manager. "/ formatID |
1336 |
1336 |
1337 owner := self owningClass. |
1337 owner := self owningClass. |
1338 |
1338 |
1339 superclass isNil ifTrue:[ |
1339 superclass isNil ifTrue:[ |
1340 s := nil. |
1340 s := nil. |
1341 sig := 0. |
1341 sig := 0. |
1342 ] ifFalse:[ |
1342 ] ifFalse:[ |
1343 s := superclass name. |
1343 s := superclass name. |
1344 sig := superclass signature. |
1344 sig := superclass signature. |
1345 ]. |
1345 ]. |
1346 s storeBinaryOn:stream manager:manager. |
1346 s storeBinaryOn:stream manager:manager. |
1347 sig storeBinaryOn:stream manager:manager. |
1347 sig storeBinaryOn:stream manager:manager. |
1348 |
1348 |
1349 name storeBinaryOn:stream manager:manager. |
1349 name storeBinaryOn:stream manager:manager. |
1350 flags storeBinaryOn:stream manager:manager. |
1350 flags storeBinaryOn:stream manager:manager. |
1351 (instvars notNil and:[instvars isEmpty]) ifTrue:[ |
1351 (instvars notNil and:[instvars isEmpty]) ifTrue:[ |
1352 s := nil |
1352 s := nil |
1353 ] ifFalse:[ |
1353 ] ifFalse:[ |
1354 s := instvars |
1354 s := instvars |
1355 ]. |
1355 ]. |
1356 s storeBinaryOn:stream manager:manager. |
1356 s storeBinaryOn:stream manager:manager. |
1357 |
1357 |
1358 (classvars notNil and:[classvars isEmpty]) ifTrue:[ |
1358 (classvars notNil and:[classvars isEmpty]) ifTrue:[ |
1359 s := nil |
1359 s := nil |
1360 ] ifFalse:[ |
1360 ] ifFalse:[ |
1361 s := classvars |
1361 s := classvars |
1362 ]. |
1362 ]. |
1363 s storeBinaryOn:stream manager:manager. |
1363 s storeBinaryOn:stream manager:manager. |
1364 |
1364 |
1365 "/ the category |
1365 "/ the category |
1366 owner notNil ifTrue:[ |
1366 owner notNil ifTrue:[ |
1367 nil storeBinaryOn:stream manager:manager. |
1367 nil storeBinaryOn:stream manager:manager. |
1368 ] ifFalse:[ |
1368 ] ifFalse:[ |
1369 category storeBinaryOn:stream manager:manager. |
1369 category storeBinaryOn:stream manager:manager. |
1370 ]. |
1370 ]. |
1371 |
1371 |
1372 "/ the classInstVarString |
1372 "/ the classInstVarString |
1373 s := self class instanceVariableString. |
1373 s := self class instanceVariableString. |
1374 (s notNil and:[s isEmpty]) ifTrue:[ |
1374 (s notNil and:[s isEmpty]) ifTrue:[ |
1375 s := nil |
1375 s := nil |
1376 ]. |
1376 ]. |
1377 s storeBinaryOn:stream manager:manager. |
1377 s storeBinaryOn:stream manager:manager. |
1378 |
1378 |
1379 "/ the comment |
1379 "/ the comment |
1380 s := comment. |
1380 s := comment. |
1381 manager sourceMode == #discard ifTrue:[ |
1381 manager sourceMode == #discard ifTrue:[ |
1382 s := nil |
1382 s := nil |
1383 ]. |
1383 ]. |
1384 s storeBinaryOn:stream manager:manager. |
1384 s storeBinaryOn:stream manager:manager. |
1385 |
1385 |
1386 "/ the revision, package & owner |
1386 "/ the revision, package & owner |
1387 owner notNil ifTrue:[ |
1387 owner notNil ifTrue:[ |
1388 nil storeBinaryOn:stream manager:manager. |
1388 nil storeBinaryOn:stream manager:manager. |
1389 nil storeBinaryOn:stream manager:manager. |
1389 nil storeBinaryOn:stream manager:manager. |
1390 owner name storeBinaryOn:stream manager:manager. |
1390 owner name storeBinaryOn:stream manager:manager. |
1391 ] ifFalse:[ |
1391 ] ifFalse:[ |
1392 package storeBinaryOn:stream manager:manager. |
1392 package storeBinaryOn:stream manager:manager. |
1393 revision storeBinaryOn:stream manager:manager. |
1393 revision storeBinaryOn:stream manager:manager. |
1394 nil storeBinaryOn:stream manager:manager. |
1394 nil storeBinaryOn:stream manager:manager. |
1395 ]. |
1395 ]. |
1396 |
1396 |
1397 "/ |
1397 "/ |
1398 "/ store class method dictionary and methods |
1398 "/ store class method dictionary and methods |
1399 "/ |
1399 "/ |
1771 syntaxHilighting := Smalltalk syntaxHilighting. |
1771 syntaxHilighting := Smalltalk syntaxHilighting. |
1772 |
1772 |
1773 owner := self owningClass. |
1773 owner := self owningClass. |
1774 |
1774 |
1775 owner isNil ifTrue:[ |
1775 owner isNil ifTrue:[ |
1776 ns := self nameSpace. |
1776 ns := self nameSpace. |
1777 ] ifFalse:[ |
1777 ] ifFalse:[ |
1778 ns := self topOwningClass nameSpace |
1778 ns := self topOwningClass nameSpace |
1779 ]. |
1779 ]. |
1780 fullName := FileOutNameSpaceQuerySignal raise == true. |
1780 fullName := FileOutNameSpaceQuerySignal raise == true. |
1781 |
1781 |
1782 ((owner isNil and:[fullName not]) |
1782 ((owner isNil and:[fullName not]) |
1783 or:[owner notNil and:[forceNameSpace and:[fullName not]]]) ifTrue:[ |
1783 or:[owner notNil and:[forceNameSpace and:[fullName not]]]) ifTrue:[ |
1784 (ns notNil and:[ns ~~ Smalltalk]) ifTrue:[ |
1784 (ns notNil and:[ns ~~ Smalltalk]) ifTrue:[ |
1785 nsName := ns name. |
1785 nsName := ns name. |
1786 (nsName includes:$:) ifTrue:[ |
1786 (nsName includes:$:) ifTrue:[ |
1787 nsName := '''' , nsName , '''' |
1787 nsName := '''' , nsName , '''' |
1788 ]. |
1788 ]. |
1789 "/ aStream nextPutLine:'"{ NameSpace: ' , nsName , ' }"'; cr. |
1789 "/ aStream nextPutLine:'"{ NameSpace: ' , nsName , ' }"'; cr. |
1790 aStream nextPutAll:'"{ NameSpace: '. |
1790 aStream nextPutAll:'"{ NameSpace: '. |
1791 syntaxHilighting ifTrue:[aStream bold]. |
1791 syntaxHilighting ifTrue:[aStream bold]. |
1792 aStream nextPutAll:nsName. |
1792 aStream nextPutAll:nsName. |
1793 syntaxHilighting ifTrue:[aStream normal]. |
1793 syntaxHilighting ifTrue:[aStream normal]. |
1794 aStream nextPutAll:' }"'; cr; cr. |
1794 aStream nextPutAll:' }"'; cr; cr. |
1795 ] |
1795 ] |
1796 ]. |
1796 ]. |
1797 |
1797 |
1798 "take care of nil-superclass" |
1798 "take care of nil-superclass" |
1799 superclass isNil ifTrue:[ |
1799 superclass isNil ifTrue:[ |
1800 s := 'nil' |
1800 s := 'nil' |
1801 ] ifFalse:[ |
1801 ] ifFalse:[ |
1802 fullName ifTrue:[ |
1802 fullName ifTrue:[ |
1803 s := superclass name |
1803 s := superclass name |
1804 ] ifFalse:[ |
1804 ] ifFalse:[ |
1805 (ns == superclass nameSpace |
1805 (ns == superclass nameSpace |
1806 and:[superclass owningClass isNil]) ifTrue:[ |
1806 and:[superclass owningClass isNil]) ifTrue:[ |
1807 s := superclass nameWithoutPrefix |
1807 s := superclass nameWithoutPrefix |
1808 ] ifFalse:[ |
1808 ] ifFalse:[ |
1809 "/ a very special (rare) situation: |
1809 "/ a very special (rare) situation: |
1810 "/ my superclass resides in another nameSpace, |
1810 "/ my superclass resides in another nameSpace, |
1811 "/ but there is something else named like this |
1811 "/ but there is something else named like this |
1812 "/ to be found in my nameSpace (or a private class) |
1812 "/ to be found in my nameSpace (or a private class) |
1813 |
1813 |
1814 superName := superclass nameWithoutNameSpacePrefix asSymbol. |
1814 superName := superclass nameWithoutNameSpacePrefix asSymbol. |
1815 cls := self privateClassesAt:superName. |
1815 cls := self privateClassesAt:superName. |
1816 cls isNil ifTrue:[ |
1816 cls isNil ifTrue:[ |
1817 (topOwner := self topOwningClass) isNil ifTrue:[ |
1817 (topOwner := self topOwningClass) isNil ifTrue:[ |
1818 ns := self nameSpace. |
1818 ns := self nameSpace. |
1819 ns notNil ifTrue:[ |
1819 ns notNil ifTrue:[ |
1820 cls := ns privateClassesAt:superName |
1820 cls := ns privateClassesAt:superName |
1821 ] ifFalse:[ |
1821 ] ifFalse:[ |
1822 "/ self error:'unexpected nil namespace' |
1822 "/ self error:'unexpected nil namespace' |
1823 ] |
1823 ] |
1824 ] ifFalse:[ |
1824 ] ifFalse:[ |
1825 cls := topOwner nameSpace at:superName. |
1825 cls := topOwner nameSpace at:superName. |
1826 ] |
1826 ] |
1827 ]. |
1827 ]. |
1828 (cls notNil and:[cls ~~ superclass]) ifTrue:[ |
1828 (cls notNil and:[cls ~~ superclass]) ifTrue:[ |
1829 s := superclass nameSpace name , '::' , superName |
1829 s := superclass nameSpace name , '::' , superName |
1830 ] ifFalse:[ |
1830 ] ifFalse:[ |
1831 s := superName |
1831 s := superName |
1832 ] |
1832 ] |
1833 ] |
1833 ] |
1834 ] |
1834 ] |
1835 ]. |
1835 ]. |
1836 |
1836 |
1837 syntaxHilighting ifTrue:[aStream bold]. |
1837 syntaxHilighting ifTrue:[aStream bold]. |
1838 aStream nextPutAll:s. "/ superclass |
1838 aStream nextPutAll:s. "/ superclass |
1839 syntaxHilighting ifTrue:[aStream normal]. |
1839 syntaxHilighting ifTrue:[aStream normal]. |
1840 aStream space. |
1840 aStream space. |
1841 self basicFileOutInstvarTypeKeywordOn:aStream. |
1841 self basicFileOutInstvarTypeKeywordOn:aStream. |
1842 |
1842 |
1843 (fullName and:[owner isNil]) ifTrue:[ |
1843 (fullName and:[owner isNil]) ifTrue:[ |
1844 aStream nextPutAll:'#'''. |
1844 aStream nextPutAll:'#'''. |
1845 syntaxHilighting ifTrue:[aStream bold]. |
1845 syntaxHilighting ifTrue:[aStream bold]. |
1846 aStream nextPutAll:(self name). |
1846 aStream nextPutAll:(self name). |
1847 syntaxHilighting ifTrue:[aStream normal]. |
1847 syntaxHilighting ifTrue:[aStream normal]. |
1848 aStream nextPutAll:''''. |
1848 aStream nextPutAll:''''. |
1849 ] ifFalse:[ |
1849 ] ifFalse:[ |
1850 aStream nextPut:$#. |
1850 aStream nextPut:$#. |
1851 syntaxHilighting ifTrue:[aStream bold]. |
1851 syntaxHilighting ifTrue:[aStream bold]. |
1852 aStream nextPutAll:(self nameWithoutPrefix). |
1852 aStream nextPutAll:(self nameWithoutPrefix). |
1853 syntaxHilighting ifTrue:[aStream normal]. |
1853 syntaxHilighting ifTrue:[aStream normal]. |
1854 ]. |
1854 ]. |
1855 |
1855 |
1856 aStream crtab. |
1856 aStream crtab. |
1857 aStream nextPutAll:'instanceVariableNames:'''. |
1857 aStream nextPutAll:'instanceVariableNames:'''. |
1858 syntaxHilighting ifTrue:[aStream bold]. |
1858 syntaxHilighting ifTrue:[aStream bold]. |
1870 aStream crtab. |
1870 aStream crtab. |
1871 aStream nextPutAll:'poolDictionaries:'''''. |
1871 aStream nextPutAll:'poolDictionaries:'''''. |
1872 |
1872 |
1873 aStream crtab. |
1873 aStream crtab. |
1874 owner isNil ifTrue:[ |
1874 owner isNil ifTrue:[ |
1875 "/ a public class |
1875 "/ a public class |
1876 aStream nextPutAll:'category:'. |
1876 aStream nextPutAll:'category:'. |
1877 category isNil ifTrue:[ |
1877 category isNil ifTrue:[ |
1878 s := '''''' |
1878 s := '''''' |
1879 ] ifFalse:[ |
1879 ] ifFalse:[ |
1880 s := category asString storeString |
1880 s := category asString storeString |
1881 ]. |
1881 ]. |
1882 aStream nextPutAll:s. |
1882 aStream nextPutAll:s. |
1883 ] ifFalse:[ |
1883 ] ifFalse:[ |
1884 "/ a private class |
1884 "/ a private class |
1885 aStream nextPutAll:'privateIn:'. |
1885 aStream nextPutAll:'privateIn:'. |
1886 syntaxHilighting ifTrue:[aStream bold]. |
1886 syntaxHilighting ifTrue:[aStream bold]. |
1887 fullName ifTrue:[ |
1887 fullName ifTrue:[ |
1888 s := owner name. |
1888 s := owner name. |
1889 ] ifFalse:[ |
1889 ] ifFalse:[ |
1890 s := owner nameWithoutNameSpacePrefix. |
1890 s := owner nameWithoutNameSpacePrefix. |
1891 ]. |
1891 ]. |
1892 aStream nextPutAll:s. |
1892 aStream nextPutAll:s. |
1893 syntaxHilighting ifTrue:[aStream normal]. |
1893 syntaxHilighting ifTrue:[aStream normal]. |
1894 ]. |
1894 ]. |
1895 aStream cr |
1895 aStream cr |
1896 |
1896 |
1897 "Created: 4.1.1997 / 20:38:16 / cg" |
1897 "Created: 4.1.1997 / 20:38:16 / cg" |
1898 "Modified: 8.8.1997 / 10:59:50 / cg" |
1898 "Modified: 8.8.1997 / 10:59:50 / cg" |
1902 "a helper for fileOutDefinition" |
1902 "a helper for fileOutDefinition" |
1903 |
1903 |
1904 |isVar s| |
1904 |isVar s| |
1905 |
1905 |
1906 superclass isNil ifTrue:[ |
1906 superclass isNil ifTrue:[ |
1907 isVar := self isVariable |
1907 isVar := self isVariable |
1908 ] ifFalse:[ |
1908 ] ifFalse:[ |
1909 "I cant remember what this is for ?" |
1909 "I cant remember what this is for ?" |
1910 isVar := (self isVariable and:[superclass isVariable not]) |
1910 isVar := (self isVariable and:[superclass isVariable not]) |
1911 ]. |
1911 ]. |
1912 |
1912 |
1913 isVar ifTrue:[ |
1913 isVar ifTrue:[ |
1914 self isBytes ifTrue:[ |
1914 self isBytes ifTrue:[ |
1915 s := 'variableByteSubclass:' |
1915 s := 'variableByteSubclass:' |
1916 ] ifFalse:[ |
1916 ] ifFalse:[ |
1917 self isWords ifTrue:[ |
1917 self isWords ifTrue:[ |
1918 s := 'variableWordSubclass:' |
1918 s := 'variableWordSubclass:' |
1919 ] ifFalse:[ |
1919 ] ifFalse:[ |
1920 self isLongs ifTrue:[ |
1920 self isLongs ifTrue:[ |
1921 s := 'variableLongSubclass:' |
1921 s := 'variableLongSubclass:' |
1922 ] ifFalse:[ |
1922 ] ifFalse:[ |
1923 self isFloats ifTrue:[ |
1923 self isFloats ifTrue:[ |
1924 s := 'variableFloatSubclass:' |
1924 s := 'variableFloatSubclass:' |
1925 ] ifFalse:[ |
1925 ] ifFalse:[ |
1926 self isDoubles ifTrue:[ |
1926 self isDoubles ifTrue:[ |
1927 s := 'variableDoubleSubclass:' |
1927 s := 'variableDoubleSubclass:' |
1928 ] ifFalse:[ |
1928 ] ifFalse:[ |
1929 self isSignedWords ifTrue:[ |
1929 self isSignedWords ifTrue:[ |
1930 s := 'variableSignedWordSubclass:' |
1930 s := 'variableSignedWordSubclass:' |
1931 ] ifFalse:[ |
1931 ] ifFalse:[ |
1932 self isSignedLongs ifTrue:[ |
1932 self isSignedLongs ifTrue:[ |
1933 s := 'variableSignedLongSubclass:' |
1933 s := 'variableSignedLongSubclass:' |
1934 ] ifFalse:[ |
1934 ] ifFalse:[ |
1935 s := 'variableSubclass:' |
1935 s := 'variableSubclass:' |
1936 ] |
1936 ] |
1937 ] |
1937 ] |
1938 ] |
1938 ] |
1939 ] |
1939 ] |
1940 ] |
1940 ] |
1941 ] |
1941 ] |
1942 ] |
1942 ] |
1943 ] ifFalse:[ |
1943 ] ifFalse:[ |
1944 s := 'subclass:' |
1944 s := 'subclass:' |
1945 ]. |
1945 ]. |
1946 aStream nextPutAll:s. |
1946 aStream nextPutAll:s. |
1947 |
1947 |
1948 "Created: 11.10.1996 / 18:57:29 / cg" |
1948 "Created: 11.10.1996 / 18:57:29 / cg" |
1949 ! |
1949 ! |
1988 |
1988 |
1989 binaryFileOutWithSourceMode:sourceMode |
1989 binaryFileOutWithSourceMode:sourceMode |
1990 "create a file 'class.cls' (in the current projects fileOut-directory), |
1990 "create a file 'class.cls' (in the current projects fileOut-directory), |
1991 consisting of all methods in myself in a portable binary format. |
1991 consisting of all methods in myself in a portable binary format. |
1992 The argument controls how sources are to be saved: |
1992 The argument controls how sources are to be saved: |
1993 #keep - include the source |
1993 #keep - include the source |
1994 #reference - include a reference to the sourceFile |
1994 #reference - include a reference to the sourceFile |
1995 #discard - dont save sources. |
1995 #discard - dont save sources. |
1996 |
1996 |
1997 With #reference, the sourceFile needs to be present after reload |
1997 With #reference, the sourceFile needs to be present after reload |
1998 in order to be browsable." |
1998 in order to be browsable." |
1999 |
1999 |
2000 |baseName fileName aStream dirName| |
2000 |baseName fileName aStream dirName| |
2001 |
2001 |
2002 baseName := (Smalltalk fileNameForClass:self name). |
2002 baseName := (Smalltalk fileNameForClass:self name). |
2003 fileName := baseName , '.cls'. |
2003 fileName := baseName , '.cls'. |
2004 |
2004 |
2005 Project notNil ifTrue:[ |
2005 Project notNil ifTrue:[ |
2006 dirName := Project currentProjectDirectory |
2006 dirName := Project currentProjectDirectory |
2007 ] ifFalse:[ |
2007 ] ifFalse:[ |
2008 dirName := '.' |
2008 dirName := '.' |
2009 ]. |
2009 ]. |
2010 fileName := dirName asFilename constructString:fileName. |
2010 fileName := dirName asFilename constructString:fileName. |
2011 |
2011 |
2012 aStream := FileStream newFileNamed:fileName. |
2012 aStream := FileStream newFileNamed:fileName. |
2013 aStream isNil ifTrue:[ |
2013 aStream isNil ifTrue:[ |
2014 ^ FileOutErrorSignal |
2014 ^ FileOutErrorSignal |
2015 raiseRequestWith:fileName |
2015 raiseRequestWith:fileName |
2016 errorString:('cannot create file:', fileName) |
2016 errorString:('cannot create file:', fileName) |
2017 ]. |
2017 ]. |
2018 |
2018 |
2019 aStream binary. |
2019 aStream binary. |
2020 self binaryFileOutOn:aStream sourceMode:sourceMode. |
2020 self binaryFileOutOn:aStream sourceMode:sourceMode. |
2021 aStream close. |
2021 aStream close. |
2088 fileOutAllMethodsOn:aStream |
2088 fileOutAllMethodsOn:aStream |
2089 |collectionOfCategories| |
2089 |collectionOfCategories| |
2090 |
2090 |
2091 collectionOfCategories := self class categories asSortedCollection. |
2091 collectionOfCategories := self class categories asSortedCollection. |
2092 collectionOfCategories notNil ifTrue:[ |
2092 collectionOfCategories notNil ifTrue:[ |
2093 collectionOfCategories do:[:aCategory | |
2093 collectionOfCategories do:[:aCategory | |
2094 self class fileOutCategory:aCategory on:aStream. |
2094 self class fileOutCategory:aCategory on:aStream. |
2095 aStream cr |
2095 aStream cr |
2096 ] |
2096 ] |
2097 ]. |
2097 ]. |
2098 collectionOfCategories := self categories asSortedCollection. |
2098 collectionOfCategories := self categories asSortedCollection. |
2099 collectionOfCategories notNil ifTrue:[ |
2099 collectionOfCategories notNil ifTrue:[ |
2100 collectionOfCategories do:[:aCategory | |
2100 collectionOfCategories do:[:aCategory | |
2101 self fileOutCategory:aCategory on:aStream. |
2101 self fileOutCategory:aCategory on:aStream. |
2102 aStream cr |
2102 aStream cr |
2103 ] |
2103 ] |
2104 ]. |
2104 ]. |
2105 |
2105 |
2106 self privateClassesSorted do:[:aClass | |
2106 self privateClassesSorted do:[:aClass | |
2107 aClass fileOutAllMethodsOn:aStream |
2107 aClass fileOutAllMethodsOn:aStream |
2108 ]. |
2108 ]. |
2109 |
2109 |
2110 "Created: 15.10.1996 / 11:13:00 / cg" |
2110 "Created: 15.10.1996 / 11:13:00 / cg" |
2111 "Modified: 22.3.1997 / 16:12:17 / cg" |
2111 "Modified: 22.3.1997 / 16:12:17 / cg" |
2112 ! |
2112 ! |
2130 if file exists, copy the existing to a .sav-file, |
2130 if file exists, copy the existing to a .sav-file, |
2131 create the new file as XXX.new-file, |
2131 create the new file as XXX.new-file, |
2132 and, if that worked rename afterwards ... |
2132 and, if that worked rename afterwards ... |
2133 " |
2133 " |
2134 (fileName exists) ifTrue:[ |
2134 (fileName exists) ifTrue:[ |
2135 sameFile := false. |
2135 sameFile := false. |
2136 |
2136 |
2137 "/ check carefully - maybe, my source does not really come from that |
2137 "/ check carefully - maybe, my source does not really come from that |
2138 "/ file (i.e. all of my methods have their source as string) |
2138 "/ file (i.e. all of my methods have their source as string) |
2139 |
2139 |
2140 anySourceRef := false. |
2140 anySourceRef := false. |
2141 self methodDictionary do:[:m| |
2141 self methodDictionary do:[:m| |
2142 m sourcePosition notNil ifTrue:[ |
2142 m sourcePosition notNil ifTrue:[ |
2143 anySourceRef := true |
2143 anySourceRef := true |
2144 ] |
2144 ] |
2145 ]. |
2145 ]. |
2146 self class methodDictionary do:[:m| |
2146 self class methodDictionary do:[:m| |
2147 m sourcePosition notNil ifTrue:[ |
2147 m sourcePosition notNil ifTrue:[ |
2148 anySourceRef := true |
2148 anySourceRef := true |
2149 ] |
2149 ] |
2150 ]. |
2150 ]. |
2151 |
2151 |
2152 anySourceRef ifTrue:[ |
2152 anySourceRef ifTrue:[ |
2153 s := self sourceStream. |
2153 s := self sourceStream. |
2154 s notNil ifTrue:[ |
2154 s notNil ifTrue:[ |
2155 mySourceFileID := s pathName asFilename info id. |
2155 mySourceFileID := s pathName asFilename info id. |
2156 sameFile := (fileName info id) == mySourceFileID. |
2156 sameFile := (fileName info id) == mySourceFileID. |
2157 s close. |
2157 s close. |
2158 ] ifFalse:[ |
2158 ] ifFalse:[ |
2159 classFilename notNil ifTrue:[ |
2159 classFilename notNil ifTrue:[ |
2160 " |
2160 " |
2161 check for overwriting my current source file |
2161 check for overwriting my current source file |
2162 this is not allowed, since it would clobber my methods source |
2162 this is not allowed, since it would clobber my methods source |
2163 file ... you have to save it to some other place. |
2163 file ... you have to save it to some other place. |
2164 This happens if you ask for a fileOut into the source-directory |
2164 This happens if you ask for a fileOut into the source-directory |
2165 (from which my methods get their source) |
2165 (from which my methods get their source) |
2166 " |
2166 " |
2167 mySourceFileName := Smalltalk getSourceFileName:classFilename. |
2167 mySourceFileName := Smalltalk getSourceFileName:classFilename. |
2168 sameFile := (fileNameString = mySourceFileName). |
2168 sameFile := (fileNameString = mySourceFileName). |
2169 sameFile ifFalse:[ |
2169 sameFile ifFalse:[ |
2170 mySourceFileName notNil ifTrue:[ |
2170 mySourceFileName notNil ifTrue:[ |
2171 sameFile := (fileName info id) == (mySourceFileName asFilename info id) |
2171 sameFile := (fileName info id) == (mySourceFileName asFilename info id) |
2172 ] |
2172 ] |
2173 ]. |
2173 ]. |
2174 ] |
2174 ] |
2175 ]. |
2175 ]. |
2176 ]. |
2176 ]. |
2177 |
2177 |
2178 sameFile ifTrue:[ |
2178 sameFile ifTrue:[ |
2179 ^ FileOutErrorSignal |
2179 ^ FileOutErrorSignal |
2180 raiseRequestWith:fileNameString |
2180 raiseRequestWith:fileNameString |
2181 errorString:('may not overwrite sourcefile:', fileNameString) |
2181 errorString:('may not overwrite sourcefile:', fileNameString) |
2182 ]. |
2182 ]. |
2183 |
2183 |
2184 savFilename := Filename newTemporary. |
2184 savFilename := Filename newTemporary. |
2185 fileName copyTo:savFilename. |
2185 fileName copyTo:savFilename. |
2186 newFileName := fileName withSuffix:'new'. |
2186 newFileName := fileName withSuffix:'new'. |
2187 needRename := true |
2187 needRename := true |
2188 ] ifFalse:[ |
2188 ] ifFalse:[ |
2189 newFileName := fileName. |
2189 newFileName := fileName. |
2190 needRename := false |
2190 needRename := false |
2191 ]. |
2191 ]. |
2192 |
2192 |
2193 aStream := newFileName writeStream. |
2193 aStream := newFileName writeStream. |
2194 aStream isNil ifTrue:[ |
2194 aStream isNil ifTrue:[ |
2195 savFilename notNil ifTrue:[ |
2195 savFilename notNil ifTrue:[ |
2196 savFilename delete |
2196 savFilename delete |
2197 ]. |
2197 ]. |
2198 ^ FileOutErrorSignal |
2198 ^ FileOutErrorSignal |
2199 raiseRequestWith:newFileName |
2199 raiseRequestWith:newFileName |
2200 errorString:('cannot create file:', newFileName name) |
2200 errorString:('cannot create file:', newFileName name) |
2201 ]. |
2201 ]. |
2202 self fileOutOn:aStream. |
2202 self fileOutOn:aStream. |
2203 aStream close. |
2203 aStream close. |
2204 |
2204 |
2205 " |
2205 " |
2206 finally, replace the old-file |
2206 finally, replace the old-file |
2207 be careful, if the old one is a symbolic link; in this case, |
2207 be careful, if the old one is a symbolic link; in this case, |
2208 we have to do a copy ... |
2208 we have to do a copy ... |
2209 " |
2209 " |
2210 needRename ifTrue:[ |
2210 needRename ifTrue:[ |
2211 newFileName copyTo:fileName. |
2211 newFileName copyTo:fileName. |
2212 newFileName delete |
2212 newFileName delete |
2213 ]. |
2213 ]. |
2214 savFilename notNil ifTrue:[ |
2214 savFilename notNil ifTrue:[ |
2215 savFilename delete |
2215 savFilename delete |
2216 ]. |
2216 ]. |
2217 |
2217 |
2336 On the other hand: I want every file created by myself to have the |
2336 On the other hand: I want every file created by myself to have the |
2337 copyright string at the beginning be preserved .... even if the |
2337 copyright string at the beginning be preserved .... even if the |
2338 code was edited in the browser and filedOut. |
2338 code was edited in the browser and filedOut. |
2339 " |
2339 " |
2340 (copyrightMethod := meta compiledMethodAt:#copyright) notNil ifTrue:[ |
2340 (copyrightMethod := meta compiledMethodAt:#copyright) notNil ifTrue:[ |
2341 " |
2341 " |
2342 get the copyright methods source, |
2342 get the copyright methods source, |
2343 and insert at beginning. |
2343 and insert at beginning. |
2344 " |
2344 " |
2345 copyrightText := copyrightMethod source. |
2345 copyrightText := copyrightMethod source. |
2346 copyrightText isNil ifTrue:[ |
2346 copyrightText isNil ifTrue:[ |
2347 " |
2347 " |
2348 no source available - trigger an error |
2348 no source available - trigger an error |
2349 " |
2349 " |
2350 FileOutErrorSignal |
2350 FileOutErrorSignal |
2351 raiseRequestWith:'no source for class ' , self name , ' available. Cannot fileOut'. |
2351 raiseRequestWith:'no source for class ' , self name , ' available. Cannot fileOut'. |
2352 ^ self |
2352 ^ self |
2353 ]. |
2353 ]. |
2354 " |
2354 " |
2355 strip off the selector-line |
2355 strip off the selector-line |
2356 " |
2356 " |
2357 copyrightText := copyrightText asCollectionOfLines asStringCollection. |
2357 copyrightText := copyrightText asCollectionOfLines asStringCollection. |
2358 copyrightText := copyrightText copyFrom:2 to:(copyrightText size). |
2358 copyrightText := copyrightText copyFrom:2 to:(copyrightText size). |
2359 "/ copyrightText do:[:line | aStream nextPutAll:line. aStream cr.]. |
2359 "/ copyrightText do:[:line | aStream nextPutAll:line. aStream cr.]. |
2360 copyrightText := copyrightText asString. |
2360 copyrightText := copyrightText asString. |
2361 aStream nextPutAllAsChunk:copyrightText. |
2361 aStream nextPutAllAsChunk:copyrightText. |
2362 ]. |
2362 ]. |
2363 |
2363 |
2364 stampIt ifTrue:[ |
2364 stampIt ifTrue:[ |
2365 "/ |
2365 "/ |
2366 "/ first, a timestamp |
2366 "/ first, a timestamp |
2367 "/ |
2367 "/ |
2368 aStream nextPutAll:(Smalltalk timeStamp). |
2368 aStream nextPutAll:(Smalltalk timeStamp). |
2369 aStream nextPutChunkSeparator. |
2369 aStream nextPutChunkSeparator. |
2370 aStream cr; cr. |
2370 aStream cr; cr. |
2371 ]. |
2371 ]. |
2372 |
2372 |
2373 "/ |
2373 "/ |
2374 "/ then the definition |
2374 "/ then the definition |
2375 "/ |
2375 "/ |
2394 "/ avoid sourcePosition-shifts when checked out later. |
2394 "/ avoid sourcePosition-shifts when checked out later. |
2395 "/ (RCS expands this string, so its size is not constant) |
2395 "/ (RCS expands this string, so its size is not constant) |
2396 "/ |
2396 "/ |
2397 collectionOfCategories := meta categories asSortedCollection. |
2397 collectionOfCategories := meta categories asSortedCollection. |
2398 collectionOfCategories notNil ifTrue:[ |
2398 collectionOfCategories notNil ifTrue:[ |
2399 "/ |
2399 "/ |
2400 "/ documentation first (if any), but not the version method |
2400 "/ documentation first (if any), but not the version method |
2401 "/ |
2401 "/ |
2402 (collectionOfCategories includes:'documentation') ifTrue:[ |
2402 (collectionOfCategories includes:'documentation') ifTrue:[ |
2403 versionMethod := meta compiledMethodAt:#version. |
2403 versionMethod := meta compiledMethodAt:#version. |
2404 versionMethod notNil ifTrue:[ |
2404 versionMethod notNil ifTrue:[ |
2405 skippedMethods := Array with:versionMethod |
2405 skippedMethods := Array with:versionMethod |
2406 ]. |
2406 ]. |
2407 meta fileOutCategory:'documentation' except:skippedMethods only:nil on:aStream. |
2407 meta fileOutCategory:'documentation' except:skippedMethods only:nil on:aStream. |
2408 aStream cr. |
2408 aStream cr. |
2409 ]. |
2409 ]. |
2410 |
2410 |
2411 "/ |
2411 "/ |
2412 "/ initialization next (if any) |
2412 "/ initialization next (if any) |
2413 "/ |
2413 "/ |
2414 (collectionOfCategories includes:'initialization') ifTrue:[ |
2414 (collectionOfCategories includes:'initialization') ifTrue:[ |
2415 meta fileOutCategory:'initialization' on:aStream. |
2415 meta fileOutCategory:'initialization' on:aStream. |
2416 aStream cr. |
2416 aStream cr. |
2417 ]. |
2417 ]. |
2418 |
2418 |
2419 "/ |
2419 "/ |
2420 "/ instance creation next (if any) |
2420 "/ instance creation next (if any) |
2421 "/ |
2421 "/ |
2422 (collectionOfCategories includes:'instance creation') ifTrue:[ |
2422 (collectionOfCategories includes:'instance creation') ifTrue:[ |
2423 meta fileOutCategory:'instance creation' on:aStream. |
2423 meta fileOutCategory:'instance creation' on:aStream. |
2424 aStream cr. |
2424 aStream cr. |
2425 ]. |
2425 ]. |
2426 collectionOfCategories do:[:aCategory | |
2426 collectionOfCategories do:[:aCategory | |
2427 ((aCategory ~= 'documentation') |
2427 ((aCategory ~= 'documentation') |
2428 and:[(aCategory ~= 'initialization') |
2428 and:[(aCategory ~= 'initialization') |
2429 and:[aCategory ~= 'instance creation']]) ifTrue:[ |
2429 and:[aCategory ~= 'instance creation']]) ifTrue:[ |
2430 meta fileOutCategory:aCategory on:aStream. |
2430 meta fileOutCategory:aCategory on:aStream. |
2431 aStream cr |
2431 aStream cr |
2432 ] |
2432 ] |
2433 ] |
2433 ] |
2434 ]. |
2434 ]. |
2435 |
2435 |
2436 "/ |
2436 "/ |
2437 "/ methods from all categories in myself |
2437 "/ methods from all categories in myself |
2438 "/ |
2438 "/ |
2439 collectionOfCategories := self categories asSortedCollection. |
2439 collectionOfCategories := self categories asSortedCollection. |
2440 collectionOfCategories notNil ifTrue:[ |
2440 collectionOfCategories notNil ifTrue:[ |
2441 collectionOfCategories do:[:aCategory | |
2441 collectionOfCategories do:[:aCategory | |
2442 self fileOutCategory:aCategory on:aStream. |
2442 self fileOutCategory:aCategory on:aStream. |
2443 aStream cr |
2443 aStream cr |
2444 ] |
2444 ] |
2445 ]. |
2445 ]. |
2446 |
2446 |
2447 "/ |
2447 "/ |
2448 "/ any private classes' methods |
2448 "/ any private classes' methods |
2449 "/ |
2449 "/ |
2450 self privateClassesSorted do:[:aClass | |
2450 self privateClassesSorted do:[:aClass | |
2451 aClass fileOutAllMethodsOn:aStream |
2451 aClass fileOutAllMethodsOn:aStream |
2452 ]. |
2452 ]. |
2453 |
2453 |
2454 |
2454 |
2455 "/ |
2455 "/ |
2456 "/ finally, the previously skipped version method |
2456 "/ finally, the previously skipped version method |
2457 "/ |
2457 "/ |
2458 versionMethod notNil ifTrue:[ |
2458 versionMethod notNil ifTrue:[ |
2459 meta fileOutCategory:'documentation' except:nil only:skippedMethods on:aStream. |
2459 meta fileOutCategory:'documentation' except:nil only:skippedMethods on:aStream. |
2460 ]. |
2460 ]. |
2461 |
2461 |
2462 "/ |
2462 "/ |
2463 "/ optionally an initialize message |
2463 "/ optionally an initialize message |
2464 "/ |
2464 "/ |
2465 (meta implements:#initialize) ifTrue:[ |
2465 (meta implements:#initialize) ifTrue:[ |
2466 self printClassNameOn:aStream. aStream nextPutAll:' initialize'. |
2466 self printClassNameOn:aStream. aStream nextPutAll:' initialize'. |
2467 aStream nextPutChunkSeparator. |
2467 aStream nextPutChunkSeparator. |
2468 aStream cr |
2468 aStream cr |
2469 ] |
2469 ] |
2470 |
2470 |
2471 "Created: 15.11.1995 / 12:53:06 / cg" |
2471 "Created: 15.11.1995 / 12:53:06 / cg" |
2472 "Modified: 22.3.1997 / 16:12:47 / cg" |
2472 "Modified: 22.3.1997 / 16:12:47 / cg" |
2473 "Modified: 1.4.1997 / 16:01:05 / stefan" |
2473 "Modified: 1.4.1997 / 16:01:05 / stefan" |
2480 |
2480 |
2481 " |
2481 " |
2482 primitive definitions - if any |
2482 primitive definitions - if any |
2483 " |
2483 " |
2484 (s := self primitiveDefinitionsString) notNil ifTrue:[ |
2484 (s := self primitiveDefinitionsString) notNil ifTrue:[ |
2485 aStream nextPutChunkSeparator. |
2485 aStream nextPutChunkSeparator. |
2486 self printClassNameOn:aStream. |
2486 self printClassNameOn:aStream. |
2487 aStream nextPutAll:' primitiveDefinitions'; |
2487 aStream nextPutAll:' primitiveDefinitions'; |
2488 nextPutChunkSeparator; |
2488 nextPutChunkSeparator; |
2489 cr. |
2489 cr. |
2490 aStream nextPutAll:s. |
2490 aStream nextPutAll:s. |
2491 aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr |
2491 aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr |
2492 ]. |
2492 ]. |
2493 (s := self primitiveVariablesString) notNil ifTrue:[ |
2493 (s := self primitiveVariablesString) notNil ifTrue:[ |
2494 aStream nextPutChunkSeparator. |
2494 aStream nextPutChunkSeparator. |
2495 self printClassNameOn:aStream. |
2495 self printClassNameOn:aStream. |
2496 aStream nextPutAll:' primitiveVariables'; |
2496 aStream nextPutAll:' primitiveVariables'; |
2497 nextPutChunkSeparator; |
2497 nextPutChunkSeparator; |
2498 cr. |
2498 cr. |
2499 aStream nextPutAll:s. |
2499 aStream nextPutAll:s. |
2500 aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr |
2500 aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr |
2501 ]. |
2501 ]. |
2502 |
2502 |
2503 "Modified: 8.1.1997 / 17:45:40 / cg" |
2503 "Modified: 8.1.1997 / 17:45:40 / cg" |
2504 ! |
2504 ! |
2505 |
2505 |
2640 |
2640 |
2641 self printOutDefinitionOn:aPrintStream. |
2641 self printOutDefinitionOn:aPrintStream. |
2642 aPrintStream cr. |
2642 aPrintStream cr. |
2643 collectionOfCategories := self class categories. |
2643 collectionOfCategories := self class categories. |
2644 collectionOfCategories notNil ifTrue:[ |
2644 collectionOfCategories notNil ifTrue:[ |
2645 aPrintStream nextPutLine:'class protocol'. |
2645 aPrintStream nextPutLine:'class protocol'. |
2646 aPrintStream cr. |
2646 aPrintStream cr. |
2647 collectionOfCategories do:[:aCategory | |
2647 collectionOfCategories do:[:aCategory | |
2648 self class printOutCategory:aCategory on:aPrintStream |
2648 self class printOutCategory:aCategory on:aPrintStream |
2649 ] |
2649 ] |
2650 ]. |
2650 ]. |
2651 collectionOfCategories := self categories. |
2651 collectionOfCategories := self categories. |
2652 collectionOfCategories notNil ifTrue:[ |
2652 collectionOfCategories notNil ifTrue:[ |
2653 aPrintStream nextPutLine:'instance protocol'. |
2653 aPrintStream nextPutLine:'instance protocol'. |
2654 aPrintStream cr. |
2654 aPrintStream cr. |
2655 collectionOfCategories do:[:aCategory | |
2655 collectionOfCategories do:[:aCategory | |
2656 self printOutCategory:aCategory on:aPrintStream |
2656 self printOutCategory:aCategory on:aPrintStream |
2657 ] |
2657 ] |
2658 ] |
2658 ] |
2659 |
2659 |
2660 "Modified: 9.11.1996 / 00:14:11 / cg" |
2660 "Modified: 9.11.1996 / 00:14:11 / cg" |
2661 ! |
2661 ! |
2662 |
2662 |
2870 |
2870 |
2871 self printOutDefinitionOn:aPrintStream. |
2871 self printOutDefinitionOn:aPrintStream. |
2872 aPrintStream cr. |
2872 aPrintStream cr. |
2873 collectionOfCategories := self class categories. |
2873 collectionOfCategories := self class categories. |
2874 collectionOfCategories notNil ifTrue:[ |
2874 collectionOfCategories notNil ifTrue:[ |
2875 aPrintStream nextPutLine:'class protocol'. |
2875 aPrintStream nextPutLine:'class protocol'. |
2876 aPrintStream cr. |
2876 aPrintStream cr. |
2877 collectionOfCategories do:[:aCategory | |
2877 collectionOfCategories do:[:aCategory | |
2878 self class printOutCategoryProtocol:aCategory on:aPrintStream |
2878 self class printOutCategoryProtocol:aCategory on:aPrintStream |
2879 ] |
2879 ] |
2880 ]. |
2880 ]. |
2881 collectionOfCategories := self categories. |
2881 collectionOfCategories := self categories. |
2882 collectionOfCategories notNil ifTrue:[ |
2882 collectionOfCategories notNil ifTrue:[ |
2883 aPrintStream nextPutLine:'instance protocol'. |
2883 aPrintStream nextPutLine:'instance protocol'. |
2884 aPrintStream cr. |
2884 aPrintStream cr. |
2885 collectionOfCategories do:[:aCategory | |
2885 collectionOfCategories do:[:aCategory | |
2886 self printOutCategoryProtocol:aCategory on:aPrintStream |
2886 self printOutCategoryProtocol:aCategory on:aPrintStream |
2887 ] |
2887 ] |
2888 ] |
2888 ] |
2889 |
2889 |
2890 "Modified: 9.11.1996 / 00:14:26 / cg" |
2890 "Modified: 9.11.1996 / 00:14:26 / cg" |
2891 ! ! |
2891 ! ! |
2892 |
2892 |
3012 "/ first, create the public class ... |
3012 "/ first, create the public class ... |
3013 sel := self definitionSelector. |
3013 sel := self definitionSelector. |
3014 |
3014 |
3015 Class nameSpaceQuerySignal answer:Smalltalk |
3015 Class nameSpaceQuerySignal answer:Smalltalk |
3016 do:[ |
3016 do:[ |
3017 newClass := self superclass |
3017 newClass := self superclass |
3018 perform:sel |
3018 perform:sel |
3019 withArguments:(Array |
3019 withArguments:(Array |
3020 with:(self nameWithoutPrefix asSymbol) |
3020 with:(self nameWithoutPrefix asSymbol) |
3021 with:(self instanceVariableString) |
3021 with:(self instanceVariableString) |
3022 with:(self classVariableString) |
3022 with:(self classVariableString) |
3023 with:'' |
3023 with:'' |
3024 with:(owner category)). |
3024 with:(owner category)). |
3025 |
3025 |
3026 "/ copy over methods ... |
3026 "/ copy over methods ... |
3027 self class copyInvalidatedMethodsFrom:self class for:newClass class. |
3027 self class copyInvalidatedMethodsFrom:self class for:newClass class. |
3028 self class copyInvalidatedMethodsFrom:self for:newClass. |
3028 self class copyInvalidatedMethodsFrom:self for:newClass. |
3029 newClass class recompileInvalidatedMethods. |
3029 newClass class recompileInvalidatedMethods. |
3030 newClass recompileInvalidatedMethods. |
3030 newClass recompileInvalidatedMethods. |
3031 ]. |
3031 ]. |
3032 |
3032 |
3033 owner changed:#newClass with:newClass. |
3033 owner changed:#newClass with:newClass. |
3034 Smalltalk changed:#newClass with:newClass. |
3034 Smalltalk changed:#newClass with:newClass. |
3035 |
3035 |
3206 ! |
3206 ! |
3207 |
3207 |
3208 localSourceStreamFor:sourceFile |
3208 localSourceStreamFor:sourceFile |
3209 "return an open stream on a local sourcefile, nil if that is not available" |
3209 "return an open stream on a local sourcefile, nil if that is not available" |
3210 |
3210 |
3211 |fileName info module dir fn| |
3211 |fileName info module dir fn package| |
3212 |
3212 |
3213 "/ |
3213 "/ |
3214 "/ old: look in 'source/<filename>' |
3214 "/ old: look in 'source/<filename>' |
3215 "/ this is still kept in order to find user-private |
3215 "/ this is still kept in order to find user-private |
3216 "/ classes in her currentDirectory. |
3216 "/ classes in her currentDirectory. |
3217 "/ |
3217 "/ |
3218 fileName := Smalltalk getSourceFileName:sourceFile. |
3218 fileName := Smalltalk getSourceFileName:sourceFile. |
3219 fileName notNil ifTrue:[ |
3219 fileName notNil ifTrue:[ |
3220 ^ fileName asFilename readStream. |
3220 ^ fileName asFilename readStream. |
|
3221 ]. |
|
3222 |
|
3223 (package := self package) notNil ifTrue:[ |
|
3224 (package includes:$:) ifTrue:[ |
|
3225 package := package asString copy replaceAll:$: with:$/ |
|
3226 ] ifFalse:[ |
|
3227 package := 'stx/' , package |
|
3228 ]. |
|
3229 fileName := Smalltalk getSourceFileName:(package , '/' , sourceFile). |
|
3230 fileName notNil ifTrue:[ |
|
3231 ^ fileName asFilename readStream. |
|
3232 ]. |
3221 ]. |
3233 ]. |
3222 |
3234 |
3223 "/ |
3235 "/ |
3224 "/ new: look in 'source/<module>/<package>/<filename> |
3236 "/ new: look in 'source/<module>/<package>/<filename> |
3225 "/ this makes the symbolic links to (or copy of) the source files |
3237 "/ this makes the symbolic links to (or copy of) the source files |
3266 the directory info defaults to library name. |
3280 the directory info defaults to library name. |
3267 The library name may not be left blank. |
3281 The library name may not be left blank. |
3268 (this is done for backward compatibility,) |
3282 (this is done for backward compatibility,) |
3269 |
3283 |
3270 For example: |
3284 For example: |
3271 '....(libbasic)' -> module: stx directory: libbasic library: libbasic |
3285 '....(libbasic)' -> module: stx directory: libbasic library: libbasic |
3272 '....(stx:libbasic)' -> module: stx directory: libbasic library: libbasic |
3286 '....(stx:libbasic)' -> module: stx directory: libbasic library: libbasic |
3273 '....(aeg:libIECInterface)' -> module: aeg directory: libIECInterface library:libIECInterface |
3287 '....(aeg:libIECInterface)' -> module: aeg directory: libIECInterface library:libIECInterface |
3274 '....(stx:goodies/persistency:libdbase)' -> module: stx directory: goodies/persistency library:libdbase |
3288 '....(stx:goodies/persistency:libdbase)' -> module: stx directory: goodies/persistency library:libdbase |
3275 |
3289 |
3276 The way how the sourceCodeManager uses this to find the source location |
3290 The way how the sourceCodeManager uses this to find the source location |
3277 depends on the scheme used. For CVS, the module is taken as the -d arg, |
3291 depends on the scheme used. For CVS, the module is taken as the -d arg, |
3278 while the directory is prepended to the file name. |
3292 while the directory is prepended to the file name. |
3279 Other schemes may do things differently - these are not yet specified. |
3293 Other schemes may do things differently - these are not yet specified. |
3280 |
3294 |
3281 Caveat: |
3295 Caveat: |
3282 Encoding this info in the package string seems somewhat kludgy. |
3296 Encoding this info in the package string seems somewhat kludgy. |
3283 " |
3297 " |
3284 |
3298 |
3285 |owner sourceInfo packageString idx1 idx2 |
3299 |owner sourceInfo packageString idx1 idx2 |
3286 moduleString directoryString libraryString components dirComponents mgr| |
3300 moduleString directoryString libraryString components dirComponents mgr| |
3287 |
3301 |
3290 package isNil ifTrue:[^ nil]. |
3304 package isNil ifTrue:[^ nil]. |
3291 |
3305 |
3292 packageString := package asString. |
3306 packageString := package asString. |
3293 idx1 := packageString lastIndexOf:$(. |
3307 idx1 := packageString lastIndexOf:$(. |
3294 idx1 ~~ 0 ifTrue:[ |
3308 idx1 ~~ 0 ifTrue:[ |
3295 idx2 := packageString indexOf:$) startingAt:idx1+1. |
3309 idx2 := packageString indexOf:$) startingAt:idx1+1. |
3296 idx2 ~~ 0 ifTrue:[ |
3310 idx2 ~~ 0 ifTrue:[ |
3297 sourceInfo := packageString copyFrom:idx1 + 1 to:idx2 - 1 |
3311 sourceInfo := packageString copyFrom:idx1 + 1 to:idx2 - 1 |
3298 ] |
3312 ] |
3299 ] ifFalse:[ |
3313 ] ifFalse:[ |
3300 sourceInfo := packageString |
3314 sourceInfo := packageString |
3301 ]. |
3315 ]. |
3302 |
3316 |
3303 sourceInfo isNil ifTrue:[^ nil]. |
3317 sourceInfo isNil ifTrue:[^ nil]. |
3304 components := sourceInfo asCollectionOfSubstringsSeparatedBy:$:. |
3318 components := sourceInfo asCollectionOfSubstringsSeparatedBy:$:. |
3305 components size == 0 ifTrue:[ |
3319 components size == 0 ifTrue:[ |
3306 "/ moduleString := 'stx'. |
3320 "/ moduleString := 'stx'. |
3307 "/ directoryString := libraryString := ''. |
3321 "/ directoryString := libraryString := ''. |
3308 ^ nil |
3322 ^ nil |
3309 ]. |
3323 ]. |
3310 components size == 1 ifTrue:[ |
3324 components size == 1 ifTrue:[ |
3311 "/ a single name given - the module becomes 'stx' or |
3325 "/ a single name given - the module becomes 'stx' or |
3312 "/ the very first directory component (if such a module exists). |
3326 "/ the very first directory component (if such a module exists). |
3313 "/ If the component includes slashes, its the directory |
3327 "/ If the component includes slashes, its the directory |
3314 "/ otherwise the library |
3328 "/ otherwise the library |
3315 "/ |
3329 "/ |
3316 dirComponents := Filename concreteClass components:(components at:1). |
3330 dirComponents := Filename concreteClass components:(components at:1). |
3317 |
3331 |
3318 (dirComponents size > 1 |
3332 (dirComponents size > 1 |
3319 and:[(mgr := self sourceCodeManager) notNil |
3333 and:[(mgr := self sourceCodeManager) notNil |
3320 and:[mgr checkForExistingModule:dirComponents first]]) ifTrue:[ |
3334 and:[mgr checkForExistingModule:dirComponents first]]) ifTrue:[ |
3321 moduleString := dirComponents first. |
3335 moduleString := dirComponents first. |
3322 directoryString := libraryString := (Filename fromComponents:(dirComponents copyFrom:2)) asString. |
3336 directoryString := libraryString := (Filename fromComponents:(dirComponents copyFrom:2)) asString. |
3323 ] ifFalse:[ |
3337 ] ifFalse:[ |
3324 moduleString := 'stx'. |
3338 moduleString := 'stx'. |
3325 directoryString := libraryString := components at:1. |
3339 directoryString := libraryString := components at:1. |
3326 ]. |
3340 ]. |
3327 |
3341 |
3328 (libraryString includes:$/) ifTrue:[ |
3342 (libraryString includes:$/) ifTrue:[ |
3329 libraryString := libraryString asFilename baseName |
3343 libraryString := libraryString asFilename baseName |
3330 ] |
3344 ] |
3331 ] ifFalse:[ |
3345 ] ifFalse:[ |
3332 components size == 2 ifTrue:[ |
3346 components size == 2 ifTrue:[ |
3333 "/ two components - assume its the module and the directory; |
3347 "/ two components - assume its the module and the directory; |
3334 "/ the library is assumed to be named after the directory |
3348 "/ the library is assumed to be named after the directory |
3335 "/ except, if slashes are in the name; then the libraryname |
3349 "/ except, if slashes are in the name; then the libraryname |
3336 "/ is the last component. |
3350 "/ is the last component. |
3337 "/ |
3351 "/ |
3338 moduleString := components at:1. |
3352 moduleString := components at:1. |
3339 directoryString := libraryString := components at:2. |
3353 directoryString := libraryString := components at:2. |
3340 (libraryString includes:$/) ifTrue:[ |
3354 (libraryString includes:$/) ifTrue:[ |
3341 libraryString := libraryString asFilename baseName |
3355 libraryString := libraryString asFilename baseName |
3342 ] |
3356 ] |
3343 ] ifFalse:[ |
3357 ] ifFalse:[ |
3344 "/ all components given |
3358 "/ all components given |
3345 moduleString := components at:1. |
3359 moduleString := components at:1. |
3346 directoryString := components at:2. |
3360 directoryString := components at:2. |
3347 libraryString := components at:3. |
3361 libraryString := components at:3. |
3348 ] |
3362 ] |
3349 ]. |
3363 ]. |
3350 |
3364 |
3351 libraryString isEmpty ifTrue:[ |
3365 libraryString isEmpty ifTrue:[ |
3352 directoryString notEmpty ifTrue:[ |
3366 directoryString notEmpty ifTrue:[ |
3353 libraryString := directoryString asFilename baseName |
3367 libraryString := directoryString asFilename baseName |
3354 ]. |
3368 ]. |
3355 libraryString isEmpty ifTrue:[ |
3369 libraryString isEmpty ifTrue:[ |
3356 "/ lets extract the library from the liblist file ... |
3370 "/ lets extract the library from the liblist file ... |
3357 libraryString := Smalltalk libraryFileNameOfClass:self. |
3371 libraryString := Smalltalk libraryFileNameOfClass:self. |
3358 libraryString isNil ifTrue:[^ nil]. |
3372 libraryString isNil ifTrue:[^ nil]. |
3359 ] |
3373 ] |
3360 ]. |
3374 ]. |
3361 |
3375 |
3362 moduleString isEmpty ifTrue:[ |
3376 moduleString isEmpty ifTrue:[ |
3363 moduleString := 'stx'. |
3377 moduleString := 'stx'. |
3364 ]. |
3378 ]. |
3365 directoryString isEmpty ifTrue:[ |
3379 directoryString isEmpty ifTrue:[ |
3366 directoryString := libraryString. |
3380 directoryString := libraryString. |
3367 ]. |
3381 ]. |
3368 |
3382 |
3369 ^ IdentityDictionary |
3383 ^ IdentityDictionary |
3370 with:(#module->moduleString) |
3384 with:(#module->moduleString) |
3371 with:(#directory->directoryString) |
3385 with:(#directory->directoryString) |
3372 with:(#library->libraryString) |
3386 with:(#library->libraryString) |
3373 |
3387 |
3374 " |
3388 " |
3375 Object packageSourceCodeInfo |
3389 Object packageSourceCodeInfo |
3376 View packageSourceCodeInfo |
3390 View packageSourceCodeInfo |
3377 Model packageSourceCodeInfo |
3391 Model packageSourceCodeInfo |
3431 |
3445 |
3432 revisionInfo |
3446 revisionInfo |
3433 "return a dictionary filled with revision info. |
3447 "return a dictionary filled with revision info. |
3434 This extracts the relevant info from the revisionString. |
3448 This extracts the relevant info from the revisionString. |
3435 The revisionInfo contains all or a subset of: |
3449 The revisionInfo contains all or a subset of: |
3436 #binaryRevision - the revision upon which the binary of this class is based |
3450 #binaryRevision - the revision upon which the binary of this class is based |
3437 #revision - the revision upon which the class is based logically |
3451 #revision - the revision upon which the class is based logically |
3438 (different, if a changed class was checked in, but not yet recompiled) |
3452 (different, if a changed class was checked in, but not yet recompiled) |
3439 #user - the user who checked in the logical revision |
3453 #user - the user who checked in the logical revision |
3440 #date - the date when the logical revision was checked in |
3454 #date - the date when the logical revision was checked in |
3441 #time - the time when the logical revision was checked in |
3455 #time - the time when the logical revision was checked in |
3442 #fileName - the classes source file name |
3456 #fileName - the classes source file name |
3443 #repositoryPath - the classes source container |
3457 #repositoryPath - the classes source container |
3444 " |
3458 " |
3445 |
3459 |
3446 |vsnString info mgr| |
3460 |vsnString info mgr| |
3447 |
3461 |
3448 vsnString := self revisionString. |
3462 vsnString := self revisionString. |
3449 vsnString notNil ifTrue:[ |
3463 vsnString notNil ifTrue:[ |
3450 mgr := self sourceCodeManager. |
3464 mgr := self sourceCodeManager. |
3451 mgr notNil ifTrue:[ |
3465 mgr notNil ifTrue:[ |
3452 info := mgr revisionInfoFromString:vsnString |
3466 info := mgr revisionInfoFromString:vsnString |
3453 ] ifFalse:[ |
3467 ] ifFalse:[ |
3454 info := Class revisionInfoFromString:vsnString. |
3468 info := Class revisionInfoFromString:vsnString. |
3455 ]. |
3469 ]. |
3456 info notNil ifTrue:[ |
3470 info notNil ifTrue:[ |
3457 info at:#binaryRevision put:self binaryRevision. |
3471 info at:#binaryRevision put:self binaryRevision. |
3458 ] |
3472 ] |
3459 ]. |
3473 ]. |
3460 ^ info |
3474 ^ info |
3461 |
3475 |
3462 " |
3476 " |
3463 Object revisionString |
3477 Object revisionString |
3484 (owner := self owningClass) notNil ifTrue:[^ owner revisionString]. |
3498 (owner := self owningClass) notNil ifTrue:[^ owner revisionString]. |
3485 |
3499 |
3486 thisContext isRecursive ifTrue:[^ nil ]. |
3500 thisContext isRecursive ifTrue:[^ nil ]. |
3487 |
3501 |
3488 self isMeta ifTrue:[ |
3502 self isMeta ifTrue:[ |
3489 meta := self. cls := self soleInstance |
3503 meta := self. cls := self soleInstance |
3490 ] ifFalse:[ |
3504 ] ifFalse:[ |
3491 cls := self. meta := self class |
3505 cls := self. meta := self class |
3492 ]. |
3506 ]. |
3493 |
3507 |
3494 m := meta compiledMethodAt:#version. |
3508 m := meta compiledMethodAt:#version. |
3495 m isNil ifTrue:[ |
3509 m isNil ifTrue:[ |
3496 m := cls compiledMethodAt:#version. |
3510 m := cls compiledMethodAt:#version. |
3497 m isNil ifTrue:[^ nil]. |
3511 m isNil ifTrue:[^ nil]. |
3498 ]. |
3512 ]. |
3499 |
3513 |
3500 m isExecutable ifTrue:[ |
3514 m isExecutable ifTrue:[ |
3501 "/ |
3515 "/ |
3502 "/ if its a method returning the string, |
3516 "/ if its a method returning the string, |
3503 "/ thats the returned value |
3517 "/ thats the returned value |
3504 "/ |
3518 "/ |
3505 val := cls version. |
3519 val := cls version. |
3506 val isString ifTrue:[^ val]. |
3520 val isString ifTrue:[^ val]. |
3507 ]. |
3521 ]. |
3508 |
3522 |
3509 "/ |
3523 "/ |
3510 "/ if its a method consisting of a comment only |
3524 "/ if its a method consisting of a comment only |
3511 "/ extract it - this may lead to a recursive call |
3525 "/ extract it - this may lead to a recursive call |
3555 |
3569 |
3556 self owningClass notNil ifTrue:[^ self]. |
3570 self owningClass notNil ifTrue:[^ self]. |
3557 |
3571 |
3558 mgr := self sourceCodeManager. |
3572 mgr := self sourceCodeManager. |
3559 mgr notNil ifTrue:[ |
3573 mgr notNil ifTrue:[ |
3560 info := mgr sourceInfoOfClass:self |
3574 info := mgr sourceInfoOfClass:self |
3561 ]. |
3575 ]. |
3562 |
3576 |
3563 info notNil ifTrue:[ |
3577 info notNil ifTrue:[ |
3564 mod := info at:#module ifAbsent:nil. "/ stx, aeg, <your-organization> |
3578 mod := info at:#module ifAbsent:nil. "/ stx, aeg, <your-organization> |
3565 dir := info at:#directory ifAbsent:nil. "/ libbasic, libtool ... |
3579 dir := info at:#directory ifAbsent:nil. "/ libbasic, libtool ... |
3566 lib := info at:#library ifAbsent:dir. |
3580 lib := info at:#library ifAbsent:dir. |
3567 |
3581 |
3568 p := ''. |
3582 p := ''. |
3569 mod notNil ifTrue:[ |
3583 mod notNil ifTrue:[ |
3570 mod ~= 'stx' ifTrue:[ |
3584 mod ~= 'stx' ifTrue:[ |
3571 p := p , mod |
3585 p := p , mod |
3572 ] |
3586 ] |
3573 ]. |
3587 ]. |
3574 dir notNil ifTrue:[ |
3588 dir notNil ifTrue:[ |
3575 p notEmpty ifTrue:[p := p , ':']. |
3589 p notEmpty ifTrue:[p := p , ':']. |
3576 p := p , dir. |
3590 p := p , dir. |
3577 ]. |
3591 ]. |
3578 lib notNil ifTrue:[ |
3592 lib notNil ifTrue:[ |
3579 lib ~= dir ifTrue:[ |
3593 lib ~= dir ifTrue:[ |
3580 p notEmpty ifTrue:[p := p , ':']. |
3594 p notEmpty ifTrue:[p := p , ':']. |
3581 p := p , lib. |
3595 p := p , lib. |
3582 ] |
3596 ] |
3583 ]. |
3597 ]. |
3584 (p notEmpty and:[p ~= package]) ifTrue:[ |
3598 (p notEmpty and:[p ~= package]) ifTrue:[ |
3585 "/ package notNil ifTrue:[ |
3599 "/ package notNil ifTrue:[ |
3586 "/ (name , ': changing packageID from ''' , package , ''' to ''' , p , '''') infoPrintCR. |
3600 "/ (name , ': changing packageID from ''' , package , ''' to ''' , p , '''') infoPrintCR. |
3587 "/ ]. |
3601 "/ ]. |
3588 package := p. |
3602 package := p. |
3589 |
3603 |
3590 self methodDictionary do:[:aMethod | |
3604 self methodDictionary do:[:aMethod | |
3591 aMethod package isNil ifTrue:[ |
3605 aMethod package isNil ifTrue:[ |
3592 aMethod package:p |
3606 aMethod package:p |
3593 ] |
3607 ] |
3594 ] |
3608 ] |
3595 ]. |
3609 ]. |
3596 ]. |
3610 ]. |
3597 ^ self |
3611 ^ self |
3598 |
3612 |
3599 " |
3613 " |
3600 MemoryMonitor autoload. |
3614 MemoryMonitor autoload. |
3640 or:[TryLocalSourceFirst == true]) ifTrue:[ |
3654 or:[TryLocalSourceFirst == true]) ifTrue:[ |
3641 aStream := self localSourceStreamFor:source. |
3655 aStream := self localSourceStreamFor:source. |
3642 ]. |
3656 ]. |
3643 |
3657 |
3644 aStream isNil ifTrue:[ |
3658 aStream isNil ifTrue:[ |
3645 "/ |
3659 "/ |
3646 "/ hard case - there is no source file for this class |
3660 "/ hard case - there is no source file for this class |
3647 "/ (in the source-dir-path). |
3661 "/ (in the source-dir-path). |
3648 "/ |
3662 "/ |
3649 |
3663 |
3650 "/ |
3664 "/ |
3651 "/ look if my binary is from a dynamically loaded module, |
3665 "/ look if my binary is from a dynamically loaded module, |
3652 "/ and, if so, look in the modules directory for the |
3666 "/ and, if so, look in the modules directory for the |
3653 "/ source file. |
3667 "/ source file. |
3654 "/ |
3668 "/ |
3655 ObjectFileLoader notNil ifTrue:[ |
3669 ObjectFileLoader notNil ifTrue:[ |
3656 ObjectFileLoader loadedObjectHandlesDo:[:h | |
3670 ObjectFileLoader loadedObjectHandlesDo:[:h | |
3657 |f classes| |
3671 |f classes| |
3658 |
3672 |
3659 aStream isNil ifTrue:[ |
3673 aStream isNil ifTrue:[ |
3660 (classes := h classes) notNil ifTrue:[ |
3674 (classes := h classes) notNil ifTrue:[ |
3661 (classes includes:self) ifTrue:[ |
3675 (classes includes:self) ifTrue:[ |
3662 f := h pathName. |
3676 f := h pathName. |
3663 f := f asFilename directory. |
3677 f := f asFilename directory. |
3664 f := f construct:source. |
3678 f := f construct:source. |
3665 f exists ifTrue:[ |
3679 f exists ifTrue:[ |
3666 aStream := f readStream. |
3680 aStream := f readStream. |
3667 ]. |
3681 ]. |
3668 ]. |
3682 ]. |
3669 ]. |
3683 ]. |
3670 ] |
3684 ] |
3671 ]. |
3685 ]. |
3672 ]. |
3686 ]. |
3673 ]. |
3687 ]. |
3674 |
3688 |
3675 aStream isNil ifTrue:[ |
3689 aStream isNil ifTrue:[ |
3676 |
3690 |
3677 "/ mhmh - still no source file. |
3691 "/ mhmh - still no source file. |
3678 "/ If there is a SourceCodeManager, ask it to aquire the |
3692 "/ If there is a SourceCodeManager, ask it to aquire the |
3679 "/ the source for my class, and return an open stream on it. |
3693 "/ the source for my class, and return an open stream on it. |
3680 "/ if that one does not know about the source, look in |
3694 "/ if that one does not know about the source, look in |
3681 "/ standard places |
3695 "/ standard places |
3682 |
3696 |
3683 mgr notNil ifTrue:[ |
3697 mgr notNil ifTrue:[ |
3684 aStream := mgr getSourceStreamFor:self. |
3698 aStream := mgr getSourceStreamFor:self. |
3685 aStream notNil ifTrue:[ |
3699 aStream notNil ifTrue:[ |
3686 (self validateSourceStream:aStream) ifFalse:[ |
3700 (self validateSourceStream:aStream) ifFalse:[ |
3687 ('Class [info]: repositories source for `' |
3701 ('Class [info]: repositories source for `' |
3688 , (self isMeta ifTrue:[self soleInstance name] |
3702 , (self isMeta ifTrue:[self soleInstance name] |
3689 ifFalse:[name]) |
3703 ifFalse:[name]) |
3690 , ''' is invalid.') infoPrintCR. |
3704 , ''' is invalid.') infoPrintCR. |
3691 aStream close. |
3705 aStream close. |
3692 aStream := nil |
3706 aStream := nil |
3693 ] ifTrue:[ |
3707 ] ifTrue:[ |
3694 validated := true. |
3708 validated := true. |
3695 ]. |
3709 ]. |
3696 ]. |
3710 ]. |
3697 |
3711 |
3698 aStream isNil ifTrue:[ |
3712 aStream isNil ifTrue:[ |
3699 aStream := self localSourceStreamFor:source. |
3713 aStream := self localSourceStreamFor:source. |
3700 ]. |
3714 ]. |
3701 ]. |
3715 ]. |
3702 |
3716 |
3703 "/ |
3717 "/ |
3704 "/ final chance: try current directory |
3718 "/ final chance: try current directory |
3705 "/ |
3719 "/ |
3706 aStream isNil ifTrue:[ |
3720 aStream isNil ifTrue:[ |
3707 aStream := source asFilename readStream. |
3721 aStream := source asFilename readStream. |
3708 ]. |
3722 ]. |
3709 ]. |
3723 ]. |
3710 |
3724 |
3711 (aStream notNil and:[validated not]) ifTrue:[ |
3725 (aStream notNil and:[validated not]) ifTrue:[ |
3712 (self validateSourceStream:aStream) ifFalse:[ |
3726 (self validateSourceStream:aStream) ifFalse:[ |
3713 ('Class [warning]: source for ''' , self name , ''' is invalid. Take care.') errorPrintCR |
3727 ('Class [warning]: source for ''' , self name , ''' is invalid. Take care.') errorPrintCR |
3714 ]. |
3728 ]. |
3715 ]. |
3729 ]. |
3716 ^ aStream |
3730 ^ aStream |
3717 |
3731 |
3718 " |
3732 " |
3719 Object sourceStream |
3733 Object sourceStream |
3777 |
3791 |
3778 |cls meta cannotCheckReason versionMethod info |
3792 |cls meta cannotCheckReason versionMethod info |
3779 versionFromCode versionFromSource oldPos pos src rev| |
3793 versionFromCode versionFromSource oldPos pos src rev| |
3780 |
3794 |
3781 self isMeta ifTrue:[ |
3795 self isMeta ifTrue:[ |
3782 meta := self. cls := self soleInstance |
3796 meta := self. cls := self soleInstance |
3783 ] ifFalse:[ |
3797 ] ifFalse:[ |
3784 cls := self. meta := self class |
3798 cls := self. meta := self class |
3785 ]. |
3799 ]. |
3786 |
3800 |
3787 cannotCheckReason := nil. |
3801 cannotCheckReason := nil. |
3788 |
3802 |
3789 versionMethod := meta compiledMethodAt:#version. |
3803 versionMethod := meta compiledMethodAt:#version. |
3790 (versionMethod isNil |
3804 (versionMethod isNil |
3791 or:[versionMethod isExecutable not]) ifTrue:[ |
3805 or:[versionMethod isExecutable not]) ifTrue:[ |
3792 versionMethod := cls compiledMethodAt:#version. |
3806 versionMethod := cls compiledMethodAt:#version. |
3793 (versionMethod isNil |
3807 (versionMethod isNil |
3794 or:[versionMethod isExecutable not]) ifTrue:[ |
3808 or:[versionMethod isExecutable not]) ifTrue:[ |
3795 cannotCheckReason := 'no valid version method'. |
3809 cannotCheckReason := 'no valid version method'. |
3796 ] |
3810 ] |
3797 ] ifFalse:[ |
3811 ] ifFalse:[ |
3798 "/ |
3812 "/ |
3799 "/ if its a method returning the string, |
3813 "/ if its a method returning the string, |
3800 "/ thats the returned value |
3814 "/ thats the returned value |
3801 "/ |
3815 "/ |
3802 versionFromCode := cls version. |
3816 versionFromCode := cls version. |
3803 versionFromCode isString ifFalse:[ |
3817 versionFromCode isString ifFalse:[ |
3804 cannotCheckReason := 'version method does not return a string' |
3818 cannotCheckReason := 'version method does not return a string' |
3805 ]. |
3819 ]. |
3806 ]. |
3820 ]. |
3807 |
3821 |
3808 "/ |
3822 "/ |
3809 "/ if its a method consisting of a comment only |
3823 "/ if its a method consisting of a comment only |
3810 "/ extract it - this may lead to a recursive call |
3824 "/ extract it - this may lead to a recursive call |
3811 "/ to myself (thats what the #isRecursive is for) |
3825 "/ to myself (thats what the #isRecursive is for) |
3812 "/ in case we need to access the source code manager |
3826 "/ in case we need to access the source code manager |
3813 "/ for the source ... |
3827 "/ for the source ... |
3814 "/ |
3828 "/ |
3815 versionMethod notNil ifTrue:[ |
3829 versionMethod notNil ifTrue:[ |
3816 pos := versionMethod sourcePosition. |
3830 pos := versionMethod sourcePosition. |
3817 pos isInteger ifFalse:[ |
3831 pos isInteger ifFalse:[ |
3818 "/ mhmh - either no version method, |
3832 "/ mhmh - either no version method, |
3819 "/ or updated due to a checkin. |
3833 "/ or updated due to a checkin. |
3820 "/ in any case, this should be a good source. |
3834 "/ in any case, this should be a good source. |
3821 |
3835 |
3822 ^ true. |
3836 ^ true. |
3823 "/ cannotCheckReason := 'no source position for version-method' |
3837 "/ cannotCheckReason := 'no source position for version-method' |
3824 ] |
3838 ] |
3825 ]. |
3839 ]. |
3826 |
3840 |
3827 cannotCheckReason notNil ifTrue:[ |
3841 cannotCheckReason notNil ifTrue:[ |
3828 ('Class [warning]: ' , cannotCheckReason) errorPrintCR. |
3842 ('Class [warning]: ' , cannotCheckReason) errorPrintCR. |
3829 'Class [info]: cannot validate source; trusting source' infoPrintCR. |
3843 'Class [info]: cannot validate source; trusting source' infoPrintCR. |
3830 ^ true |
3844 ^ true |
3831 ]. |
3845 ]. |
3832 |
3846 |
3833 oldPos := aStream position. |
3847 oldPos := aStream position. |
3834 aStream position:pos. |
3848 aStream position:pos. |
3835 src := aStream nextChunk. |
3849 src := aStream nextChunk. |
3836 aStream position:oldPos. |
3850 aStream position:oldPos. |
3837 |
3851 |
3838 (src isNil or:[src isEmpty]) ifTrue:[ |
3852 (src isNil or:[src isEmpty]) ifTrue:[ |
3839 "/ 'empty source for version-method' printCR. |
3853 "/ 'empty source for version-method' printCR. |
3840 ^ false |
3854 ^ false |
3841 ]. |
3855 ]. |
3842 |
3856 |
3843 versionFromSource := Class revisionStringFromSource:src. |
3857 versionFromSource := Class revisionStringFromSource:src. |
3844 versionFromSource = versionFromCode ifTrue:[^ true]. |
3858 versionFromSource = versionFromCode ifTrue:[^ true]. |
3845 |
3859 |