Smalltalk.st
branchjv
changeset 18080 9ae1db7ef04a
parent 18079 7b5afc0ad3d5
parent 15596 6e05c159e789
child 18084 ab5b38bd8f81
--- a/Smalltalk.st	Thu Aug 01 10:22:20 2013 +0100
+++ b/Smalltalk.st	Thu Aug 08 11:09:31 2013 +0100
@@ -4836,6 +4836,32 @@
     "Created: 17.10.1997 / 13:00:56 / cg"
 !
 
+installAutoloadedClassFromSourceFile:aFilename
+    "install aFilename (which must be a smalltalk source file) as autoloaded class
+     (extract the class definition chunk from the file and create an autoloaded
+      class stub for it)"
+
+    |chunks filename|
+
+    filename := aFilename asFilename.
+
+    ChangeSet::InvalidChangeChunkError handle:[:ex |
+        ^ self
+    ] do:[
+        filename readingFileDo:[:s|
+            chunks := ChangeSet fromStream:s while:[:chunk | chunk isMethodChange not].
+        ].
+    ].
+
+    chunks 
+        select:[:eachChunk | eachChunk isClassDefinitionChange]
+        thenDo:[:eachClassChunk | 
+                eachClassChunk installAsAutoloadedClassIfPublicWithFilename:filename asAbsoluteFilename "withoutSuffix" name "baseName"
+        ].
+
+    "Created: / 01-08-2013 / 16:57:26 / cg"
+!
+
 installAutoloadedClassNamed:clsName category:cat package:package revision:revisionOrNil
     "create & install an autoload stub for a class named: clsName,
      to be loaded from package.
@@ -5178,117 +5204,127 @@
      (however, the directories are searched for packages)
      If a file called NOPACKAGES is found, no further searching is done in that directory or below."
 
-    |dir noAutoloadHere dirName pkgName directoryContents|
+    |dir noAutoloadHere dirName pkgName directoryContents haveAbbrevDotSTC|
 
     maxLevels == 0 ifTrue:[
 "/        'Smalltalk [warning]: max directory nesting reached.' infoPrintCR.
-	^ self
+        ^ self
     ].
 
     dir := aDirectory asFilename.
     dirName := dir pathName.
 
     (dirsConsulted includes:dirName) ifTrue:[
-	^ self
+        ^ self
     ].
     dirsConsulted add:dirName.
 
     (dir / 'NOPACKAGES') exists ifTrue:[
-	^ self.
+        ^ self.
     ].
     (dir / 'NOSUBAUTOLOAD') exists ifTrue:[
-	^ self.
+        ^ self.
     ].
 
     noAutoloadHere := noAutoloadIn.
     noAutoloadHere ifFalse:[
-	(dir / 'NOAUTOLOAD') exists ifTrue:[
-	    noAutoloadHere := true.
-	].
+        (dir / 'NOAUTOLOAD') exists ifTrue:[
+            noAutoloadHere := true.
+        ].
     ] ifTrue:[
-	(dir / 'AUTOLOAD') exists ifTrue:[
-	    noAutoloadHere := false.
-	].
+        (dir / 'AUTOLOAD') exists ifTrue:[
+            noAutoloadHere := false.
+        ].
     ].
 
     ((dir / 'loadAll') exists or:[(dir / 'abbrev.stc') exists]) ifTrue:[
-	packageTopPath notNil ifTrue:[
-	    KnownPackages isNil ifTrue:[
-		KnownPackages := Set new.
-	    ].
-	    pkgName := dirName copyFrom:(packageTopPath asFilename pathName) size + 1 + 1.
-	    KnownPackages add:pkgName
-	].
+        packageTopPath notNil ifTrue:[
+            KnownPackages isNil ifTrue:[
+                KnownPackages := Set new.
+            ].
+            pkgName := dirName copyFrom:(packageTopPath asFilename pathName) size + 1 + 1.
+            KnownPackages add:pkgName
+        ].
     ].
 
     showSplashInLevels >= 0 ifTrue:[
-	self showSplashMessage:('Smalltalk [info]: installing autoloaded classes found under "%1"...'
-				bindWith:(dirName contractAtBeginningTo:35)).
+        self showSplashMessage:('Smalltalk [info]: installing autoloaded classes found under "%1"...'
+                                bindWith:(dirName contractAtBeginningTo:35)).
     ].
 
     "/
     "/ suppress installation as autoloaded in this and everything
     "/ below; however, still traverse the directories to find packages ...
     "/
+    haveAbbrevDotSTC := false.
     noAutoloadHere ifFalse:[
-	[
-	    self installAutoloadedClassesFromAbbrevFile:(dir / 'abbrev.stc').
-	] on:FileStream openErrorSignal do:[:ex| "ignore this file"].
+        [
+            self installAutoloadedClassesFromAbbrevFile:(dir / 'abbrev.stc').
+            haveAbbrevDotSTC := true.
+        ] on:FileStream openErrorSignal 
+        do:[:ex| 
+            "ignore this file"
+        ].
     ].
 
     [
-	directoryContents := dir directoryContents asSet.   "asSet to speed up remove"
+        directoryContents := dir directoryContents asSet.   "asSet to speed up remove"
     ] on:FileStream openErrorSignal do:[:ex|
-	"non-accessable directory: we are done"
-	^ self
+        "non-accessable directory: we are done"
+        ^ self
     ].
 
     directoryContents removeAllFoundIn:#(
-			    'objbc'
-			    'objvc'
-			    'doc'
-			    'CVS'
-			    'bitmaps'
-			    'resources'
-			    'source'
-			    'not_delivered'
-			    'not_ported'
-			).
+                            'objbc' 'objvc' 'objmingw'
+                            'doc'
+                            'CVS'
+                            'bitmaps'
+                            'resources'
+                            'source'
+                            'not_delivered'
+                            'not_ported'
+                        ).
     dir baseName = 'stx' ifTrue:[
-	directoryContents removeAllFoundIn:#(
-			    'configurations'
-			    'include'
-			    'rules'
-			    'stc'
-			    'support'
-			).
+        directoryContents removeAllFoundIn:#(
+                            'configurations'
+                            'include'
+                            'rules'
+                            'stc'
+                            'support'
+                        ).
     ].
 
     directoryContents do:[:eachFilenameString |
-	|f|
-
-	f := dir / eachFilenameString.
-	f isDirectory ifTrue:[
-	     self
-		recursiveInstallAutoloadedClassesFrom:f
-		rememberIn:dirsConsulted
-		maxLevels:maxLevels-1
-		noAutoload:noAutoloadHere
-		packageTop:packageTopPath
-		showSplashInLevels:showSplashInLevels - 1.
-	]
+        |f|
+
+        f := dir / eachFilenameString.
+        f isDirectory ifTrue:[
+             self
+                recursiveInstallAutoloadedClassesFrom:f
+                rememberIn:dirsConsulted
+                maxLevels:maxLevels-1
+                noAutoload:noAutoloadHere
+                packageTop:packageTopPath
+                showSplashInLevels:showSplashInLevels - 1.
+        ] ifFalse:[
+            (noAutoloadHere not and:[haveAbbrevDotSTC not]) ifTrue:[
+                f suffix = 'st' ifTrue:[
+                    self installAutoloadedClassFromSourceFile:f
+                ]            
+            ].
+        ]
     ].
 
     showSplashInLevels >= 0 ifTrue:[
-	self showSplashMessage:('Smalltalk [info]: installing autoloaded classes from "%1"...'
-				bindWith:(dirName contractAtBeginningTo:35)).
+        self showSplashMessage:('Smalltalk [info]: installing autoloaded classes from "%1"...'
+                                bindWith:(dirName contractAtBeginningTo:35)).
     ].
 
     "
      Smalltalk installAutoloadedClasses
     "
 
-    "Modified: / 31-07-2012 / 15:26:54 / cg"
+    "Modified: / 01-08-2013 / 16:57:49 / cg"
 !
 
 replaceReferencesTo:anObject with:newRef
@@ -5425,12 +5461,12 @@
      If silent is true, no compiler messages are output to the transcript.
      Giving nil for silent/lazy will use the current settings.
      This method can load almost anything which makes sense:
-	.st    - source files
-	.cls   - binary smalltalk bytecode files
-	.so    - binary compiled machine code class libraries
-	[.class - java bytecode -- soon to come]"
-
-    |fileNameString aStream path morePath bos|
+        .st    - source files
+        .cls   - binary smalltalk bytecode files
+        .so    - binary compiled machine code class libraries
+        [.class - java bytecode -- soon to come]"
+
+    |fileNameString inStream lineStream path morePath bos|
 
     fileNameString := aFileNameOrString asString.
 
@@ -5439,47 +5475,46 @@
     "
     (ObjectFileLoader notNil
     and:[ObjectFileLoader hasValidBinaryExtension:fileNameString]) ifTrue:[
-	"/ LoadBinaries ifFalse:[^ false].
-	path := self getBinaryFileName:fileNameString.
-	path isNil ifTrue:[
-	    path := self getSystemFileName:fileNameString.
-	].
-	path isNil ifTrue:[^ false].
-	^ (ObjectFileLoader loadObjectFile:path) notNil
-    ].
+        "/ LoadBinaries ifFalse:[^ false].
+        path := self getBinaryFileName:fileNameString.
+        path isNil ifTrue:[
+            path := self getSystemFileName:fileNameString.
+        ].
+        path isNil ifTrue:[^ false].
+        ^ (ObjectFileLoader loadObjectFile:path) notNil
+    ].
+
+    inStream := self systemFileStreamFor:fileNameString.
+    inStream isNil ifTrue:[^ false].
 
     (fileNameString asFilename hasSuffix:'cls') ifTrue:[
-	BinaryObjectStorage notNil ifTrue:[
-	    aStream := self systemFileStreamFor:fileNameString.
-"/            path := self getBinaryFileName:fileNameString.
-"/            path isNil ifTrue:[^ false].
-"/            aStream := path asFilename readStream.
-	    aStream notNil ifTrue:[
-		aStream binary.
-		bos := BinaryObjectStorage onOld:aStream.
-		bos next.
-		bos close.
-		^ true
-	    ].
-	    ^ false
-	]
-    ].
-
-    aStream := self systemFileStreamFor:fileNameString.
-    aStream isNil ifTrue:[^ false].
+        BinaryObjectStorage notNil ifTrue:[
+            [
+                inStream binary.
+                bos := BinaryObjectStorage onOld:inStream.
+                bos next.
+            ] ensure:[
+                bos close.
+            ].
+            ^ true
+        ].
+        ^ false
+    ].
 
     (fileNameString includes:$/) ifTrue:[
-	"/ temporarily prepend the files directory
-	"/ to the searchPath.
-	"/ This allows fileIn-driver files to refer to local
-	"/ files via a relative path, and drivers to fileIn other
-	"/ drivers ...
-	morePath := aStream pathName asFilename directoryName.
-    ].
-    ^ self fileInStream:aStream lazy:lazy silent:silent logged:logged addPath:morePath
-
-    "
-     Smalltalk fileIn:'source/TicTacToe.st' lazy:true silent:true
+        "/ temporarily prepend the files directory
+        "/ to the searchPath.
+        "/ This allows fileIn-driver files to refer to local
+        "/ files via a relative path, and drivers to fileIn other
+        "/ drivers ...
+        morePath := inStream pathName asFilename directoryName.
+    ].
+    lineStream := LineNumberReadStream on:inStream.
+    ^ self fileInStream:lineStream lazy:lazy silent:silent logged:logged addPath:morePath
+
+    "
+     Smalltalk fileIn:'clients/TicTacToe/TicTacToe.st' lazy:true silent:true
+     Smalltalk fileIn:'keyboard.rc'
     "
 
     "Modified: / 08-09-2006 / 19:21:16 / cg"
@@ -7986,11 +8021,11 @@
 !Smalltalk class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1031 2013-07-27 13:54:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1033 2013-08-01 15:09:25 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1031 2013-07-27 13:54:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.1033 2013-08-01 15:09:25 cg Exp $'
 !
 
 version_HG