Class.st
changeset 22810 16b2394f9b18
parent 22659 1fe75ac33b44
child 22847 2839af336c1c
equal deleted inserted replaced
22809:89897abfad56 22810:16b2394f9b18
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     3 	       All Rights Reserved
     5 	       All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
    14 "{ NameSpace: Smalltalk }"
    16 "{ NameSpace: Smalltalk }"
    15 
    17 
    16 ClassDescription subclass:#Class
    18 ClassDescription subclass:#Class
    17 	instanceVariableNames:'name category classvars comment subclasses classFilename package
    19 	instanceVariableNames:'name category classvars comment subclasses classFilename package
    18 		revision environment signature attributes'
    20 		revision environment signature attributes'
    19 	classVariableNames:'DefaultCategoryForSTV DefaultCategoryForVAGE
    21 	classVariableNames:'DefaultCategoryForDolphin DefaultCategoryForSTV
    20 		DefaultCategoryForDolphin ValidateSourceOnlyOnce ValidatedClasses
       
    21 		SubclassCacheSequenceNumber
       
    22 		DefaultCategoryForUncategorizedClasses
    22 		DefaultCategoryForUncategorizedClasses
    23 		DefaultCategoryForUndeclaredClasses'
    23 		DefaultCategoryForUndeclaredClasses DefaultCategoryForVAGE
       
    24 		SubclassCacheSequenceNumber ValidateSourceOnlyOnce
       
    25 		ValidatedClasses'
    24 	poolDictionaries:''
    26 	poolDictionaries:''
    25 	category:'Kernel-Classes'
    27 	category:'Kernel-Classes'
    26 !
    28 !
    27 
    29 
    28 Array variableSubclass:#ArrayWithSequenceNumberValidation
    30 Array variableSubclass:#ArrayWithSequenceNumberValidation
    76     Class adds more functionality to classes; minimum stuff has already
    78     Class adds more functionality to classes; minimum stuff has already
    77     been defined in Behavior and ClassDescription; this adds naming, categories etc.
    79     been defined in Behavior and ClassDescription; this adds naming, categories etc.
    78 
    80 
    79     [Instance variables:]
    81     [Instance variables:]
    80 
    82 
    81 	name            <Symbol>                    the classes name
    83         name            <Symbol>                    the classes name
    82 
    84 
    83 	category        <Symbol>                    the classes category
    85         category        <Symbol>                    the classes category
    84 
    86 
    85 	classvars       <String>                    the names of the class variables;
    87         classvars       <String>                    the names of the class variables;
    86 			| <Collection of words>     initially, stc generates a string; this is converted on the fly
    88                         | <Collection of words>     initially, stc generates a string; this is converted on the fly
    87 						    to an array of names. In the future, stc may be changed.
    89                                                     to an array of names. In the future, stc may be changed.
    88 
    90 
    89 	comment         <String>                    the classes comment; either a string,
    91         comment         <String>                    the classes comment; either a string,
    90 						    a number specifying the offset in classFilename, or nil
    92                                                     a number specifying the offset in classFilename, or nil
    91 
    93 
    92 	subclasses      <Collection>                cached collection of subclasses
    94         subclasses      <Collection>                cached collection of subclasses
    93 						    (not used for execution, but for the IDE to speed up certain operations)
    95                                                     (not used for execution, but for the IDE to speed up certain operations)
    94 
    96 
    95 	classFilename   <String>                    the file (or nil) where the classes' sources are found
    97         classFilename   <String>                    the file (or nil) where the classes' sources are found
    96 
    98 
    97 	package         <Symbol>                    the package, in which the class was defined (inserted by compilers)
    99         package         <Symbol>                    the package, in which the class was defined (inserted by compilers)
    98 
   100 
    99 	revision        <String>                    revision string - inserted by stc
   101         revision        <String>                    revision string - inserted by stc
   100 
   102 
   101 	environment     <Symbol | nil>              cached environment (i.e. Smalltalk or a namespace)
   103         environment     <Symbol | nil>              cached environment (i.e. Smalltalk or a namespace)
   102 
   104 
   103 	signature       <SmallInteger>              the classes signature (used to detect obsolete or changed classes with binaryStorage)
   105         signature       <SmallInteger>              the classes signature (used to detect obsolete or changed classes with binaryStorage)
   104 						    This is filled in lazy - i.e. upon the first signature query.
   106                                                     This is filled in lazy - i.e. upon the first signature query.
   105 
   107 
   106 	attributes   <Array | nil>                  describes primitiveIncludes, primitiveFunctions etc.
   108         attributes   <Array | nil>                  describes primitiveIncludes, primitiveFunctions etc.
   107 						    also a place to add additional attributes, without a need to recompile all classes.
   109                                                     also a place to add additional attributes, without a need to recompile all classes.
   108 
   110 
   109 
   111 
   110     WARNING: layout known by compiler and runtime system
   112     WARNING: layout known by compiler and runtime system
   111 
   113 
       
   114     [note:]
       
   115         the subclasses instvar keeps a cached collection of the known subclasses in the system.
       
   116         this cache is lazyly flushed when a SubclassCacheSequenceNumber comparison detects a mismatch.
       
   117         (this seqNr is incremented, whenever something in any class hierarchy changes).
       
   118         This is a q&d mechanism to allow for no-overhead fileIn and package loading,
       
   119         and reasonable speedup in the hierarchy walkers (i.e. the browsers).
       
   120         (flushing all is obviously too much flushing, and we could do better in many situations)
       
   121 
   112     [author:]
   122     [author:]
   113 	Claus Gittinger
   123         Claus Gittinger
   114 
   124 
   115     [see also:]
   125     [see also:]
   116 	Behavior ClassDescription Metaclass
   126         Behavior ClassDescription Metaclass
   117 "
   127 "
   118 !
   128 !
   119 
   129 
   120 versionManagement
   130 versionManagement
   121 "
   131 "
   397 !
   407 !
   398 
   408 
   399 revisionStringFromSource:aMethodSourceString
   409 revisionStringFromSource:aMethodSourceString
   400     "{ Pragma: +optSpace }"
   410     "{ Pragma: +optSpace }"
   401 
   411 
   402     "extract a revision string from a methods source string.
   412     "extract a revision string from a method's source string.
   403      Caveat: Assumes CVS."
   413      Caveat: Assumes CVS."
   404 
   414 
   405     |lines line|
   415     |lines line|
   406 
   416 
   407     lines := aMethodSourceString asCollectionOfLines.
   417     lines := aMethodSourceString asCollectionOfLines.
   447 ! !
   457 ! !
   448 
   458 
   449 !Class class methodsFor:'private'!
   459 !Class class methodsFor:'private'!
   450 
   460 
   451 flushSubclassInfo
   461 flushSubclassInfo
   452     "throw away (forget) the cached subclass information, as created
   462     "throw away (forget) the cached subclass information, 
   453      by #subclassInfo.
   463      as created by #subclassInfo.
   454      This is private protocol"
   464      This is private protocol"
   455 
   465 
   456     SubclassCacheSequenceNumber := (SubclassCacheSequenceNumber ? 0) + 1.
   466     SubclassCacheSequenceNumber := (SubclassCacheSequenceNumber ? 0) + 1.
   457 
   467 
   458 "/    self allSubInstancesDo:[:cls |
   468 "/    self allSubInstancesDo:[:cls |
   465 
   475 
   466     "Modified: / 06-12-2011 / 16:20:13 / cg"
   476     "Modified: / 06-12-2011 / 16:20:13 / cg"
   467 !
   477 !
   468 
   478 
   469 flushSubclassInfoFor:aClass
   479 flushSubclassInfoFor:aClass
   470     "throw away (forget) the cached subclass information for aClass, as created
   480     "throw away (forget) the cached subclass information for aClass, 
   471      by #subclassInfo.
   481      as created by #subclassInfo.
   472      This is private protocol"
   482      This is private protocol"
   473 
   483 
   474     aClass notNil ifTrue:[
   484     aClass notNil ifTrue:[
   475 	aClass flushSubclasses
   485         aClass flushSubclasses
   476     ].
   486     ].
   477 
   487 
   478     "
   488     "
   479      Class flushSubclassInfoFor:View
   489      Class flushSubclassInfoFor:View
   480     "
   490     "
   486 
   496 
   487 isBuiltInClass
   497 isBuiltInClass
   488     "return true if this class is known by the run-time-system.
   498     "return true if this class is known by the run-time-system.
   489      Here, true is returned for myself, false for subclasses."
   499      Here, true is returned for myself, false for subclasses."
   490 
   500 
   491     ^ self == Class class or:[self == Class]
   501     ^ self == (Class class) or:[self == Class]
   492 
   502 
   493     "Created: 15.4.1996 / 17:17:13 / cg"
   503     "Created: 15.4.1996 / 17:17:13 / cg"
   494     "Modified: 23.4.1996 / 15:56:58 / cg"
   504     "Modified: 23.4.1996 / 15:56:58 / cg"
   495 ! !
   505 ! !
       
   506 
   496 
   507 
   497 
   508 
   498 !Class methodsFor:'Compatibility-Dolphin'!
   509 !Class methodsFor:'Compatibility-Dolphin'!
   499 
   510 
   500 defaultCategoryForDolphinClasses
   511 defaultCategoryForDolphinClasses
  1692 
  1703 
  1693     "Modified: / 09-08-2006 / 17:59:13 / fm"
  1704     "Modified: / 09-08-2006 / 17:59:13 / fm"
  1694 !
  1705 !
  1695 
  1706 
  1696 sharedPoolNames
  1707 sharedPoolNames
  1697     "this returns a collection of the plain (non-namespace aware) pool names"
  1708     "this returns a collection of the plain (non-namespace aware) pool names.
       
  1709      Read the comment in sharedPools on why this is done."
  1698 
  1710 
  1699     |pools|
  1711     |pools|
  1700 
  1712 
  1701     pools := self getAttribute:#sharedPools.
  1713     pools := self getAttribute:#sharedPools.
  1702     pools isNil ifTrue:[
  1714     pools isNil ifTrue:[
  1707         self setAttribute:#sharedPools to:pools.
  1719         self setAttribute:#sharedPools to:pools.
  1708     ].
  1720     ].
  1709     ^ pools
  1721     ^ pools
  1710 
  1722 
  1711     "
  1723     "
       
  1724      ZipArchive sharedPoolNames
  1712      OSI::ASN1_Coder sharedPoolNames
  1725      OSI::ASN1_Coder sharedPoolNames
  1713      Croquet::OpenGL sharedPoolNames
  1726      Croquet::OpenGL sharedPoolNames
  1714      OpenGLRenderingContext sharedPoolNames
  1727      OpenGLRenderingContext sharedPoolNames
  1715      Character sharedPoolNames
  1728      Character sharedPoolNames
  1716      Win32OperatingSystem sharedPoolNames
  1729      Win32OperatingSystem sharedPoolNames
  1732     "Modified: / 18-01-2011 / 20:41:17 / cg"
  1745     "Modified: / 18-01-2011 / 20:41:17 / cg"
  1733 !
  1746 !
  1734 
  1747 
  1735 sharedPools
  1748 sharedPools
  1736     "this returns a collection of the real pools (i.e. the PoolDictionaries),
  1749     "this returns a collection of the real pools (i.e. the PoolDictionaries),
  1737      not their names (see sharedPoolNames)"
  1750      not their names (see sharedPoolNames).
       
  1751      This cares for the namespace in which the class is located
       
  1752 
       
  1753      Notice, that for source compatibility with other smalltalks,
       
  1754      the namespace is not in the pool name, as to make it is easy to fileIn an alien class
       
  1755      into an ST/X namespace. 
       
  1756      However, then we must resolve the actual pool later - i.e. here"
  1738 
  1757 
  1739     |ns ns2 pools|
  1758     |ns ns2 pools|
  1740 
  1759 
  1741     ns := self nameSpace.
  1760     ns := self nameSpace.
  1742     ns2 := self topNameSpace.
  1761     ns2 := self topNameSpace.
  1743     pools :=
  1762     pools :=
  1744          self sharedPoolNames
  1763          self sharedPoolNames
  1745             collect:[:eachName |
  1764             collect:[:eachName |
  1746                     |pool|
  1765                     |pool|
  1747 
  1766 
  1748                     ns ~= Smalltalk ifTrue:[
  1767                     (ns notNil and:[ns ~= Smalltalk]) ifTrue:[
  1749                         pool := ns classNamed:eachName.
  1768                         pool := ns classNamed:eachName.
  1750                     ].
  1769                     ].
  1751                     pool isNil ifTrue:[
  1770                     pool isNil ifTrue:[
  1752                         ns2 ~= Smalltalk ifTrue:[
  1771                         (ns2 notNil and:[ns2 ~~ ns and:[ns2 ~= Smalltalk]]) ifTrue:[
  1753                             pool := ns2 classNamed:eachName.
  1772                             pool := ns2 classNamed:eachName.
  1754                         ].
  1773                         ].
  1755                     ].
       
  1756                     pool isNil ifTrue:[
       
  1757                         pool := Smalltalk classNamed:eachName.
       
  1758                         pool isNil ifTrue:[
  1774                         pool isNil ifTrue:[
  1759                             Transcript showCR:('Warning: no such pool: ',eachName).
  1775                             pool := Smalltalk classNamed:eachName.
  1760                         ]
  1776                             pool isNil ifTrue:[
       
  1777                                 Transcript showCR:('Warning: no such pool: ',eachName).
       
  1778                             ]
       
  1779                         ].
  1761                     ].
  1780                     ].
  1762                     pool
  1781                     pool
  1763                 ]
  1782                 ]
  1764             thenSelect:[:pool | pool notNil].
  1783             thenSelect:[:pool | pool notNil].
  1765 
  1784 
  1766     ^ pools.
  1785     ^ pools.
  1767 
  1786 
  1768 
  1787 
  1769     "
  1788     "
       
  1789      an example for a pool inside a namespace (in this case: a private pool):
       
  1790         UnixOperatingSystem::ELFFileHeader sharedPools
       
  1791 
       
  1792      Smalltalk allClasses 
       
  1793             collect:[:cls | cls -> cls sharedPools]
       
  1794             thenSelect:[:assoc | assoc value notEmptyOrNil].
       
  1795 
  1770      OSI::ASN1_Coder sharedPoolNames
  1796      OSI::ASN1_Coder sharedPoolNames
  1771      OSI::ASN1_Coder sharedPools
  1797      ZipArchive sharedPools
  1772      Croquet::OpenGL sharedPools
  1798      Croquet::OpenGL sharedPools
  1773      OpenGLRenderingContext sharedPools
  1799      OpenGLRenderingContext sharedPools
  1774      Character sharedPools
  1800      Character sharedPools
  1775      Win32OperatingSystem sharedPools
  1801      Win32OperatingSystem sharedPools
  1776     "
  1802     "
  1927 !
  1953 !
  1928 
  1954 
  1929 subclasses
  1955 subclasses
  1930     "return a collection of the direct subclasses of the receiver"
  1956     "return a collection of the direct subclasses of the receiver"
  1931 
  1957 
  1932     "/ use cached information (avoid class hierarchy search), if possible
  1958     "/ use cached information (to avoid class hierarchy search if possible)
  1933     (subclasses isNil
  1959     (subclasses isNil
  1934     or:[ subclasses sequenceNumber ~= SubclassCacheSequenceNumber ]) ifTrue:[
  1960     or:[ subclasses sequenceNumber ~= SubclassCacheSequenceNumber ]) ifTrue:[
  1935 	self updateAllCachedSubclasses.
  1961         self updateAllCachedSubclasses.
  1936 	"subclasses may still be nil - obsolete classes may not be updated"
  1962         "subclasses may still be nil - obsolete classes may not be updated"
  1937 	^ subclasses ? #().
  1963         ^ subclasses ? #().
  1938     ].
  1964     ].
  1939     ^ subclasses.
  1965     ^ subclasses.
  1940 
  1966 
  1941     "
  1967     "
  1942      Class flushSubclassInfo.
  1968      Class flushSubclassInfo.
  1999     self withAllPrivateClassesDo:[:cls | coll add:cls].
  2025     self withAllPrivateClassesDo:[:cls | coll add:cls].
  2000     ^ coll
  2026     ^ coll
  2001 
  2027 
  2002     "Created: / 18-07-2011 / 09:14:38 / cg"
  2028     "Created: / 18-07-2011 / 09:14:38 / cg"
  2003 ! !
  2029 ! !
  2004 
       
  2005 
  2030 
  2006 !Class methodsFor:'adding & removing'!
  2031 !Class methodsFor:'adding & removing'!
  2007 
  2032 
  2008 removeFromSystem
  2033 removeFromSystem
  2009     "ST-80 compatibility
  2034     "ST-80 compatibility
  4260 
  4285 
  4261     "
  4286     "
  4262      StandardSystemView whichClassDefinesClassVar:'ErrorSignal'
  4287      StandardSystemView whichClassDefinesClassVar:'ErrorSignal'
  4263      StandardSystemView whichClassDefinesClassVar:'Foo'
  4288      StandardSystemView whichClassDefinesClassVar:'Foo'
  4264     "
  4289     "
  4265 !
       
  4266 
       
  4267 whichPoolDefinesPoolVar:aVariableName
       
  4268     "return the shared which defines the class variable named aVariableName or nil."
       
  4269 
       
  4270     self sharedPools do:[:eachPool |
       
  4271         (eachPool classVariableNames includes:aVariableName) ifTrue:[ ^ eachPool].
       
  4272     ].
       
  4273     ^ nil
       
  4274 
       
  4275     "
       
  4276      ZipArchiveConstants classVariableNames
       
  4277      ZipArchive sharedPools
       
  4278      ZipArchive whichPoolDefinesPoolVar:'ECREC_SIZE'
       
  4279     "
       
  4280 ! !
  4290 ! !
  4281 
  4291 
  4282 !Class methodsFor:'renaming'!
  4292 !Class methodsFor:'renaming'!
  4283 
  4293 
  4284 makePrivateIn:newOwner
  4294 makePrivateIn:newOwner