From: <ro...@lo...> - 2002-09-20 14:23:04
|
Hi List, over the last month I've worked with OpenC++. Now there is the end of my project near and I would like to share the changes I've made on occ with you in case someone else might find useful what I did. Please note that this patch is for version 2.5.12, I haven't found time to tweak the source to work with the daily snapshots and 2.5.12 fit my needs most of the time. In all the changes I thought about backward-compatibility so even I you wrote code which depends heavily on the occ internal object implementations this shouldn't break anything: - for all pure virtual functions you can remove the pure specifier with Member::RemovePureSpecifier(). Had to do this, since the member's declarator is private and I didn't want to mess around with the access specifiers. - for all array declarations you can get a PtreeList of the array range expressions by calling Member::GetArrayRange (e.g. int a[3][b][4] would get [[3],[b],[4]]). Had to do this since the declarator is private. - as mentioned in another mail about 1 month ago: member variables of type array of builtin-type weren't treated as member variables in respect to the various TranslateMember(Write/...) routines. I fixed that with that a rudimentary patch, which handles these cases as special cases, so you would have to define new methods (TranslateArrayMemberWrite, TranslatePostfixOnArrayMember, etc.) to get the corresponding hooks in the translation. The added member methods are: virtual Ptree* TranslateMemberSubscript virtual Ptree* TranslateArrayMemberWrite virtual Ptree* TranslateUnaryOnArrayMember virtual Ptree* TranslatePostfixOnArrayMember - I had to set MaxNameLen in encoding.h to 1024, due to some complicated namespace nestings, which exceeded the 512 character limit. I personally would prefer to make this limit unnecessary at all but what I understand from the source it seems that this might mean to change code at various, essential places so I am not sure if I will do it. - I added a new suffix as an indicator for C++ source (.eti, it's really an internal thing but I don't have the time to clean up my patch at the moment). - I added a new command line switch (-T) which let's occ output the translated parse tree on stdout in addition to writing it to an .ii file. - last, but not least: I added a method similar to CopyList to ptree-core. CloneList has some advantages over CopyList which I found to be very useful: 1.) in contrast to CopyList CloneList creates a copy of *each* node in the parse tree. CopyList on the contrary just makes a copy of the topmost list of nodes and let's the corresponding nodes Car fields stay the same (at pointer equality) so you won't really get a totally independent list of Ptree. CloneList on the other hand resembles the exact structure of the original tree but with copies of each node (either non-leaf or leaf). 2.) CloneList uses a kind of a virtual constructor which I added to every subclass of (and including) Ptree. It therefore is possible to do something like this: ClassWalker walker(env); Ptree* body = Ptree::CloneList(member.FunctionBody()); body = walker.Translate(body); where Translate will call the corresponding TranslationHooks of your method class *without* relexing and parsing the created parse tree, since a Ptree-subclass will stay of the same type as the original nodes one. (thanks to Grzegorz Jakacki for pointing me in the right directions). I thought this might be interesting to others so I will make my patch available here: http://lo-res.org/~rost/patch-openc++2.5.12-changes.rost.19092002.gz Any comments are welcome, cu, Robert --- GPG: gpg --keyserver wwwkeys.pgp.net --recv-keys CCFDEB89 |