Re: [sv-ec] forward declaration of a parameterized classes

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Mon Sep 10 2007 - 07:08:45 PDT
Don,

Right now the syntactic form:
    typedef class b_c #(type T int);
that you tried is not permitted by the LRM.

The other form:
    typedef class b_c;
is conceptually problematic at best.

Let's take a closer look at what you did.  This is
a toy example so you may have just oversimplified,
but I'll work with the example as given.

In the example, it appears that the "set" routines
in each of a_c and b_c are intended to operate on the other's
type.  However, I think that you intended to couple the
types and you haven't done that.

The prototype for "set" in a_c is:
     function void set (b_c b);
but "b_c" is the default specialization of b_c and NOT
b_c#(T) which is what I think you intended.

So really what I think you want is:

   class a_c #(type T = int);
     int a1;
     function void set (b_c#(T) b);     <<<<<<<<<<<
       b.b1 = 5;
     endfunction
   endclass

   class b_c # (type T = int);
     int b1;
     function void set (a_c#(T) a);     <<<<<<<<<<<
       a.a1 = 4;
     endfunction
   endclass

You probably want "a1" and "b1" to be of type "T" in
each case as well.

I think that is crucial that the forward include the
information that the forward type is a parameterized
class type so that the intent and consistency of
the code is clear.


I would fully support extending the syntax of a forward
typedef to permit the form that you tried:
    typedef class b_c #(type T int);

That would be a simple and effective change that clearly
expresses intent and consistency while permitting what
you are trying to do.

I would not support allowing "typedef class b_c;" to be
treated as a parameterized class.


Gord.



Neil Korpusik wrote:
> <I think this was meant to go to the alias>
> 
> -------- Original Message --------
> Subject: 	forward declaration of a parameterized classes
> Date: 	Fri, 07 Sep 2007 16:09:25 -0700
> From: 	Don Mills <mills@lcdm-eng.com>
> Reply-To: 	mills@lcdm-eng.com
> Organization: 	LCDM Engineering
> To: 	owner-sv-ec@eda.org
> 
> 
> 
> Can I combine section 8.24 and 8.25 (draft 3a) for the following code?
> IE can I use forward declarations on classes that are parameterizable?
> I don't see anything in the LRM that prevents this.
> 
> program test;
>   //typedef class b_c #(type T int);
>   typedef class b_c;
> 
>   class a_c #(type T = int);
>     int a1;
>     function void set (b_c b);
>       b.b1 = 5;
>     endfunction
>   endclass
> 
>   class b_c # (type T = int);
>     int b1;
>     function void set (a_c a);
>       a.a1 = 4;
>     endfunction
>   endclass
> endprogram
> 
> 
> 

-- 
--------------------------------------------------------------------
Gordon Vreugdenhil                                503-685-0808
Model Technology (Mentor Graphics)                gordonv@model.com


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon Sep 10 07:09:01 2007

This archive was generated by hypermail 2.1.8 : Mon Sep 10 2007 - 07:09:32 PDT