[Webkit-unassigned] [Bug 16571] New: JSC needs a NodeWalker class to walk the AST tree

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Dec 21 22:02:52 PST 2007


http://bugs.webkit.org/show_bug.cgi?id=16571

           Summary: JSC needs a NodeWalker class to walk the AST tree
           Product: WebKit
           Version: 525+ (Nightly build)
          Platform: Macintosh
        OS/Version: Mac OS X 10.4
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: eric at webkit.org


JSC needs a NodeWalker class to walk the AST tree

I'm writing this out in a bug, so I make sure to cover most/all of the
foreseeable uses with my implementation.

Uses I know of:
1.  Syntax checking -- needs to walk all StatementNodes (which may be buried
under FuncExprNodes), and needs eachNode and leavingNode callbacks (entering to
push labels & check syntax and after to pop labels)
2.  optimizeVariableAccess -- needs to walk all StatementNodes (not necessarily
including those buried in FuncExprNodes), needs an eachNode callback
3.  enable/disable debugging -- needs to walk all StatementNodes (including
those buried under FuncExprNodes), needs eachNode callback

If there are more uses which we can think of now, we should list them in this
bug so I can design for them.

Current thoughts I've had include:

1.  Having an "add your kids to this stack" method, keeping a kid stack and a
parent stack, all nodes get pushed onto the parent stack and the kid stack,
then the "add your kids method" is called, during advance() the top kid node is
compared with the top parent node, if they match, the "leaving" callback is
called, and then both stacks are popped, this repeats until either the stacks
are empty or the kid stack does not agree with the parent stack in which case
that's the next node.

2.  Similar to above, but instead keeping a single stack of node* + state
variable.  Push yourself onto the stack with a "leaving" state, then call the
"push your kids" method, each gets pushed with an "entering" state.  When
poping nodes of the stack, check state and call the leaving callback for each
with a leaving state, until you reach one with an "entering" state which is the
next node.

3.  Add childNodes() virtual accessor function and possibly as
"hasChildNodes()" virtual function.  You still need a stack with states, or two
stacks, but you avoid pushing leaf nodes with a "leaving" state only to then
immediately pop them.  Instead you end up having to copy the returned child
node pointers onto the stack. :(

None of these methods are perfect yet.  I'm sure there is a good solution here.
 Perhaps a bit of algorithms research is what's in order. :)


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list