[nem-en] Re: compiler generated locations

Kamil Skalski kamil.skalski at gmail.com
Mon Nov 20 22:43:23 CET 2006


Continuing on Locations and generated code - it might be quite
feasible to modify either Util.locate macro, or even Location_stack
()
with something like:

Index: parsing/Utility.n
===================================================================
--- parsing/Utility.n   (revision 6956)
+++ parsing/Utility.n   (working copy)
@@ -312,7 +312,10 @@
       if (s.IsEmpty)
         Location.Default
       else
-        s [s.Count - 1]
+        if (Manager.IsInCompletionMode)
+          GeneratedLocation (s [s.Count - 1])
+        else
+          s [s.Count - 1]
     }
   }
 }


Now GeneratedLocation should have the method IsGenerated  returning
true for not-original locations. This would probably solve quite much
of the problem, since most of quotations rely on Util.locate and
location taken from Location_stack.
The problem I'm still thinking about is how to define
GeneratedLocation / IsGenerated method. My idea was:

+  [Record]
+  class GeneratedLocation : Location {
+    public this (existing : Location) {
+      base (existing.FileIndex, existing.Line, existing.Column,
existing.EndLine, existing.EndColumn)
+    }
+
+    public override IsGenerated : bool
+    { get { true } }
+  }
+


But this requires changing Location into class and this appears to be
a real pain.. :(
I was playing with it some time, but I got many NullPointerExceptions
first from lexer then parser (where I stopped). It looks like we have
many places where location is not initialized at all and when we
change it from struct to class we get nulls.
I still think approach might be good, but requires a lot of debugging work :(

On 11/20/06, vc <vc at rsdn.ru> wrote:
> > Are we talking about PExpr only? Or TExpr also?
>
> Mainly I talking about: TopDeclaration's, PExpr'e and soon. But TExpr also
> deen contain right locations.
>
> > Probably it would be possible to mark PExprs somehow in parser -
> > because this is the distinction you need:  created by parser from text
> > stream  vs  created in any other context by PExpr constructors / code
> > quotation.
>
> It's will be bood. And TopDeclaration's to.
>
> But we need method of marking locations.
>
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list