SystemBrowser.st
changeset 6581 ae69dc905971
parent 6560 80370d5aa971
child 6640 326360e94271
equal deleted inserted replaced
6580:db726b209298 6581:ae69dc905971
  4241 !
  4241 !
  4242 
  4242 
  4243 searchBlockForCode:aCodeString isMethod:isMethod
  4243 searchBlockForCode:aCodeString isMethod:isMethod
  4244     "return a block to search for a pice of code (intelligent search)."
  4244     "return a block to search for a pice of code (intelligent search)."
  4245 
  4245 
  4246     |errAction searchTree searcher globalVariablesUsed sentMessages searchBlock foundMatch|
  4246     |errAction searchTree searcher globalVariablesUsed usedSymbols
       
  4247      sentMessages searchBlock foundMatch|
  4247 
  4248 
  4248 "/self halt.
  4249 "/self halt.
  4249 "/rule := ParseTreeLintRule 
  4250 "/rule := ParseTreeLintRule 
  4250 "/    createParseTreeRule: (Array with: aCodeString)
  4251 "/    createParseTreeRule: (Array with: aCodeString)
  4251 "/    method: isMethod
  4252 "/    method: isMethod
  4278 
  4279 
  4279     Error handle:[:ex |
  4280     Error handle:[:ex |
  4280     ] do:[
  4281     ] do:[
  4281         sentMessages := searchTree sentMessages.         
  4282         sentMessages := searchTree sentMessages.         
  4282     ].
  4283     ].
       
  4284 
  4283     globalVariablesUsed := searchTree referencedVariables 
  4285     globalVariablesUsed := searchTree referencedVariables 
  4284                     select:[:node | 
  4286                     select:[:node | 
  4285                                 node isPatternNode not
  4287                                 node isPatternNode not
  4286                                 and:[ Smalltalk includesKey: node name asSymbol ]
  4288                                 and:[ Smalltalk includesKey: node name asSymbol ]
  4287                            ]   
  4289                            ]   
  4288                     thenCollect:[:node | node name asSymbol]. 
  4290                     thenCollect:[:node | node name asSymbol]. 
       
  4291 
       
  4292     usedSymbols := searchTree usedSymbols.
  4289 
  4293 
  4290     searcher := ParseTreeSearcher new.
  4294     searcher := ParseTreeSearcher new.
  4291     isMethod ifTrue:[
  4295     isMethod ifTrue:[
  4292         searcher 
  4296         searcher 
  4293             matchesMethod:searchTree
  4297             matchesMethod:searchTree
  4296         searcher 
  4300         searcher 
  4297             matchesTree:searchTree
  4301             matchesTree:searchTree
  4298             do:[:aNode :answer | foundMatch := true].
  4302             do:[:aNode :answer | foundMatch := true].
  4299     ].
  4303     ].
  4300 
  4304 
  4301     sentMessages notEmptyOrNil ifTrue:[
  4305 
  4302         "/ can speedup the search, by filtering for sent messages first...
  4306     searchBlock := [:c :m :sel | 
  4303 
  4307                         |allSelectorsInLiteralArray allMessagesSent 
  4304         searchBlock := [:c :m :sel | 
  4308                          allGlobalsReferenced allUsedSymbolsInLiteralArray allSent src rslt parseTree|       
  4305                             |allSelectorsInLiteralArray allMessagesSent 
  4309 
  4306                              allGlobalsReferenced allSent src rslt parseTree|       
  4310                         foundMatch := false.
  4307 
  4311 
  4308                             foundMatch := false.
  4312                         m isLazyMethod ifTrue:[
  4309 
  4313                             src := m source.
  4310                             m isLazyMethod ifTrue:[
  4314                             src notNil ifTrue:[
  4311                                 src := m source.
  4315                                 m makeRealMethod.
  4312                                 src notNil ifTrue:[
       
  4313                                     m makeRealMethod.
       
  4314                                 ].
       
  4315                             ].
  4316                             ].
  4316                             allSelectorsInLiteralArray := m literals includesAll:sentMessages.
  4317                         ].
  4317                             allSelectorsInLiteralArray ifTrue:[
  4318                         "/ can speedup the search, by filtering for sent messages first...
  4318                                 allMessagesSent := m messages includesAll:sentMessages.
  4319                         allSelectorsInLiteralArray := sentMessages isEmptyOrNil or:[ m literals includesAll:sentMessages ].
       
  4320                         allSelectorsInLiteralArray ifTrue:[
       
  4321                             allUsedSymbolsInLiteralArray := usedSymbols isEmptyOrNil or:[ m literals includesAll:usedSymbols ].
       
  4322                             allUsedSymbolsInLiteralArray ifTrue:[
       
  4323                                 allMessagesSent := sentMessages isEmptyOrNil or:[ m messages includesAll:sentMessages ].
  4319                                 allMessagesSent ifTrue:[
  4324                                 allMessagesSent ifTrue:[
  4320                                     allGlobalsReferenced := globalVariablesUsed conform:[:varName | m referencesGlobal:varName].
  4325                                     allGlobalsReferenced := globalVariablesUsed conform:[:varName | m referencesGlobal:varName].
  4321                                     allGlobalsReferenced ifTrue:[
  4326                                     allGlobalsReferenced ifTrue:[
  4322                                         allSent := sentMessages conform:[:sel | (m sends:sel)].
  4327                                         allSent := sentMessages conform:[:sel | (m sends:sel)].
  4323                                         allSent ifTrue:[
  4328                                         allSent ifTrue:[
  4343                                                 ]
  4348                                                 ]
  4344                                             ]
  4349                                             ]
  4345                                         ]
  4350                                         ]
  4346                                     ]
  4351                                     ]
  4347                                 ]
  4352                                 ]
  4348                             ].
  4353                             ]
  4349                             foundMatch.
  4354                         ].
  4350                        ].
  4355                         foundMatch.
  4351     ] ifFalse:[
  4356                    ].
  4352         searchBlock := [:c :m :sel | 
       
  4353                             |src rslt parseTree|       
       
  4354 
       
  4355                             foundMatch := false.
       
  4356 
       
  4357                             src := m source.
       
  4358                             src isNil ifTrue:[
       
  4359                                 ('Browser [info]: no source for ' , m printString) infoPrintCR.
       
  4360                                 false
       
  4361                             ] ifFalse:[
       
  4362                                 parseTree := RBParser 
       
  4363                                                 parseSearchMethod:src 
       
  4364                                                 onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos. nil].
       
  4365 
       
  4366                                 parseTree isNil ifTrue:[
       
  4367                                     Transcript showCR:('ParseError in ' , m whoString , ' - please verify.').
       
  4368                                 ] ifFalse:[
       
  4369                                     false "isMethod" ifTrue:[
       
  4370                                         rslt := searcher executeMethod:parseTree.
       
  4371                                     ] ifFalse:[
       
  4372                                         rslt := searcher executeTree:parseTree.
       
  4373                                     ].
       
  4374                                 ].
       
  4375                             ].
       
  4376                             foundMatch.
       
  4377                        ].
       
  4378     ].
       
  4379     ^ searchBlock.
  4357     ^ searchBlock.
  4380 !
  4358 !
  4381 
  4359 
  4382 searchBlockForString:aString ignoreCase:ignoreCase match:doMatch
  4360 searchBlockForString:aString ignoreCase:ignoreCase match:doMatch
  4383     "return a block to search for a string."
  4361     "return a block to search for a string."
  5380 ! !
  5358 ! !
  5381 
  5359 
  5382 !SystemBrowser class methodsFor:'documentation'!
  5360 !SystemBrowser class methodsFor:'documentation'!
  5383 
  5361 
  5384 version
  5362 version
  5385     ^ '$Header: /cvs/stx/stx/libtool/SystemBrowser.st,v 1.226 2006-02-15 16:31:49 cg Exp $'
  5363     ^ '$Header: /cvs/stx/stx/libtool/SystemBrowser.st,v 1.227 2006-02-20 09:50:53 cg Exp $'
  5386 ! !
  5364 ! !
  5387 
  5365 
  5388 SystemBrowser initialize!
  5366 SystemBrowser initialize!