[sv-bc] Issue 131 / Mantis 2611 -- package/class lookup

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Fri Apr 24 2009 - 08:40:41 PDT
The question in 2611 is as follows:

    package p;
       integer i = 0;
    endpackage // p

    class p;
       static integer i = 1;
    endclass

    module top;
      initial
         $display (p::i);    // Is this class p or package p?
    endmodule


This isn't answered directly, but I think that the two
following statements imply an answer:

Sect 26.3
     The search algorithm shall be repeated for each outer lexical
     scope until an identifier is found that matches the reference or
     there are no more outer lexical scopes, the compilation unit scope
     being the final scope searched.

Sect 23.7.1
     The package or class prefix shall be resolved using the normal
     resolution rules.


The question is whether the package "p" is part of the compilation
scope or whether it is at a more "global" outer scope.  I think
that part is reasonably clear -- design elements are not "scoped" in
the same manner as other declarations and are visible design-wide.
The package name isn't really a part of the compilation unit scope
(it is in a different name space).

Given all of that, I think that one must interpret to rules
as implying that p::i in the example binds to the class
(which is scoped within the compilation unit) before looking
for the package design element.

This could certainly be clarified.

One possible change for 23.7.1 is as follows:
   CHANGE:
     The package or class prefix shall be resolved using the normal
     resolution rules.
   TO:
     If the prefix name is resolved using the normal scope resolution
     rules, the '::' shall denote the class resolution operator.  Otherwise
     the '::' shall denote the package resolution operator.

But an implication of the above is that

    package C;
      int y;
    endpackage
    module top;
      int C;
      int x = C::y;
    endmodule

would be illegal as "C" would bind to the integer declaration
and not resolve.

I don't know if everyone prefers that behavior(I do).

If you claim that you must pay attention to the *type* of
C then you have issues with:
    package C;
      int y;
    endpackage
    module top #(type T);
      T C;
      int x = C::y;
    endmodule

Given that this is purely lexical search, I think it makes the
most sense to say that '::' prefix resolution is eager and
does package resolution only if no other intervening name
exists.

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 Fri Apr 24 08:42:15 2009

This archive was generated by hypermail 2.1.8 : Fri Apr 24 2009 - 08:43:19 PDT