From: Stefan S. <se...@sy...> - 2004-07-08 22:46:59
|
Grzegorz Jakacki wrote: >> And I don't see a problem having two separate constructors, one operating >> on Ptree pointers, the other on the typed counterpart. > > > I am not sure if you get the exact picture. The "untyped" constructor > does not construct the NonLeaf auxiliary nodes. It is just: > > > PtreeIfStatement(Ptree* p, Ptree* q) : NonLeaf(p, q) {} > > If we have another, "typed" constructor like this one: > > PtreeIfStatement( > PtreeExprStatement* cond > , PtreeExprStatement *th > , PtreeExprStatement* el > ) > : NonLeaf(cond, new NonLeaf(th, new NonLeaf(el, NULL))) > {} > > Then, as you noticed, there is a question of who owns auxiliary > NonLeaf nodes (and, consequently, if ~PtreeIfStatement should delete them). right, but I didn't mean the 'typed constructor' to construct any nodes himself, but rather to take 'PtreeExprStatement' arguments instead of 'Ptree'. The ownership semantics remains the same. >> That sounds indeed like a bad idea. Either Ptrees >> own their children, or they don't. > > > I agree. However I am not sure what you mean by "child". What is a > "child" of PtreeIfStatement node? Do you consider "else-part" to be a > "child" of PtreeIfStatement node? yes. > It is also not clear to me if you would like to keep the existing > representation of if-statement as three physical nodes or if you > eventually would like to modify PtreeIfStatement so that it becomes > > struct PtreeIfStatement > { > ... > PtreeExprStatement *cond_, *then_, *else_; > }; the latter. Regards, Stefan |