[patch, fortran] use vec<> in frontend-passes.c

Thomas Koenig tkoenig@netcologne.de
Sun Aug 24 12:49:00 GMT 2014


Hi,

Trevor Saunders wrote:

>> -static gfc_expr ***expr_array;
>> -static int expr_size, expr_count;
>> +static vec<gfc_expr **> expr_array = vec<gfc_expr **>();
> 
> that's usually written as just static vec<T> foo; vec doesn't actually
> have ctors, and 0 initialization works fine.

Fixed (also below).


>> +  //  doloop_list = ;
> 
> what is this comment supposed to mean?

Leftover from a commented piece of code, removed.

>>    doloop_warn (ns);
>> -  XDELETEVEC (doloop_list);
>> +  doloop_list.truncate (0);
> 
> .release () would be more typical.

Changed (also below).

>> -  for (i=1; i<expr_count; i++)
>> +  for (i=1; expr_array.iterate (i, &ei); i++)
> 
> FOR_EACH_VEC_ELT, though Its not really clear to my why that's better
> than
> size_t length = vec.length ();
> for (size_t i = 0; i < length; i++)

Done in a slightly different way (see the patch).


>> +      for (j=0; j<i && expr_array.iterate (j, &ej); j++)
> 
> the .iterate call is useless since j must be < i, and the vector is
> at least i long right?

I was using the iterate call to get the current value of the vector.
I have now replaced this with using expr_array[j] below.

Steve wrote:

> Does this fix a bug in gfortran?  "If it is not broken,
> don't fix it".

It doesn't fix a bug by itself, but it clears up the code by
avoiding hand-rolled memory management in two places.  I also
want to do some more things in front-end optimization which
require vectors, so I think it makes sense to have a consistent
style, in a single file at least :-)

Therefore: OK for trunk?

	Thomas

2014-08-24  Thomas Koenig  <tkoenig@gcc.gnu.org>

        * frontend_passes (expr_array):  Replace by vec template.
        (expr_size):  Remove.
        (expr_count):  Remove.
        (doloop_list):  Replace by vec template.
        (doloop_size):  Remove.
        (gfc_run_passes):  Adjust to use of vec template.
        (cfe_register_funcs):  Likewise.
        (cfe_expr_0):  Likewise.
        (doloop_code):  Likewise.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: p3.diff
Type: text/x-patch
Size: 5479 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140824/10bcd8aa/attachment.bin>


More information about the Fortran mailing list