RE: [sv-ec] Re: [sv-bc] operators and data type compatibility rules

From: Arturo Salz <Arturo.Salz_at_.....>
Date: Fri Sep 15 2006 - 09:33:59 PDT
Gord,

 

I believe the LRM does say that:

 

If the elements match, the element is returned. If they do not match,
then the default

un-initialized value for that element's type shall be returned.

 

The thing to notice is that when two handles are used in the conditional
operator then the 

operator does a *handle comparison* not a deep compare of the object's
properties - this

BTW is no different from if( handle1 == handle2 ). Thus, if the handles
are the same then the 

operator returns that handle, and if they are not the same, the operator
returns null. Perhaps 

all that's missing is a note that details how class handles are handled.


 

            Arturo

 

-----Original Message-----
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of
Gordon Vreugdenhil
Sent: Friday, September 15, 2006 8:19 AM
To: Francoise Martinolle
Cc: sv-bc@eda.org; sv-ec@eda.org
Subject: [sv-ec] Re: [sv-bc] operators and data type compatibility rules

 

 

 

Francoise Martinolle wrote:

 

> Can you use logical equality and inequality for class handles which
are 

> not of the same class hierarchy or which are

> in the same class hierarchy but different derived classes?

[...]

> My opinion is that only class handles of the same class data type can
be 

> compared.

 

 

Since "==" is a handle comparison, the least restrictive approach

would be to just allow any comparison.  The LRM doesn't define rules

for this; I prefer minimal restrictions here.

 

 

> Depending on what we decide here, has an impact on the conditional 

> operator. Today the LRM section 8.18

> requires that the datatype of the true and false arms be equivalent.
The 

> LRM defines that 2 class datatypes

> are equivalent if they match, so this seems to imply that you have to 

> have the same

> class datatype. so the following ex is illegal:

>  

> b1 = (cond ? b :c); // Note that either assigment of b or c to b1 are 

> legal (not the case if I had c1 = (cond? b:c);

>  

> but you can write:

> b1 = (cond ? b : b1);

>  

> Can you write

> b1 = (cond ? b : null) ; since null does not have a datatype?

 

My view of the conditional operator for classes is that they

should allow anything on either branch that is assignment compatible

with the target.

 

 

> What happen in the above case if the condition is X? How do we compare


> each field of b and null?  They probably do not compare equal so

> the assigned value to b1 should be null.

 

I don't think that property comparison is correct for classes.  If the

*handles* are not the same, you get null, otherwise you get the handle.

This makes things reasonable when combined with the "assignment

compatible" view of the conditional operator for classes.

 

This is not what the LRM currently says, but I think it is likely

what people expect and what makes the most sense for classes.

 

Gord

 

-- 

--------------------------------------------------------------------

Gordon Vreugdenhil                                503-685-0808

Model Technology (Mentor Graphics)                gordonv@model.com
Received on Fri Sep 15 09:34:14 2006

This archive was generated by hypermail 2.1.8 : Fri Sep 15 2006 - 09:34:26 PDT