Re: [sv-ec] reference to outer scope name from nested class

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Tue Dec 18 2007 - 07:37:14 PST
This is all explicitly covered in 8.22 of 1800-2008 draft 4:

     Nested classes shall have the same access rights as methods
     do in the containing class. They have full access rights to
     local and protected methods and properties of the containing
     class. Nested classes have lexically-scoped, unqualified
     access to the static properties and methods of the containing
     class. They shall not have implicit access to non-static
     properties and methods except through a handle either passed to
     it or otherwise accessible by it. There is no implicit this
     handle to the outer class.

I think the 2008 version has resolved the issue completely.

Gord.

Steven Sharp wrote:
>> From: "danielm" <danielm@aldec.com.pl>
> 
[...]

> 
>> 2. Problem with classes declaration nested in classes:
>>
>>
>>    class C;
>>        int i;
>>        static int si;
>>        class CC;
>>                function new();
>>                    $display(i,,si);
>>                endfunction
>>        endclass
>>    endclass
>>    
>>    C:CC cc=new;
>>
>> Should non-static properties and function declared in outer class be visible
>> in inner class? 
>> IMHO  in above only the static property 'si'  should be accesible (like i C
>> language) -  this should be clearly pointed out by LRM.
>> If we allow reference to 'i' what will be the value if C::i not exists?
> 
> The LRM has a problem here.  It implies that properties and methods
> declared in the outer class will be visible in the inner class, since
> these are nested scopes.  However, this cannot work for non-static
> members.  Accessing a non-static property of the class requires having
> a handle to an object of a class type.  Inside the non-static methods
> of the class, this is provided by the 'this' handle with which the method
> was invoked.  But inside a method of the nested class, we do not have a
> 'this' handle of the outer class.  So we cannot allow access to the
> non-static properties of the outer class from the inner class.
> 
> Similarly, a call to a non-static method of the outer class from another
> non-static method of the outer class is done via the 'this' handle.
> Since a method of the inner class does not have a 'this' handle of the
> outer class type, it should not call a non-static method of the outer
> class.
> 
> As you say, the inner class methods should only have access to the static
> members of the outer class, and this should be made clear in the LRM.
> 
> 
> Steven Sharp
> sharp@cadence.com
> 
> 

-- 
--------------------------------------------------------------------
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 Tue Dec 18 07:37:58 2007

This archive was generated by hypermail 2.1.8 : Tue Dec 18 2007 - 07:38:37 PST