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/cm/smlfile/smlinfo.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 305 - (view) (download)

1 : blume 275 (*
2 : blume 282 * Bundling information pertaining to one SML source file.
3 :     * - only includes information that does not require running
4 :     * the machine-dependent part of the compiler
5 : blume 275 *
6 :     * (C) 1999 Lucent Technologies, Bell Laboratories
7 :     *
8 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
9 :     *)
10 : blume 270 signature SMLINFO = sig
11 :    
12 :     type info
13 : blume 305 type ord_key = info
14 : blume 270
15 : blume 295 type complainer = GenericVC.ErrorMsg.complainer
16 : blume 297 type ast = GenericVC.Ast.dec
17 :     type region = GenericVC.SourceMap.region
18 : blume 299 type source = GenericVC.Source.inputSource
19 : blume 274
20 : blume 282 val resync : unit -> unit (* rebuild internal table *)
21 : blume 277
22 : blume 279 val eq : info * info -> bool (* compares sourcepaths *)
23 :     val compare : info * info -> order (* compares sourcepaths *)
24 :    
25 : blume 299 val info : GeneralParams.info ->
26 : blume 274 { sourcepath: AbsPath.t,
27 : blume 297 group: AbsPath.t * region,
28 : blume 277 share: bool option }
29 : blume 270 -> info
30 :    
31 : blume 277 val sourcepath : info -> AbsPath.t
32 : blume 299 val error : GeneralParams.info -> info -> complainer
33 : blume 277
34 : blume 299 val parsetree : GeneralParams.info -> info -> (ast * source) option
35 : blume 301 val exports : GeneralParams.info -> info -> SymbolSet.set option
36 :     val skeleton : GeneralParams.info -> info -> Skeleton.decl option
37 : blume 295 val share : info -> bool option
38 : blume 301 val lastseen : info -> TStamp.t
39 : blume 279
40 : blume 301 (* forget a parse tree that we are done with *)
41 :     val forgetParsetree : info -> unit
42 :    
43 :     (* evict all but the reachable nodes in the cache *)
44 :     val forgetAllBut : AbsPathSet.set -> unit
45 :    
46 : blume 280 (* different ways of describing an sml file using group and source *)
47 :     val spec : info -> string (* sspec *)
48 :     val fullSpec : info -> string (* gspec(sspec) *)
49 :     val name : info -> string (* sname *)
50 :     val fullName : info -> string (* gname(sspec) *)
51 : blume 305
52 :     val mkBinInfo : info -> int -> BinInfo.info
53 : blume 270 end
54 :    
55 :     structure SmlInfo :> SMLINFO = struct
56 :    
57 : blume 275 structure Source = GenericVC.Source
58 :     structure Print = GenericVC.Control.Print
59 :     structure SF = GenericVC.SmlFile
60 :     structure EM = GenericVC.ErrorMsg
61 : blume 286 structure FNP = FilenamePolicy
62 : blume 275
63 :     type source = Source.inputSource
64 : blume 297 type ast = GenericVC.Ast.dec
65 :     type region = GenericVC.SourceMap.region
66 : blume 274
67 : blume 295 type complainer = EM.complainer
68 : blume 274
69 : blume 297 datatype persinfo =
70 :     PERS of { group: AbsPath.t * region,
71 :     lastseen: TStamp.t ref,
72 : blume 299 parsetree: (ast * source) option ref,
73 : blume 297 skeleton: Skeleton.decl option ref }
74 :    
75 : blume 275 datatype info =
76 : blume 297 INFO of { sourcepath: AbsPath.t,
77 :     persinfo: persinfo,
78 :     share: bool option }
79 : blume 270
80 : blume 305 type ord_key = info
81 :    
82 : blume 277 fun sourcepath (INFO { sourcepath = sp, ... }) = sp
83 : blume 295 fun share (INFO { share = s, ... }) = s
84 : blume 270
85 : blume 299 fun gerror (gp: GeneralParams.info) = GroupReg.error (#groupreg gp)
86 : blume 297
87 :     fun error gp (INFO { persinfo = PERS { group, ... }, ... }) =
88 :     gerror gp group
89 :    
90 : blume 279 fun compare (INFO { sourcepath = p, ... }, INFO { sourcepath = p', ... }) =
91 :     AbsPath.compare (p, p')
92 :     fun eq (i, i') = compare (i, i') = EQUAL
93 :    
94 : blume 301 fun lastseen (INFO { persinfo = PERS { lastseen, ... }, ... }) =
95 :     !lastseen
96 :    
97 : blume 277 (* If files change their file ids, then CM will be seriously
98 :     * disturbed because the ordering relation will change.
99 :     * We'll asume that this won't happen in general. However, we provide
100 :     * a "resync" function that -- at the very least -- should be run
101 :     * at startup time. *)
102 : blume 297 val knownInfo = ref (AbsPathMap.empty: persinfo AbsPathMap.map)
103 : blume 277
104 :     fun resync () = let
105 :     val l = AbsPathMap.listItemsi (!knownInfo)
106 :     in
107 :     AbsPath.newEra (); (* force recalculation of file ids *)
108 :     knownInfo := foldl AbsPathMap.insert' AbsPathMap.empty l
109 :     end
110 :    
111 : blume 301 fun forgetParsetree (INFO { persinfo = PERS { parsetree, ... }, ... }) =
112 :     parsetree := NONE
113 :    
114 :     fun forgetAllBut reachable = let
115 : blume 302 fun isReachable (p, m) = AbsPathSet.member (reachable, p)
116 : blume 301 in
117 : blume 302 knownInfo := AbsPathMap.filteri isReachable (!knownInfo)
118 : blume 301 end
119 :    
120 : blume 299 fun info (gp: GeneralParams.info) arg = let
121 : blume 297 val { sourcepath, group = gr as (group, region), share } = arg
122 :     val groupreg = #groupreg gp
123 :     fun newpersinfo () = let
124 :     val pi = PERS { group = gr, lastseen = ref TStamp.NOTSTAMP,
125 :     parsetree = ref NONE, skeleton = ref NONE }
126 : blume 281 in
127 : blume 297 knownInfo := AbsPathMap.insert (!knownInfo, sourcepath, pi);
128 :     pi
129 : blume 281 end
130 : blume 297 fun persinfo () =
131 :     case AbsPathMap.find (!knownInfo, sourcepath) of
132 :     NONE => newpersinfo ()
133 :     | SOME (pi as PERS { group = gr' as (g, r), ... }) =>
134 :     if AbsPath.compare (group, g) <> EQUAL then
135 :     (if GroupReg.registered groupreg g then
136 :     let val n = AbsPath.name sourcepath
137 :     in gerror gp gr EM.COMPLAIN
138 :     (concat ["ML source file ", n,
139 :     " appears in more than one group"])
140 :     EM.nullErrorBody;
141 :     gerror gp gr' EM.COMPLAIN
142 :     (concat ["(previous occurence of ", n, ")"])
143 :     EM.nullErrorBody
144 :     end
145 :     else ();
146 :     newpersinfo ())
147 :     else pi
148 : blume 281 in
149 : blume 297 INFO { sourcepath = sourcepath,
150 :     persinfo = persinfo (),
151 :     share = share }
152 : blume 281 end
153 : blume 277
154 : blume 275 (* check timestamp and throw away any invalid cache *)
155 :     fun validate (INFO ir) = let
156 :     (* don't use "..." pattern to have the compiler catch later
157 :     * additions to the type! *)
158 : blume 297 val { sourcepath, persinfo = PERS pir, share } = ir
159 :     val { group, lastseen, parsetree, skeleton } = pir
160 : blume 275 val ts = !lastseen
161 :     val nts = AbsPath.tstamp sourcepath
162 : blume 274 in
163 : blume 275 if TStamp.earlier (ts, nts) then
164 :     (lastseen := nts;
165 :     parsetree := NONE;
166 :     skeleton := NONE)
167 :     else ()
168 : blume 274 end
169 :    
170 : blume 275 (* the following functions are only concerned with getting the data,
171 :     * not with checking time stamps *)
172 : blume 297 fun getParseTree gp (i as INFO ir, quiet, noerrors) = let
173 :     val { sourcepath, persinfo = PERS { parsetree, ... }, ... } = ir
174 : blume 276 val name = AbsPath.name sourcepath
175 : blume 281 val err = if noerrors then (fn m => ())
176 : blume 297 else (fn m => error gp i EM.COMPLAIN m EM.nullErrorBody)
177 : blume 274 in
178 : blume 275 case !parsetree of
179 :     SOME pt => SOME pt
180 :     | NONE => let
181 :     val stream = AbsPath.openTextIn sourcepath
182 : blume 281 val _ = if noerrors orelse quiet then ()
183 : blume 275 else Say.vsay (concat ["[parsing ", name, "]\n"])
184 :     val source =
185 :     Source.newSource (name, 1, stream, false,
186 :     { linewidth = !Print.linewidth,
187 :     flush = Print.flush,
188 :     consumer = Print.say })
189 :     val pto = let
190 :     val tree = SF.parse source
191 :     in
192 : blume 299 SOME (tree, source)
193 : blume 275 end handle SF.Compile msg => (TextIO.closeIn stream;
194 : blume 281 err msg;
195 : blume 275 NONE)
196 : blume 276 | exn => (TextIO.closeIn stream; raise exn)
197 : blume 275 in
198 :     TextIO.closeIn stream;
199 :     parsetree := pto;
200 :     pto
201 : blume 281 end handle exn as IO.Io _ => (err (General.exnMessage exn);
202 :     NONE)
203 : blume 274 end
204 :    
205 : blume 297 fun getSkeleton gp (i as INFO ir, noerrors) = let
206 :     val { sourcepath, persinfo = PERS pir, ... } = ir
207 :     val { skeleton, lastseen, ... } = pir
208 : blume 275 in
209 :     case !skeleton of
210 : blume 301 SOME sk => SOME sk
211 : blume 297 | NONE => let
212 : blume 299 val policy = #fnpolicy (#param gp)
213 :     val skelpath = FNP.mkSkelPath policy sourcepath
214 : blume 297 in
215 :     case SkelIO.read (skelpath, !lastseen) of
216 : blume 301 SOME sk => (skeleton := SOME sk; SOME sk)
217 : blume 297 | NONE =>
218 :     (case getParseTree gp (i, false, noerrors) of
219 : blume 299 SOME (tree, source) => let
220 : blume 297 fun err sv region s =
221 :     EM.error source region sv s
222 : blume 275 EM.nullErrorBody
223 : blume 297 val { skeleton = sk, complain } =
224 :     SkelCvt.convert { tree = tree, err = err }
225 :     in
226 :     if noerrors then () else complain ();
227 :     if EM.anyErrors (EM.errors source) then
228 :     if noerrors then ()
229 :     else error gp i EM.COMPLAIN
230 :     "error(s) in ML source file"
231 :     EM.nullErrorBody
232 :     else (SkelIO.write (skelpath, sk);
233 :     skeleton := SOME sk);
234 : blume 301 SOME sk
235 : blume 297 end
236 : blume 301 | NONE => NONE)
237 : blume 297 end
238 : blume 275 end
239 :    
240 :     (* first check the time stamp, then do your stuff... *)
241 : blume 297 fun skeleton0 noerrors gp i = (validate i; getSkeleton gp (i, noerrors))
242 : blume 281
243 :     (* we only complain at the time of getting the exports *)
244 : blume 301 fun exports gp i = Option.map SkelExports.exports (skeleton0 false gp i)
245 : blume 281 val skeleton = skeleton0 true
246 : blume 275
247 : blume 301 fun parsetree gp i =
248 :     (validate i;
249 :     getParseTree gp (i, true, true))
250 : blume 282
251 : blume 280 fun spec (INFO { sourcepath, ... }) = AbsPath.spec sourcepath
252 : blume 297 fun fullSpec (INFO { sourcepath, persinfo = PERS { group, ... }, ... }) =
253 :     concat [AbsPath.spec (#1 group), "(", AbsPath.spec sourcepath, ")"]
254 : blume 280 fun name (INFO { sourcepath, ... }) = AbsPath.name sourcepath
255 : blume 297 fun fullName (INFO { sourcepath, persinfo = PERS { group, ... }, ... }) =
256 :     concat [AbsPath.name (#1 group), "(", AbsPath.spec sourcepath, ")"]
257 : blume 305
258 :     fun mkBinInfo (INFO i) offset = let
259 :     val { persinfo = PERS { group, ... }, sourcepath, share, ... } = i
260 :     in
261 :     BinInfo.new { group = group,
262 :     spec = AbsPath.spec sourcepath,
263 :     offset = offset,
264 :     share = share }
265 :     end
266 : blume 270 end

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