Nesting withExtDeclHandler

Bueno, Denis denbuen at
Thu Jul 16 09:41:30 EDT 2009

Hi all,

While trying to do some analysis with the TravMonad I wrote some code that
looked like so:

    withExtDeclHandler (analyseAST cTranslUnit) handleFun

    handleFun (DeclEvent (FunctionDef (FunDef varDecl bodyStat info)) =
        modifyUserState update
        withExtDeclHandler (analyseFunctionBody info varDecl bodyStat)
        return ()

    recordLocalEvents (LocalEvent ...) =
        modifyUserState recordEvent

That is, I was doing a pass over the entire AST with one external DeclEvent
handler, and I wanted to temporarily override that handler locally to
process the local declarations of a FunDef.  After finishing the FunDef, I
wanted to resume the main analysis with the original handler (`handleFun').

This didn't work out as planned; debugging revealed that after the second
handler (`recordLocalEvents') is invoked the first time, the first handler
never gets invoked again on the rest of the AST.

Running the same analysis on the same C code with just one external handler
invokes all the events I expected.

Is this intended behavior?  Is there a simple workaround so that I can use
two handlers?  I've come up with a way to do what I want using only one
handler, but it's not a simple as I'd like.

More information about the Language-c mailing list