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/trunk/src/compiler/MiscUtil/util/source.nw
ViewVC logotype

Annotation of /sml/trunk/src/compiler/MiscUtil/util/source.nw

Parent Directory Parent Directory | Revision Log Revision Log


Revision 246 - (view) (download)

1 : monnier 245 <<source.sig>>=
2 :     (* source.sig
3 :     *
4 :     * COPYRIGHT (c) 1996 Bell Laboratories.
5 :     *
6 :     * $Log: source.nw,v $
7 :     * Revision 1.1.1.1 1997/01/14 01:38:49 george
8 :     * Version 109.24
9 :     *
10 :     # Revision 1.1 1996/08/08 19:30:29 nr
11 :     # split old Source structure into Source and SourceMap
12 :     #
13 :     # changed ErrorMsg to use SourceMap to get source locations; only the
14 :     # formatting is done internally
15 :     #
16 :     # added SourceMap structure
17 :     #
18 :     # .sig and .sml for sourcemap, source, and errormsg are derived from .nw
19 :     # files. to extract, try
20 :     # for base in sourcemap source errormsg
21 :     # do
22 :     # for suffix in sml sig
23 :     # do
24 :     # $cmd -L'(*#line %L "%F"*)' -R$base.$suffix $base.nw > $base.$suffix
25 :     # done
26 :     # done
27 :     # where
28 :     # cmd=notangle
29 :     # or
30 :     # cmd="nountangle -ml"
31 :     #
32 :     # At some point, it may be desirable to move noweb support into CM
33 :     #
34 :     * Revision 1.6 1996/07/29 15:24:04 jhr
35 :     * Removed index file mechanism.
36 :     *
37 :     * Revision 1.5 1996/03/22 15:58:23 jhr
38 :     * Changed code to use TextIO.openString.
39 :     *
40 :     * Revision 1.4 1996/02/26 14:56:52 george
41 :     * print no longer overloaded.
42 :     * use of makestring has been removed and replaced with Int.toString ..
43 :     * use of IO replaced with TextIO
44 :     *
45 :     * Revision 1.3 1996/02/21 16:28:52 jhr
46 :     * Added copyright and CVS Log tag
47 :     *
48 :     *)
49 :     <<source.sig>>=
50 :     signature SOURCE =
51 :     sig
52 :     type inputSource = {
53 :     sourceMap: SourceMap.sourcemap,
54 :     fileOpened: string,
55 :     interactive: bool,
56 :     sourceStream: TextIO.instream,
57 :     anyErrors: bool ref,
58 :     errConsumer: PrettyPrint.ppconsumer
59 :     }
60 :    
61 :     val newSource : (string * int * TextIO.instream * bool * PrettyPrint.ppconsumer)
62 :     -> inputSource
63 :     val closeSource: inputSource -> unit
64 :     val filepos: inputSource -> SourceMap.charpos -> string * int * int
65 :    
66 :     end
67 :     @
68 :     The [[fileOpened]] field contains the name of the file that was opened
69 :     to produce a particular [[inputSource]].
70 :     It is used only to derive related file names.
71 :     (For an example, see [[CompileF.codeopt]] and [[CompileF.parse]] in
72 :     \texttt{build/compile.sml}.)
73 :    
74 :     [[newSource]] has some old warts build in. It takes as argument a
75 :     file and line number, and it assumes column~1. The reason we don't
76 :     simply pass a [[SourceMap.sourcemap]] is that we have to hide the
77 :     awful truth about the beginning position according to ml-lex (it's~2).
78 :     That position, and therefore the creation of the source map, are
79 :     encapsulated inside [[newSource]].
80 :    
81 :     [[filepos]] is kept around for historical reasons, to avoid having to
82 :     change lots of code elsewhere in the compiler; it wraps a
83 :     call to [[SourceMap.filepos]] and massages the return type.
84 :     It probably should be eliminated, but then somebody would have to fix
85 :     all those call sites.
86 :     <<source.sig>>=
87 :     @
88 :     <<source.sml>>=
89 :     (* source.sml
90 :     *
91 :     * COPYRIGHT (c) 1996 Bell Laboratories.
92 :     *
93 :     * $Log: source.nw,v $
94 :     * Revision 1.1.1.1 1997/01/14 01:38:49 george
95 :     * Version 109.24
96 :     *
97 :     # Revision 1.1 1996/08/08 19:30:29 nr
98 :     # split old Source structure into Source and SourceMap
99 :     #
100 :     # changed ErrorMsg to use SourceMap to get source locations; only the
101 :     # formatting is done internally
102 :     #
103 :     # added SourceMap structure
104 :     #
105 :     # .sig and .sml for sourcemap, source, and errormsg are derived from .nw
106 :     # files. to extract, try
107 :     # for base in sourcemap source errormsg
108 :     # do
109 :     # for suffix in sml sig
110 :     # do
111 :     # $cmd -L'(*#line %L "%F"*)' -R$base.$suffix $base.nw > $base.$suffix
112 :     # done
113 :     # done
114 :     # where
115 :     # cmd=notangle
116 :     # or
117 :     # cmd="nountangle -ml"
118 :     #
119 :     # At some point, it may be desirable to move noweb support into CM
120 :     #
121 :     * Revision 1.7 1996/07/29 15:24:05 jhr
122 :     * Removed index file mechanism.
123 :     *
124 :     * Revision 1.6 1996/03/22 15:58:24 jhr
125 :     * Changed code to use TextIO.openString.
126 :     *
127 :     * Revision 1.5 1996/03/18 15:33:53 jhr
128 :     * Added new I/O implementation, which implements the SML Basis Library API.
129 :     *
130 :     * Revision 1.4 1996/02/26 14:56:52 george
131 :     * print no longer overloaded.
132 :     * use of makestring has been removed and replaced with Int.toString ..
133 :     * use of IO replaced with TextIO
134 :     *
135 :     * Revision 1.3 1996/02/21 16:28:52 jhr
136 :     * Added copyright and CVS Log tag
137 :     *
138 :     *)
139 :    
140 :     structure Source : SOURCE =
141 :     struct
142 :    
143 :     type inputSource = {
144 :     sourceMap: SourceMap.sourcemap,
145 :     fileOpened: string,
146 :     anyErrors: bool ref,
147 :     errConsumer: PrettyPrint.ppconsumer,
148 :     interactive: bool,
149 :     sourceStream: TextIO.instream
150 :     }
151 :    
152 :     fun say (msg : string) = Control.Print.say msg
153 :    
154 :     val lexer_initial_position = 2 (* position of first char according to ml-lex *)
155 :    
156 :     fun newSource(fileName,lineNum,sourceStream,interactive, errConsumer) =
157 :     {sourceMap=SourceMap.newmap(lexer_initial_position,
158 :     {fileName=fileName, line=lineNum, column=1}),
159 :     sourceStream=sourceStream,interactive=interactive,fileOpened=fileName,
160 :     errConsumer=errConsumer,anyErrors=ref false}
161 :    
162 :     fun closeSource ({interactive=true, ...} : inputSource) = ()
163 :     | closeSource ({sourceStream, ...}) = (
164 :     (* app say ["[closing ", (Pathnames.trim fileName), "]\n"];*)
165 :     TextIO.closeIn sourceStream handle IO.Io _ => ())
166 :    
167 :     fun filepos({sourceMap,...}: inputSource) pos =
168 :     let val {fileName, line, column} = SourceMap.filepos sourceMap pos
169 :     in (fileName, line, column)
170 :     end
171 :    
172 :     end (* structure Source *)

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