From: sdflemin <sdf...@cs...> - 2005-01-03 02:42:02
|
Hi, I have been using OpenC++ for about a year now, and recently ran into a problem. I am doing member call translations (using MemberCallTranslate), and I need to know if the member function that the call is being made on returns void. I find that when the call is made outside the member's class, the Environment does not contain the member function's symbol. A stripped-down sample that illustrates the problem follows. // THE METAPROGRAM ///////////////////////////////////////////////////////////// // File: My_Meta.mc #include <iostream> #include <mop.h> using namespace std; char* const SYNC_CMOD = "my_meta"; class My_Meta : public Class { public: My_Meta() : Class() {} My_Meta(Environment* e, char* name) : Class(e, name) {} My_Meta(Environment* e, Ptree* name) : Class(e, name) {} static bool Initialize() { RegisterMetaclass(SYNC_CMOD, "My_Meta"); return true; } Ptree* TranslateMemberCall(Environment* env, Ptree* object, Ptree* op, Ptree* member, Ptree* arglist); }; Ptree* My_Meta::TranslateMemberCall(Environment* env, Ptree* object, Ptree* op, Ptree* member, Ptree* arglist) { TypeInfo member_type; if (!env->Lookup(member, member_type)) { // <---- LOOKUP ATTEMPTED HERE!!!!!!! ErrorMessage(env, "environment cannot find member: ", member, member); exit(1); } member_type.Dereference(); ... } // THE BASE-LEVEL PROGRAM ////////////////////////////////////////////////////// // File: base_level.cpp #include <iostream> using namespace std; my_meta class Foo { public: Foo() {} void foo_do_it() { return; } }; class Bar { public: Bar(Foo* a_foo) : my_foo(a_foo) {} void bar_do_it(); private: Foo* my_foo; }; void Bar::bar_do_it() { my_foo->foo_do_it(); // <----LOOKUP FAILS ON THIS LINE!!!!!!!!!!!!!!!!!!!!!!!! } int main() { Foo* a_foo = new Foo; Bar* a_bar = new Bar(a_foo); a_bar->bar_do_it(); ... } // COMPILATION OUTPUT ////////////////////////////////////////////////////////// occ2 -c My_Meta.mc -o My_Meta.o In file included from My_Meta.mc:5: /.../include/mop.h:19:2: warning: #warning "header <mop.h> is deprecated, use <opencxx/mop.h>" g++ -o my_occ My_Meta.o -L/.../lib -locc -lltdl ./my_occ -c base_level.cpp [MetaclassRegistration(My_Meta)] [Class::RegisterMetaclass(my_meta,My_Meta] EXECUTING: g++ g++ -D__opencxx -E -o base_level.occ -x c++ base_level.cpp ---> base_level.cpp:34: environment cannot find member: foo_do_it //////////////////////////////////////////////////////////////////////////////// I have used the Environment::Dump function before the Lookup to help debug this, and sure enough, none of the Foo member functions appear in the dump. The Foo class does, however... My question to you: is this behavior a feature that I don't understand or a bug? If it's a feature, can you suggest a way for me to determine the return type of foo_do_it() in the TranslateMemberCall() function? If it's a bug, can you suggest a patch? I am happy to patch the OpenC++ source myself, but it will take me awhile to understand it. Any pointers you can give me would be great, and also, is there a document that describes the OpenC++ source design? Many Thanks, Scott PS: My thanks to the OpenC++ maintainers. It has been an extremely useful tool for me, and I am glad that the project is alive and well. |