SystemBrowser.st
changeset 2642 cab6366238a4
parent 2631 bd18074649ed
child 2655 9e90bbd1eb18
equal deleted inserted replaced
2641:cfd94f3cc611 2642:cab6366238a4
  1186 
  1186 
  1187 browseImplementorsOf:aSelectorString in:aCollectionOfClasses ignoreCase:ignoreCase title:title
  1187 browseImplementorsOf:aSelectorString in:aCollectionOfClasses ignoreCase:ignoreCase title:title
  1188     "launch a browser for all implementors of aSelector in
  1188     "launch a browser for all implementors of aSelector in
  1189      the classes contained in aCollectionOfClasses and its metaclasses"
  1189      the classes contained in aCollectionOfClasses and its metaclasses"
  1190 
  1190 
       
  1191     |list|
       
  1192 
       
  1193     list := self 
       
  1194                 findImplementorsOf:aSelectorString 
       
  1195                 in:aCollectionOfClasses 
       
  1196                 ignoreCase:ignoreCase.
       
  1197 
       
  1198     list size == 0 ifTrue:[
       
  1199         self showNoneFound:title.
       
  1200         ^ nil
       
  1201     ].
       
  1202 
       
  1203     ^ self browseMethods:list asOrderedCollection title:title
       
  1204 
       
  1205     "
       
  1206      SystemBrowser browseImplementorsOf:#+
       
  1207                                      in:(Array with:Number
       
  1208                                                with:Float
       
  1209                                                with:SmallInteger)
       
  1210                                   title:'some implementors of +'
       
  1211     "
       
  1212 
       
  1213     "Modified: / 4.9.1995 / 17:33:39 / claus"
       
  1214     "Modified: / 19.6.1996 / 14:19:02 / stefan"
       
  1215     "Modified: / 16.10.1998 / 13:16:29 / cg"
       
  1216 !
       
  1217 
       
  1218 browseImplementorsOf:aSelectorString in:aCollectionOfClasses title:title
       
  1219     "launch a browser for all implementors of aSelector in
       
  1220      the classes contained in aCollectionOfClasses and its metaclasses"
       
  1221 
       
  1222     ^ self
       
  1223         browseImplementorsOf:aSelectorString 
       
  1224         in:aCollectionOfClasses 
       
  1225         ignoreCase:false
       
  1226         title:title
       
  1227 
       
  1228 !
       
  1229 
       
  1230 browseImplementorsOf:aSelectorString under:aClass
       
  1231     "launch a browser for all implementors of aSelector in aClass
       
  1232      and its subclasses"
       
  1233 
       
  1234     ^ self 
       
  1235         browseImplementorsOf:aSelectorString
       
  1236         in:(aClass withAllSubclasses)
       
  1237         title:(self classResources 
       
  1238                 string:'implementors of: %1 (in and below %2)' 
       
  1239                 with:aSelectorString
       
  1240                 with:aClass name)
       
  1241 
       
  1242     "
       
  1243      SystemBrowser browseImplementorsOf:#+ under:Integer
       
  1244     "
       
  1245 
       
  1246     "Created: 9.12.1995 / 18:06:09 / cg"
       
  1247     "Modified: 9.12.1995 / 18:11:38 / cg"
       
  1248 !
       
  1249 
       
  1250 browseInstRefsTo:aString in:aCollectionOfClasses modificationsOnly:modsOnly
       
  1251     "launch a browser for all methods in aClass where the instVar named
       
  1252      aString is referenced; if modsOnly is true, browse only methods where the
       
  1253      instvar is modified"
       
  1254 
       
  1255     ^ self browseRefsTo:aString classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly
       
  1256 !
       
  1257 
       
  1258 browseInstRefsTo:varName in:aCollectionOfClasses modificationsOnly:modsOnly title:title
       
  1259     "launch a browser for all methods in aClass where the instVar named
       
  1260      varName is referenced; if modsOnly is true, browse only methods where the
       
  1261      instvar is modified"
       
  1262 
       
  1263     ^ self browseRefsTo:varName classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly title:title
       
  1264 !
       
  1265 
       
  1266 browseInstRefsTo:aString under:aClass modificationsOnly:modsOnly
       
  1267     "launch a browser for all methods in aClass and subclasses
       
  1268      where the instVar named aString is referenced; 
       
  1269      if modsOnly is true, browse only methods where the instvar is modified"
       
  1270 
       
  1271     ^ self browseInstRefsTo:aString in:(aClass withAllSubclasses) modificationsOnly:modsOnly
       
  1272 !
       
  1273 
       
  1274 browseReferendsOf:aGlobalName
       
  1275     "launch a browser for all methods referencing a global
       
  1276      named aGlobalName. The argument may be a symbol, a string or
       
  1277      a matchPattern.
       
  1278     "
       
  1279 
       
  1280     ^ self browseReferendsOf:aGlobalName warnIfNone:true 
       
  1281 
       
  1282    "
       
  1283     Browser browseReferendsOf:#Transcript
       
  1284     Browser browseReferendsOf:'Tr*'
       
  1285    "
       
  1286 
       
  1287     "Modified: / 30.10.1997 / 23:45:52 / cg"
       
  1288 !
       
  1289 
       
  1290 browseReferendsOf:aGlobalName ifNone:actionIfNone
       
  1291     "launch a browser for all methods referencing a global
       
  1292      named aGlobalName.
       
  1293     "
       
  1294 
       
  1295     ^ self
       
  1296         browseReferendsOf:aGlobalName 
       
  1297         title:(self classResources string:'users of: %1' with:aGlobalName)
       
  1298         ifNone:actionIfNone
       
  1299 
       
  1300     "Modified: / 31.10.1997 / 15:42:05 / cg"
       
  1301 
       
  1302 
       
  1303 !
       
  1304 
       
  1305 browseReferendsOf:aGlobalName in:aSetOfClasses
       
  1306     "launch a browser for all methods referencing a global
       
  1307      named aGlobalName.
       
  1308     "
       
  1309 
       
  1310     ^ self browseReferendsOf:aGlobalName in:aSetOfClasses warnIfNone:true 
       
  1311 
       
  1312    "
       
  1313     Browser browseReferendsOf:#Transcript
       
  1314    "
       
  1315 
       
  1316     "Created: 10.7.1996 / 10:37:30 / cg"
       
  1317 !
       
  1318 
       
  1319 browseReferendsOf:aGlobalName in:aSetOfClasses warnIfNone:doWarn
       
  1320     "launch a browser for all methods referencing a global
       
  1321      named aGlobalName.
       
  1322     "
       
  1323 
       
  1324     |globalsPlainName idx|
       
  1325 
       
  1326     globalsPlainName := aGlobalName.
       
  1327     (idx := globalsPlainName lastIndexOf:$:) ~~ 0 ifTrue:[
       
  1328         globalsPlainName := globalsPlainName copyFrom:idx+1
       
  1329     ].
       
  1330 
       
  1331     ^ self browseForSymbol:aGlobalName
       
  1332                         in:aSetOfClasses
       
  1333                      title:(self classResources string:'users of: %1' with:aGlobalName) 
       
  1334                 warnIfNone:doWarn
       
  1335                  searchFor:globalsPlainName
       
  1336 
       
  1337     "Created: 10.7.1996 / 10:37:02 / cg"
       
  1338     "Modified: 31.10.1996 / 14:56:38 / cg"
       
  1339 !
       
  1340 
       
  1341 browseReferendsOf:aGlobalName title:title ifNone:actionIfNone
       
  1342     "launch a browser for all methods referencing a global
       
  1343      named aGlobalName.
       
  1344     "
       
  1345 
       
  1346     |globalsPlainName idx|
       
  1347 
       
  1348     globalsPlainName := aGlobalName.
       
  1349     (idx := globalsPlainName lastIndexOf:$:) ~~ 0 ifTrue:[
       
  1350         globalsPlainName := globalsPlainName copyFrom:idx+1.
       
  1351         (globalsPlainName size == 0
       
  1352         or:[globalsPlainName = '*']) ifTrue:[
       
  1353             globalsPlainName := aGlobalName
       
  1354         ]
       
  1355     ].
       
  1356 
       
  1357     ^ self browseForSymbol:aGlobalName 
       
  1358                      title:title 
       
  1359                     ifNone:actionIfNone
       
  1360                  searchFor:globalsPlainName
       
  1361 
       
  1362     "Modified: / 31.10.1996 / 14:47:48 / cg"
       
  1363     "Created: / 31.10.1997 / 15:41:28 / cg"
       
  1364 
       
  1365 
       
  1366 !
       
  1367 
       
  1368 browseReferendsOf:aGlobalName title:title warnIfNone:doWarn
       
  1369     "launch a browser for all methods referencing a global
       
  1370      named aGlobalName.
       
  1371     "
       
  1372 
       
  1373     |b|
       
  1374 
       
  1375     doWarn ifTrue: [
       
  1376 	b := [self showNoneFound:title]
       
  1377     ].
       
  1378 
       
  1379     ^ self
       
  1380         browseReferendsOf:aGlobalName 
       
  1381         title:title 
       
  1382         ifNone:b
       
  1383 
       
  1384 !
       
  1385 
       
  1386 browseReferendsOf:aGlobalName warnIfNone:doWarn
       
  1387     "launch a browser for all methods referencing a global
       
  1388      named aGlobalName.
       
  1389     "
       
  1390 
       
  1391     ^ self
       
  1392         browseReferendsOf:aGlobalName 
       
  1393         title:(self classResources string:'users of: %1' with:aGlobalName)
       
  1394         warnIfNone:doWarn
       
  1395 
       
  1396     "Modified: / 31.10.1997 / 15:42:05 / cg"
       
  1397 !
       
  1398 
       
  1399 browseRefsTo:aString classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly
       
  1400     "launch a browser for all methods in aClass where the instVar/classVar named
       
  1401      aString is referenced; if modsOnly is true, browse only methods where the
       
  1402      instvar is modified"
       
  1403 
       
  1404     |title|
       
  1405 
       
  1406     modsOnly ifTrue:[
       
  1407         title := 'modifications of: %1'
       
  1408     ] ifFalse:[
       
  1409         title := 'references to: %1 '
       
  1410     ].
       
  1411     ^ self 
       
  1412         browseRefsTo:aString 
       
  1413         classVars:classVars 
       
  1414         in:aCollectionOfClasses 
       
  1415         modificationsOnly:modsOnly 
       
  1416         title:(self classResources string:title with:aString)
       
  1417 
       
  1418     "Created: 9.12.1995 / 18:07:05 / cg"
       
  1419     "Modified: 9.12.1995 / 18:11:49 / cg"
       
  1420 !
       
  1421 
       
  1422 browseRefsTo:varName classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly title:title
       
  1423     "launch a browser for all methods in aClass where the instVar/classVar named
       
  1424      varName is referenced; if modsOnly is true, browse only methods where the
       
  1425      instvar is modified"
       
  1426 
       
  1427     |filter browser pattern|
       
  1428 
       
  1429     filter := self filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly.
       
  1430     browser := self browseMethodsIn:aCollectionOfClasses 
       
  1431 			inst:true class:classVars where:filter title:title.
       
  1432 
       
  1433     browser notNil ifTrue:[
       
  1434 	modsOnly ifTrue:[
       
  1435 	    pattern := varName , ' :='
       
  1436 	] ifFalse:[
       
  1437 	    pattern := varName
       
  1438 	].
       
  1439 	browser autoSearch:pattern 
       
  1440     ].
       
  1441     ^ browser
       
  1442 !
       
  1443 
       
  1444 browseSuperCallsIn:aCollectionOfClasses title:title
       
  1445     "launch a browser for all super sends in aCollectionOfClasses"
       
  1446 
       
  1447     |browser searchBlock|
       
  1448 
       
  1449     searchBlock := [:class :method :s | 
       
  1450         |src parser|
       
  1451 
       
  1452         src := method source.
       
  1453         (src notNil and:[src findString:'super']) ~~ 0 ifTrue:[
       
  1454             parser := Parser 
       
  1455                         parseMethod:src 
       
  1456                         in:class 
       
  1457                         ignoreErrors:true 
       
  1458                         ignoreWarnings:true.
       
  1459 
       
  1460             parser notNil and:[parser usesSuper]
       
  1461         ] ifFalse:[
       
  1462             false
       
  1463         ]
       
  1464     ].
       
  1465 
       
  1466     browser := self browseMethodsIn:aCollectionOfClasses
       
  1467                               where:searchBlock
       
  1468                               title:title.
       
  1469 
       
  1470     browser notNil ifTrue:[
       
  1471         browser autoSearch:'super' 
       
  1472     ].
       
  1473     ^ browser
       
  1474 
       
  1475     "
       
  1476      SystemBrowser
       
  1477          browseSuperCallsIn:(Array with:SortedCollection)
       
  1478                       title:'superSends in SortedCollection'
       
  1479     "
       
  1480 
       
  1481     "Created: 23.11.1995 / 14:08:55 / cg"
       
  1482     "Modified: 24.4.1996 / 13:25:31 / cg"
       
  1483 !
       
  1484 
       
  1485 browseSuperCallsUnder:aClass
       
  1486     "launch a browser for all supersends in aClass and subclasses"
       
  1487 
       
  1488     ^ self browseSuperCallsIn:(aClass withAllSubclasses)
       
  1489                         title:(self classResources string:'supersends (in and below %1)' with:aClass name)
       
  1490 
       
  1491     "
       
  1492      SystemBrowser browseSuperCallsUnder:Number
       
  1493     "
       
  1494 
       
  1495     "Created: 23.11.1995 / 12:06:06 / cg"
       
  1496     "Modified: 9.12.1995 / 18:11:59 / cg"
       
  1497 !
       
  1498 
       
  1499 browseUsesOf:aClass
       
  1500     |dict owners offsets
       
  1501      sz  "{ Class: SmallInteger }"
       
  1502      n   "{ Class: SmallInteger }"
       
  1503      removeSet newDict|
       
  1504 
       
  1505     owners := ObjectMemory whoReferencesInstancesOf:aClass.
       
  1506 
       
  1507     "
       
  1508      collect set of offsets in dict; key is class
       
  1509     "
       
  1510     dict := IdentityDictionary new.
       
  1511     owners do:[:someObject |
       
  1512 	|cls create|
       
  1513 
       
  1514 	someObject isContext ifFalse:[
       
  1515 	    "
       
  1516 	     someObject refers to an instance of aClass;
       
  1517 	     find out, which instVar(s)
       
  1518 	    "
       
  1519 	    cls := someObject class.
       
  1520 	    cls ~~ Array ifTrue:[
       
  1521 		n := cls instSize.
       
  1522 		create := [|s| s := Set new. dict at:cls put:s. s].
       
  1523 
       
  1524 		1 to:n do:[:i |
       
  1525 		    |ref|
       
  1526 
       
  1527 		    ref := someObject instVarAt:i.
       
  1528 		    (ref isMemberOf:aClass) ifTrue:[
       
  1529 			offsets := dict at:cls ifAbsent:create.
       
  1530 			offsets add:i.
       
  1531 		    ]
       
  1532 		].
       
  1533 		cls isVariable ifTrue:[
       
  1534 		    cls isPointers ifTrue:[
       
  1535 			| idx "{ Class: SmallInteger }" |
       
  1536 
       
  1537 			sz := someObject basicSize.
       
  1538 			idx := 1.
       
  1539 			[idx <= sz] whileTrue:[
       
  1540 			    |ref|
       
  1541 
       
  1542 			    ref := someObject basicAt:idx.
       
  1543 			    (ref isMemberOf:aClass) ifTrue:[
       
  1544 				offsets := dict at:cls ifAbsent:create.
       
  1545 				offsets add:0.
       
  1546 				idx := sz
       
  1547 			    ].
       
  1548 			    idx := idx + 1
       
  1549 			]
       
  1550 		    ]        
       
  1551 		]
       
  1552 	    ]
       
  1553 	]
       
  1554     ].
       
  1555 
       
  1556     "
       
  1557      merge with superclass refs
       
  1558     "
       
  1559     dict keysAndValuesDo:[:cls :set |
       
  1560 	cls allSuperclasses do:[:aSuperclass |
       
  1561 	    |superSet|
       
  1562 
       
  1563 	    superSet := dict at:aSuperclass ifAbsent:[].
       
  1564 	    superSet notNil ifTrue:[
       
  1565 		|removeSet|
       
  1566 
       
  1567 		superSet := dict at:aSuperclass.
       
  1568 		removeSet := Set new.
       
  1569 		set do:[:offset |
       
  1570 		    (superSet includes:offset) ifTrue:[
       
  1571 			removeSet add:offset
       
  1572 		    ]
       
  1573 		].
       
  1574 		set removeAll:removeSet
       
  1575 	    ]
       
  1576 	]
       
  1577     ].
       
  1578 
       
  1579     "
       
  1580      remove empty ones
       
  1581     "
       
  1582     removeSet := Set new.
       
  1583     dict keysAndValuesDo:[:cls :set |
       
  1584 	set isEmpty ifTrue:[
       
  1585 	    removeSet add:cls
       
  1586 	]
       
  1587     ].
       
  1588     removeSet do:[:cls |
       
  1589 	dict removeKey:cls
       
  1590     ].
       
  1591 
       
  1592     "
       
  1593      replace the indices by real names
       
  1594     "
       
  1595     newDict := IdentityDictionary new.
       
  1596     dict keysAndValuesDo:[:cls :set |
       
  1597 	|newSet names|
       
  1598 
       
  1599 	names := cls allInstVarNames.
       
  1600 	newSet := set collect:[:index | 
       
  1601 		index == 0 ifTrue:['*indexed*'] ifFalse:[names at:index].
       
  1602 	].
       
  1603 	newDict at:cls put:newSet
       
  1604     ].
       
  1605 
       
  1606     newDict inspect
       
  1607 
       
  1608 
       
  1609 !
       
  1610 
       
  1611 filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly
       
  1612     "return a searchblock for variable references"
       
  1613 
       
  1614     |searchBlock|
       
  1615 
       
  1616     searchBlock := [:c :m :s |
       
  1617         |src result parser vars needMatch|
       
  1618 
       
  1619         needMatch := varName includesMatchCharacters.
       
  1620 
       
  1621         src := m source.
       
  1622         src isNil ifTrue:[
       
  1623             result := false
       
  1624         ] ifFalse:[
       
  1625             needMatch ifFalse:[
       
  1626                 "
       
  1627                  before doing a slow parse, quickly scan the
       
  1628                  methods source for the variables name ...
       
  1629                 "
       
  1630                 result := (src findString:varName) ~~ 0.
       
  1631             ] ifTrue:[
       
  1632                 result := true.
       
  1633             ].
       
  1634             result ifTrue:[
       
  1635                 result := false.
       
  1636                 parser := Parser
       
  1637                                 parseMethod:src 
       
  1638                                 in:c 
       
  1639                                 ignoreErrors:true 
       
  1640                                 ignoreWarnings:true.
       
  1641 
       
  1642                 (parser notNil and:[parser ~~ #Error]) ifTrue:[
       
  1643                     classVars ifFalse:[
       
  1644                         modsOnly ifTrue:[
       
  1645                             vars := parser modifiedInstVars
       
  1646                         ] ifFalse:[
       
  1647                             vars := parser usedInstVars
       
  1648                         ].
       
  1649                     ] ifTrue:[    
       
  1650                         modsOnly ifTrue:[
       
  1651                             vars := parser modifiedClassVars
       
  1652                         ] ifFalse:[
       
  1653                             vars := parser usedClassVars
       
  1654                         ].
       
  1655                     ].
       
  1656                     vars size > 0 ifTrue:[
       
  1657                         needMatch ifTrue:[
       
  1658                             vars do:[:cv |
       
  1659                                 (varName match:cv) ifTrue:[result := true]
       
  1660                             ]
       
  1661                         ] ifFalse:[
       
  1662                             result := vars includes:varName
       
  1663                         ]
       
  1664                     ]
       
  1665                 ].
       
  1666             ].
       
  1667         ].
       
  1668         Processor yield.
       
  1669         result
       
  1670     ].
       
  1671     ^ searchBlock
       
  1672 
       
  1673     "Modified: 19.6.1997 / 18:27:57 / cg"
       
  1674 !
       
  1675 
       
  1676 findImplementorsOf:aSelectorString in:aCollectionOfClasses ignoreCase:ignoreCase
       
  1677     "search for all implementors of aSelector in
       
  1678      the classes contained in aCollectionOfClasses and its metaclasses.
       
  1679      Return a collection of methods"
       
  1680 
  1191     |list sel srchST srchJava lcSelector|
  1681     |list sel srchST srchJava lcSelector|
  1192 
  1682 
  1193     list := IdentitySet new.
  1683     list := IdentitySet new.
  1194 
  1684 
  1195     ((aSelectorString ~= '*') and:[aSelectorString includesMatchCharacters]) ifTrue:[
  1685     ((aSelectorString ~= '*') and:[aSelectorString includesMatchCharacters]) ifTrue:[
  1223     ] ifFalse:[
  1713     ] ifFalse:[
  1224         "can do a faster search"
  1714         "can do a faster search"
  1225 
  1715 
  1226         sel := aSelectorString asSymbolIfInterned.
  1716         sel := aSelectorString asSymbolIfInterned.
  1227         sel isNil ifTrue:[
  1717         sel isNil ifTrue:[
  1228             self showNoneFound:title.
       
  1229             ^ nil
  1718             ^ nil
  1230         ].
  1719         ].
  1231 
  1720 
  1232         ignoreCase == true ifTrue:[
  1721         ignoreCase == true ifTrue:[
  1233             lcSelector := sel asLowercase.
  1722             lcSelector := sel asLowercase.
  1275                 aClass class methodDictionary keysAndValuesDo:srchBlock
  1764                 aClass class methodDictionary keysAndValuesDo:srchBlock
  1276             ]
  1765             ]
  1277         ]
  1766         ]
  1278     ].
  1767     ].
  1279 
  1768 
  1280     ^ self browseMethods:list asOrderedCollection title:title
  1769     ^ list
  1281 
  1770 
  1282     "
  1771     "
  1283      SystemBrowser browseImplementorsOf:#+
  1772      SystemBrowser findImplementorsOf:#+
  1284                                      in:(Array with:Number
  1773                                      in:(Array with:Number
  1285                                                with:Float
  1774                                                with:Float
  1286                                                with:SmallInteger)
  1775                                                with:SmallInteger)
  1287                                   title:'some implementors of +'
  1776     "
  1288     "
  1777 
  1289 
  1778 !
  1290     "Modified: / 4.9.1995 / 17:33:39 / claus"
  1779 
  1291     "Modified: / 19.6.1996 / 14:19:02 / stefan"
  1780 findSendersOf:aSelectorString in:aCollectionOfClasses ignoreCase:ignoreCase
  1292     "Modified: / 16.10.1998 / 13:16:29 / cg"
  1781     "search for all senders of aSelector in
  1293 !
  1782      the classes contained in aCollectionOfClasses and its metaclasses.
  1294 
  1783      Return a collection of methods"
  1295 browseImplementorsOf:aSelectorString in:aCollectionOfClasses title:title
  1784 
  1296     "launch a browser for all implementors of aSelector in
  1785     ^ self allCallsOn:aSelectorString in:aCollectionOfClasses ignoreCase:ignoreCase
  1297      the classes contained in aCollectionOfClasses and its metaclasses"
  1786 
  1298 
  1787     "
  1299     ^ self
  1788      SystemBrowser findSendersOf:#+
  1300         browseImplementorsOf:aSelectorString 
  1789                    in:(Array with:Number
  1301         in:aCollectionOfClasses 
  1790                              with:Float
  1302         ignoreCase:false
  1791                              with:SmallInteger)
  1303         title:title
  1792                    ignoreCase:false
  1304 
  1793     "
  1305 !
  1794 
  1306 
       
  1307 browseImplementorsOf:aSelectorString under:aClass
       
  1308     "launch a browser for all implementors of aSelector in aClass
       
  1309      and its subclasses"
       
  1310 
       
  1311     ^ self 
       
  1312         browseImplementorsOf:aSelectorString
       
  1313         in:(aClass withAllSubclasses)
       
  1314         title:(self classResources 
       
  1315                 string:'implementors of: %1 (in and below %2)' 
       
  1316                 with:aSelectorString
       
  1317                 with:aClass name)
       
  1318 
       
  1319     "
       
  1320      SystemBrowser browseImplementorsOf:#+ under:Integer
       
  1321     "
       
  1322 
       
  1323     "Created: 9.12.1995 / 18:06:09 / cg"
       
  1324     "Modified: 9.12.1995 / 18:11:38 / cg"
       
  1325 !
       
  1326 
       
  1327 browseInstRefsTo:aString in:aCollectionOfClasses modificationsOnly:modsOnly
       
  1328     "launch a browser for all methods in aClass where the instVar named
       
  1329      aString is referenced; if modsOnly is true, browse only methods where the
       
  1330      instvar is modified"
       
  1331 
       
  1332     ^ self browseRefsTo:aString classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly
       
  1333 !
       
  1334 
       
  1335 browseInstRefsTo:varName in:aCollectionOfClasses modificationsOnly:modsOnly title:title
       
  1336     "launch a browser for all methods in aClass where the instVar named
       
  1337      varName is referenced; if modsOnly is true, browse only methods where the
       
  1338      instvar is modified"
       
  1339 
       
  1340     ^ self browseRefsTo:varName classVars:false in:aCollectionOfClasses modificationsOnly:modsOnly title:title
       
  1341 !
       
  1342 
       
  1343 browseInstRefsTo:aString under:aClass modificationsOnly:modsOnly
       
  1344     "launch a browser for all methods in aClass and subclasses
       
  1345      where the instVar named aString is referenced; 
       
  1346      if modsOnly is true, browse only methods where the instvar is modified"
       
  1347 
       
  1348     ^ self browseInstRefsTo:aString in:(aClass withAllSubclasses) modificationsOnly:modsOnly
       
  1349 !
       
  1350 
       
  1351 browseReferendsOf:aGlobalName
       
  1352     "launch a browser for all methods referencing a global
       
  1353      named aGlobalName. The argument may be a symbol, a string or
       
  1354      a matchPattern.
       
  1355     "
       
  1356 
       
  1357     ^ self browseReferendsOf:aGlobalName warnIfNone:true 
       
  1358 
       
  1359    "
       
  1360     Browser browseReferendsOf:#Transcript
       
  1361     Browser browseReferendsOf:'Tr*'
       
  1362    "
       
  1363 
       
  1364     "Modified: / 30.10.1997 / 23:45:52 / cg"
       
  1365 !
       
  1366 
       
  1367 browseReferendsOf:aGlobalName ifNone:actionIfNone
       
  1368     "launch a browser for all methods referencing a global
       
  1369      named aGlobalName.
       
  1370     "
       
  1371 
       
  1372     ^ self
       
  1373         browseReferendsOf:aGlobalName 
       
  1374         title:(self classResources string:'users of: %1' with:aGlobalName)
       
  1375         ifNone:actionIfNone
       
  1376 
       
  1377     "Modified: / 31.10.1997 / 15:42:05 / cg"
       
  1378 
       
  1379 
       
  1380 !
       
  1381 
       
  1382 browseReferendsOf:aGlobalName in:aSetOfClasses
       
  1383     "launch a browser for all methods referencing a global
       
  1384      named aGlobalName.
       
  1385     "
       
  1386 
       
  1387     ^ self browseReferendsOf:aGlobalName in:aSetOfClasses warnIfNone:true 
       
  1388 
       
  1389    "
       
  1390     Browser browseReferendsOf:#Transcript
       
  1391    "
       
  1392 
       
  1393     "Created: 10.7.1996 / 10:37:30 / cg"
       
  1394 !
       
  1395 
       
  1396 browseReferendsOf:aGlobalName in:aSetOfClasses warnIfNone:doWarn
       
  1397     "launch a browser for all methods referencing a global
       
  1398      named aGlobalName.
       
  1399     "
       
  1400 
       
  1401     |globalsPlainName idx|
       
  1402 
       
  1403     globalsPlainName := aGlobalName.
       
  1404     (idx := globalsPlainName lastIndexOf:$:) ~~ 0 ifTrue:[
       
  1405         globalsPlainName := globalsPlainName copyFrom:idx+1
       
  1406     ].
       
  1407 
       
  1408     ^ self browseForSymbol:aGlobalName
       
  1409                         in:aSetOfClasses
       
  1410                      title:(self classResources string:'users of: %1' with:aGlobalName) 
       
  1411                 warnIfNone:doWarn
       
  1412                  searchFor:globalsPlainName
       
  1413 
       
  1414     "Created: 10.7.1996 / 10:37:02 / cg"
       
  1415     "Modified: 31.10.1996 / 14:56:38 / cg"
       
  1416 !
       
  1417 
       
  1418 browseReferendsOf:aGlobalName title:title ifNone:actionIfNone
       
  1419     "launch a browser for all methods referencing a global
       
  1420      named aGlobalName.
       
  1421     "
       
  1422 
       
  1423     |globalsPlainName idx|
       
  1424 
       
  1425     globalsPlainName := aGlobalName.
       
  1426     (idx := globalsPlainName lastIndexOf:$:) ~~ 0 ifTrue:[
       
  1427         globalsPlainName := globalsPlainName copyFrom:idx+1.
       
  1428         (globalsPlainName size == 0
       
  1429         or:[globalsPlainName = '*']) ifTrue:[
       
  1430             globalsPlainName := aGlobalName
       
  1431         ]
       
  1432     ].
       
  1433 
       
  1434     ^ self browseForSymbol:aGlobalName 
       
  1435                      title:title 
       
  1436                     ifNone:actionIfNone
       
  1437                  searchFor:globalsPlainName
       
  1438 
       
  1439     "Modified: / 31.10.1996 / 14:47:48 / cg"
       
  1440     "Created: / 31.10.1997 / 15:41:28 / cg"
       
  1441 
       
  1442 
       
  1443 !
       
  1444 
       
  1445 browseReferendsOf:aGlobalName title:title warnIfNone:doWarn
       
  1446     "launch a browser for all methods referencing a global
       
  1447      named aGlobalName.
       
  1448     "
       
  1449 
       
  1450     |b|
       
  1451 
       
  1452     doWarn ifTrue: [
       
  1453 	b := [self showNoneFound:title]
       
  1454     ].
       
  1455 
       
  1456     ^ self
       
  1457         browseReferendsOf:aGlobalName 
       
  1458         title:title 
       
  1459         ifNone:b
       
  1460 
       
  1461 !
       
  1462 
       
  1463 browseReferendsOf:aGlobalName warnIfNone:doWarn
       
  1464     "launch a browser for all methods referencing a global
       
  1465      named aGlobalName.
       
  1466     "
       
  1467 
       
  1468     ^ self
       
  1469         browseReferendsOf:aGlobalName 
       
  1470         title:(self classResources string:'users of: %1' with:aGlobalName)
       
  1471         warnIfNone:doWarn
       
  1472 
       
  1473     "Modified: / 31.10.1997 / 15:42:05 / cg"
       
  1474 !
       
  1475 
       
  1476 browseRefsTo:aString classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly
       
  1477     "launch a browser for all methods in aClass where the instVar/classVar named
       
  1478      aString is referenced; if modsOnly is true, browse only methods where the
       
  1479      instvar is modified"
       
  1480 
       
  1481     |title|
       
  1482 
       
  1483     modsOnly ifTrue:[
       
  1484         title := 'modifications of: %1'
       
  1485     ] ifFalse:[
       
  1486         title := 'references to: %1 '
       
  1487     ].
       
  1488     ^ self 
       
  1489         browseRefsTo:aString 
       
  1490         classVars:classVars 
       
  1491         in:aCollectionOfClasses 
       
  1492         modificationsOnly:modsOnly 
       
  1493         title:(self classResources string:title with:aString)
       
  1494 
       
  1495     "Created: 9.12.1995 / 18:07:05 / cg"
       
  1496     "Modified: 9.12.1995 / 18:11:49 / cg"
       
  1497 !
       
  1498 
       
  1499 browseRefsTo:varName classVars:classVars in:aCollectionOfClasses modificationsOnly:modsOnly title:title
       
  1500     "launch a browser for all methods in aClass where the instVar/classVar named
       
  1501      varName is referenced; if modsOnly is true, browse only methods where the
       
  1502      instvar is modified"
       
  1503 
       
  1504     |filter browser pattern|
       
  1505 
       
  1506     filter := self filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly.
       
  1507     browser := self browseMethodsIn:aCollectionOfClasses 
       
  1508 			inst:true class:classVars where:filter title:title.
       
  1509 
       
  1510     browser notNil ifTrue:[
       
  1511 	modsOnly ifTrue:[
       
  1512 	    pattern := varName , ' :='
       
  1513 	] ifFalse:[
       
  1514 	    pattern := varName
       
  1515 	].
       
  1516 	browser autoSearch:pattern 
       
  1517     ].
       
  1518     ^ browser
       
  1519 !
       
  1520 
       
  1521 browseSuperCallsIn:aCollectionOfClasses title:title
       
  1522     "launch a browser for all super sends in aCollectionOfClasses"
       
  1523 
       
  1524     |browser searchBlock|
       
  1525 
       
  1526     searchBlock := [:class :method :s | 
       
  1527         |src parser|
       
  1528 
       
  1529         src := method source.
       
  1530         (src notNil and:[src findString:'super']) ~~ 0 ifTrue:[
       
  1531             parser := Parser 
       
  1532                         parseMethod:src 
       
  1533                         in:class 
       
  1534                         ignoreErrors:true 
       
  1535                         ignoreWarnings:true.
       
  1536 
       
  1537             parser notNil and:[parser usesSuper]
       
  1538         ] ifFalse:[
       
  1539             false
       
  1540         ]
       
  1541     ].
       
  1542 
       
  1543     browser := self browseMethodsIn:aCollectionOfClasses
       
  1544                               where:searchBlock
       
  1545                               title:title.
       
  1546 
       
  1547     browser notNil ifTrue:[
       
  1548         browser autoSearch:'super' 
       
  1549     ].
       
  1550     ^ browser
       
  1551 
       
  1552     "
       
  1553      SystemBrowser
       
  1554          browseSuperCallsIn:(Array with:SortedCollection)
       
  1555                       title:'superSends in SortedCollection'
       
  1556     "
       
  1557 
       
  1558     "Created: 23.11.1995 / 14:08:55 / cg"
       
  1559     "Modified: 24.4.1996 / 13:25:31 / cg"
       
  1560 !
       
  1561 
       
  1562 browseSuperCallsUnder:aClass
       
  1563     "launch a browser for all supersends in aClass and subclasses"
       
  1564 
       
  1565     ^ self browseSuperCallsIn:(aClass withAllSubclasses)
       
  1566                         title:(self classResources string:'supersends (in and below %1)' with:aClass name)
       
  1567 
       
  1568     "
       
  1569      SystemBrowser browseSuperCallsUnder:Number
       
  1570     "
       
  1571 
       
  1572     "Created: 23.11.1995 / 12:06:06 / cg"
       
  1573     "Modified: 9.12.1995 / 18:11:59 / cg"
       
  1574 !
       
  1575 
       
  1576 browseUsesOf:aClass
       
  1577     |dict owners offsets
       
  1578      sz  "{ Class: SmallInteger }"
       
  1579      n   "{ Class: SmallInteger }"
       
  1580      removeSet newDict|
       
  1581 
       
  1582     owners := ObjectMemory whoReferencesInstancesOf:aClass.
       
  1583 
       
  1584     "
       
  1585      collect set of offsets in dict; key is class
       
  1586     "
       
  1587     dict := IdentityDictionary new.
       
  1588     owners do:[:someObject |
       
  1589 	|cls create|
       
  1590 
       
  1591 	someObject isContext ifFalse:[
       
  1592 	    "
       
  1593 	     someObject refers to an instance of aClass;
       
  1594 	     find out, which instVar(s)
       
  1595 	    "
       
  1596 	    cls := someObject class.
       
  1597 	    cls ~~ Array ifTrue:[
       
  1598 		n := cls instSize.
       
  1599 		create := [|s| s := Set new. dict at:cls put:s. s].
       
  1600 
       
  1601 		1 to:n do:[:i |
       
  1602 		    |ref|
       
  1603 
       
  1604 		    ref := someObject instVarAt:i.
       
  1605 		    (ref isMemberOf:aClass) ifTrue:[
       
  1606 			offsets := dict at:cls ifAbsent:create.
       
  1607 			offsets add:i.
       
  1608 		    ]
       
  1609 		].
       
  1610 		cls isVariable ifTrue:[
       
  1611 		    cls isPointers ifTrue:[
       
  1612 			| idx "{ Class: SmallInteger }" |
       
  1613 
       
  1614 			sz := someObject basicSize.
       
  1615 			idx := 1.
       
  1616 			[idx <= sz] whileTrue:[
       
  1617 			    |ref|
       
  1618 
       
  1619 			    ref := someObject basicAt:idx.
       
  1620 			    (ref isMemberOf:aClass) ifTrue:[
       
  1621 				offsets := dict at:cls ifAbsent:create.
       
  1622 				offsets add:0.
       
  1623 				idx := sz
       
  1624 			    ].
       
  1625 			    idx := idx + 1
       
  1626 			]
       
  1627 		    ]        
       
  1628 		]
       
  1629 	    ]
       
  1630 	]
       
  1631     ].
       
  1632 
       
  1633     "
       
  1634      merge with superclass refs
       
  1635     "
       
  1636     dict keysAndValuesDo:[:cls :set |
       
  1637 	cls allSuperclasses do:[:aSuperclass |
       
  1638 	    |superSet|
       
  1639 
       
  1640 	    superSet := dict at:aSuperclass ifAbsent:[].
       
  1641 	    superSet notNil ifTrue:[
       
  1642 		|removeSet|
       
  1643 
       
  1644 		superSet := dict at:aSuperclass.
       
  1645 		removeSet := Set new.
       
  1646 		set do:[:offset |
       
  1647 		    (superSet includes:offset) ifTrue:[
       
  1648 			removeSet add:offset
       
  1649 		    ]
       
  1650 		].
       
  1651 		set removeAll:removeSet
       
  1652 	    ]
       
  1653 	]
       
  1654     ].
       
  1655 
       
  1656     "
       
  1657      remove empty ones
       
  1658     "
       
  1659     removeSet := Set new.
       
  1660     dict keysAndValuesDo:[:cls :set |
       
  1661 	set isEmpty ifTrue:[
       
  1662 	    removeSet add:cls
       
  1663 	]
       
  1664     ].
       
  1665     removeSet do:[:cls |
       
  1666 	dict removeKey:cls
       
  1667     ].
       
  1668 
       
  1669     "
       
  1670      replace the indices by real names
       
  1671     "
       
  1672     newDict := IdentityDictionary new.
       
  1673     dict keysAndValuesDo:[:cls :set |
       
  1674 	|newSet names|
       
  1675 
       
  1676 	names := cls allInstVarNames.
       
  1677 	newSet := set collect:[:index | 
       
  1678 		index == 0 ifTrue:['*indexed*'] ifFalse:[names at:index].
       
  1679 	].
       
  1680 	newDict at:cls put:newSet
       
  1681     ].
       
  1682 
       
  1683     newDict inspect
       
  1684 
       
  1685 
       
  1686 !
       
  1687 
       
  1688 filterToSearchRefsTo:varName classVars:classVars modificationsOnly:modsOnly
       
  1689     "return a searchblock for variable references"
       
  1690 
       
  1691     |searchBlock|
       
  1692 
       
  1693     searchBlock := [:c :m :s |
       
  1694         |src result parser vars needMatch|
       
  1695 
       
  1696         needMatch := varName includesMatchCharacters.
       
  1697 
       
  1698         src := m source.
       
  1699         src isNil ifTrue:[
       
  1700             result := false
       
  1701         ] ifFalse:[
       
  1702             needMatch ifFalse:[
       
  1703                 "
       
  1704                  before doing a slow parse, quickly scan the
       
  1705                  methods source for the variables name ...
       
  1706                 "
       
  1707                 result := (src findString:varName) ~~ 0.
       
  1708             ] ifTrue:[
       
  1709                 result := true.
       
  1710             ].
       
  1711             result ifTrue:[
       
  1712                 result := false.
       
  1713                 parser := Parser
       
  1714                                 parseMethod:src 
       
  1715                                 in:c 
       
  1716                                 ignoreErrors:true 
       
  1717                                 ignoreWarnings:true.
       
  1718 
       
  1719                 (parser notNil and:[parser ~~ #Error]) ifTrue:[
       
  1720                     classVars ifFalse:[
       
  1721                         modsOnly ifTrue:[
       
  1722                             vars := parser modifiedInstVars
       
  1723                         ] ifFalse:[
       
  1724                             vars := parser usedInstVars
       
  1725                         ].
       
  1726                     ] ifTrue:[    
       
  1727                         modsOnly ifTrue:[
       
  1728                             vars := parser modifiedClassVars
       
  1729                         ] ifFalse:[
       
  1730                             vars := parser usedClassVars
       
  1731                         ].
       
  1732                     ].
       
  1733                     vars size > 0 ifTrue:[
       
  1734                         needMatch ifTrue:[
       
  1735                             vars do:[:cv |
       
  1736                                 (varName match:cv) ifTrue:[result := true]
       
  1737                             ]
       
  1738                         ] ifFalse:[
       
  1739                             result := vars includes:varName
       
  1740                         ]
       
  1741                     ]
       
  1742                 ].
       
  1743             ].
       
  1744         ].
       
  1745         Processor yield.
       
  1746         result
       
  1747     ].
       
  1748     ^ searchBlock
       
  1749 
       
  1750     "Modified: 19.6.1997 / 18:27:57 / cg"
       
  1751 ! !
  1795 ! !
  1752 
  1796 
  1753 !SystemBrowser class methodsFor:'startup'!
  1797 !SystemBrowser class methodsFor:'startup'!
  1754 
  1798 
  1755 browseAllSelect:aBlock
  1799 browseAllSelect:aBlock
  2213 ! !
  2257 ! !
  2214 
  2258 
  2215 !SystemBrowser class methodsFor:'documentation'!
  2259 !SystemBrowser class methodsFor:'documentation'!
  2216 
  2260 
  2217 version
  2261 version
  2218     ^ '$Header: /cvs/stx/stx/libtool/SystemBrowser.st,v 1.102 2000-02-22 18:40:47 cg Exp $'
  2262     ^ '$Header: /cvs/stx/stx/libtool/SystemBrowser.st,v 1.103 2000-03-21 11:24:17 cg Exp $'
  2219 ! !
  2263 ! !
  2220 SystemBrowser initialize!
  2264 SystemBrowser initialize!