ClassDescription.st
changeset 620 c7353f86a302
parent 528 a083413dfbe8
child 662 df7953db3847
equal deleted inserted replaced
619:95efb21c1fac 620:c7353f86a302
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 Behavior subclass:#ClassDescription
    13 Behavior subclass:#ClassDescription
    14        instanceVariableNames:'name category instvars primitiveSpec signature'
    14 	 instanceVariableNames:'name category instvars primitiveSpec signature'
    15        classVariableNames:''
    15 	 classVariableNames:''
    16        poolDictionaries:''
    16 	 poolDictionaries:''
    17        category:'Kernel-Classes'
    17 	 category:'Kernel-Classes'
    18 !
    18 !
    19 
    19 
    20 !ClassDescription class methodsFor:'documentation'!
    20 !ClassDescription class methodsFor:'documentation'!
    21 
    21 
    22 copyright
    22 copyright
    31  other person.  No title to or ownership of the software is
    31  other person.  No title to or ownership of the software is
    32  hereby transferred.
    32  hereby transferred.
    33 "
    33 "
    34 !
    34 !
    35 
    35 
    36 version
       
    37     ^ '$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.20 1995-11-11 14:27:50 cg Exp $'
       
    38 !
       
    39 
       
    40 documentation
    36 documentation
    41 "
    37 "
    42     this class has been added for ST-80 compatibility only.
    38     this class has been added for ST-80 compatibility only.
    43     All class stuff used to be in Behavior and Class - but, to be
    39     All class stuff used to be in Behavior and Class - but, to be
    44     able to file in some PD code, it became nescessary to add C'Description
    40     able to file in some PD code, it became nescessary to add C'Description
    53 	instvars        <String>        the names of the instance variables
    49 	instvars        <String>        the names of the instance variables
    54 	primitiveSpec   <Array|nil>     describes primitiveIncludes, primitiveFunctions etc.
    50 	primitiveSpec   <Array|nil>     describes primitiveIncludes, primitiveFunctions etc.
    55 	signature       <SmallInteger>  the classes signature (used to detect obsolete
    51 	signature       <SmallInteger>  the classes signature (used to detect obsolete
    56 					or changed classes with binaryStorage)
    52 					or changed classes with binaryStorage)
    57 "
    53 "
       
    54 !
       
    55 
       
    56 version
       
    57     ^ '$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.21 1995-11-23 10:46:35 cg Exp $'
    58 ! !
    58 ! !
    59 
    59 
    60 !ClassDescription class methodsFor:'instance creation'!
    60 !ClassDescription class methodsFor:'instance creation'!
    61 
    61 
    62 new
    62 new
    68     newClass := super new.
    68     newClass := super new.
    69     newClass setName:('some' , self name).
    69     newClass setName:('some' , self name).
    70     ^ newClass
    70     ^ newClass
    71 ! !
    71 ! !
    72 
    72 
    73 !ClassDescription methodsFor:'special accessing'!
       
    74 
       
    75 setName:aString
       
    76     "set the classes name - be careful, it will be still
       
    77      in the Smalltalk dictionary - under another key.
       
    78      This is NOT for general use - see renameTo:"
       
    79 
       
    80     name := aString
       
    81 !
       
    82 
       
    83 setInstanceVariableString:aString
       
    84     "set the classes instvarnames string - no recompilation
       
    85      or updates are done and no changeList records are written.
       
    86      This is NOT for general use."
       
    87 
       
    88     instvars := aString.
       
    89 ! !
       
    90 
       
    91 !ClassDescription methodsFor:'accessing'!
    73 !ClassDescription methodsFor:'accessing'!
    92 
    74 
    93 instanceVariableString
       
    94     "return a string of the instance variable names"
       
    95 
       
    96     instvars isNil ifTrue:[^ ''].
       
    97     ^ instvars
       
    98 
       
    99     "
       
   100      Point instanceVariableString   
       
   101     "
       
   102 !
       
   103 
       
   104 instVarNames
       
   105     "return a collection of the instance variable name-strings"
       
   106 
       
   107     instvars isNil ifTrue:[
       
   108 	^ OrderedCollection new
       
   109     ].
       
   110     ^ instvars asCollectionOfWords
       
   111 
       
   112     "
       
   113      Point instVarNames  
       
   114     "
       
   115 !
       
   116 
       
   117 instanceVariableOffsets
       
   118     "returns a dictionary containing the instance variable index
       
   119      for each instVar name"
       
   120 
       
   121     |dict index|
       
   122 
       
   123     index := 0. dict := Dictionary new.
       
   124     self allInstVarNames do:[:nm | index := index + 1. dict at:nm put:index].
       
   125     ^ dict
       
   126 
       
   127     "
       
   128      Point instanceVariableOffsets 
       
   129      GraphicsContext instanceVariableOffsets 
       
   130     "
       
   131 !
       
   132         
       
   133 allInstVarNames
    75 allInstVarNames
   134     "return a collection of all the instance variable name-strings
    76     "return a collection of all the instance variable name-strings
   135      this includes all superclass-instance variables.
    77      this includes all superclass-instance variables.
   136      Instvars of superclasses come first (i.e. the position matches
    78      Instvars of superclasses come first (i.e. the position matches
   137      the instVarAt:-index)."
    79      the instVarAt:-index)."
   142      Dictionary instVarNames       
    84      Dictionary instVarNames       
   143      Dictionary allInstVarNames    
    85      Dictionary allInstVarNames    
   144     "
    86     "
   145 !
    87 !
   146 
    88 
   147 instVarOffsetOf:aVariableName
       
   148     "return the index (as used in instVarAt:/instVarAt:put:) of a named instance
       
   149      variable. The returned number is 1..instSize for valid variable names, nil for
       
   150      illegal names."
       
   151 
       
   152     ^ self allInstVarNames indexOf:aVariableName ifAbsent:nil
       
   153 !
       
   154 
       
   155 instVarAtOffset:index
       
   156     "return the name of the instance variable at index"
       
   157 
       
   158     ^ self allInstanceVariableNames at:index
       
   159 !
       
   160 
       
   161 name
       
   162     "return the name of the class. In the current implementation,
       
   163      this returns a string, but will be changed to Symbol soon."
       
   164 
       
   165     ^ name
       
   166 !
       
   167 
       
   168 category
    89 category
   169     "return the category of the class. 
    90     "return the category of the class. 
   170      The returned value may be a string or symbol."
    91      The returned value may be a string or symbol."
   171 
    92 
   172     ^ category
    93     ^ category
   185     ] ifFalse:[
   106     ] ifFalse:[
   186 	category := aStringOrSymbol asSymbol
   107 	category := aStringOrSymbol asSymbol
   187     ]
   108     ]
   188 !
   109 !
   189 
   110 
       
   111 instVarAtOffset:index
       
   112     "return the name of the instance variable at index"
       
   113 
       
   114     ^ self allInstanceVariableNames at:index
       
   115 !
       
   116 
       
   117 instVarNames
       
   118     "return a collection of the instance variable name-strings"
       
   119 
       
   120     instvars isNil ifTrue:[
       
   121 	^ OrderedCollection new
       
   122     ].
       
   123     ^ instvars asCollectionOfWords
       
   124 
       
   125     "
       
   126      Point instVarNames  
       
   127     "
       
   128 !
       
   129 
       
   130 instVarOffsetOf:aVariableName
       
   131     "return the index (as used in instVarAt:/instVarAt:put:) of a named instance
       
   132      variable. The returned number is 1..instSize for valid variable names, nil for
       
   133      illegal names."
       
   134 
       
   135     ^ self allInstVarNames indexOf:aVariableName ifAbsent:nil
       
   136 !
       
   137 
       
   138 instanceVariableOffsets
       
   139     "returns a dictionary containing the instance variable index
       
   140      for each instVar name"
       
   141 
       
   142     |dict index|
       
   143 
       
   144     index := 0. dict := Dictionary new.
       
   145     self allInstVarNames do:[:nm | index := index + 1. dict at:nm put:index].
       
   146     ^ dict
       
   147 
       
   148     "
       
   149      Point instanceVariableOffsets 
       
   150      GraphicsContext instanceVariableOffsets 
       
   151     "
       
   152 !
       
   153 
       
   154 instanceVariableString
       
   155     "return a string of the instance variable names"
       
   156 
       
   157     instvars isNil ifTrue:[^ ''].
       
   158     ^ instvars
       
   159 
       
   160     "
       
   161      Point instanceVariableString   
       
   162     "
       
   163 !
       
   164 
       
   165 name
       
   166     "return the name of the class. In the current implementation,
       
   167      this returns a string, but will be changed to Symbol soon."
       
   168 
       
   169     ^ name
       
   170 !
       
   171 
   190 organization
   172 organization
   191     "for ST80 compatibility; 
   173     "for ST80 compatibility; 
   192      read the documentation in ClassOrganizer for more info."
   174      read the documentation in ClassOrganizer for more info."
   193 
   175 
   194     ^ ClassOrganizer for:self
   176     ^ ClassOrganizer for:self
   195 ! !
   177 ! !
   196 
   178 
       
   179 !ClassDescription methodsFor:'printing & storing'!
       
   180 
       
   181 displayString
       
   182     "return a string for display in inspectors"
       
   183 
       
   184     |nm more|
       
   185 
       
   186     category == #obsolete ifTrue:[
       
   187 	"add obsolete - to make life easier ..."
       
   188 	more := ' (obsolete)'
       
   189     ].
       
   190     category == #removed ifTrue:[
       
   191 	"add removed - to make life easier ..."
       
   192 	more := ' (removed)'
       
   193     ].
       
   194 
       
   195     nm := self name.
       
   196     more isNil ifTrue:[^ nm].
       
   197     ^ nm , more    
       
   198 ! !
       
   199 
       
   200 !ClassDescription methodsFor:'private'!
       
   201 
       
   202 addAllInstVarNamesTo:aCollection
       
   203     "helper for allInstVarNames - add the name-strings of the instance variables
       
   204      and of the inst-vars of all superclasses to the argument, aCollection. 
       
   205      Return aCollection."
       
   206 
       
   207     |superInsts|
       
   208 
       
   209     (superclass notNil) ifTrue:[
       
   210 	superclass addAllInstVarNamesTo:aCollection
       
   211     ].
       
   212     instvars notNil ifTrue:[
       
   213 	aCollection addAll:(instvars asCollectionOfWords).
       
   214     ] ifFalse:[
       
   215 	"/ mhmh - either someone klduged around, or this is
       
   216 	"/ a system running without sourceInfo. Generate
       
   217 	"/ synthetic names.
       
   218 
       
   219 	superclass isNil ifTrue:[
       
   220 	    superInsts := 0
       
   221 	] ifFalse:[
       
   222 	    superInsts := superclass instSize
       
   223 	].
       
   224 	aCollection addAll:((superInsts+1 to:self instSize) 
       
   225 				collect:[:index | '* instVar' , index printString , ' *'])
       
   226     ].
       
   227     ^ aCollection
       
   228 
       
   229     "Modified: 30.10.1995 / 19:46:21 / cg"
       
   230 ! !
       
   231 
       
   232 !ClassDescription methodsFor:'renaming'!
       
   233 
       
   234 renameTo:newName
       
   235     "change the name of the class"
       
   236 
       
   237     |oldSym|
       
   238 
       
   239     oldSym := name asSymbol.
       
   240     self setName:newName.
       
   241 
       
   242     Smalltalk at:oldSym put:nil.
       
   243     Smalltalk removeKey:oldSym.             "26.jun 93"
       
   244     Smalltalk at:(newName asSymbol) put:self.
       
   245 ! !
       
   246 
   197 !ClassDescription methodsFor:'signature checking'!
   247 !ClassDescription methodsFor:'signature checking'!
       
   248 
       
   249 classinstSizeFromSignature:aSignature
       
   250     "for checking class compatibility: return some number based on 
       
   251      the classinstSize from a signature key (not always the real classinstsize)."
       
   252 
       
   253     ^ (aSignature bitShift:-7) bitAnd:7
       
   254 !
       
   255 
       
   256 instNameKeyFromSignature:aSignature
       
   257     "for checking class compatibility: return a number based on the
       
   258      names and order of the instance variables from a signature key."
       
   259 
       
   260     ^ (aSignature bitShift:-14) bitAnd:16rFFFF
       
   261 
       
   262     "
       
   263      Point instNameKeyFromSignature:Point signature.             
       
   264      Association instNameKeyFromSignature:Association signature.  
       
   265     "
       
   266 !
       
   267 
       
   268 instSizeFromSignature:aSignature
       
   269     "for checking class compatibility: return the some number based on
       
   270      the instSize from a signature key (not always the real instSize)."
       
   271 
       
   272     ^ aSignature bitAnd:16r7F
       
   273 
       
   274     "
       
   275      Class instSizeFromSignature:Point signature.     
       
   276      Class instSizeFromSignature:Association signature.   
       
   277      Class instSizeFromSignature:Dictionary signature.    
       
   278     "
       
   279 !
       
   280 
       
   281 instTypeFromSignature:aSignature
       
   282     "for checking class compatibility: return some number based on
       
   283      the instType (i.e. variableBytes/Pointers etc.) from a signature key."
       
   284 
       
   285     ^ (aSignature bitShift:-10) bitAnd:(Class maskIndexType)
       
   286 
       
   287     "
       
   288      Class instTypeFromSignature:Object signature.               
       
   289      Class instTypeFromSignature:Array signature.                
       
   290      Class instTypeFromSignature:String signature.               
       
   291      Class instTypeFromSignature:OrderedCollection signature.    
       
   292     "
       
   293 !
   198 
   294 
   199 signature
   295 signature
   200     "return a signature number - this number is useful for a quick
   296     "return a signature number - this number is useful for a quick
   201      check for changed classes, and is done in the binary-object loader, 
   297      check for changed classes, and is done in the binary-object loader, 
   202      and the dynamic class loader.
   298      and the dynamic class loader.
   229     "
   325     "
   230      Array signature
   326      Array signature
   231      ByteArray signature
   327      ByteArray signature
   232      View signature
   328      View signature
   233     "
   329     "
   234 !
   330 ! !
   235 
   331 
   236 instSizeFromSignature:aSignature
   332 !ClassDescription methodsFor:'special accessing'!
   237     "for checking class compatibility: return the some number based on
   333 
   238      the instSize from a signature key (not always the real instSize)."
   334 setInstanceVariableString:aString
   239 
   335     "set the classes instvarnames string - no recompilation
   240     ^ aSignature bitAnd:16r7F
   336      or updates are done and no changeList records are written.
   241 
   337      This is NOT for general use."
   242     "
   338 
   243      Class instSizeFromSignature:Point signature.     
   339     instvars := aString.
   244      Class instSizeFromSignature:Association signature.   
   340 !
   245      Class instSizeFromSignature:Dictionary signature.    
   341 
   246     "
   342 setName:aString
   247 !
   343     "set the classes name - be careful, it will be still
   248 
   344      in the Smalltalk dictionary - under another key.
   249 classinstSizeFromSignature:aSignature
   345      This is NOT for general use - see renameTo:"
   250     "for checking class compatibility: return some number based on 
   346 
   251      the classinstSize from a signature key (not always the real classinstsize)."
   347     name := aString
   252 
   348 ! !
   253     ^ (aSignature bitShift:-7) bitAnd:7
   349 
   254 !
       
   255 
       
   256 instTypeFromSignature:aSignature
       
   257     "for checking class compatibility: return some number based on
       
   258      the instType (i.e. variableBytes/Pointers etc.) from a signature key."
       
   259 
       
   260     ^ (aSignature bitShift:-10) bitAnd:(Class maskIndexType)
       
   261 
       
   262     "
       
   263      Class instTypeFromSignature:Object signature.               
       
   264      Class instTypeFromSignature:Array signature.                
       
   265      Class instTypeFromSignature:String signature.               
       
   266      Class instTypeFromSignature:OrderedCollection signature.    
       
   267     "
       
   268 !
       
   269 
       
   270 instNameKeyFromSignature:aSignature
       
   271     "for checking class compatibility: return a number based on the
       
   272      names and order of the instance variables from a signature key."
       
   273 
       
   274     ^ (aSignature bitShift:-14) bitAnd:16rFFFF
       
   275 
       
   276     "
       
   277      Point instNameKeyFromSignature:Point signature.             
       
   278      Association instNameKeyFromSignature:Association signature.  
       
   279     "
       
   280 ! !
       
   281 
       
   282 !ClassDescription methodsFor:'renaming'!
       
   283 
       
   284 renameTo:newName
       
   285     "change the name of the class"
       
   286 
       
   287     |oldSym|
       
   288 
       
   289     oldSym := name asSymbol.
       
   290     self setName:newName.
       
   291 
       
   292     Smalltalk at:oldSym put:nil.
       
   293     Smalltalk removeKey:oldSym.             "26.jun 93"
       
   294     Smalltalk at:(newName asSymbol) put:self.
       
   295 ! !
       
   296 
       
   297 !ClassDescription methodsFor:'printing & storing'!
       
   298 
       
   299 displayString
       
   300     "return a string for display in inspectors"
       
   301 
       
   302     |nm more|
       
   303 
       
   304     category == #obsolete ifTrue:[
       
   305 	"add obsolete - to make life easier ..."
       
   306 	more := ' (obsolete)'
       
   307     ].
       
   308     category == #removed ifTrue:[
       
   309 	"add removed - to make life easier ..."
       
   310 	more := ' (removed)'
       
   311     ].
       
   312 
       
   313     nm := self name.
       
   314     more isNil ifTrue:[^ nm].
       
   315     ^ nm , more    
       
   316 ! !
       
   317 
       
   318 !ClassDescription methodsFor:'private'!
       
   319 
       
   320 addAllInstVarNamesTo:aCollection
       
   321     "helper for allInstVarNames - add the name-strings of the instance variables
       
   322      and of the inst-vars of all superclasses to the argument, aCollection. 
       
   323      Return aCollection."
       
   324 
       
   325     |superInsts|
       
   326 
       
   327     (superclass notNil) ifTrue:[
       
   328 	superclass addAllInstVarNamesTo:aCollection
       
   329     ].
       
   330     instvars notNil ifTrue:[
       
   331 	aCollection addAll:(instvars asCollectionOfWords).
       
   332     ] ifFalse:[
       
   333 	"/ mhmh - either someone klduged around, or this is
       
   334 	"/ a system running without sourceInfo. Generate
       
   335 	"/ synthetic names.
       
   336 
       
   337 	superclass isNil ifTrue:[
       
   338 	    superInsts := 0
       
   339 	] ifFalse:[
       
   340 	    superInsts := superclass instSize
       
   341 	].
       
   342 	aCollection addAll:((superInsts+1 to:self instSize) 
       
   343 				collect:[:index | '* instVar' , index printString , ' *'])
       
   344     ].
       
   345     ^ aCollection
       
   346 
       
   347     "Modified: 30.10.1995 / 19:46:21 / cg"
       
   348 ! !