comparison src/basic/SourceLocation.d @ 207:e0551773a005

Added the correct version.
author Anders Johnsen <skabet@gmail.com>
date Tue, 12 Aug 2008 18:19:34 +0200
parents d3c148ca429b
children
comparison
equal deleted inserted replaced
206:d3c148ca429b 207:e0551773a005
1 module basic.SourceLocation; 1 module basic.SourceLocation;
2
3 import Integer = tango.text.convert.Integer;
2 4
3 /// Shorter alias for SourceLocation 5 /// Shorter alias for SourceLocation
4 public alias SourceLocation SLoc; 6 public alias SourceLocation SLoc;
5 7
6 /// SourceLocation points to a place in some buffer 8 /// SourceLocation points to a place in some buffer
60 SourceLocation res = *this; 62 SourceLocation res = *this;
61 res.val -= n; 63 res.val -= n;
62 return res; 64 return res;
63 } 65 }
64 66
67 /// Get the length between two location
68 int opSub(SourceLocation loc)
69 {
70 return val - loc.val;
71 }
72
65 /// Creates a SourceLocation from a File ID 73 /// Creates a SourceLocation from a File ID
66 static SourceLocation fromFileID(uint fileID) 74 static SourceLocation fromFileID(uint fileID)
67 { 75 {
68 assert(fileID < Bits.MaxFileID, "To large fileID"); 76 assert(fileID < Bits.MaxFileID, "To large fileID");
69 SourceLocation res; 77 SourceLocation res;
70 res.val = fileID << Bits.FileOffset; 78 res.val = fileID << Bits.FileOffset;
71 return res; 79 return res;
72 } 80 }
73 81
82 char[] toString()
83 {
84 return Integer.toString(val);
85 }
74 /** 86 /**
75 Used for invalid/unknown locations. (also the default value, but this is 87 Used for invalid/unknown locations. (also the default value, but this is
76 more explicit) 88 more explicit)
77 **/ 89 **/
78 static const SourceLocation Invalid = {val: uint.max}; 90 static const SourceLocation Invalid = {val: uint.max};