From: Grzegorz J. <ja...@he...> - 2004-04-02 12:49:59
|
On Mon, 29 Mar 2004, Raphael Yokoingawa de Camargo wrote: > Thanks very much for the fast help. > > Actually, I hadn't notice the documentation appendix page. Maybe if there was a > link from the official openc++ page it would be easier to find... The appendix should me merged with main docs, that would eliminate the problem. Any takers? > I hadn't say that in the first question but I still have a problem in finding > global variables declarations. By what I've seen, It doesn't seems to be a > simple way of finding them. Maybe I'll have to look at the source code... OpenC++ is not one thing, but two: * metacompiler framework --- you feed it with metaclass definitions, it does the rest, * frontend library --- you can call it to parse code, it returns typed source tree and program object model (representation of classes, methods, etc.) You have to decide which model you want to use. Metacompiler has complete documentation, frontend library has not. Metacompiler constraints you in some ways (because it is a framework), library gives you more freedom. Using OpenC++ as library requires tweaking source code. I am working on separation of this functionality, but it is not ready yet. Also OpenC++'s main purpose was to explore OO-side of C++ programs, consequently its obect model does not represents e.g. toplevel functions. You can have your code called back when such function is translated, but OpenC++ itself does not create a metaobject for function, the way it creates metaobjects for classes or methods. > I hadn't say that in the first question but I still have a problem in finding > global variables declarations. Create new empty Environment and create a Walker out of it. Run the Walker on your parse tree, after it is done you will find the global variables in the Environment (at least I believe so...). See Walker::TranslateDeclarators() to see how the variables get stored there. > By what I've seen, It doesn't seems to be a > simple way of finding them. I think it is not straightforward if you use "metacompiler framework" model. I suggest switching to "frontend library" model. > Maybe I'll have to look at the source code... Definitely... :-) BR Grzegorz > > thanks, > Raphael > > Citando Jean-Sebastien Mouret <js_...@us...>: > > > Raphael Yokoingawa de Camargo <rca...@im...> writes: > > > > > Hi, > > > > > > I am new openc++ user and I'm using it in my doctoral research. I'm > > encountering > > > some difficulties. > > > > > > 1) Is there a way for me to access the entire program PTree instead of only > > the > > > PTree relative to classes. I need this functionality because I will also > > use > > > openc++ to manipulate C code (that don't have classes) and I need to know > > about > > > all the function definitions in the code. > > > > have a look in the documentation appendix. > > > > > > > > 2) Is there a way to only include some selected source files in the AST > > tree? > > > The generated source trees are to big because they include all the system > > header > > > files. It also makes much more difficult for me to analize the code, since > > I don > > > know wich code is from the applications. > > > > To do this, I use a special include directive for everything I don't > > want openc++ to parse. The technic is rather gory and I'd like to know if > > there is a nicer way to do it. > > > > for example, in your occ file just do: > > > > #include <common.hh> > > // and then > > include("iostream") > > > > > > the common.hh contains something like: > > > > metaclass Tools internal_Tools; > > struct internal_Tools {}; > > # define include(FILE) void internal_Tools::include() { FILE; } > > > > > > then in your openc++ compiler: > > > > struct Tools : public Class > > { > > static bool Initialize(); > > void TranslateMemberFunction(Environment* env, Member& m); > > void TranslateClass(Environment* env); > > }; > > > > bool Tools::Initialize() > > { > > return Class::Initialize(); > > } > > > > void Tools::TranslateClass(Environment* env) > > { > > RemoveClass(); > > return Class::TranslateClass(env); > > } > > > > void Tools::TranslateMemberFunction(Environment* env, Member& m) > > { > > if (Ptree::Match(m.Name(),"include")) > > { > > //FIXME: delete the member instead of commenting out > > InsertBeforeToplevel(env,Ptree::Make("/*")); > > AppendAfterToplevel(env,Ptree::Make("*/")); > > > > for(PtreeIter i = m.FunctionBody()->Rest()->First(); !i.Empty(); i++) > > AppendAfterToplevel(env,Ptree::Make("\n#include > > %p",(*i)->First())); > > } > > } > > > > > > Hope this helps > > > > > > -- > > js > > > > Raphael Yokoingawa de Camargo <rca...@im...> > > > ------------------------------------------------------- > 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. # ################################################################## |