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

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