Testers needed for ISO C Binding patch

Christopher D. Rickett crickett@lanl.gov
Thu Jun 7 17:05:00 GMT 2007


hi all,

i started looking at the comments and have some replies below.

>> +  if (expr != NULL && expr->ts.type == BT_DERIVED
>> +      && expr->ts.is_iso_c && expr->ts.derived)
>> +    if (expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_PTR
>> +        || expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_FUNPTR)
>> +      expr = gfc_int_expr (0);
>> + 
>
> A single if would be sufficient.

changed.

>
>> +  /* We need to convert the expressions for the iso_c_binding derived 
>> types.
>> +     C_NULL_PTR and C_NULL_FUNPTR will be made EXPR_NULL, which evaluates 
>> to
>> +     null_pointer_node.  C_PTR and C_FUNPTR are converted to match the
>> +     typespec for the C_PTR and C_FUNPTR symbols, which has already been
>> +     updated to be an integer with a kind equal to the size of a (void *). 
>> */
>> +  if (expr->ts.type == BT_DERIVED && expr->ts.derived
>> +      && expr->ts.derived->attr.is_iso_c)
>> +    {
>> +      if (expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_PTR
>> +          || expr->symtree->n.sym->intmod_sym_id == 
>> ISOCBINDING_NULL_FUNPTR)
>> +        {
>> +          /* Try simply setting expr_type to EXPR_NULL, which should 
>> result
>> +             in null_pointer_node being used below.  */
>> +          expr->expr_type = EXPR_NULL;
>
> So, does it work or not? :-)

yes.  :-)  changed.

>> +  /* Initialize the derived type as being C interoperable.
>> +     If we find an error in the components, this will be set false.  */
>> +  derived_sym->ts.is_c_interop = 1;
>> +  +  /* Loop through the list of components to verify that the kind of
>> +     each is a C interoperable type.  */
>> +  do
>> +    {
>> +      /* BIND(C) derived types can't have derived types in them unless
>> +	 they're c_ptr or c_funptr. J3/04-007, Section 15.2.3, C1502.  */
>> +      if (curr_comp->ts.type == BT_DERIVED
>> +	  && curr_comp->ts.derived->ts.is_iso_c != 1)
>> +        {
>> +          /* This should be allowed; the draft says a derived-type can not
>> +             have type parameters if it is has the BIND attribute.  Type
>> +             parameters seem to be for making parameterized derived types.
>> +             There's no need to verify the type if it is c_ptr/c_funptr. 
>> */
>> +          retval = verify_bind_c_derived_type (curr_comp->ts.derived);
>
> This will break for POINTER components, unless I'm mistaken.
> type t
>  type (t), pointer :: next
> end type t
> -> infinite recursion
> I also believe this will break for ALLOCATABLE array components -- they are 
> not C interoperable, but I don't see it checked here.

i think i've fixed the infinite recursion case.  what case are you 
referring to for ALLOCATABLE components?


> Hm, reading forther I realize that zou have the appropriate checks, just not 
> in place where they're are performed for derived type components: these two 
> should be moved to hte beginning of the loop.
>
>> +	  /* The components can not be pointers (fortran sense).  + 
>> J3/04-007, Section 15.2.3, C1505.	*/
>> +	  if (curr_comp->pointer != 0)
>> +	    {
>> +	      gfc_error ("Component '%s' at %L cannot have the "
>> +                         "POINTER attribute because it is a member "
>> +                         "of the BIND(C) derived type '%s' at %L",
>> +                         curr_comp->name, &(curr_comp->loc),
>> +                         derived_sym->name, &(derived_sym->declared_at));
>> +	      retval = FAILURE;
>> +	    }
>> +
>> +	  /* The components can not be allocatable.
>> +	     J3/04-007, Section 15.2.3, C1505.	*/
>> +	  if (curr_comp->allocatable != 0)
>> +	    {
>> +	      gfc_error ("Component '%s' at %L cannot have the "
>> +			 "ALLOCATABLE attribute because it is a member "
>> +			 "of the BIND(C) derived type '%s' at %L",
>> +			 curr_comp->name, &(curr_comp->loc),
>> +			 derived_sym->name, &(derived_sym->declared_at));
>> +	      retval = FAILURE;
>> +	    }
>> +	}
>> +      +      curr_comp = curr_comp->next;
>> +    } while (curr_comp != NULL);


thanks for the feedback.

Chris



More information about the Fortran mailing list