Re: [Ctool-develop] using ctool as a library
Brought to you by:
flisakow
From: Stefan S. <se...@sy...> - 2003-08-01 06:39:37
|
Shaun Flisakowski wrote: > > 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. ok, I had a first try tonight at this: I added 'accept' methods to a number of classes, which all accept a 'Traversal' object and call an appropriate method on it to resolve the dynamic type. I wrote a 'PrintTraversal' which should (once debugged and cleaned up) do all the work that is now implemented by the various 'print' methods. This is just an illustration of the pattern, but if you accept it, you could remove all the 'print' methods from the individual classes, as that code would then be completely contained in PrintTraversal.cpp. The idea is then that the actual library would only contain the parser, the individual node types, and the Traversal interface. The PrintTraversal (and any other Traversal implementations users want to implement) are part of the applications that actually use the library. Specifically, the PrintTraversal would go into the 'ctdemo' application, while the library would not contain any print functionality. Speaking of the library, do you think it would make sense to build it as a shared library ? Also, if you want to 'go public' with that, I'd suggest a somewhat longer name such as 'libctool.so' instead of the short and unspecific name 'libct.so'. Finally, I'd suggest to rework the build system a little to make the whole thing more flexible and portable. I'd suggest to use autoconf for that, and I'm willing to provide a patch. However, I'll be on vacation starting this weekend, so I'm only able to work more on this project in two weeks. Kind regards, Stefan |