Method.st
changeset 12854 3a3d3c02c3bd
parent 12695 14b7044c2e4a
child 12899 5c3e8ec6f8bb
equal deleted inserted replaced
12853:3d15dcbe0057 12854:3a3d3c02c3bd
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libbasic' }"
    12 "{ Package: 'stx:libbasic' }"
    13 
    13 
    14 CompiledCode variableSubclass:#Method
    14 CompiledCode variableSubclass:#Method
    15 	instanceVariableNames:'source sourcePosition category package mclass'
    15         instanceVariableNames:'source sourcePosition category package mclass'
    16 	classVariableNames:'PrivateMethodSignal LastFileReference LastSourceFileName
    16         classVariableNames:'PrivateMethodSignal LastFileReference LastSourceFileName
    17 		LastWhoClass LastFileLock LastMethodSources LastMethodSourcesLock
    17                 LastWhoClass LastFileLock LastMethodSources LastMethodSourcesLock
    18 		CompilationLock'
    18                 CompilationLock'
    19 	poolDictionaries:''
    19         poolDictionaries:''
    20 	category:'Kernel-Methods'
    20         category:'Kernel-Methods'
    21 !
    21 !
    22 
    22 
    23 Object subclass:#MethodWhoInfo
    23 Object subclass:#MethodWhoInfo
    24 	instanceVariableNames:'myClass mySelector'
    24         instanceVariableNames:'myClass mySelector'
    25 	classVariableNames:''
    25         classVariableNames:''
    26 	poolDictionaries:''
    26         poolDictionaries:''
    27 	privateIn:Method
    27         privateIn:Method
    28 !
    28 !
    29 
    29 
    30 !Method class methodsFor:'documentation'!
    30 !Method class methodsFor:'documentation'!
    31 
    31 
    32 copyright
    32 copyright
   114     which is compiled by the machines native C-compiler.
   114     which is compiled by the machines native C-compiler.
   115     As opposed to JITted code, this allows for embedded primitive C-code.
   115     As opposed to JITted code, this allows for embedded primitive C-code.
   116 "
   116 "
   117 !
   117 !
   118 
   118 
   119 privacy 
   119 privacy
   120 "
   120 "
   121     ST/X includes an EXPERIMENTAL implementation of method privacy.
   121     ST/X includes an EXPERIMENTAL implementation of method privacy.
   122     Individual methods may be set to private or protected via the
   122     Individual methods may be set to private or protected via the
   123     privacy:#private and privacy:#protected messages. Also, categories may be
   123     privacy:#private and privacy:#protected messages. Also, categories may be
   124     filedIn as a whole as private using #privateMethodsFor: or as
   124     filedIn as a whole as private using #privateMethodsFor: or as
   128     is equivalent to #methodsFor: (also to support fileIn of ENVY methods).
   128     is equivalent to #methodsFor: (also to support fileIn of ENVY methods).
   129 
   129 
   130     Protected methods may be executed only when called via a self-send
   130     Protected methods may be executed only when called via a self-send
   131     from the superclass-methods and self or super-sends from methods in the
   131     from the superclass-methods and self or super-sends from methods in the
   132     class itself or subclasses.
   132     class itself or subclasses.
   133     Private methods may not be called from subclasses-methods, 
   133     Private methods may not be called from subclasses-methods,
   134     i.e. they may only be called via self sends from within the current class.
   134     i.e. they may only be called via self sends from within the current class.
   135     (i.e. protected methods are less private than private ones)
   135     (i.e. protected methods are less private than private ones)
   136 
   136 
   137     When such a situation arises, the VM (runtime system) will raise the
   137     When such a situation arises, the VM (runtime system) will raise the
   138     PrivateMethodSignal exception (if nonNil), which usually brings you into the
   138     PrivateMethodSignal exception (if nonNil), which usually brings you into the
   141     If PrivateMethodSignal is nil, the VM will not check for this, and
   141     If PrivateMethodSignal is nil, the VM will not check for this, and
   142     execution is as usual. (you may want to nil-it for production code,
   142     execution is as usual. (you may want to nil-it for production code,
   143     and leave it non nil during development).
   143     and leave it non nil during development).
   144 
   144 
   145     NOTICE: there is no (not yet ?) standard defined for method privacy,
   145     NOTICE: there is no (not yet ?) standard defined for method privacy,
   146     however, the definition protocol was designed to be somewhat ENVY compatible 
   146     however, the definition protocol was designed to be somewhat ENVY compatible
   147     (from what can be deduced by reading PD code).
   147     (from what can be deduced by reading PD code).
   148 
   148 
   149     Also, the usability of privacy is still to be tested.
   149     Also, the usability of privacy is still to be tested.
   150     This interface, the implementation and the rules for when a privacy violation
   150     This interface, the implementation and the rules for when a privacy violation
   151     may change (in case of some ANSI standard being defined).
   151     may change (in case of some ANSI standard being defined).
   229     (nA := aSelector numArgs) == 1 ifTrue:[
   229     (nA := aSelector numArgs) == 1 ifTrue:[
   230         argNames := #('arg')
   230         argNames := #('arg')
   231     ] ifFalse:[
   231     ] ifFalse:[
   232         argNames := (1 to:nA) collect:[:i | 'arg' , i printString].
   232         argNames := (1 to:nA) collect:[:i | 'arg' , i printString].
   233     ].
   233     ].
   234     ^ self 
   234     ^ self
   235         methodDefinitionTemplateForSelector:aSelector 
   235         methodDefinitionTemplateForSelector:aSelector
   236         andArgumentNames:argNames.
   236         andArgumentNames:argNames.
   237 
   237 
   238     "
   238     "
   239      Method methodDefinitionTemplateForSelector:#foo           
   239      Method methodDefinitionTemplateForSelector:#foo
   240      Method methodDefinitionTemplateForSelector:#+             
   240      Method methodDefinitionTemplateForSelector:#+
   241      Method methodDefinitionTemplateForSelector:#foo:bar:baz:  
   241      Method methodDefinitionTemplateForSelector:#foo:bar:baz:
   242     "
   242     "
   243 !
   243 !
   244 
   244 
   245 methodDefinitionTemplateForSelector:aSelector andArgumentNames:argNames
   245 methodDefinitionTemplateForSelector:aSelector andArgumentNames:argNames
   246     "given a selector, return a prototype definition string"
   246     "given a selector, return a prototype definition string"
   247 
   247 
   248     aSelector numArgs > 0 ifTrue:[
   248     aSelector numArgs > 0 ifTrue:[
   249         aSelector isKeyword ifTrue:[
   249         aSelector isKeyword ifTrue:[
   250             ^ String streamContents:[:stream |
   250             ^ String streamContents:[:stream |
   251                 aSelector keywords with:argNames do:[:eachKeyword :eachArgName| 
   251                 aSelector keywords with:argNames do:[:eachKeyword :eachArgName|
   252                     stream nextPutAll:eachKeyword; nextPutAll:eachArgName; space.
   252                     stream nextPutAll:eachKeyword; nextPutAll:eachArgName; space.
   253                 ].
   253                 ].
   254                 stream backStep.   "remove the last space"
   254                 stream backStep.   "remove the last space"
   255              ].
   255              ].
   256         ].
   256         ].
   257         ^ aSelector , ' ' , (argNames at:1)
   257         ^ aSelector , ' ' , (argNames at:1)
   258     ].
   258     ].
   259     ^ aSelector
   259     ^ aSelector
   260 
   260 
   261     "
   261     "
   262      Method methodDefinitionTemplateForSelector:#foo          andArgumentNames:#()        
   262      Method methodDefinitionTemplateForSelector:#foo          andArgumentNames:#()
   263      Method methodDefinitionTemplateForSelector:#+            andArgumentNames:#('aNumber') 
   263      Method methodDefinitionTemplateForSelector:#+            andArgumentNames:#('aNumber')
   264      Method methodDefinitionTemplateForSelector:#foo:bar:baz: andArgumentNames:#('fooArg' 'barArg' 'bazArg') 
   264      Method methodDefinitionTemplateForSelector:#foo:bar:baz: andArgumentNames:#('fooArg' 'barArg' 'bazArg')
   265     "
   265     "
   266 !
   266 !
   267 
   267 
   268 methodPrivacySupported
   268 methodPrivacySupported
   269     "return true, if the system was compiled to support methodPrivacy.
   269     "return true, if the system was compiled to support methodPrivacy.
   302 !Method methodsFor:'Compatibility-VW'!
   302 !Method methodsFor:'Compatibility-VW'!
   303 
   303 
   304 classIsMeta
   304 classIsMeta
   305     "return true, if this method is a class method"
   305     "return true, if this method is a class method"
   306 
   306 
   307     ^ self mclass isMeta 
   307     ^ self mclass isMeta
   308 !
   308 !
   309 
   309 
   310 sendsSelector:aSelectorSymbol
   310 sendsSelector:aSelectorSymbol
   311     "return true, if this method contains a message-send
   311     "return true, if this method contains a message-send
   312      with aSelectorSymbol as selector."
   312      with aSelectorSymbol as selector."
   336             cls := self mclass.
   336             cls := self mclass.
   337             cls notNil ifTrue:[
   337             cls notNil ifTrue:[
   338                 cls addChangeRecordForMethodCategory:self category:newCategory.
   338                 cls addChangeRecordForMethodCategory:self category:newCategory.
   339                 self changed:#category with:oldCategory.            "/ will vanish
   339                 self changed:#category with:oldCategory.            "/ will vanish
   340                 cls changed:#organization with:self selector.       "/ will vanish
   340                 cls changed:#organization with:self selector.       "/ will vanish
   341                 Smalltalk changed:#methodCategory with:(Array with:cls with:self with:oldCategory). 
   341                 Smalltalk changed:#methodCategory with:(Array with:cls with:self with:oldCategory).
   342             ]
   342             ]
   343         ]
   343         ]
   344     ]
   344     ]
   345 
   345 
   346     "Modified: / 25-09-2007 / 16:15:24 / cg"
   346     "Modified: / 25-09-2007 / 16:15:24 / cg"
   347 !
   347 !
   348 
   348 
   349 comment
   349 comment
   350     "return the methods comment.
   350     "return the methods comment.
   351      This is done by searching for and returning the first comment
   351      This is done by searching for and returning the first comment
   352      from the methods source (excluding any double-quotes). 
   352      from the methods source (excluding any double-quotes).
   353      Returns nil if there is no comment (or source is not available)."
   353      Returns nil if there is no comment (or source is not available)."
   354 
   354 
   355     |src comment comments parser|
   355     |src comment comments parser|
   356 
   356 
   357     src := self source.
   357     src := self source.
   373         ].
   373         ].
   374     ].
   374     ].
   375     ^ comment.
   375     ^ comment.
   376 
   376 
   377     "
   377     "
   378      (Method compiledMethodAt:#comment) comment  
   378      (Method compiledMethodAt:#comment) comment
   379      (Object class compiledMethodAt:#infoPrinting:) comment  
   379      (Object class compiledMethodAt:#infoPrinting:) comment
   380     "
   380     "
   381 
   381 
   382     "Modified: / 17.2.1998 / 14:50:00 / cg"
   382     "Modified: / 17.2.1998 / 14:50:00 / cg"
   383     "Modified: / 23.2.1998 / 10:26:08 / stefan"
   383     "Modified: / 23.2.1998 / 10:26:08 / stefan"
   384 !
   384 !
   404 
   404 
   405     ^ sourcePosition
   405     ^ sourcePosition
   406 !
   406 !
   407 
   407 
   408 localSourceFilename:aFileName position:aNumber
   408 localSourceFilename:aFileName position:aNumber
   409     "set the methods sourcefile/position indicating, that 
   409     "set the methods sourcefile/position indicating, that
   410      this is a local file."
   410      this is a local file."
   411 
   411 
   412     source := aFileName.
   412     source := aFileName.
   413     sourcePosition := aNumber negated
   413     sourcePosition := aNumber negated
   414 
   414 
   432     ].
   432     ].
   433 !
   433 !
   434 
   434 
   435 mclass:aClass
   435 mclass:aClass
   436     "set the method's class"
   436     "set the method's class"
   437      
   437 
   438     mclass == aClass ifTrue:[ ^ self ].
   438     mclass == aClass ifTrue:[ ^ self ].
   439 
   439 
   440 "/     (mclass notNil and:[aClass notNil]) ifTrue:[
   440 "/     (mclass notNil and:[aClass notNil]) ifTrue:[
   441 "/         'Method [warning]: mclass already set' errorPrintCR.
   441 "/         'Method [warning]: mclass already set' errorPrintCR.
   442 "/     ].
   442 "/     ].
   485         cls := self mclass.
   485         cls := self mclass.
   486 
   486 
   487         self changed:#package.                                              "/ will vanish
   487         self changed:#package.                                              "/ will vanish
   488         cls changed:#methodPackage with:self selector.                      "/ will vanish
   488         cls changed:#methodPackage with:self selector.                      "/ will vanish
   489 
   489 
   490         Smalltalk changed:#projectOrganization with:(Array with:cls with:self with:oldPackage). 
   490         Smalltalk changed:#projectOrganization with:(Array with:cls with:self with:oldPackage).
   491         cls addChangeRecordForMethodPackage:self package:newPackage.
   491         cls addChangeRecordForMethodPackage:self package:newPackage.
   492     ]
   492     ]
   493 
   493 
   494     "Modified: / 23-11-2006 / 17:01:02 / cg"
   494     "Modified: / 23-11-2006 / 17:01:02 / cg"
   495 !
   495 !
   531         chunk notNil ifTrue:[
   531         chunk notNil ifTrue:[
   532             ^ chunk
   532             ^ chunk
   533         ].
   533         ].
   534 
   534 
   535         LastFileLock critical:[
   535         LastFileLock critical:[
   536             "have to protect sourceStream from being closed as a side effect 
   536             "have to protect sourceStream from being closed as a side effect
   537              of some other process fetching some the source from a different source file"
   537              of some other process fetching some the source from a different source file"
   538 
   538 
   539             sourceStream := self sourceStreamUsingCache:true.
   539             sourceStream := self sourceStreamUsingCache:true.
   540             sourceStream notNil ifTrue:[
   540             sourceStream notNil ifTrue:[
   541                 [
   541                 [
   639     "return true, if this is an ignored method.
   639     "return true, if this is an ignored method.
   640      Ignored methods are physically present in the source file,
   640      Ignored methods are physically present in the source file,
   641      but no code is generated for it by stc, and the VM does not see
   641      but no code is generated for it by stc, and the VM does not see
   642      it in its message lookup.
   642      it in its message lookup.
   643      (i.e. setting a method to #ignored, and sending that selector,
   643      (i.e. setting a method to #ignored, and sending that selector,
   644       leads to either the superclasses implementation to be called, 
   644       leads to either the superclasses implementation to be called,
   645       or a doesNotUnderstand exception to be raised)
   645       or a doesNotUnderstand exception to be raised)
   646 
   646 
   647      Notice: this is a nonstandard feature, not supported
   647      Notice: this is a nonstandard feature, not supported
   648      by other smalltalk implementations and not specified in the ANSI spec.
   648      by other smalltalk implementations and not specified in the ANSI spec.
   649 
   649 
   706 !
   706 !
   707 
   707 
   708 isRestricted
   708 isRestricted
   709     "return the flag bit stating that this method is restricted.
   709     "return the flag bit stating that this method is restricted.
   710      Execution of the receiver will only be allowed if the system is not in
   710      Execution of the receiver will only be allowed if the system is not in
   711      'trap restricted mode' (-->ObjectMemory) otherise a runtime 
   711      'trap restricted mode' (-->ObjectMemory) otherise a runtime
   712      error (PrivateMethodSignal) is raised.
   712      error (PrivateMethodSignal) is raised.
   713 
   713 
   714      Notice: method restriction is a nonstandard feature, not supported
   714      Notice: method restriction is a nonstandard feature, not supported
   715      by other smalltalk implementations and not specified in the ANSI spec.
   715      by other smalltalk implementations and not specified in the ANSI spec.
   716 
   716 
   732 !Method privateMethodsFor:'accessing-visibility'!
   732 !Method privateMethodsFor:'accessing-visibility'!
   733 
   733 
   734 primSetPrivacy:aSymbol
   734 primSetPrivacy:aSymbol
   735     "set the methods access rights (privacy) from a symbol;
   735     "set the methods access rights (privacy) from a symbol;
   736      Currently, this must be one of #private, #protected, #public or #ignored.
   736      Currently, this must be one of #private, #protected, #public or #ignored.
   737      #setPrivacy: simply sets the attribute. When changing methods, that 
   737      #setPrivacy: simply sets the attribute. When changing methods, that
   738      have already been called, #privacy: should be used.
   738      have already been called, #privacy: should be used.
   739 
   739 
   740      Notice: method privacy is a nonstandard feature, not supported
   740      Notice: method privacy is a nonstandard feature, not supported
   741      by other smalltalk implementations and not specified in the ANSI spec.
   741      by other smalltalk implementations and not specified in the ANSI spec.
   742      If at all, use it for debugging purposes, to catch messagesends
   742      If at all, use it for debugging purposes, to catch messagesends
   760         p = F_CLASSPRIVATE;
   760         p = F_CLASSPRIVATE;
   761     else if (aSymbol == @symbol(ignored))
   761     else if (aSymbol == @symbol(ignored))
   762         p = F_IGNORED;
   762         p = F_IGNORED;
   763     else
   763     else
   764         RETURN(false);  /* illegal symbol */
   764         RETURN(false);  /* illegal symbol */
   765         
   765 
   766 
   766 
   767     f = (f & ~M_PRIVACY) | p;
   767     f = (f & ~M_PRIVACY) | p;
   768     __INST(flags) = __mkSmallInteger(f);
   768     __INST(flags) = __mkSmallInteger(f);
   769 #endif
   769 #endif
   770 
   770 
   844 
   844 
   845         self changed:#privacy.                                       "/ will vanish
   845         self changed:#privacy.                                       "/ will vanish
   846         myClass notNil ifTrue:[
   846         myClass notNil ifTrue:[
   847             mySelector notNil ifTrue:[
   847             mySelector notNil ifTrue:[
   848                 myClass changed:#methodPrivacy with:mySelector.      "/ will vanish
   848                 myClass changed:#methodPrivacy with:mySelector.      "/ will vanish
   849                 Smalltalk changed:#privacyOfMethod with:(Array with:myClass with:self with:oldPrivacy). 
   849                 Smalltalk changed:#privacyOfMethod with:(Array with:myClass with:self with:oldPrivacy).
   850                 myClass addChangeRecordForMethodPrivacy:self.
   850                 myClass addChangeRecordForMethodPrivacy:self.
   851             ]
   851             ]
   852         ]
   852         ]
   853     ]
   853     ]
   854 
   854 
   855     "Modified: / 23-11-2006 / 17:03:20 / cg"
   855     "Modified: / 23-11-2006 / 17:03:20 / cg"
   856 !
   856 !
   857 
   857 
   858 restricted:aBoolean
   858 restricted:aBoolean
   859     "set or clear the flag bit stating that this method is restricted. 
   859     "set or clear the flag bit stating that this method is restricted.
   860      Execution of the receiver will only be allowed if the system is not in
   860      Execution of the receiver will only be allowed if the system is not in
   861      'trap restricted mode' (-->ObjectMemory) otherise a runtime
   861      'trap restricted mode' (-->ObjectMemory) otherise a runtime
   862      error (PrivateMethodSignal) is raised.
   862      error (PrivateMethodSignal) is raised.
   863 
   863 
   864      Notice: method restriction is a nonstandard feature, not supported
   864      Notice: method restriction is a nonstandard feature, not supported
   873 #ifdef F_RESTRICTED
   873 #ifdef F_RESTRICTED
   874     INT f = __intVal(__INST(flags));
   874     INT f = __intVal(__INST(flags));
   875     INT old;
   875     INT old;
   876 
   876 
   877     old = f;
   877     old = f;
   878     if (aBoolean == true) 
   878     if (aBoolean == true)
   879         f |= F_RESTRICTED;
   879         f |= F_RESTRICTED;
   880     else
   880     else
   881         f &= ~F_RESTRICTED;
   881         f &= ~F_RESTRICTED;
   882     __INST(flags) = __mkSmallInteger(f);
   882     __INST(flags) = __mkSmallInteger(f);
   883     if (old & F_RESTRICTED)
   883     if (old & F_RESTRICTED)
   894 !
   894 !
   895 
   895 
   896 setPrivacy:aSymbol
   896 setPrivacy:aSymbol
   897     "set the methods access rights (privacy) from a symbol;
   897     "set the methods access rights (privacy) from a symbol;
   898      Currently, this must be one of #private, #protected, #public or #ignored.
   898      Currently, this must be one of #private, #protected, #public or #ignored.
   899      #setPrivacy: simply sets the attribute. When changing methods, that 
   899      #setPrivacy: simply sets the attribute. When changing methods, that
   900      have already been called, #privacy: should be used.
   900      have already been called, #privacy: should be used.
   901 
   901 
   902      Notice: method privacy is a nonstandard feature, not supported
   902      Notice: method privacy is a nonstandard feature, not supported
   903      by other smalltalk implementations and not specified in the ANSI spec.
   903      by other smalltalk implementations and not specified in the ANSI spec.
   904      If at all, use it for debugging purposes, to catch messagesends
   904      If at all, use it for debugging purposes, to catch messagesends
   912 !
   912 !
   913 
   913 
   914 setPrivacy:aSymbol flushCaches:doFlush
   914 setPrivacy:aSymbol flushCaches:doFlush
   915     "set the methods access rights (privacy) from a symbol;
   915     "set the methods access rights (privacy) from a symbol;
   916      Currently, this must be one of #private, #protected, #public or #ignored.
   916      Currently, this must be one of #private, #protected, #public or #ignored.
   917      #setPrivacy: simply sets the attribute. When changing methods, that 
   917      #setPrivacy: simply sets the attribute. When changing methods, that
   918      have already been called, #privacy: should be used.
   918      have already been called, #privacy: should be used.
   919 
   919 
   920      Notice: method privacy is a nonstandard feature, not supported
   920      Notice: method privacy is a nonstandard feature, not supported
   921      by other smalltalk implementations and not specified in the ANSI spec.
   921      by other smalltalk implementations and not specified in the ANSI spec.
   922      If at all, use it for debugging purposes, to catch messagesends
   922      If at all, use it for debugging purposes, to catch messagesends
   954      the same semantics as the receiver, but uses interpreted bytecodes.
   954      the same semantics as the receiver, but uses interpreted bytecodes.
   955      Otherwise, return the receiver. The new method is not installed in
   955      Otherwise, return the receiver. The new method is not installed in
   956      the methodDictionary of any class - just returned.
   956      the methodDictionary of any class - just returned.
   957      If the method contains primitive code, this may return a method
   957      If the method contains primitive code, this may return a method
   958      without bytecode.
   958      without bytecode.
   959      Can be used to obtain a bytecode version of a machine-code method, 
   959      Can be used to obtain a bytecode version of a machine-code method,
   960      for binary storage or dynamic recompilation (which is not yet finished)
   960      for binary storage or dynamic recompilation (which is not yet finished)
   961      or to compile lazy methods down to executable ones."
   961      or to compile lazy methods down to executable ones."
   962 
   962 
   963     |mthd|
   963     |mthd|
   964 
   964 
   981 !
   981 !
   982 
   982 
   983 asByteCodeMethodWithSource:newSource
   983 asByteCodeMethodWithSource:newSource
   984     |mthd|
   984     |mthd|
   985 
   985 
   986     ParserFlags 
   986     ParserFlags
   987         withSTCCompilation:#never
   987         withSTCCompilation:#never
   988         do:[
   988         do:[
   989             mthd := self asExecutableMethodWithSource:newSource.
   989             mthd := self asExecutableMethodWithSource:newSource.
   990         ].
   990         ].
   991     ^ mthd
   991     ^ mthd
   993     "Created: 24.10.1995 / 14:02:32 / cg"
   993     "Created: 24.10.1995 / 14:02:32 / cg"
   994     "Modified: 5.1.1997 / 01:01:53 / cg"
   994     "Modified: 5.1.1997 / 01:01:53 / cg"
   995 !
   995 !
   996 
   996 
   997 asExecutableMethod
   997 asExecutableMethod
   998     "if the receiver has neither bytecodes nor machinecode, create & return a 
   998     "if the receiver has neither bytecodes nor machinecode, create & return a
   999      method having semantics as the receivers source. This may be machine code,
   999      method having semantics as the receivers source. This may be machine code,
  1000      if the system supports dynamic loading of object code and the source includes
  1000      if the system supports dynamic loading of object code and the source includes
  1001      primitive code. However, bytecode is preferred, since it compiles faster.
  1001      primitive code. However, bytecode is preferred, since it compiles faster.
  1002      Otherwise, return the receiver. The new method is not installed in
  1002      Otherwise, return the receiver. The new method is not installed in
  1003      the methodDictionary of any class - just returned.
  1003      the methodDictionary of any class - just returned.
  1025         ^ nil.
  1025         ^ nil.
  1026     ].
  1026     ].
  1027     "/
  1027     "/
  1028     "/ try to save a bit of memory, by sharing the source (whatever it is)
  1028     "/ try to save a bit of memory, by sharing the source (whatever it is)
  1029     "/
  1029     "/
  1030     temporaryMethod sourceFilename:source position:sourcePosition. 
  1030     temporaryMethod sourceFilename:source position:sourcePosition.
  1031     ^ temporaryMethod
  1031     ^ temporaryMethod
  1032 !
  1032 !
  1033 
  1033 
  1034 asExecutableMethodWithSource:newSource
  1034 asExecutableMethodWithSource:newSource
  1035     |temporaryMethod cls|
  1035     |temporaryMethod cls|
  1047      (happened when autoloading animation demos)
  1047      (happened when autoloading animation demos)
  1048     "
  1048     "
  1049     CompilationLock critical:[
  1049     CompilationLock critical:[
  1050         "
  1050         "
  1051          dont want this to go into the changes file,
  1051          dont want this to go into the changes file,
  1052          dont want output on Transcript and definitely 
  1052          dont want output on Transcript and definitely
  1053          dont want a lazy method ...
  1053          dont want a lazy method ...
  1054         "
  1054         "
  1055         Class withoutUpdatingChangesDo:[
  1055         Class withoutUpdatingChangesDo:[
  1056             |silent lazy|
  1056             |silent lazy|
  1057 
  1057 
  1077                                              inCategory:(self category)
  1077                                              inCategory:(self category)
  1078                                              notifying:nil
  1078                                              notifying:nil
  1079                                              install:false.
  1079                                              install:false.
  1080                     ] ifFalse:[
  1080                     ] ifFalse:[
  1081                         temporaryMethod := compiler new
  1081                         temporaryMethod := compiler new
  1082                                              compile:newSource 
  1082                                              compile:newSource
  1083                                              in:cls 
  1083                                              in:cls
  1084                                              notifying:nil 
  1084                                              notifying:nil
  1085                                              ifFail:nil
  1085                                              ifFail:nil
  1086                     ].
  1086                     ].
  1087                 ].
  1087                 ].
  1088             ] ensure:[
  1088             ] ensure:[
  1089                 Compiler compileLazy:lazy.
  1089                 Compiler compileLazy:lazy.
  1096         ^ nil.
  1096         ^ nil.
  1097     ].
  1097     ].
  1098     "/
  1098     "/
  1099     "/ try to save a bit of memory, by sharing the source (whatever it is)
  1099     "/ try to save a bit of memory, by sharing the source (whatever it is)
  1100     "/
  1100     "/
  1101     temporaryMethod source:newSource. 
  1101     temporaryMethod source:newSource.
  1102     "/
  1102     "/
  1103     "/ dont forget the methods class & package ...
  1103     "/ dont forget the methods class & package ...
  1104     "/
  1104     "/
  1105     temporaryMethod setPackage:package.
  1105     temporaryMethod setPackage:package.
  1106     temporaryMethod mclass:mclass.
  1106     temporaryMethod mclass:mclass.
  1137      this method if - after a class change - a method cannot be compiled
  1137      this method if - after a class change - a method cannot be compiled
  1138      and is therefore no longer executable (for example, after an instvar
  1138      and is therefore no longer executable (for example, after an instvar
  1139      has been removed, and a method still tries to access this instvar)
  1139      has been removed, and a method still tries to access this instvar)
  1140 
  1140 
  1141      Thus, we arrive here, when playing around in a classes methodArray,
  1141      Thus, we arrive here, when playing around in a classes methodArray,
  1142      or compiler/runtime system is broken :-(, 
  1142      or compiler/runtime system is broken :-(,
  1143      or you ignore the error messages during some recompile."
  1143      or you ignore the error messages during some recompile."
  1144 
  1144 
  1145 %{
  1145 %{
  1146     /*
  1146     /*
  1147      * for reasons too far from being explained here,
  1147      * for reasons too far from being explained here,
  1458     "{ Pragma: +optSpace }"
  1458     "{ Pragma: +optSpace }"
  1459 
  1459 
  1460     "this error is triggered, if a private or protected method is called.
  1460     "this error is triggered, if a private or protected method is called.
  1461 
  1461 
  1462      If you continue in the debugger, the method will be called,
  1462      If you continue in the debugger, the method will be called,
  1463      and further privacy exceptions will NOT be reported at this call location, 
  1463      and further privacy exceptions will NOT be reported at this call location,
  1464      until any new method is compiled, or the privacy of any method changes,
  1464      until any new method is compiled, or the privacy of any method changes,
  1465      or the caches are flushed.
  1465      or the caches are flushed.
  1466      (the reason is that after the continue, the method is enterred into the
  1466      (the reason is that after the continue, the method is enterred into the
  1467       calling cache, for which method privacy is not checked.
  1467       calling cache, for which method privacy is not checked.
  1468       Any of the above actions flushes this cache and a privacy check
  1468       Any of the above actions flushes this cache and a privacy check
  1588         ^ who methodClass name , ' >> ' , (who methodSelector storeString)
  1588         ^ who methodClass name , ' >> ' , (who methodSelector storeString)
  1589     ].
  1589     ].
  1590     ^ 'unboundMethod'
  1590     ^ 'unboundMethod'
  1591 
  1591 
  1592     "
  1592     "
  1593      Method new whoString   
  1593      Method new whoString
  1594      (Method compiledMethodAt:#whoString) whoString
  1594      (Method compiledMethodAt:#whoString) whoString
  1595     "
  1595     "
  1596 
  1596 
  1597     "Modified: 1.11.1996 / 16:27:04 / cg"
  1597     "Modified: 1.11.1996 / 16:27:04 / cg"
  1598 ! !
  1598 ! !
  1669     usingCacheBoolean ifTrue:[
  1669     usingCacheBoolean ifTrue:[
  1670         (package notNil and:[package ~= PackageId noProjectID]) ifTrue:[
  1670         (package notNil and:[package ~= PackageId noProjectID]) ifTrue:[
  1671             "/ keep the last source file open, because open/close
  1671             "/ keep the last source file open, because open/close
  1672             "/ operations maybe slow on NFS-mounted file systems.
  1672             "/ operations maybe slow on NFS-mounted file systems.
  1673             "/ Since the reference to the file is weak, it will be closed
  1673             "/ Since the reference to the file is weak, it will be closed
  1674             "/ automatically if the file is not referenced for a while. 
  1674             "/ automatically if the file is not referenced for a while.
  1675             "/ Neat trick.
  1675             "/ Neat trick.
  1676 
  1676 
  1677             LastFileLock critical:[
  1677             LastFileLock critical:[
  1678                 aStream := LastFileReference at:1.
  1678                 aStream := LastFileReference at:1.
  1679                 (aStream isNil or:[aStream == 0 or:[aStream isOpen not]]) ifTrue:[
  1679                 (aStream isNil or:[aStream == 0 or:[aStream isOpen not]]) ifTrue:[
  1690             ].
  1690             ].
  1691         ].
  1691         ].
  1692     ].
  1692     ].
  1693 
  1693 
  1694     "/ a negative sourcePosition indicates
  1694     "/ a negative sourcePosition indicates
  1695     "/ that this is a local file 
  1695     "/ that this is a local file
  1696     "/ (not to be requested via the sourceCodeManager)
  1696     "/ (not to be requested via the sourceCodeManager)
  1697     "/ This kludge was added, to allow sourceCode to be
  1697     "/ This kludge was added, to allow sourceCode to be
  1698     "/ saved to a local source file (i.e. 'st.src')
  1698     "/ saved to a local source file (i.e. 'st.src')
  1699     "/ and having a clue for which file is meant later.
  1699     "/ and having a clue for which file is meant later.
  1700 
  1700 
  1767             ^ aStream
  1767             ^ aStream
  1768         ].
  1768         ].
  1769     ].
  1769     ].
  1770 
  1770 
  1771     "/
  1771     "/
  1772     "/ nope - look in standard places 
  1772     "/ nope - look in standard places
  1773     "/ (if there is a source-code manager - otherwise, we already did that)
  1773     "/ (if there is a source-code manager - otherwise, we already did that)
  1774     "/
  1774     "/
  1775     (mgr notNil and:[Class tryLocalSourceFirst not]) ifTrue:[
  1775     (mgr notNil and:[Class tryLocalSourceFirst not]) ifTrue:[
  1776         aStream := self localSourceStream.
  1776         aStream := self localSourceStream.
  1777         aStream notNil ifTrue:[
  1777         aStream notNil ifTrue:[
  1814                     ].
  1814                     ].
  1815                     ^ aStream
  1815                     ^ aStream
  1816                 ].
  1816                 ].
  1817             ]
  1817             ]
  1818         ]
  1818         ]
  1819     ].                
  1819     ].
  1820 
  1820 
  1821     ^ nil
  1821     ^ nil
  1822 
  1822 
  1823     "Modified: / 26-11-2006 / 22:33:38 / cg"
  1823     "Modified: / 26-11-2006 / 22:33:38 / cg"
  1824 !
  1824 !
  1915     |src parser|
  1915     |src parser|
  1916 
  1916 
  1917     src := self source.
  1917     src := self source.
  1918     src notNil ifTrue:[
  1918     src notNil ifTrue:[
  1919         parser := Parser
  1919         parser := Parser
  1920                         parseMethod:src 
  1920                         parseMethod:src
  1921                         in:self containingClass 
  1921                         in:self containingClass
  1922                         ignoreErrors:true 
  1922                         ignoreErrors:true
  1923                         ignoreWarnings:true.
  1923                         ignoreWarnings:true.
  1924 
  1924 
  1925         (parser notNil and:[parser ~~ #Error]) ifTrue:[
  1925         (parser notNil and:[parser ~~ #Error]) ifTrue:[
  1926             ^ parser usedInstVars
  1926             ^ parser usedInstVars
  1927         ].
  1927         ].
  1930 
  1930 
  1931     "Modified: 19.6.1997 / 17:54:09 / cg"
  1931     "Modified: 19.6.1997 / 17:54:09 / cg"
  1932 !
  1932 !
  1933 
  1933 
  1934 containingClass
  1934 containingClass
  1935     "return the class I am defined in. 
  1935     "return the class I am defined in.
  1936      See comment in who."
  1936      See comment in who."
  1937 
  1937 
  1938     "based on who, which has been added for ST-80 compatibility"
  1938     "based on who, which has been added for ST-80 compatibility"
  1939 
  1939 
  1940     |who|
  1940     |who|
  1953      none found - sorry
  1953      none found - sorry
  1954     "
  1954     "
  1955     ^ nil
  1955     ^ nil
  1956 
  1956 
  1957     "
  1957     "
  1958      (Object compiledMethodAt:#at:) containingClass   
  1958      (Object compiledMethodAt:#at:) containingClass
  1959 
  1959 
  1960      (Object class compiledMethodAt:#version) containingClass   
  1960      (Object class compiledMethodAt:#version) containingClass
  1961     "
  1961     "
  1962 !
  1962 !
  1963 
  1963 
  1964 externalLibraryFunction
  1964 externalLibraryFunction
  1965     "if this is an externalLibraryFunction call, return the externalLibraryFunction.
  1965     "if this is an externalLibraryFunction call, return the externalLibraryFunction.
  2009     "/ ok; it may or may not ...
  2009     "/ ok; it may or may not ...
  2010 
  2010 
  2011     ^ self parse:#'parseMethodSilent:' return:#hasPrimitiveCode or:false
  2011     ^ self parse:#'parseMethodSilent:' return:#hasPrimitiveCode or:false
  2012 
  2012 
  2013     "
  2013     "
  2014      (Method compiledMethodAt:#hasPrimitiveCode) hasPrimitiveCode 
  2014      (Method compiledMethodAt:#hasPrimitiveCode) hasPrimitiveCode
  2015      (Object compiledMethodAt:#at:) hasPrimitiveCode   
  2015      (Object compiledMethodAt:#at:) hasPrimitiveCode
  2016      (Object compiledMethodAt:#basicAt:) hasPrimitiveCode 
  2016      (Object compiledMethodAt:#basicAt:) hasPrimitiveCode
  2017     "
  2017     "
  2018 
  2018 
  2019     "Modified: 22.1.1997 / 00:03:45 / cg"
  2019     "Modified: 22.1.1997 / 00:03:45 / cg"
  2020 !
  2020 !
  2021 
  2021 
  2063     funcOrNil := self externalLibraryFunction.
  2063     funcOrNil := self externalLibraryFunction.
  2064     (funcOrNil isNil or:[funcOrNil isCallTypeOLE not]) ifTrue:[^ nil].
  2064     (funcOrNil isNil or:[funcOrNil isCallTypeOLE not]) ifTrue:[^ nil].
  2065     ^ funcOrNil vtableIndex
  2065     ^ funcOrNil vtableIndex
  2066 
  2066 
  2067     "
  2067     "
  2068      (Method compiledMethodAt:#hasPrimitiveCode) isOLECall  
  2068      (Method compiledMethodAt:#hasPrimitiveCode) isOLECall
  2069      (Method compiledMethodAt:#hasPrimitiveCode) indexOfOLECall 
  2069      (Method compiledMethodAt:#hasPrimitiveCode) indexOfOLECall
  2070 
  2070 
  2071      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) isOLECall    
  2071      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) isOLECall
  2072      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) indexOfOLECall    
  2072      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) indexOfOLECall
  2073      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) isExternalLibraryFunctionCall    
  2073      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) isExternalLibraryFunctionCall
  2074      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) externalLibraryFunctionCall    
  2074      (Win32OperatingSystem class compiledMethodAt:#primClosePrinter:) externalLibraryFunctionCall
  2075 
  2075 
  2076      (IUnknownPointer compiledMethodAt:#invokeAddRef) isExternalLibraryFunctionCall    
  2076      (IUnknownPointer compiledMethodAt:#invokeAddRef) isExternalLibraryFunctionCall
  2077      (IUnknownPointer compiledMethodAt:#invokeAddRef) externalLibraryFunction    
  2077      (IUnknownPointer compiledMethodAt:#invokeAddRef) externalLibraryFunction
  2078      (IUnknownPointer compiledMethodAt:#invokeAddRef) isOLECall    
  2078      (IUnknownPointer compiledMethodAt:#invokeAddRef) isOLECall
  2079      (IUnknownPointer compiledMethodAt:#invokeAddRef) indexOfOLECall    
  2079      (IUnknownPointer compiledMethodAt:#invokeAddRef) indexOfOLECall
  2080     "
  2080     "
  2081 !
  2081 !
  2082 
  2082 
  2083 isDocumentationMethod
  2083 isDocumentationMethod
  2084     "Return true, if this is a documentation only (only a comment) method
  2084     "Return true, if this is a documentation only (only a comment) method
  2162 
  2162 
  2163     ^ self mclass isMeta
  2163     ^ self mclass isMeta
  2164     and:[(AbstractSourceCodeManager isVersionMethodSelector:self selector)]
  2164     and:[(AbstractSourceCodeManager isVersionMethodSelector:self selector)]
  2165 
  2165 
  2166     "
  2166     "
  2167      (Method class compiledMethodAt:#version) isVersionMethod  
  2167      (Method class compiledMethodAt:#version) isVersionMethod
  2168      (Method class compiledMethodAt:#documentation) isVersionMethod
  2168      (Method class compiledMethodAt:#documentation) isVersionMethod
  2169     "
  2169     "
  2170 !
  2170 !
  2171 
  2171 
  2172 isVisualWorksTypedef
  2172 isVisualWorksTypedef
  2201 messagesSent
  2201 messagesSent
  2202     "return a collection with the message selectors sent to by the receiver.
  2202     "return a collection with the message selectors sent to by the receiver.
  2203      Uses Parser to parse methods source and extract the names.
  2203      Uses Parser to parse methods source and extract the names.
  2204      The returned collection includes all used message selectors (i.e. including super-send messages)"
  2204      The returned collection includes all used message selectors (i.e. including super-send messages)"
  2205 
  2205 
  2206     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#messagesSent or:#() 
  2206     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#messagesSent or:#()
  2207 
  2207 
  2208     "
  2208     "
  2209      (Method compiledMethodAt:#printOn:) messagesSent 
  2209      (Method compiledMethodAt:#printOn:) messagesSent
  2210      (Point compiledMethodAt:#x:) messagesSent 
  2210      (Point compiledMethodAt:#x:) messagesSent
  2211     "
  2211     "
  2212 !
  2212 !
  2213 
  2213 
  2214 messagesSentToSelf
  2214 messagesSentToSelf
  2215     "return a collection with the message selectors sent to self by the receiver.
  2215     "return a collection with the message selectors sent to self by the receiver.
  2216      Uses Parser to parse methods source and extract the names."
  2216      Uses Parser to parse methods source and extract the names."
  2217 
  2217 
  2218     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#messagesSentToSelf or:#() 
  2218     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#messagesSentToSelf or:#()
  2219 
  2219 
  2220 !
  2220 !
  2221 
  2221 
  2222 messagesSentToSuper
  2222 messagesSentToSuper
  2223     "return a collection with the message selectors sent to super by the receiver.
  2223     "return a collection with the message selectors sent to super by the receiver.
  2224      Uses Parser to parse methods source and extract the names."
  2224      Uses Parser to parse methods source and extract the names."
  2225 
  2225 
  2226     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#messagesSentToSuper or:#() 
  2226     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#messagesSentToSuper or:#()
  2227 
  2227 
  2228 !
  2228 !
  2229 
  2229 
  2230 methodArgAndVarNames
  2230 methodArgAndVarNames
  2231     "return a collection with the methods argument and variable names.
  2231     "return a collection with the methods argument and variable names.
  2312 !
  2312 !
  2313 
  2313 
  2314 methodDefinitionTemplate
  2314 methodDefinitionTemplate
  2315     "return the string that defines the method and the arguments"
  2315     "return the string that defines the method and the arguments"
  2316 
  2316 
  2317     ^ Method 
  2317     ^ Method
  2318         methodDefinitionTemplateForSelector:self selector 
  2318         methodDefinitionTemplateForSelector:self selector
  2319         andArgumentNames:self methodArgNames
  2319         andArgumentNames:self methodArgNames
  2320 
  2320 
  2321     "
  2321     "
  2322       (self compiledMethodAt:#printOn:) methodDefinitionTemplate
  2322       (self compiledMethodAt:#printOn:) methodDefinitionTemplate
  2323     "
  2323     "
  2336     "Modified: 31.10.1995 / 14:36:49 / cg"
  2336     "Modified: 31.10.1995 / 14:36:49 / cg"
  2337 !
  2337 !
  2338 
  2338 
  2339 modificationTime
  2339 modificationTime
  2340     "try to extract the modificationTime as a timeStamp from
  2340     "try to extract the modificationTime as a timeStamp from
  2341      the receivers source. If there is no source or no history line, 
  2341      the receivers source. If there is no source or no history line,
  2342      we do not know the modification time, and nil is returned."
  2342      we do not know the modification time, and nil is returned."
  2343 
  2343 
  2344     |s list histLine|
  2344     |s list histLine|
  2345 
  2345 
  2346     HistoryManager isNil ifTrue:[^ nil].
  2346     HistoryManager isNil ifTrue:[^ nil].
  2348     s := self source.
  2348     s := self source.
  2349     s isNil ifTrue:[^ nil].
  2349     s isNil ifTrue:[^ nil].
  2350     list := HistoryManager getAllHistoriesFrom:s.
  2350     list := HistoryManager getAllHistoriesFrom:s.
  2351     list size == 0 ifTrue:[^ nil].
  2351     list size == 0 ifTrue:[^ nil].
  2352     histLine := list last.
  2352     histLine := list last.
  2353     ^ Timestamp 
  2353     ^ Timestamp
  2354         fromDate:histLine date 
  2354         fromDate:histLine date
  2355         andTime:histLine time
  2355         andTime:histLine time
  2356 
  2356 
  2357     "
  2357     "
  2358      (Method compiledMethodAt:#modificationTime) modificationTime
  2358      (Method compiledMethodAt:#modificationTime) modificationTime
  2359      (Method compiledMethodAt:#isMethod) modificationTime 
  2359      (Method compiledMethodAt:#isMethod) modificationTime
  2360     "
  2360     "
  2361 
  2361 
  2362     "Modified: 8.9.1995 / 15:08:22 / claus"
  2362     "Modified: 8.9.1995 / 15:08:22 / claus"
  2363     "Modified: 4.11.1996 / 22:28:17 / cg"
  2363     "Modified: 4.11.1996 / 22:28:17 / cg"
  2364 !
  2364 !
  2369     ^ self selector
  2369     ^ self selector
  2370 
  2370 
  2371     "Created: / 9.11.1998 / 06:15:08 / cg"
  2371     "Created: / 9.11.1998 / 06:15:08 / cg"
  2372 !
  2372 !
  2373 
  2373 
  2374 parse:parseSelector return:accessSelector or:valueIfNoSource 
  2374 parse:parseSelector return:accessSelector or:valueIfNoSource
  2375     "helper for methodArgNames, methodVarNames etc.
  2375     "helper for methodArgNames, methodVarNames etc.
  2376      Get the source, let parser parse it using parseSelector,
  2376      Get the source, let parser parse it using parseSelector,
  2377      return parser-info using accessSelector"
  2377      return parser-info using accessSelector"
  2378 
  2378 
  2379     ^ self parse:parseSelector with:nil return:accessSelector or:valueIfNoSource
  2379     ^ self parse:parseSelector with:nil return:accessSelector or:valueIfNoSource
  2380 
  2380 
  2381     "
  2381     "
  2382      (Method compiledMethodAt:#parse:return:or:)
  2382      (Method compiledMethodAt:#parse:return:or:)
  2383         parse:#'parseMethodSilent:' return:#sentMessages or:#() 
  2383         parse:#'parseMethodSilent:' return:#sentMessages or:#()
  2384     "
  2384     "
  2385 !
  2385 !
  2386 
  2386 
  2387 parse:parseSelector with:arg2 return:accessSelector or:valueIfNoSource 
  2387 parse:parseSelector with:arg2 return:accessSelector or:valueIfNoSource
  2388     "helper for methodArgNames, methodVarNames etc.
  2388     "helper for methodArgNames, methodVarNames etc.
  2389      Get the source, let parser parse it using parseSelector,
  2389      Get the source, let parser parse it using parseSelector,
  2390      return parser-info using accessSelector"
  2390      return parser-info using accessSelector"
  2391 
  2391 
  2392     |parser parserClass sourceString|
  2392     |parser parserClass sourceString|
  2404     ].
  2404     ].
  2405     ^ valueIfNoSource
  2405     ^ valueIfNoSource
  2406 
  2406 
  2407     "
  2407     "
  2408      (Method compiledMethodAt:#parse:return:or:)
  2408      (Method compiledMethodAt:#parse:return:or:)
  2409         parse:#'parseMethodSilent:' return:#sentMessages or:#() 
  2409         parse:#'parseMethodSilent:' return:#sentMessages or:#()
  2410     "
  2410     "
  2411 !
  2411 !
  2412 
  2412 
  2413 parseResources
  2413 parseResources
  2414     "return the methods resource spec; either nil or a collection of symbols."
  2414     "return the methods resource spec; either nil or a collection of symbols."
  2423     (src findString:'resource:') == 0 ifTrue:[
  2423     (src findString:'resource:') == 0 ifTrue:[
  2424         ^ nil "/ actually: error
  2424         ^ nil "/ actually: error
  2425     ].
  2425     ].
  2426     "/ no need to parse all - only interested in resource-info
  2426     "/ no need to parse all - only interested in resource-info
  2427     self parserClass isNil ifTrue:[
  2427     self parserClass isNil ifTrue:[
  2428         ^ nil 
  2428         ^ nil
  2429     ].
  2429     ].
  2430     parser := self parserClass parseMethodArgAndVarSpecificationSilent:src in:nil.
  2430     parser := self parserClass parseMethodArgAndVarSpecificationSilent:src in:nil.
  2431     parser isNil ifTrue:[
  2431     parser isNil ifTrue:[
  2432         ^ nil "/ actually error
  2432         ^ nil "/ actually error
  2433     ].
  2433     ].
  2443     sel isNil ifTrue:[ ^ nil ].
  2443     sel isNil ifTrue:[ ^ nil ].
  2444 
  2444 
  2445     cls := self mclass.
  2445     cls := self mclass.
  2446     cls isNil ifTrue:[ ^ nil ].
  2446     cls isNil ifTrue:[ ^ nil ].
  2447 
  2447 
  2448     ChangeSet current reverseDo:[:change | 
  2448     ChangeSet current reverseDo:[:change |
  2449         (change isMethodChange 
  2449         (change isMethodChange
  2450         and:[ (change selector == sel)
  2450         and:[ (change selector == sel)
  2451         and:[ change changeClass == cls ]]) 
  2451         and:[ change changeClass == cls ]])
  2452         ifTrue:[
  2452         ifTrue:[
  2453             previous := change previousVersion.
  2453             previous := change previousVersion.
  2454             previous notNil ifTrue:[
  2454             previous notNil ifTrue:[
  2455                 ^ previous
  2455                 ^ previous
  2456             ]
  2456             ]
  2468 "/                                        new := entry third.
  2468 "/                                        new := entry third.
  2469 "/                                        new == self
  2469 "/                                        new == self
  2470 "/                                    ] ifFalse:[
  2470 "/                                    ] ifFalse:[
  2471 "/                                        false
  2471 "/                                        false
  2472 "/                                    ]
  2472 "/                                    ]
  2473 "/                             ] 
  2473 "/                             ]
  2474 "/                     ifNone:nil.
  2474 "/                     ifNone:nil.
  2475 "/    entry isNil ifTrue:[^nil].
  2475 "/    entry isNil ifTrue:[^nil].
  2476 "/    ^ entry second.
  2476 "/    ^ entry second.
  2477 "/    ^ history at:self ifAbsent:nil
  2477 "/    ^ history at:self ifAbsent:nil
  2478 
  2478 
  2501     cls := self mclass.
  2501     cls := self mclass.
  2502     cls isNil ifTrue:[^ #()].
  2502     cls isNil ifTrue:[^ #()].
  2503 
  2503 
  2504     versions := OrderedCollection new.
  2504     versions := OrderedCollection new.
  2505 
  2505 
  2506     ChangeSet current reverseDo:[:change | 
  2506     ChangeSet current reverseDo:[:change |
  2507          (change isMethodChange 
  2507          (change isMethodChange
  2508         and:[ (change selector == sel)
  2508         and:[ (change selector == sel)
  2509         and:[ change changeClass == cls ]]) 
  2509         and:[ change changeClass == cls ]])
  2510         ifTrue:[
  2510         ifTrue:[
  2511             versions addFirst:change.
  2511             versions addFirst:change.
  2512             lastChange := change.    
  2512             lastChange := change.
  2513         ]
  2513         ]
  2514     ].
  2514     ].
  2515 
  2515 
  2516     lastChange notNil ifTrue:[
  2516     lastChange notNil ifTrue:[
  2517         last := lastChange previousVersion.
  2517         last := lastChange previousVersion.
  2518         last notNil ifTrue:[
  2518         last notNil ifTrue:[
  2519             firstSrc := last source.
  2519             firstSrc := last source.
  2520             (firstSrc size > 0
  2520             (firstSrc size > 0
  2521             and:[ firstSrc ~= lastChange source]) ifTrue:[
  2521             and:[ firstSrc ~= lastChange source]) ifTrue:[
  2522                 versions addFirst:(MethodChange 
  2522                 versions addFirst:(MethodChange
  2523                                     className:lastChange className 
  2523                                     className:lastChange className
  2524                                     selector:lastChange selector
  2524                                     selector:lastChange selector
  2525                                     source:firstSrc
  2525                                     source:firstSrc
  2526                                     category:lastChange category).
  2526                                     category:lastChange category).
  2527             ]
  2527             ]
  2528         ]
  2528         ]
  2541     ^ readInstVars includes:varName.
  2541     ^ readInstVars includes:varName.
  2542 !
  2542 !
  2543 
  2543 
  2544 resourceType
  2544 resourceType
  2545     "ST-80 compatibility:
  2545     "ST-80 compatibility:
  2546      return the methods first resource specs key. 
  2546      return the methods first resource specs key.
  2547      Returns either nil, or a single symbol."
  2547      Returns either nil, or a single symbol."
  2548 
  2548 
  2549     |resources|
  2549     |resources|
  2550 
  2550 
  2551     (resources := self resources) notNil ifTrue:[
  2551     (resources := self resources) notNil ifTrue:[
  2563     ^ self parseResources.
  2563     ^ self parseResources.
  2564 !
  2564 !
  2565 
  2565 
  2566 selector
  2566 selector
  2567     "return the selector under which I am found in my containingClasses
  2567     "return the selector under which I am found in my containingClasses
  2568      method-table. 
  2568      method-table.
  2569      See comment in who."
  2569      See comment in who."
  2570 
  2570 
  2571     "based on who, which has been added for ST-80 compatibility"
  2571     "based on who, which has been added for ST-80 compatibility"
  2572 
  2572 
  2573     |who|
  2573     |who|
  2629 
  2629 
  2630 usedGlobals
  2630 usedGlobals
  2631     "return a collection with the global names referred to by the receiver.
  2631     "return a collection with the global names referred to by the receiver.
  2632      Uses Parser to parse methods source and extract them."
  2632      Uses Parser to parse methods source and extract them."
  2633 
  2633 
  2634     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#usedGlobals or:#() 
  2634     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#usedGlobals or:#()
  2635 
  2635 
  2636     "
  2636     "
  2637      (Method compiledMethodAt:#resources) usedGlobals 
  2637      (Method compiledMethodAt:#resources) usedGlobals
  2638     "
  2638     "
  2639 !
  2639 !
  2640 
  2640 
  2641 usedSymbols
  2641 usedSymbols
  2642     "return a collection with the symbols referred to by the receiver.
  2642     "return a collection with the symbols referred to by the receiver.
  2643      Uses Parser to parse methods source and extract them.
  2643      Uses Parser to parse methods source and extract them.
  2644      This collection only includes implicit symbols references 
  2644      This collection only includes implicit symbols references
  2645      (i.e. not messages sent)"
  2645      (i.e. not messages sent)"
  2646 
  2646 
  2647     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#usedSymbols or:#() 
  2647     ^ self parse:#'parseMethodSilent:in:' with:self mclass return:#usedSymbols or:#()
  2648 
  2648 
  2649     "
  2649     "
  2650      (Method compiledMethodAt:#usedSymbols) usedSymbols 
  2650      (Method compiledMethodAt:#usedSymbols) usedSymbols
  2651      (Method compiledMethodAt:#usedSymbols) messagesSent 
  2651      (Method compiledMethodAt:#usedSymbols) messagesSent
  2652     "
  2652     "
  2653 !
  2653 !
  2654 
  2654 
  2655 who
  2655 who
  2656     "return the class and selector of where I am defined in;
  2656     "return the class and selector of where I am defined in;
  2657      nil is returned for unbound methods.
  2657      nil is returned for unbound methods.
  2658 
  2658 
  2659      ST/X special notice: 
  2659      ST/X special notice:
  2660         returns an instance of MethodWhoInfo, which
  2660         returns an instance of MethodWhoInfo, which
  2661         responds to #methodClass and #methodSelector query messages.
  2661         responds to #methodClass and #methodSelector query messages.
  2662         For backward- (& ST-80) compatibility, the returned object also
  2662         For backward- (& ST-80) compatibility, the returned object also
  2663         responds to #at:1 and #at:2 messages.
  2663         responds to #at:1 and #at:2 messages.
  2664 
  2664 
  2665      Implementation notice:
  2665      Implementation notice:
  2666         Since there is no information of the containing class 
  2666         Since there is no information of the containing class
  2667         in the method, we have to do a search here.
  2667         in the method, we have to do a search here.
  2668 
  2668 
  2669         Normally, this is not a problem, except when a method is
  2669         Normally, this is not a problem, except when a method is
  2670         accepted in the debugger or redefined from within a method
  2670         accepted in the debugger or redefined from within a method
  2671         (maybe done indirectly, if #doIt is done recursively)
  2671         (maybe done indirectly, if #doIt is done recursively)
  2672         - the information about which class the original method was 
  2672         - the information about which class the original method was
  2673         defined in is lost in this case.
  2673         defined in is lost in this case.
  2674 
  2674 
  2675      Problem: 
  2675      Problem:
  2676         this is heavily called for in the debugger to create
  2676         this is heavily called for in the debugger to create
  2677         a readable context walkback. For unbound methods, it is
  2677         a readable context walkback. For unbound methods, it is
  2678         slow, since the search (over all classes) will always fail.
  2678         slow, since the search (over all classes) will always fail.
  2679 
  2679 
  2680      Q: should we add a backref from the method to the class 
  2680      Q: should we add a backref from the method to the class
  2681         and/or add a subclass of Method for unbound ones ?
  2681         and/or add a subclass of Method for unbound ones ?
  2682      Q2: if so, what about the bad guy then, who copies methods around to
  2682      Q2: if so, what about the bad guy then, who copies methods around to
  2683          other classes ?"
  2683          other classes ?"
  2684 
  2684 
  2685     |classes cls sel fn clsName checkBlock|
  2685     |classes cls sel fn clsName checkBlock|
  2735             checkBlock value:cls theMetaclass.
  2735             checkBlock value:cls theMetaclass.
  2736         ]
  2736         ]
  2737     ].
  2737     ].
  2738 
  2738 
  2739     "
  2739     "
  2740      first, limit the search to global classes only - 
  2740      first, limit the search to global classes only -
  2741      since probability is high, that the receiver is found in there ...
  2741      since probability is high, that the receiver is found in there ...
  2742     "
  2742     "
  2743     classes := Smalltalk allClasses.
  2743     classes := Smalltalk allClasses.
  2744     "
  2744     "
  2745      instance methods are usually more common - search those first
  2745      instance methods are usually more common - search those first
  2773 
  2773 
  2774     "untypical situation: an anonymous class"
  2774     "untypical situation: an anonymous class"
  2775     "
  2775     "
  2776      |m cls|
  2776      |m cls|
  2777 
  2777 
  2778      Object 
  2778      Object
  2779         subclass:#FunnyClass 
  2779         subclass:#FunnyClass
  2780         instanceVariableNames:'foo'
  2780         instanceVariableNames:'foo'
  2781         classVariableNames:''
  2781         classVariableNames:''
  2782         poolDictionaries:''
  2782         poolDictionaries:''
  2783         category:'testing'.
  2783         category:'testing'.
  2784      cls := Smalltalk at:#FunnyClass.
  2784      cls := Smalltalk at:#FunnyClass.
  2992 ! !
  2992 ! !
  2993 
  2993 
  2994 !Method class methodsFor:'documentation'!
  2994 !Method class methodsFor:'documentation'!
  2995 
  2995 
  2996 version
  2996 version
  2997     ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.346 2010-02-04 17:34:50 stefan Exp $'
  2997     ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.347 2010-04-07 17:36:33 cg Exp $'
  2998 !
  2998 !
  2999 
  2999 
  3000 version_CVS
  3000 version_CVS
  3001     ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.346 2010-02-04 17:34:50 stefan Exp $'
  3001     ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.347 2010-04-07 17:36:33 cg Exp $'
  3002 ! !
  3002 ! !
  3003 
  3003 
  3004 Method initialize!
  3004 Method initialize!