Re: [Ctool-develop] using ctool as a library
Brought to you by:
flisakow
From: Stefan S. <se...@sy...> - 2003-07-31 20:03:02
|
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 |