Re: [sv-ec] Where can you use "this"?

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Mon Sep 08 2008 - 09:10:48 PDT
Francoise,

I don't believe that you can use "this" to initialize class properties
other than within the constructor.  So the example you have would not
be legal in the current LRM.

This question relates indirectly to other discussions related to
defaults of methods.  For example, can you have something like
the following:
    function void new (MyType me = this);
    endfuncion

I'd like the answer to be consistent with the answer to the legality of
the following:
    function void new (int a = 1, int b = a);
    endfuncion


My view (reflected indirectly by the LRM) is that "this" behaves like
an implicit formal to all non-static methods which is why you
can't use it for an initialization expression.  The use of "this" as
even a default would then be related to the question of using other
formals in default expressions.

The point has been made in the past that the current LRM requires that
defaults be resolved in the context of the scope containing the
routine so I think that current LRM wording would most consistently
be treated as disallowing the use of "this" even as the default
of task/function formal.

I would not be opposed to relaxing the rules for defaults nor would I
be opposed to allowing "this" as an initializer for a non-static property.
But I do think that the current LRM disallows both and that such a
change would have to be in the next PAR.

Gord.


Francoise Martinolle wrote:
> The LRM says that you can only use "this" within non static class methods.
> But it seems that we should be able to write to use it to initialize 
> automatic class properties.
> Should the LRM test be fixed?
>  
> module top;
>   class C;
>      C m = this;
>   endclass
> endmodule
>  
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.

-- 
--------------------------------------------------------------------
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 8 09:12:30 2008

This archive was generated by hypermail 2.1.8 : Mon Sep 08 2008 - 09:12:42 PDT