[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] playing with code-searching

From: Stephen Compall
Subject: [Help-smalltalk] playing with code-searching
Date: Tue, 23 Jan 2007 17:25:48 -0600

Here is some preliminary code I have been playing with:

| hasWorthlessDoBlockSearch foundList handleParseError |
hasWorthlessDoBlockSearch := STInST.ParseTreeSearcher new
    matches: '[:`var | address@hidden value: `var]'
    do: [:aNode :ans | true].
foundList := OrderedCollection new.
handleParseError := [:class :methodSrc :error :posn |
    Transcript nextPutAll: 'Error while parsing in ';
        print: class;
        nextPutAll: ': '; display: error; nl;
        next: posn - 1 putAll: methodSrc startingAt: 1;
        nextPutAll: '<**>';
        next: methodSrc size - (posn - 1) putAll: methodSrc startingAt: posn;
Object withAllSubclassesDo: [:class |
    class methodDictionary isNil
        ifFalse: [class methodDictionary keysDo: [:methodName |
            | methodSrc errorHandle gotError |
            gotError := false.
            methodSrc := class sourceCodeAt: methodName.
            errorHandle := [:error :posn |
                handleParseError valueWithArguments:
                    {class. methodSrc. error. posn}.
                gotError := true].
                 executeTree: (STInST.RBParser parseMethod: methodSrc
                                               onError: errorHandle)
                 initialAnswer: false)
                ifTrue: [foundList add: (class compiledMethodAt: methodName).
                         Transcript print: class; nextPutAll: '>>';
                             nextPutAll: methodSrc; nl; nl]]
                on: Error
                do: [:e | gotError ifTrue: [e return] ifFalse: [e pass]]]]].
foundList do: [:each | each printNl]

No clean design here, but it's a quick way to look for patterns
throughout the GST Smalltalk codebase (the loaded packages, anyway).
Just change the matches: string to whatever pattern you're looking for.
It scans every method source code and prints the methods that match,
with a summary list at the end.

For example, I used this one to produce
also attached.  (I was looking at Dictionary>>#associationsDo: when I
noticed this pattern, hence my choice of searches.)

This is also a good benchmark for method source storage and access, as
accessing every method for a given class is a common pattern.

;;; Stephen Compall ** **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
  -- Lee Gomes, performing every Wednesday in his tech column
     "Portals" on page B1 of The Wall Street Journal

Attachment: redund-blocks.diff
Description: Text Data

Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

[Prev in Thread] Current Thread [Next in Thread]