4148 ! |
4148 ! |
4149 |
4149 |
4150 searchBlockForCode:aCodeString isMethod:isMethod |
4150 searchBlockForCode:aCodeString isMethod:isMethod |
4151 "return a block to search for a pice of code (intelligent search)." |
4151 "return a block to search for a pice of code (intelligent search)." |
4152 |
4152 |
4153 |errAction searchTree searcher messages searchBlock foundMatch| |
4153 |errAction searchTree searcher variables messages searchBlock foundMatch| |
4154 |
4154 |
4155 errAction := [:str :pos | |
4155 errAction := [:str :pos | |
4156 Dialog warn:'Error during parse: ' , str , ' (position ' , pos printString , ')'. |
4156 Dialog warn:'Error during parse: ' , str , ' (position ' , pos printString , ')'. |
4157 ^ nil |
4157 ^ nil |
4158 ]. |
4158 ]. |
4168 ]. |
4168 ]. |
4169 |
4169 |
4170 searchTree isMessage ifTrue:[ |
4170 searchTree isMessage ifTrue:[ |
4171 messages := searchTree sentMessages |
4171 messages := searchTree sentMessages |
4172 ]. |
4172 ]. |
|
4173 variables := searchTree referencedVariables |
|
4174 select:[:node | |
|
4175 node isPatternNode not |
|
4176 and:[ Smalltalk includesKey: node name asSymbol ] |
|
4177 ] |
|
4178 thenCollect:[:node | node name asSymbol]. |
4173 |
4179 |
4174 searcher := ParseTreeSearcher new. |
4180 searcher := ParseTreeSearcher new. |
4175 searcher |
4181 searcher |
4176 matchesTree:searchTree |
4182 matchesTree:searchTree |
4177 do:[:aNode :answer | foundMatch := true]. |
4183 do:[:aNode :answer | foundMatch := true]. |
4178 |
4184 |
4179 messages size > 0 ifTrue:[ |
4185 messages size > 0 ifTrue:[ |
4180 "/ can speedup the search, by filtering for sent messages first... |
4186 "/ can speedup the search, by filtering for sent messages first... |
4181 |
4187 |
4182 searchBlock := [:c :m :sel | |
4188 searchBlock := [:c :m :sel | |
4183 |allSent src rslt parseTree| |
4189 |allGlobalsReferenced allSent src rslt parseTree| |
4184 |
4190 |
4185 m isLazyMethod ifTrue:[ |
4191 m isLazyMethod ifTrue:[ |
4186 src := m source. |
4192 src := m source. |
4187 src notNil ifTrue:[ |
4193 src notNil ifTrue:[ |
4188 m makeRealMethod. |
4194 m makeRealMethod. |
4189 ]. |
4195 ]. |
4190 ]. |
4196 ]. |
4191 allSent := (messages contains:[:sel | (m sends:sel) not]) not. |
4197 sel == #numArgs ifTrue:[self halt]. |
4192 allSent ifTrue:[ |
4198 allGlobalsReferenced := variables conform:[:varName | m referencesGlobal:varName]. |
4193 src := m source. |
4199 allGlobalsReferenced ifTrue:[ |
4194 src isNil ifTrue:[ |
4200 allSent := messages conform:[:sel | (m sends:sel)]. |
4195 ('Browser [info]: no source for ' , m printString) infoPrintCR. |
4201 allSent ifTrue:[ |
4196 false |
4202 src := m source. |
4197 ] ifFalse:[ |
4203 src isNil ifTrue:[ |
4198 parseTree := RBParser |
4204 ('Browser [info]: no source for ' , m printString) infoPrintCR. |
4199 parseSearchMethod:src |
4205 false |
4200 onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos. nil]. |
4206 ] ifFalse:[ |
4201 |
4207 parseTree := RBParser |
4202 foundMatch := false. |
4208 parseSearchMethod:src |
4203 rslt := searcher executeTree:parseTree. |
4209 onError: [:str :pos | Transcript showCR:str. Transcript showCR:pos. nil]. |
4204 foundMatch. |
4210 |
|
4211 foundMatch := false. |
|
4212 rslt := searcher executeTree:parseTree. |
|
4213 foundMatch. |
|
4214 ] |
4205 ] |
4215 ] |
4206 ] |
4216 ] |
4207 ]. |
4217 ]. |
4208 ] ifFalse:[ |
4218 ] ifFalse:[ |
4209 searchBlock := [:c :m :sel | |
4219 searchBlock := [:c :m :sel | |