From 71f8c1bb366154083ff5eff5943520d9511ea014 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Sun, 6 Apr 2014 16:47:11 +0100 Subject: Added /useBaseNameForFile command line argument. The Scanner and Parser constructors have been modified to take an optional argument specifying this and the ExecutionEngine passes for that value CommandLineOptions.Clo.UseBaseNameForFileName This option when true causes the basename of file to be used inside created Tokens instead of what the user passed on the command line which might be a relative or absolute path. The motivation for adding this option is that it is needed for the lit driven tests so that the output of Boogie can be reliably checked. --- Source/Core/Scanner.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Source/Core/Scanner.cs') diff --git a/Source/Core/Scanner.cs b/Source/Core/Scanner.cs index f0c9063d..b050fcdd 100644 --- a/Source/Core/Scanner.cs +++ b/Source/Core/Scanner.cs @@ -296,7 +296,7 @@ public class Scanner { } // [NotDelayed] - public Scanner (string/*!*/ fileName, Errors/*!*/ errorHandler) : base() { + public Scanner (string/*!*/ fileName, Errors/*!*/ errorHandler, bool useBaseName) : base() { Contract.Requires(fileName != null); Contract.Requires(errorHandler != null); this.errorHandler = errorHandler; @@ -305,7 +305,7 @@ public class Scanner { try { Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); buffer = new Buffer(stream, false); - Filename = fileName; + Filename = useBaseName? GetBaseName(fileName): fileName; Init(); } catch (IOException) { throw new FatalError("Cannot open file " + fileName); @@ -313,7 +313,7 @@ public class Scanner { } // [NotDelayed] - public Scanner (Stream/*!*/ s, Errors/*!*/ errorHandler, string/*!*/ fileName) : base() { + public Scanner (Stream/*!*/ s, Errors/*!*/ errorHandler, string/*!*/ fileName, bool useBaseName) : base() { Contract.Requires(s != null); Contract.Requires(errorHandler != null); Contract.Requires(fileName != null); @@ -321,10 +321,14 @@ public class Scanner { t = new Token(); // dummy because t is a non-null field buffer = new Buffer(s, true); this.errorHandler = errorHandler; - this.Filename = fileName; + this.Filename = useBaseName? GetBaseName(fileName) : fileName; Init(); } + private string GetBaseName(string fileName) { + return System.IO.Path.GetFileName(fileName); // Return basename + } + void Init() { pos = -1; line = 1; col = 0; oldEols = 0; -- cgit v1.2.3