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

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