Re: [Ctool-develop] using ctool as a library
Brought to you by:
flisakow
From: Shaun F. <fli...@so...> - 2003-07-31 20:21:11
|
Limited forms of visitors exist, see TransUnit in project.h: void findStemnt( fnStemntCallback cb ); void findFunctionDef( fnFunctionCallback cb ); and Expression in express.h: void findExpr( fnExprCallback cb ); The 'cgraph' example in examples/cgraph uses findFunctionDef() to demonstrate how to create a call-graph for a program. I have my doubts that this method is going to be powerful enough to transfer the entire AST to another form though - they are intended for users who need to collect information from the AST, or to make slight tweaks to the AST before reprinting it. If you try it, I'd like to hear your suggestions for improvements. Thanks, Shaun On Thursday, July 31, 2003, at 01:02 PM, Stefan Seefeld wrote: > Shaun Flisakowski wrote: >> Stefan, >> The best example to look at is probably the code that prints out the >> AST. This starts at: >> operator<<(std::ostream& out, const TransUnit& tu) >> in project.cpp >> Each translation unit is composed of a list of statements, an >> hierarchy of C++ classes for each type (for, while, expression, >> etc). Each of the statements has members in it that give pointers >> to the expressions it uses, or in some cases, the statement >> required. >> Most of the members of the AST are public, you can just reach in and >> grab what you need. > > > I see. Well, what do you think of the visitor pattern as a general way > to traverse the tree ? Each type and statement type would implement an > 'accept' method (say), which only calls a visitor's 'visit' method with > the appropriate type. > > Then you could provide specific visitors to print out what the current > 'print' methods do, and I could write my own visitor(s) to map ctool's > AST to my own. > > I think such a traversal is useful because else everybody has to > reimplement the traversing mechanism. > > Regards, > Stefan > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100003ave/ > direct;at.aspnet_072303_01/01 > _______________________________________________ > Ctool-develop mailing list > Cto...@li... > https://lists.sourceforge.net/lists/listinfo/ctool-develop > |