Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/branches/SMLNJ/src/compiler/MiscUtil/util/sourcemap.sig
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/compiler/MiscUtil/util/sourcemap.sig

Parent Directory Parent Directory | Revision Log Revision Log


Revision 245 - (view) (download) (as text)

1 : monnier 245 (* \section{Source locations} *)
2 :     (* *)
3 :     (* The goal of this interface is to map character positions to *)
4 :     (* locations in source files, where a location is described in *)
5 :     (* ``file-line-column'' format. *)
6 :     (* The major type exported by this interface is [[sourcemap]], which *)
7 :     (* maintains the mapping. *)
8 :     (* This way, most of a compiler can work with character positions, but we *)
9 :     (* can use real source locations in error messages. *)
10 :     (* *)
11 :     (* A \emph{region} represents a contiguous span of *)
12 :     (* source locations as seen by the compiler. *)
13 :     (* Because of preprocessing, any region could be spread out over multiple *)
14 :     (* overlapping regions in the original source. *)
15 :     (* *)
16 :     (* A source map is maintained as mutable state. *)
17 :     (* We create such a map by giving the initial character position, file *)
18 :     (* name, line, and column number. *)
19 :     (* Column numbers are obtained by counting characters from the beginning *)
20 :     (* of the line; the first character on the line is deemed to be in *)
21 :     (* column~1. *)
22 :     (* Tabs are given no special treatment. *)
23 :     (* *)
24 :     (* Character positions increase as the compiler moves through the source, *)
25 :     (* and the lexer mutates the source map any time something interesting *)
26 :     (* happens. *)
27 :     (* The two interesting events are: *)
28 :     (* \begin{itemize} *)
29 :     (* \item *)
30 :     (* The lexer encounters a newline (changing the line number in the source *)
31 :     (* file). *)
32 :     (* \item *)
33 :     (* The lexer encounters \verb+#line+ or its equivalent, changing the *)
34 :     (* source coordinates. *)
35 :     (* By analogy with the \texttt{{\tt lcc}} implementation, I call this *)
36 :     (* event a \emph{resynchronization}. *)
37 :     (* A resynchronization must change the line number. *)
38 :     (* It may change the file name and column number; if not specified they *)
39 :     (* default to the current file name and~1, respectively. *)
40 :     (* As suggested by John Reppy, *)
41 :     (* a resynchronization can specify a line number of~0 (in order to make *)
42 :     (* the numbering of the following line come out right). *)
43 :     (* \end{itemize} *)
44 :     (* Character positions must be nonnegative, and they must *)
45 :     (* increase in successive mutations of a single *)
46 :     (* [[sourcemap]] (where the initialization counts as a mutation). *)
47 :     (* *)
48 :     (* [[forgetOldPositions]] causes the sourcemap to discard information *)
49 :     (* about positions already known to the source map. *)
50 :     (* Subsequent queries may refer only to new positions (which must still *)
51 :     (* be larger than the old ones). *)
52 :     (* The only reason to call [[forgetOldPositions]] is to avoid space leaks. *)
53 :     (* *)
54 :     (* [[lastChange]] returns the position of the last mutation, or the *)
55 :     (* initial position if no mutations have taken place. *)
56 :     (* *)
57 :     (* [[filepos]] and [[fileregion]] map character positions and regions *)
58 :     (* back to the source level. *)
59 :     (* If the null region is passed to [[fileregion]], it returns the empty list. *)
60 :     (* In any pair returned by [[fileregion]], the two source locations are *)
61 :     (* guaranteed to have the same file name. *)
62 :     (* [[newlineCount]] returns the number of newlines that occurred in the given *)
63 :     (* region. *)
64 :     (* *)
65 :     (* <sourcemap.sig>= *)
66 :     (* sourcemap.sig *)
67 :     (* <sig RCS log>= *)
68 :     (*
69 :     * changed ErrorMsg to use SourceMap to get source locations; only the
70 :     * formatting is done internally
71 :     *
72 :     * added SourceMap structure
73 :     *
74 :     * .sig and .sml for sourcemap, source, and errormsg are derived from .nw
75 :     * files. to extract, try
76 :     * for base in sourcemap source errormsg
77 :     * do
78 :     * for suffix in sml sig
79 :     * do
80 :     * $cmd -L'(*#line %L "%F"*)' -R$base.$suffix $base.nw > $base.$suffix
81 :     * done
82 :     * done
83 :     * where
84 :     * cmd=notangle
85 :     * or
86 :     * cmd="nountangle -ml"
87 :     *
88 :     * At some point, it may be desirable to move noweb support into CM
89 :     * *)
90 :     signature SOURCE_MAP = sig
91 :     type charpos (* = int *)
92 :     type 'a pair (* = 'a * 'a *)
93 :     type region (* = charpos pair *)
94 :     val span : region * region -> region (* smallest region containing the two regions *)
95 :     val nullRegion : region (* left and right identity of span *)
96 :    
97 :     type sourceloc (* = {fileName:string, line:int, column:int} *)
98 :    
99 :     type sourcemap (* = opaque mutable *)
100 :     val newmap : charpos * sourceloc -> sourcemap
101 :     val newline : sourcemap -> charpos -> unit
102 :     val resynch : sourcemap ->
103 :     charpos * {fileName:string option, line:int, column:int option} -> unit
104 :     val forgetOldPositions : sourcemap -> unit
105 :    
106 :     val filepos : sourcemap -> charpos -> sourceloc
107 :     val fileregion : sourcemap -> region -> sourceloc pair list
108 :     val positions : sourcemap -> sourceloc -> charpos list
109 :    
110 :     val lastChange : sourcemap -> charpos
111 :     val newlineCount: sourcemap -> region -> int
112 :     end
113 :    
114 :     (*
115 :     * $Log$
116 :     *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0