[nem-en] usesite
Vladimir Reshetnikov
v.reshetnikov at gmail.com
Wed Feb 14 14:38:31 CET 2007
On 2/13/07, Kamil Skalski <kamil.skalski at gmail.com> wrote:
> It makes the created name bind to fields in class, breaking hygiene of
> macro generated expressions. This makes compiler look at the name as
> it was created plainly in contex of macro use-site.
I began to fix bug 892. I want to exclude null values from hashcode computation.
So, I changed macro in the following way:
[Nemerle.MacroUsage (Nemerle.MacroPhase.WithTypedMembers,
Nemerle.MacroTargets.Class,
Inherited = false, AllowMultiple = false)]
macro StructuralHashCode (t : TypeBuilder) {
def flds = t.GetFields (BindingFlags.Public %|
BindingFlags.NonPublic %|
BindingFlags.Instance %| BindingFlags.DeclaredOnly);
def body =
List.FoldLeft (flds, <[ 0 ]>, fun (x : IField, acc) {
<[ $acc %^ (if (object.ReferenceEquals($(x.Name : usesite),
null)) 0 else $(x.Name : usesite).GetHashCode ()) ]>
});
t.Define (<[ decl:
public override GetHashCode () : int {
$body
}
]>);
}
But this check for null makes sense only for reference types and
nullable value types. For non-nullale value types it is redundant. How
can I check in macro that target filed has a non-nullable value type?
More information about the devel-en
mailing list