1 (* Copyright (C
) 2017 Matthew Fluet
.
2 * Copyright (C
) 1999-2007 Henry Cejtin
, Matthew Fluet
, Suresh
3 * Jagannathan
, and Stephen Weeks
.
4 * Copyright (C
) 1997-2000 NEC Research Institute
.
6 * MLton is released under a BSD
-style license
.
7 * See the file MLton
-LICENSE for details
.
10 structure SourcePos
: SOURCE_POS
=
13 datatype t
= T
of {column
: int,
20 val column
= f #column
24 fun compare (T
{column
= c
, file
= f
, line
= l
},
25 T
{column
= c
', file
= f
', line
= l
'}) =
26 case String.compare (f
, f
') of
28 (case Int.compare (l
, l
') of
29 EQUAL
=> Int.compare (c
, c
')
33 fun equals (T r
, T r
') = r
= r
'
35 fun fileEquals (T
{file
= f
, ...}, T
{file
= f
', ...}) =
38 fun make
{column
, file
, line
} =
43 fun getLib (T
{file
, ...}) =
45 val libDir
= concat
[!ControlFlags
.libDir
, "/sml"]
47 if String.hasPrefix (file
, {prefix
= libDir
})
48 then SOME (String.size libDir
)
52 fun file (p
as T
{file
, ...}) =
53 if !ControlFlags
.preferAbsPaths
59 concat
["$(SML_LIB)", String.dropPrefix (file
, i
)]
61 val bogus
= T
{column
= ~
1,
65 fun isBogus p
= equals (p
, bogus
)
67 fun posToString (T
{line
, column
, ...}) =
68 concat
[Int.toString line
, ".", Int.toString column
]
71 concat
[file p
, " ", posToString p
]