From: Grzegorz J. <ja...@ac...> - 2004-12-09 11:02:51
|
Scott Shumaker wrote: > I've been writing some code with OpenC++, and have run into the > following problem: > > testClass class A > { > int mData; > void Foo() > { > mData = 7; > } > }; > > I've written a TranslateMemberWrite for testClass, which gets called > when mData = 7 is referenced. However, when I call > InsertBeforeStatement with some additional code, nothing gets > inserted. > > On the other hand, this DOES work: > > class A > { > int mData; > void Foo(); > }; > > > void A::Foo() > { > mData = 7; > } > > Looking through the code, the problem arises in ClassWalker.cc, line > 757 (your line #s may be slightly different. The code in question is > as follows: > > metaobject = GetClassMetaobject(type); > if(metaobject != 0){ > exp2 = metaobject->TranslateMemberWrite(env, object, op, > member, assign_op, right); > return CheckMemberEquiv(exp, exp2); > } > } > else if((scope = env->IsMember(left)) != 0){ > metaobject = scope->IsClassEnvironment(); > if(metaobject != 0){ > exp2 = metaobject->TranslateMemberWrite(env, left, Second(exp), > right); > > return CheckEquiv(exp, exp2); > } > > The code has dropped into the else if case. Looking at the variables, > the environment variable env has a ClassBodyWalker, while the current > context of the function is in a ClassWalker. The > InsertBeforeStatement thus inserts the code into the ClassBodyWalker's > before_function list, which is never applied or copied over to the > ClassWalker's before_function list, so it never gets inserted. > > This probably would happen with any other code you write inside of an > inlined function body - InsertBeforeStatement, etc wouldn't work. > > Any suggestions for a fix? Sorry, I don't have much time to look into it now. Can you get hold on the right walker at the point where TranslateMemberWrite is called? BR Grzegorz |