[m-rev.] [dotnet-foreign] diff: handle properties

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jun 16 14:30:39 AEST 2001


On 16-Jun-2001, Peter Ross <petdr at cs.mu.OZ.AU> wrote:
> 
> Treat functions with the name get_PropertyName and predicates with the
> name set_PropertyName as properties in the generated IL.

What if ordinary Mercury functions happen to have those names?
I don't think it is always right to treat such things as properties.
In particular, the code below calls error/1 in some cases which I think
are inappropriate.

Also, wouldn't it be better to map Mercury field functions
(i.e. "foo"/"foo:=") to .NET properties, rather than (or perhaps
as well as?) mapping "get_foo"/"set_foo" to properties?

> +:- func merge_properties(list(class_member)) = list(class_member).

A comment explaining (in more detail than the name)
what that function does would be helpful.

> @@ -814,7 +872,28 @@
>  	{ MethodDefn = make_method_defn(InstrsTree) },
>  
>  	{ MethodHead = methodhead(MethodAttrs, Id, ILSignature, ImplAttrs) },
> -	{ ILClassMember = method(MethodHead, MethodDefn) }.
> +	{ Method = method(MethodHead, MethodDefn) },
> +
> +	{ (Id = id(IdName), string__append("get_", PropertyName, IdName)) ->
> +		ILSignature = signature(_, ReturnType, _),
> +		( ReturnType = simple_type(SimpleType) ->
> +			ILDSType = ilds__type([], SimpleType)
> +		;
> +			error("mlds__to_il: no return type for get method")

It should not be an error to define a Mercury procedure named "get_xyz"
which doesn't have a return type.

> +		),
> +		Property = property(ILDSType, id(PropertyName),
> +				yes(MethodHead), no),
> +		ILClassMember = [Method, Property]
> +	; (Id = id(IdName), string__append("set_", PropertyName, IdName)) ->
> +		ILSignature = signature(_, _, ILParams),
> +		ILDSType - _Name = list__det_head(list__reverse(ILParams)),

Likewise here it should not be an error to define a Mercury procedure
named "set_xyz" with no parameters.  So you shouldn't call list__det_head here.
(And you should use list__last rather than list__head(list__reverse(...)))

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list