From: Sven R. <rei...@ma...> - 2002-12-11 14:41:18
|
On Wed, 11 Dec 2002, Baptiste Lepilleur wrote: > Not so easy. You need to find where a temporary is being reassigned to which > means some additional expression analysis. I think that more 'thinking' need > to be done concerning this refactoring for C++. For example: > > double temp = 2 * (height_ + width_); > print( temp ); > computeArea( height_, width_, temp ); > ... > > void computeArea( double height, double width, double &area ) > { > area = height + width; > } > > computeArea() is an indirect assignment to the local variable temp... We can start by looking at direct assignments. Nobody says that this refactoring has to catch all hidden assignments to the temporary. Direct assignments are of the form <name> = <expr>; The first of those should be transformed to <type> <name> = <expr>; and all prior occurences of <name> need to be renamed. If we deal with "indirect assignments", we need a global analysis of the code (i.e., find the definition of computeArea). > > Also, I don't get what you means by 'determining the type of a variable'. > For a given local variable identifier, we can already find its declaration > (see ScopeHolderTest) and therefore its type. So the real issue is > determining where a temporary is being reassigned to. I tried playing around with this; maybe the issue was getting access to the contents of a boost::weak_pointer. Sven. -- Sven Reichard Dept. of Math. Sci. University of Delaware rei...@ma... |