RE: [sv-ec] Matching defaults

From: Arturo Salz <Arturo.Salz_at_.....>
Date: Fri Jul 18 2008 - 15:55:43 PDT
Dave,

 

One correction: C++ does not require default arguments to be constant;
it allows variables and expressions.

 

Also, you forgot to mention the biggest difference between C++ and SV
default arguments. In C++, default arguments are interpreted in the
context of the caller, whereas in SV they are interpreted in the context
of the declaration. SV 3.1 had the same semantics as C++, but was later
changed to use the declaration context to avoid having the same
expression interpreted differently in the caller's context.

 

I'd say that in the case of out-of-body method declarations, the LRM is
ambiguous since there are effectively two declarations - the prototype
(class) definition and the method definition itself. Also, note that the
sentence:

 

The out of block method declaration must match the prototype declaration
exactly; the only syntactical difference is that the method name is
preceded by the class name and scope operator (::).

 

Came from the SV-3.1 LRM, in which default arguments had different
semantics. What seems to have happened is that when the committee
changed the context of interpretation from caller to declaration, we
failed to revise that sentence and specify whether default arguments
could be specified in both declarations, in either, or must be specified
in both. I don't believe the intent was to restrict the language to
require specification in both declarations, which would be consistent
with other languages that provide such a feature.

 

Like Gord, I'm in favor of explicit verbiage stating that a body default
*if present* must match the prototype, but  it isn't required. That
change would align the semantics of virtual methods and out-of-body
methods. But, until such time, I would not consider a missing body
default an error, and instead assume that it is consistent from the
semantics stated for virtual methods. Forcing users to enter the default
twice serves no useful purpose.

 

            Arturo

 

-----Original Message-----
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of
Rich, Dave
Sent: Friday, July 18, 2008 8:16 AM
To: Mirek Forczek; Bresticker, Shalom; Surya Pratik Saha; sv-ec@eda.org
Subject: [sv-ec] Matching defaults

 

(I've changed the subject line and removed sv-bc from the discussion)

 

There are a few key differences with the functionality of default

arguments between C++ and SV. 

 

Because SV has argument referencing by name, not just by position, SV

argument names much match, so defaults can be placed on any argument,

not just the trailing one as in C++. 

 

C++ allows you to specify defaults in the prototype, and add more

defaults in the actual definition, but not override an existing default.

 

C++ requires constant default values, while SV allows non-constant

expressions. With non-constant expressions came the desire to override

the default expressions.

 

When you have call to a virtual method in SV, the compiler needs to know

exactly which arguments are required by name and which ones are

optional, not just the total number of arguments. This is why presence

of a default is required to match for a virtual method in a subclass,

while an override of the default is not required to match to allow an

override.

 

For extern (out-of-class-body) declarations, I've seen code written for

at least 3 different implementations. Default allowed in: prototype

only, definition only, and required in both. The latter being what's

currently required by the LRM.

 

Dave

 

 

 

 

> -----Original Message-----

> From: owner-sv-bc@server.eda.org [mailto:owner-sv-bc@server.eda.org]

On

> Behalf Of Mirek Forczek

> Sent: Friday, July 18, 2008 2:53 AM

> To: 'Bresticker, Shalom'; 'Surya Pratik Saha'; sv-ec@server.eda.org;

sv-

> bc@server.eda.org

> Subject: [sv-bc] RE: [sv-ec] Wrong SV code in VMM

> 

> Hi,

> 

> ad 2)

> 

> Please note that in C++ in example having the default in both places

is

> considered as an error.

> 

> And such resolution is reasonable somehow: once you allow the default

to

> be

> specified in two places, there is a risk that one othe placed will be

> updated later and the other not,

> which will lead to hard-tracking bugs.

> 

> Regards,

> Mirek

> 

> -----Original Message-----

> From: owner-sv-ec@server.eda.org [mailto:owner-sv-ec@server.eda.org]

On

> Behalf Of Bresticker, Shalom

> Sent: 18 lipca 2008 11:41

> To: Surya Pratik Saha; sv-ec@server.eda.org; sv-bc@server.eda.org

> Subject: RE: [sv-ec] Wrong SV code in VMM

> 

> Hi,

> 

> You're correct, there is no SV 1800-2008 LRM.

> 

> 1. You're correct, `" is only defined in macro text. In fact, this is

one

> of

> the gotchas appearing in the SV Gotchas paper I will be presenting at

> Boston

> SNUG in September.

> 

> 2. In Draft 6, 8.23 says,

> 

> "The out-of-block method declaration shall match the prototype

declaration

> exactly; the only syntactical difference is that the method name is

> preceded

> by the class name and the class scope resolution operator ::."

> 

> That seems to require that the default appear in both places.

> 

> Regards,

> Shalom

> 

> > -----Original Message-----

> > From: owner-sv-ec@server.eda.org

> > [mailto:owner-sv-ec@server.eda.org] On Behalf Of Surya Pratik Saha

> > Sent: Friday, July 18, 2008 12:19 PM

> > To: sv-ec@server.eda.org; sv-bc@server.eda.org

> > Subject: [sv-ec] Wrong SV code in VMM

> >

> > Hi,

> > I am not sure whether this is the appropriate body to discuss about

> > this matter, but since it is related to SV, so I am sending the

mail.

> > If it is not appropriate, please ignore this.

> >

> > I have downloaded the freely available VMM release (version 1.0.1),

> > where it is mentioned it is compatible with SV 1800-2008. But I

don't

> > think there is any SV 1800-2008 LRM.

> > Or do I miss any?

> >

> > Moreover, I have seen following problems in that VMM.

> > 1) A special syntax used with `".

> > Consider the e.g:

> > `define VMM_CHANNEL xxx

> > module top;

> >     initial begin

> >         $display("VMM_CHANNEL %s", `"`VMM_CHANNEL`");

> >     end

> > endmodule

> >

> > Here `" is used in normal position. But as per SV 1800-2005 LRM, `"

> > can only be used in macro text. Is it changed later?

> >

> > 2) Function declaration having default argument, though body does

not

> > have.

> > Consider the e.g.:

> > module top;

> >     class C;

> >         extern function int f(input x, input y = 1);

> >         endclass

> >     function int C::f(input x, input y);

> >         f = x;

> >     endfunction

> >     int x;

> >     C c;

> >     initial begin

> >         x = c.f(1);

> >     end

> > endmodule

> >

> > Where for 'y', the function declaration is having default argument

> > value, whereas the body does not have. I am not sure whether LRM

> > supports that or not.

> >

> > --

> > Regards

> > Surya

> ---------------------------------------------------------------------

> Intel Israel (74) Limited

> 

> This e-mail and any attachments may contain confidential material for

the

> sole use of the intended recipient(s). Any review or distribution by

> others

> is strictly prohibited. If you are not the intended recipient, please

> contact the sender and delete all copies.

> 

> 

> --

> This message has been scanned for viruses and dangerous content by

> MailScanner, and is believed to be clean.

> 

> 

> 

> --

> This message has been scanned for viruses and

> dangerous content by MailScanner, and is

> believed to be clean.

 

 

-- 

This message has been scanned for viruses and

dangerous content by MailScanner, and is

believed to be clean.

 

 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Jul 18 15:58:33 2008

This archive was generated by hypermail 2.1.8 : Fri Jul 18 2008 - 15:59:11 PDT