Re: [sv-bc] Task function identifier searching rule

From: Steven Sharp <sharp_at_.....>
Date: Mon Jan 12 2009 - 16:52:13 PST
>From: Surya Pratik Saha <spsaha@cal.interrasystems.com>

>Hi Steven,
>I did not see anything in the LRM as you have commented. So if I write 
>the example in a little bit different way by putting the import before 
>initial block:
>
>package p;
>function int f();
>return 1;
>endfunction
>endpackage
>module top;
>int x;
>if (1) begin : b
>import p::*; // line 3
>initial x = f(); // line 2
>end
>function int f();
>return 1;
>endfunction
>endmodule
>
>Then as per your comment, still top.f will be selected not p::f.

No.  The reference to f() after the import causes the name f to be
imported from p into the scope top.b, and used by the reference to f().
There will be no hierarchical name resolution.  Note that if you had

if (1) begin : b
initial y = f(); // my new line
import p::*; // line 3
initial x = f(); // line 2
end

That the f in my new line will also resolve to p::f.  The reference
to f() after the import causes the name f to be imported into top.b.
Then the hierarchical resolution for the f in my new line will find
that name f first in the search up the hierarchy.

This occurs even though the import appears after my new line.  The rule
for hierarchical name resolution does not depend on the position of the
import.  It depends on whether the name appears in the scope that it is
searching.  That may in turn depend on the position of the import with
respect to symbol references, but the hierarchical name resolution does
not directly depend on the position of any imports.

You need to recognize that this is a two stage process, or you will
not understand it.

>Also I think by "It doesn't look for imports" you want to mean 
>wildcard import only, not explicit import.

No, I mean it doesn't look for imports.  It doesn't matter whether they
are wildcard imports or explicit imports.  It doesn't look for either
one.  It looks for the name in the scope.

An explicit import will cause the name to be in the scope, so the name
resolution is sure to find it.  But that is not because the name
resolution looked for the import.  It is because the name resolution
looked for the name in the scope and found it.  It doesn't care whether
the name got into the scope because of an explicit import or wildcard
import or because it was declared in the scope.

Steven Sharp
sharp@cadence.com


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon Jan 12 16:53:22 2009

This archive was generated by hypermail 2.1.8 : Mon Jan 12 2009 - 16:54:09 PST