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

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