From: Aitor Garay-R. <ter...@gm...> - 2004-05-10 17:51:34
|
Hi there!, Lately I have been thinking on how it could be possible to implement an iContract like tool for C++. iContract is a Design by Contract tool for Java. The basic idea is to parse the C++ source code looking for special comment blocks that specify the precondition/postcondition/invariants of the class. Then the input source code is extended with code that check the contracts at runtime. There are a few options for implementing such a DbC tool for C++. I have come to OpenC++ and believe that is the most promising way to implement it "easily". Other alternatives I'm considering are implementing a standalone application that uses some freely available grammar or may be extending the AspectC compiler. I have no experience at all with OpenC++ and I have a few doubts. - do OpenC++ meta-programs have access to the source code comments? - are the meta-programs able to transverse the inheritance hierarchy of a given class? - how well does OpenC++ handle macros? And namespaces? - is it possible to introduce new methods in the generated classes? Is it possible to do arbitrary transformations like nesting the body of a method inside some try/catch blocks? Sorry for the long list of questions, it would be very helpful if I can get a rough idea of OpenC++ possibilities before getting deep into it. Has someone hear about some similar effort of implementing DbC for C++? Any ideas? Thanks!, /AITOR |
From: Stefan S. <se...@sy...> - 2004-05-10 19:03:46
|
hi Aitor, Aitor Garay-Romero wrote: > - do OpenC++ meta-programs have access to the source code comments? the current opencxx code doesn't allow this. However, I'm using a branched version of opencxx as part of the synopsis project (http://synopsis.fresco.org) where we added support for comments (specifically to document the code, but indeed any metadata could be embedded and processed). I plan to get synopsis and opencxx closer to each other, as I believe both have important features that would be even more powerful when used together. What you suggest sounds entirely possible and actually a very nice example of C++ meta programming. > - are the meta-programs able to transverse the inheritance hierarchy of a > given class? what do you mean by 'meta-program' here ? Tools like occ and synopsis certainly have access to that information, as they operate on the parse / syntax trees of the original source code. So they could generate the additional code you want. Note that this is a compile-time issue, there is no runtime support for introspection. > - how well does OpenC++ handle macros? And namespaces? Macros are not handled at all by opencxx, I believe. Again, synopsis deals with macros, and I'd like to find a way to give opencxx access to that, too. Namespaces should be fine (I recently patched opencxx to support namespace aliases, but that patch only fixes the parser, not the occ runtime environment. > - is it possible to introduce new methods in the generated classes? Is it > possible to do arbitrary transformations like nesting the body of a method > inside some try/catch blocks? yes, any transformation of the parse tree is possible, at least in theory. A special 'Walker' class that traverses the tree can find the nodes you are looking for and then based on these apply some modifications. I don't know how flexible the occ frontend right now is, i.e. how you would teach occ what exactly to do. From personal experience I believe that a scripting frontend to opencxx would be most powerful for really fine-grained control over the code manipulation. I don't know what opencxx's current support for code generation is. Regards, Stefan |
From: Grzegorz J. <ja...@he...> - 2004-05-11 00:42:52
|
On Mon, 10 May 2004, Aitor Garay-Romero wrote: > Hi there!, > > Lately I have been thinking on how it could be possible to implement an > iContract like tool for C++. iContract is a Design by Contract tool for > Java. The basic idea is to parse the C++ source code looking for special > comment blocks that specify the precondition/postcondition/invariants of the > class. Then the input source code is extended with code that check the > contracts at runtime. > There are a few options for implementing such a DbC tool for C++. I have > come to OpenC++ and believe that is the most promising way to implement it > "easily". Other alternatives I'm considering are implementing a standalone > application that uses some freely available grammar or may be extending the > AspectC compiler. > I have no experience at all with OpenC++ and I have a few doubts. > > - do OpenC++ meta-programs have access to the source code comments? Only at the class level, see Class::Comments(). However lexer recognizes comments, you would need to tweak parser to put the comments in the parse tree. > - are the meta-programs able to transverse the inheritance hierarchy of a > given class? Yes. > - how well does OpenC++ handle macros? OpenC++ does not see any macros, OpenC++ works on preprocessed sources. AFAIU this is what you need. Some applications, however, need to understand code with macros unexpanded (e.g. if you want to regenerate human-readable source code). Asen Kovachev, Stefan Seelfeld and myself are thinking of this functionality, but it is definitely still in "thinking" phase. > And namespaces? OpenC++ understand namespaces and qualified names except namespace aliases. Thanks to Stefan namespace alias declarations can be parsed now, but still they are not considered in lookup :-( > - is it possible to introduce new methods in the generated classes? Yes. > Is it > possible to do arbitrary transformations like nesting the body of a method > inside some try/catch blocks? Yes. > > Sorry for the long list of questions, it would be very helpful if I can get > a rough idea of OpenC++ possibilities before getting deep into it. Has > someone hear about some similar effort of implementing DbC for C++? Any > ideas? (1) Browse archives of this list to get more insight of what can be done. (2) There are two major modes of using OpenC++: * Deriving classes from "Class" in order to customize the source-to-source translation. * Taking OpenC++ source code as a code base to build your own application of top of it (it usually means deriving from "Abstract...Walker" and/or making modifications to existing code). (3) The most up-to-date version of OpenC++ is in sandbox_jakacki_frontend1, Stefan and myself are working now on merging it to MAIN and releasing it soon. BR Grzegorz > > Thanks!, > > /AITOR > > > > ------------------------------------------------------- > This SF.Net email is sponsored by Sleepycat Software > Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to deliver > higher performing products faster, at low TCO. > http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3 > _______________________________________________ > 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. # ################################################################## |