Re: [sv-ec] Mantis 1857 - extern method types for parameterized classes

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Wed Jun 20 2007 - 11:07:29 PDT
Arturo Salz wrote:

I reordered the question since I have a longish nasty case
for the other part

 >
 > 	function #(T) T C::get();
 >
 > One final question, is the "type" keyword needed?

I think so.

One needs to differentiate between type and value for "b" in:

    function #(a,b) a[b] C::get();

One could potentially defer the semantics but there may be
more convoluted types involving other specializations for
which there might be deeper ambiguities.  I'd have to think
for a while about that but the possibility makes me nervous
enough that I'd want to require "type" so that we KNOW
what the types are versus the values.  If in the future we
became convinced that we could live with the specifier,
we could make it optional.  Of course if I knew the name
"C" as well, I'd be happy without "type"... :-)


> I agree with Mike's comments (and sympathize with Neil's ordering). I
> believe that we could accept both forms (3) and (4), and consider from
> (4) as a shorthand for (3). The shorthand form avoids in a somewhat
> elegant way the problem of specifying the wrong (i.e., different)
> default parameter type.
> 
> In particular, as Gord mentioned, form (3) - and (4) - are very
> symmetric to the look of parameterized tasks and functions. The change I
> propose is to allow form (4) for parameterized tasks/functions, and
> since this form provides no default specialization, such tasks/functions
> would *always* require an explicit specialization - something that I
> consider a good methodology.

I would disagree with the "no default" rule since that is so irregular
with everything else.  I might go along with disallowing implicit
specialization of parameterized functions.  I.e. for a non-method
parameterized function we could have:
     function #(type T = int) T f(); ...
   ...

     f#()()
but not
     f()


BTW, there is a bit of potential future ugliness lurking here.  What
would the syntax be for an extern parameterized function in
a parameterized class?

ie.
     class C #(type T = int);
        extern function #(type T2 = int) T2 f(T2 x, Ty);
     endclass

In C++ the following is the corresponding code:

    #include <iostream>
    using namespace std;

    template <class T> class C {
    public:
        template<class T2> T2 f(T x, T2 y);
    };

   template <class T> template<class T2> T2 C<T>::f(T x, T2 y) {
      cout << x << " " << y << endl;
      return 1;
   }

   main()
   {
      C<int> c;
      c.f(1,2);
      c.f(1,2.7);
   }


I wouldn't mind making this illegal in SV (requiring
non-extern methods in such cases) but if anyone cares
about this, we'd need to have some correspondingly ugly
syntax to deal with it.

Gord
-- 
--------------------------------------------------------------------
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 Wed Jun 20 11:07:41 2007

This archive was generated by hypermail 2.1.8 : Wed Jun 20 2007 - 11:07:59 PDT