From: Grzegorz J. <ja...@he...> - 2004-04-02 14:10:49
|
On Mon, 29 Mar 2004, Maarten de Boer wrote: > Hello, > > I am looking for an application that can parse c++, store it in a AST, > and regenerate the original c++ code. Obviously, the interesting part > would be to apply some modification to the AST before regenerating. > > For example, I want to remove all constructors that match a certain > pattern (first argument is of type Foo), from classes that are derived > from class Bar. > > Or, another example, I have a header and source file for each class, and > for each header, I want to move all included headers to the > corresponding source file, and use forward declarations instead, if the > classes from the headers included are only used by reference. > > Someone pointed me to OpenC++, and at a first glance, it seems to > contain the code to do just the thing, though it is not clear to me if > it would actually be able to regenerate the code... This is a recurring subject, Asen Kovachev had some ideas on that recently. The main problem is that you have to deal somehow with preprocessor expansion. In fact you want to keep as much as possible unexpanded, yet in most cases you want the parser to be able to "see through" the preprocessor symbols. Asen and myself came up with an idea to add new AST nodes that would represent macro expansions and #include expansions. This is not enough to incorporate any usage of macros (e.g. expansions of '#define LBR [' or swines like that), but is close enough to be usable. OpenC++ does not implement it now, hopefully we can get it to work soon. If you would like to help to make it happen, please contact me off-line. > Could you please help me out? Would OpenC++ indeed be suitable for such > a task, is there some example code available that I could work upon, or > maybe you can suggest some other project that would be (more) suitable? I don't think it is easy to find tools that would understand the syntax and preserve preprocessor. Eclipse's CDT does some attempt at refactoring C++, which obviously means regenerating sources without preprocessor expansion, but AFAIK they are not there yet. It is free, you can try it. (Please post the results here.) Microsoft had something called Intensional Programming Tool and I am told it can parse and unparse C++ without trashing preprocessor constructs, but I have never seen it. Perhaps it was spinned-off from Microsoft with Simonyi. There is a company www.semdesigns.com, they have heavy-weight multi-language refactoring tool, perhaps it does what you need (but I doubt it does it out-of-the-box). I would also ask this question at comp.compilers, if you have not done it already. In any case I would be very much interested in your findings, I would appreciate if you could e-mail me with results of you search. Thanks Grzegorz > Kind regards, > > Maarten > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Opencxx-users mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/opencxx-users > > ################################################################## # Grzegorz Jakacki Huada Electronic Design # # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # # tel. +86-10-64365577 x2074 Beijing 100015, China # # Copyright (C) 2004 Grzegorz Jakacki, HED. All Rights Reserved. # ################################################################## |