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 281 - (view) (download)

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

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