22using System ;
33using System . Collections . Generic ;
44using System . Diagnostics . Contracts ;
5- using System . IO ;
65using System . Text ;
76
87namespace Microsoft . Dafny ;
@@ -18,14 +17,12 @@ public interface IToken : Microsoft.Boogie.IToken {
1817 string val { get; set; }
1918 bool IsValid { get; }*/
2019 string Boogie . IToken . filename {
21- get => Uri == null ? null : Path . GetFileName ( Uri . LocalPath ) ;
22- set => throw new NotSupportedException ( ) ;
20+ get => Filename ;
21+ set => Filename = value ;
2322 }
2423
25- public string ActualFilename => Uri . LocalPath ;
26- string Filepath => Uri . LocalPath ;
27-
28- Uri Uri { get ; set ; }
24+ public string ActualFilename { get ; }
25+ string Filename { get ; set ; }
2926
3027 /// <summary>
3128 /// TrailingTrivia contains everything after the token,
@@ -73,9 +70,8 @@ public Token(int linenum, int colnum) {
7370
7471 public int kind { get ; set ; } // Used by coco, so we can't rename it to Kind
7572
76- public string ActualFilename => Filepath ;
77- public string Filepath => Uri ? . LocalPath ;
78- public Uri Uri { get ; set ; }
73+ public string ActualFilename => Filename ;
74+ public string Filename { get ; set ; }
7975
8076 public int pos { get ; set ; } // Used by coco, so we can't rename it to Pos
8177
@@ -108,7 +104,7 @@ public IToken WithVal(string newVal) {
108104 line = line ,
109105 Prev = Prev ,
110106 Next = Next ,
111- Uri = Uri ,
107+ Filename = Filename ,
112108 kind = kind ,
113109 val = newVal
114110 } ;
@@ -119,7 +115,7 @@ public override int GetHashCode() {
119115 }
120116
121117 public override string ToString ( ) {
122- return $ "' { val } ': { Path . GetFileName ( Filepath ) } @{ pos } - @{ line } :{ col } ";
118+ return $ "{ Filename } @{ pos } - @{ line } :{ col } ";
123119 }
124120}
125121
@@ -140,11 +136,9 @@ public virtual int col {
140136
141137 public string ActualFilename => WrappedToken . ActualFilename ;
142138
143- public virtual string Filepath => WrappedToken . Filepath ;
144-
145- public Uri Uri {
146- get => WrappedToken . Uri ;
147- set => WrappedToken . Uri = value ;
139+ public virtual string Filename {
140+ get { return WrappedToken . Filename ; }
141+ set { WrappedToken . filename = value ; }
148142 }
149143
150144 public bool IsValid {
@@ -186,32 +180,6 @@ public virtual IToken Prev {
186180}
187181
188182public static class TokenExtensions {
189-
190- public static string TokenToString ( this Boogie . IToken tok , DafnyOptions options ) {
191- if ( tok is IToken dafnyToken ) {
192- return dafnyToken . TokenToString ( options ) ;
193- }
194-
195- return $ "{ tok . filename } ({ tok . line } ,{ tok . col - 1 } )";
196- }
197-
198- public static string TokenToString ( this IToken tok , DafnyOptions options ) {
199- if ( tok . Uri == null ) {
200- return $ "({ tok . line } ,{ tok . col - 1 } )";
201- }
202-
203- var currentDirectory = Directory . GetCurrentDirectory ( ) ;
204- string filename = tok . Uri . Scheme switch {
205- "stdin" => "<stdin>" ,
206- "transcript" => Path . GetFileName ( tok . Filepath ) ,
207- _ => options . UseBaseNameForFileName
208- ? Path . GetFileName ( tok . Filepath )
209- : ( tok . Filepath . StartsWith ( currentDirectory ) ? Path . GetRelativePath ( currentDirectory , tok . Filepath ) : tok . Filepath )
210- } ;
211-
212- return $ "{ filename } ({ tok . line } ,{ tok . col - 1 } )";
213- }
214-
215183 public static RangeToken ToRange ( this IToken token ) {
216184 if ( token is BoogieRangeToken boogieRangeToken ) {
217185 return new RangeToken ( boogieRangeToken . StartToken , boogieRangeToken . EndToken ) ;
@@ -333,6 +301,54 @@ public override IToken WithVal(string newVal) {
333301 }
334302}
335303
304+ /// <summary>
305+ /// An IncludeToken is a wrapper that indicates that the function/method was
306+ /// declared in a file that was included. Any proof obligations from such an
307+ /// included file are to be ignored.
308+ /// </summary>
309+ public class IncludeToken : TokenWrapper {
310+ public Include Include ;
311+ public IncludeToken ( Include include , IToken wrappedToken )
312+ : base ( wrappedToken ) {
313+ Contract . Requires ( wrappedToken != null ) ;
314+ this . Include = include ;
315+ }
316+
317+ public override string val {
318+ get { return WrappedToken . val ; }
319+ set { WrappedToken . val = value ; }
320+ }
321+
322+ public override int pos {
323+ get { return WrappedToken . pos ; }
324+ set { WrappedToken . pos = value ; }
325+ }
326+
327+ public override int line {
328+ get { return WrappedToken . line ; }
329+ set { WrappedToken . line = value ; }
330+ }
331+
332+ public override int col {
333+ get { return WrappedToken . col ; }
334+ set { WrappedToken . col = value ; }
335+ }
336+
337+ public override IToken Prev {
338+ get { return WrappedToken . Prev ; }
339+ set { WrappedToken . Prev = value ; }
340+ }
341+
342+ public override IToken Next {
343+ get { return WrappedToken . Next ; }
344+ set { WrappedToken . Next = value ; }
345+ }
346+
347+ public override IToken WithVal ( string newVal ) {
348+ return new IncludeToken ( Include , WrappedToken . WithVal ( newVal ) ) ;
349+ }
350+ }
351+
336352/// <summary>
337353/// A token wrapper used to produce better type checking errors
338354/// for quantified variables. See QuantifierVar.ExtractSingleRange()
0 commit comments