|
From: Baptiste L. <gai...@fr...> - 2002-12-11 18:59:49
|
----- Original Message -----
From: "Sven Reichard" <rei...@ma...>
To: "CppTool Mailing List" <Cpp...@li...>
Sent: Wednesday, December 11, 2002 3:41 PM
Subject: Re: [Cpptool-develop] SplitTemporary refactoring
> 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>;
Sound fine for me. Limiting ourselves to finding assignement to the local
variable and splitting each time, this would make thing simpler.
[...]
> > 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.
See the smart_ptr documentation the boost/libs directory. Basically:
- boost::make_shared( weakPointer ) creates a shared_ptr, returning a null
pointer is the pointed object not longer exist.
- shared_ptr constructor also take a weak_ptr, but throw an exception is the
pointed object no longer exist.
Baptiste.
>
> Sven.
>
> --
> Sven Reichard
> Dept. of Math. Sci.
> University of Delaware
> rei...@ma...
|