Procedure Pointers: a first patch

Tobias Burnus burnus@net-b.de
Sat Jun 14 19:27:00 GMT 2008


Hello Janus,

Janus Weil wrote:
> These are due to my present inability to distinguish between:
>   
>> interface
>>  function f()
>>    integer, pointer :: f
>>
>> ***
>>
>> interface
>>  function f()
>>    integer :: f
>>  end function
>> end interface
>> pointer :: f
>>     
And there is:

interface
 function f()
   integer :: f
   pointer :: f
 end function
end interface
pointer :: f

which is a procedure pointer to a pointer-returning function.


> My idea for solving this would be to make the proc_pointer field
> wider, so that it can hold an additional state, which would indicate
> that the symbol can definitely *not* be a procedure pointer. E.g. one
> could use an enumeration like
>
> typedef enum
> {
>   PROCPTR_MAYBE = 0,
>   PROCPTR_NO,
>   PROCPTR_YES
> }
> is_procptr;
>   
My feeling is that one does not need a tri-state, see below.

> So if a symbol has attr.pointer, then the default value PROCPTR_MAYBE
> would indicate that this symbol *could* be a procedure pointer (e.g.
> in the second case above). At some late resolving stage we would have
> to convert this into PROCPTR_YES and delete attr.pointer.
> For the first test case above, we would have to detect that the
> POINTER attribute is specified inside the function body, which means
> that it can not be a procedure pointer, and set PROCPTR_NO. With the
> present patch we cannot make this distinction (i.e. we have no way to
> remember this state).
>   

Sounds OK, however, one needs to implement such that also the third case 
work.

Let's try whether I can come up with a scheme where pointer:1 + 
procpointer:1 is enough.

In resolve.c do:

if (sym->attr.pointer && sym->attr.external && sym->attr.if_source != 
IFSRC_IFBODY)
  {
    sym->attr.pointer = 0;
    sym->attr.procpointer = 1;
  }


In decl.c's gfc_match_function_decl:

if (gfc_current_state () == COMP_INTERFACE && sym->attr.pointer)
  {
    sym->attr.pointer = 0;
    sym->attr.procpointer = 1;
  }

and in decl.c's attr_decl1:

if (gfc_current_state () != COMP_INTERFACE
    && sym->attr.if_source == IFSRC_IFBODY)
  {
    current_attr.pointer = 0;
    current_attr.procpointer = 1;
  }

I think this should work - or have I missed something?

Tobias

PS: It should be enough to write to fortran@ (and when the patch is 
ready to gcc-patches@) without CCing all the people. At least in my 
case, I got the email trice.



More information about the Fortran mailing list