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

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