[Mono-devel-list] mcs patch for precise location handling

Marek Safar marek.safar at seznam.cz
Fri Jul 1 12:30:12 EDT 2005


Hello Eno,

> Thanks, as usual. I put a revised patch here:
> http://monkey.workarea.jp/tmp/20050630/precise-location-20050630.diff
>
>> I think can be useful make 'public class LocatedToken' struct as is 
>> passed only as an argument.
>> And use this class in similar way as MemberName for every relevant 
>> consumers.
>
>
> Do you mean, passing LocatedToken as an argument for each MemberCore-
> derived types, such as Class, Struct, Event etc.?

Only where it is appropriate not for `if', `foreach', etc.
I think it will be easier to read and probably a little bit faster.

Like this

+        LocatedToken lt = (LocatedToken) $1;
+        LabeledStatement labeled = new LabeledStatement 
(lt.StringValue, lt.Location);

or this

-        CheckBinaryOperator ((Operator.OpType) $3);
+        LocatedToken ltParam1 = (LocatedToken) $6;
+        LocatedToken ltParam2 = (LocatedToken) $9;
+        CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
 
         Parameter [] pars = new Parameter [2];
 
         Expression typeL = (Expression) $5;
         Expression typeR = (Expression) $8;
 
-           pars [0] = new Parameter (typeL, (string) $6, 
Parameter.Modifier.NONE, null, lexer.Location);
-           pars [1] = new Parameter (typeR, (string) $9, 
Parameter.Modifier.NONE, null, lexer.Location);
+           pars [0] = new Parameter (typeL, ltParam1.StringValue, 
Parameter.Modifier.NONE, null, ltParam1.Location);
+           pars [1] = new Parameter (typeR, ltParam2.StringValue, 
Parameter.Modifier.NONE, null, ltParam2.Location);

>
> I once thought about that, but it makes those constructors too
> parser-specific while some of them are invoked inside some other
> types (Iterators etc.) where we have dare
> to create LocatedToken. So I felt that it won't be worthy of
> making those changes just to make parser a bit readable. Especially
> I was afraid that there might be need for LocatedToken-less
> ctor()s in the future (or that could already happen in gmcs).

I think 99% are parser specific. Otherwise Iterator can always create 
this container.
I cannot talk about gmcs as I don't know the sources.

But you don't need to introduce the `LocatedToken' when you just reuse 
`MemberName'.
It will simplify this mainly when you rewrite `VariableDeclaration' to 
hold this MemberName then
we will have just 1 name container.

>> MemberBase is derived from MemberCore
>>
>> +Location GetLocation (object obj)
>> +{
>> +    if (obj is MemberCore)
>> +        return ((MemberCore) obj).Location;
>> +    if (obj is MemberName)
>> +        return ((MemberName) obj).Location;
>
>
> Mmm, I couldn't understand what you meant. MemberBase will be
> thus handled here, so I don't see possible improvements here.

+    if (obj is MemberName)
This `if' never happens.

Marek



More information about the Mono-devel-list mailing list