From: suresh <su...@em...> - 2002-11-22 21:50:29
|
Hi, My name is Suresh. I am new to OpenC++ group. I am working on a project which basically does the source code translation. I am facing few problems. These problems are:- 1. When I am trying to load the metaclass for c functions. It is giving warning that: 'Mop is not able to load the "CFunctionClass" '. CFunctionClass is a metaclass which I defined for translation of C functions. Here is the code //In my main metaclass inside Initialize(), I have setMetaclassForFunctions("CFunctionClass"); //and in CFunctionClass.mc, I have overloaded a class member function TranslateFunctionCall(...) { .. .. } The idea is I want to change the function call in main() method and this function is not part of any class which have metaclass declaration. This function is like C library function defined by some other vendor. 2. I have several classes. I am using the same metaclass for all classes' code translation. The problem is I need to see how many objects of a class (say classA) are instantiated in the whole application. I.e. there may be a class classB where the object of classA is instantiated. I want to know all such objects and put the MACRO definition for them in the class header file. 3. As I have one metaclass, I want to statically overload this metaclass so that I don't need to insert the metaclass declaration before every class definition. I tried using "ChangeDefaultMetaClass("mainMetaClass)" by calling it from the Initialize() method and using -S option at the time of compilation but this is not working. %occ -S mainMetaClass.mc this command is giving me problems at the time of linking. If anybody know about any of the problem. Plzz email me. Thanks in advance - Suresh Lalwani. |
From: Grzegorz J. <ja...@he...> - 2002-11-25 09:04:18
|
On Fri, 22 Nov 2002, suresh wrote: [...] > 1. When I am trying to load the metaclass for c functions. It is > giving warning that: 'Mop is not able to load the "CFunctionClass" '. Which version of OpenC++ is it? What OS is this? Are you compiling your metaclass to dlopenable module (usually something like CFunctionClass.so)? Are you sure the library function (dlopen() or lt_dlopen(), depending on the version of OpenC++) is able to find your dlopenable module (depending on OS you may be required to set up LD_LIBRARY_PATH or something similar)? [...] > 2. I have several classes. I am using the same metaclass for all > classes' code translation. The problem is I need to see how many objects > of a class (say classA) are instantiated in the whole application. I.e. > there may be a class classB where the object of classA is instantiated. > I want to know all such objects and put the MACRO definition for them in > the class header file. I do not quite understand. Object instantiation takes place during the execution. OpenC++ deals with classes defined in the input file, not objects that are instantiated during the execution of (possibly compiled) input file. Perhaps you are trying to find all classes in which instantiation of objects of 'classA' can possibly take place. In general this is difficult, but possible. Observe, that object of type 'classA' can be instantiated in many ways, for instance: * definition of variable of type 'classA', * instantiation of object that has (possibly indirect) subobject of type 'classA' or member of type 'classA' * 'new classA' * 'classA()' within expression * user-defined conversion (this one is difficult to find!!!) Think also about distasters like: template <class T> class Foo { ... }; template <class T> class Foo<T*> { ... new classA ... }; There is a possible instantiation of object of type 'classA' within some (!) specializations of class template Foo. Hopefully you do not need to handle all the above cases. It is also not clear to me where you want to put your macro, why you want to do it and what would it expand to --- declaration, expression? > 3. As I have one metaclass, I want to statically overload this > metaclass so that I don't need to insert the metaclass declaration > before every class definition. I do not quite understand what you mean by "overloading a metaclass". In C++ you can overload functions, not classes (nor metaclasses in OpenC++). > I tried using > "ChangeDefaultMetaClass("mainMetaClass)" by calling it from the > Initialize() method and using -S option at the time of compilation but > this is not working. > > %occ -S mainMetaClass.mc > > this command is giving me problems at the time of linking. Error message would help a lot to see what is really going wrong. If you can post short exemplary source on which occ fails, that would help even more. Best regards Grzegorz ################################################################## # Grzegorz Jakacki Huada Electronic Design # # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # # tel. +86-10-64365577 x2074 Beijing 100015, China # # Copyright (C) 2002 Grzegorz Jakacki, HED. All Rights Reserved. # ################################################################## |
From: Francois T. <fra...@la...> - 2002-11-25 09:04:18
|
Hi Suresh, I'm not a big expert on opencxx, but here are the few hints I can give you regarding your questions: On Fri, 2002-11-22 at 22:46, suresh wrote: > > 1. When I am trying to load the metaclass for c functions. It is > giving warning that: 'Mop is not able to load the "CFunctionClass" '. > CFunctionClass is a metaclass which I defined for translation of C > functions. Here is the code > Metaclasses are compiled into shared libraries. The error may come from occ not finding CFunctionClass.so in its library search path. Here's what the command reference says on the topic (man occ): " "First, MyClass.mc should be compiled into shared libraries MyClass.so and MyClass-init.so. The produced shared libraries must be under the directory specified by LD_LIBRARY_PATH." > > 2. I have several classes. I am using the same metaclass for all > classes' code translation. The problem is I need to see how many objects > of a class (say classA) are instantiated in the whole application. If you want to know the number of instantiation *statements* (i.e. the number of places in your code where you have "new classA"), I think occ can do that. If you need to know the number of instances of a given class that may be constructed on a given program run, I'm afraid no open compiler can do that. (I'm afraid that's what is called an undecidable property.) For the first question, I think you can use the Class::TranslateNew method. --- Ptree* TranslateNew(Environment* env, Ptree* header, Ptree* new_op, Ptree* placement, Ptree* type_name, Ptree* arglist) This translates a new expression. header is a user-defined keyword (type modifier), :: (if the expression is ::new), or nil. new_op is the new operator. type_name may include an array size surrounded by []. arglist is arguments to the constructor. It includes parentheses () . placement, type_name, and arglist have not been translated yet. -- > > > 3. As I have one metaclass, I want to statically overload this > metaclass so that I don't need to insert the metaclass declaration > before every class definition. I tried using > "ChangeDefaultMetaClass("mainMetaClass)" by calling it from the > Initialize() method and using -S option at the time of compilation but > this is not working. > > %occ -S mainMetaClass.mc > > this command is giving me problems at the time of linking. > What kind of linking problems? I have a small example that exactly do that and compiles fine. Here's what it looks like: -- class MyMetaClass : public Class { public: static bool Initialize(); [...] } // ---------------------------------------------------------- bool MyMetaClass::Initialize() { Class::ChangeDefaultMetaclass ("MyMetaClass"); Class::SetMetaclassForFunctions("MyMetaClass"); return true ; } // EndMethod MyMetaClass::Initialize -- Cheers Francois |
From: suresh <su...@em...> - 2002-11-25 17:15:41
|
Hi, I have solved the first and third problem mentioned in my previous email. Thanx for you guys help. For the second problem, which is finding the instantiation of all the objects of a class (classA), I just need to know the instantiation statements. I don't want any runtime information. Based on the objects (object names), I have to add MACROs in the header file of ClassA. The macro will take object name as an argument. Explaination: /* classA in file classA.h and classA.cpp */ Class classA { ..... ..... ...... } /* classB in file classB.h and classB.cpp */ class classB { ..... classA objA1; classA objA2 = new classA; ..... } Now I need to add MACRONAME(objA1) and MACRONAME(objA2) in the header file of classA. Any help is welcome. I am facing one more problem, I tried translateNew But translateNew's arguments don't have the object name. Is there anyway, I can get the name of object? Thanx in advance -Suresh Lalwani Note: I am using opencxx-2.5.12 version on windows XP for development purpose. Later on I will use this program on a Sun machine. -----Original Message----- From: own...@cs... [mailto:own...@cs...] On Behalf Of Francois Taiani Sent: Monday, November 25, 2002 1:57 AM To: OpenC++ Subject: Re: [opencxx] Looking for help Hi Suresh, I'm not a big expert on opencxx, but here are the few hints I can give you regarding your questions: On Fri, 2002-11-22 at 22:46, suresh wrote: > > 1. When I am trying to load the metaclass for c functions. It is > giving warning that: 'Mop is not able to load the "CFunctionClass" '. > CFunctionClass is a metaclass which I defined for translation of C > functions. Here is the code > Metaclasses are compiled into shared libraries. The error may come from occ not finding CFunctionClass.so in its library search path. Here's what the command reference says on the topic (man occ): " "First, MyClass.mc should be compiled into shared libraries MyClass.so and MyClass-init.so. The produced shared libraries must be under the directory specified by LD_LIBRARY_PATH." > > 2. I have several classes. I am using the same metaclass for all > classes' code translation. The problem is I need to see how many objects > of a class (say classA) are instantiated in the whole application. If you want to know the number of instantiation *statements* (i.e. the number of places in your code where you have "new classA"), I think occ can do that. If you need to know the number of instances of a given class that may be constructed on a given program run, I'm afraid no open compiler can do that. (I'm afraid that's what is called an undecidable property.) For the first question, I think you can use the Class::TranslateNew method. --- Ptree* TranslateNew(Environment* env, Ptree* header, Ptree* new_op, Ptree* placement, Ptree* type_name, Ptree* arglist) This translates a new expression. header is a user-defined keyword (type modifier), :: (if the expression is ::new), or nil. new_op is the new operator. type_name may include an array size surrounded by []. arglist is arguments to the constructor. It includes parentheses () . placement, type_name, and arglist have not been translated yet. -- > > > 3. As I have one metaclass, I want to statically overload this > metaclass so that I don't need to insert the metaclass declaration > before every class definition. I tried using > "ChangeDefaultMetaClass("mainMetaClass)" by calling it from the > Initialize() method and using -S option at the time of compilation but > this is not working. > > %occ -S mainMetaClass.mc > > this command is giving me problems at the time of linking. > What kind of linking problems? I have a small example that exactly do that and compiles fine. Here's what it looks like: -- class MyMetaClass : public Class { public: static bool Initialize(); [...] } // ---------------------------------------------------------- bool MyMetaClass::Initialize() { Class::ChangeDefaultMetaclass ("MyMetaClass"); Class::SetMetaclassForFunctions("MyMetaClass"); return true ; } // EndMethod MyMetaClass::Initialize -- Cheers Francois |
From: Grzegorz J. <ja...@he...> - 2002-11-26 09:11:08
|
On Mon, 25 Nov 2002, suresh wrote: > Hi, > I have solved the first and third problem mentioned in my previous > email. Thanx for you guys help. For the second problem, which is finding > the instantiation of all the objects of a class (classA), I just need to > know the instantiation statements. I don't want any runtime information. > Based on the objects (object names), I have to add MACROs in the header > file of ClassA. The macro will take object name as an argument. > > Explaination: > > /* classA in file classA.h and classA.cpp */ > Class classA { > ..... > ..... > ...... > } > > /* classB in file classB.h and classB.cpp */ > class classB { > ..... > classA objA1; > classA objA2 = new classA; ^^^^^^^^^^^^ classA* objA2 ? > ..... > } > > Now I need to add MACRONAME(objA1) and MACRONAME(objA2) in the header > file of classA. Do you want to translate individual header files? It is going to be difficult, since OpenC++ sits behind preprocessor, so it does not really see separate header files. If it is enough to just add the macros in *translation unit*, that should be easy (see AppendAfterTopLevel()). Remember to instruct OpenC++ to perform second preprocessor pass. If this advice is not what you are looking for then I am afraid you have to shed some more light on why do you need those macros. > Any help is welcome. I am facing one more problem, I > tried translateNew But translateNew's arguments don't have the object > name. Because object created with "new" does not have a name. What do you mean by "object name" in: some_function(2, new classA); ? Do you really want to find all instantiations or just instantiations of some specific form (e.g. "classA* ID = new classA") and nothing else? Best regards Grzegorz ################################################################## # Grzegorz Jakacki Huada Electronic Design # # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # # tel. +86-10-64365577 x2074 Beijing 100015, China # # Copyright (C) 2002 Grzegorz Jakacki, HED. All Rights Reserved. # ################################################################## |
From: suresh <su...@em...> - 2002-11-27 23:37:07
|
Hi, I want to change the function return type from double to string. Can anybody tell me how to accomplish it? //sample code Class A { Public: A(){} ~A(){} double func(); }; double A::func() { double d; cout<<"func is called"<<endl; return d; } In this code, I want to change the function return type to char in all the places i.e. in function declaration and definition. Inside the function definition, I am able to change it but not the return type. Any help is welcome. - Thanx SureshLalwani. -----Original Message----- From: own...@cs... [mailto:own...@cs...] On Behalf Of Grzegorz Jakacki Sent: Tuesday, November 26, 2002 2:10 AM To: OpenC++ Subject: RE: [opencxx] Looking for help On Mon, 25 Nov 2002, suresh wrote: > Hi, > I have solved the first and third problem mentioned in my previous > email. Thanx for you guys help. For the second problem, which is finding > the instantiation of all the objects of a class (classA), I just need to > know the instantiation statements. I don't want any runtime information. > Based on the objects (object names), I have to add MACROs in the header > file of ClassA. The macro will take object name as an argument. > > Explaination: > > /* classA in file classA.h and classA.cpp */ > Class classA { > ..... > ..... > ...... > } > > /* classB in file classB.h and classB.cpp */ > class classB { > ..... > classA objA1; > classA objA2 = new classA; ^^^^^^^^^^^^ classA* objA2 ? > ..... > } > > Now I need to add MACRONAME(objA1) and MACRONAME(objA2) in the header > file of classA. Do you want to translate individual header files? It is going to be difficult, since OpenC++ sits behind preprocessor, so it does not really see separate header files. If it is enough to just add the macros in *translation unit*, that should be easy (see AppendAfterTopLevel()). Remember to instruct OpenC++ to perform second preprocessor pass. If this advice is not what you are looking for then I am afraid you have to shed some more light on why do you need those macros. > Any help is welcome. I am facing one more problem, I > tried translateNew But translateNew's arguments don't have the object > name. Because object created with "new" does not have a name. What do you mean by "object name" in: some_function(2, new classA); ? Do you really want to find all instantiations or just instantiations of some specific form (e.g. "classA* ID = new classA") and nothing else? Best regards Grzegorz ################################################################## # Grzegorz Jakacki Huada Electronic Design # # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # # tel. +86-10-64365577 x2074 Beijing 100015, China # # Copyright (C) 2002 Grzegorz Jakacki, HED. All Rights Reserved. # ################################################################## |
From: Grzegorz J. <ja...@he...> - 2002-12-02 08:58:09
|
> I want to change the function return type from double to string. Can > anybody tell me how to accomplish it? This is a good question. I am not sure if OpenC++ lets you do it out-of-the-box. If you figure out that you want to implement this functionality by yourself, have a look at Member::SetArgumentList() and search for 'new_args' in member.{h,cc} . Best regards GJ > > //sample code > Class A { > Public: > > A(){} > ~A(){} > double func(); > > }; > double A::func() { > double d; > cout<<"func is called"<<endl; > return d; > } > > In this code, I want to change the function return type to char in all > the places i.e. in function declaration and definition. Inside the > function definition, I am able to change it but not the return type. > > Any help is welcome. > - Thanx SureshLalwani. > > > > > > -----Original Message----- > From: own...@cs... > [mailto:own...@cs...] On Behalf Of Grzegorz Jakacki > Sent: Tuesday, November 26, 2002 2:10 AM > To: OpenC++ > Subject: RE: [opencxx] Looking for help > > On Mon, 25 Nov 2002, suresh wrote: > > > Hi, > > I have solved the first and third problem mentioned in my previous > > email. Thanx for you guys help. For the second problem, which is > finding > > the instantiation of all the objects of a class (classA), I just need > to > > know the instantiation statements. I don't want any runtime > information. > > Based on the objects (object names), I have to add MACROs in the > header > > file of ClassA. The macro will take object name as an argument. > > > > Explaination: > > > > /* classA in file classA.h and classA.cpp */ > > Class classA { > > ..... > > ..... > > ...... > > } > > > > /* classB in file classB.h and classB.cpp */ > > class classB { > > ..... > > classA objA1; > > classA objA2 = new classA; > ^^^^^^^^^^^^ > classA* objA2 ? > > > ..... > > } > > > > Now I need to add MACRONAME(objA1) and MACRONAME(objA2) in the header > > file of classA. > > Do you want to translate individual header files? It is going to be > difficult, since OpenC++ sits behind preprocessor, so it does not really > see separate header files. If it is enough to just add the macros in > *translation unit*, that should be easy (see AppendAfterTopLevel()). > Remember to instruct OpenC++ to perform second preprocessor pass. > If this advice is not what you are looking for then I am afraid you have > to shed some more light on why do you need those macros. > > > Any help is welcome. I am facing one more problem, I > > tried translateNew But translateNew's arguments don't have the object > > name. > > Because object created with "new" does not have a name. What do you mean > by "object name" in: > > some_function(2, new classA); > > ? > > Do you really want to find all instantiations or just instantiations of > some specific form (e.g. "classA* ID = new classA") and nothing else? > > Best regards > Grzegorz > > ################################################################## > # Grzegorz Jakacki Huada Electronic Design # > # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # > # tel. +86-10-64365577 x2074 Beijing 100015, China # > # Copyright (C) 2002 Grzegorz Jakacki, HED. All Rights Reserved. # > ################################################################## > > > > > > > ################################################################## # Grzegorz Jakacki Huada Electronic Design # # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # # tel. +86-10-64365577 x2074 Beijing 100015, China # # Copyright (C) 2002 Grzegorz Jakacki, HED. All Rights Reserved. # ################################################################## |