nitc/location: add named constructor `opaque_file`
authorJean Privat <jean@pryen.org>
Sun, 1 May 2016 15:39:28 +0000 (11:39 -0400)
committerJean Privat <jean@pryen.org>
Fri, 13 May 2016 17:52:09 +0000 (13:52 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/loader.nit
src/location.nit

index 6df4d61..991a1fd 100644 (file)
@@ -395,8 +395,7 @@ redef class ModelBuilder
                        end
                end
 
-               var src = new SourceFile.from_string(path, "")
-               var loc = new Location(src, 0, 0, 0, 0)
+               var loc = new Location.opaque_file(path)
                var res = new MModule(model, mgroup, pn, loc)
                res.filepath = path
 
index 0c5b55d..99083ad 100644 (file)
@@ -140,6 +140,15 @@ class Location
                end
        end
 
+       # Initialize a location corresponding to an opaque file.
+       #
+       # The path is used as is and is not open nor read.
+       init opaque_file(path: String)
+       do
+               var source = new SourceFile.from_string(path, "")
+               init(source, 0, 0, 0, 0)
+       end
+
        # The index in the start character in the source
        fun pstart: Int do return file.line_starts[line_start-1] + column_start-1