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/semant/members.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/semant/members.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 387 - (view) (download)

1 : blume 267 (*
2 :     * Collections of members in CM descriptions.
3 :     * Involves:
4 :     * - running tools
5 :     * - fully analyzing sub-groups and sub-libraries
6 :     * - parsing ML files and getting their export lists
7 :     *
8 :     * (C) 1999 Lucent Technologies, Bell Laboratories
9 :     *
10 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
11 :     *)
12 :     signature MEMBERCOLLECTION = sig
13 :    
14 : blume 278 type symbol = Symbol.symbol
15 : blume 270 type smlinfo = SmlInfo.info
16 : blume 283 type impexp = DependencyGraph.impexp
17 : blume 297 type region = GenericVC.SourceMap.region
18 : blume 269
19 : blume 267 type collection
20 :    
21 : blume 274 val empty : collection
22 :    
23 : blume 354 val expandOne : GeneralParams.info * (SrcPath.t -> GroupGraph.group)
24 :     -> { sourcepath: SrcPath.t, group: SrcPath.t * region,
25 : blume 297 class: string option }
26 : blume 270 -> collection
27 : blume 275 val sequential : collection * collection * (string -> unit) -> collection
28 : blume 267
29 : blume 297 val build :
30 : blume 364 collection * SymbolSet.set option * GeneralParams.info
31 : blume 301 -> impexp SymbolMap.map * GroupGraph.privileges
32 : blume 280
33 : blume 380 val subgroups : collection -> GroupGraph.group list
34 : blume 294
35 : blume 336 val num_look : GeneralParams.info -> collection -> string -> int
36 :     val cm_look : GeneralParams.info -> collection -> string -> bool
37 : blume 278 val ml_look : collection -> symbol -> bool
38 : blume 267 end
39 :    
40 :     structure MemberCollection :> MEMBERCOLLECTION = struct
41 :    
42 : blume 269 structure DG = DependencyGraph
43 : blume 277 structure EM = GenericVC.ErrorMsg
44 : blume 278 structure CBE = GenericVC.BareEnvironment
45 : blume 286 structure SS = SymbolSet
46 : blume 294 structure GG = GroupGraph
47 : blume 267
48 : blume 270 type smlinfo = SmlInfo.info
49 : blume 275 type symbol = Symbol.symbol
50 : blume 283 type impexp = DG.impexp
51 : blume 297 type region = GenericVC.SourceMap.region
52 : blume 267
53 : blume 269 datatype collection =
54 : blume 283 COLLECTION of { imports: impexp SymbolMap.map,
55 :     gimports: impexp SymbolMap.map,
56 : blume 269 smlfiles: smlinfo list,
57 : blume 294 localdefs: smlinfo SymbolMap.map,
58 : blume 380 subgroups: GG.group list,
59 : blume 301 reqpriv: GG.privileges }
60 : blume 269
61 : blume 274 val empty =
62 : blume 283 COLLECTION { imports = SymbolMap.empty,
63 :     gimports = SymbolMap.empty,
64 : blume 274 smlfiles = [],
65 : blume 294 localdefs = SymbolMap.empty,
66 : blume 301 subgroups = [],
67 :     reqpriv = StringSet.empty }
68 : blume 274
69 : blume 275 fun sequential (COLLECTION c1, COLLECTION c2, error) = let
70 :     fun describeSymbol (s, r) = let
71 :     val ns = Symbol.nameSpace s
72 :     in
73 :     Symbol.nameSpaceToString ns :: " " :: Symbol.name s :: r
74 :     end
75 : blume 353 fun i_error (s, x as ((f, sbn), e), ((f', sbn'), e')) = let
76 :     fun complain () =
77 :     error (concat (describeSymbol
78 :     (s, [" imported from ", DG.describeSBN sbn,
79 :     " and also from ", DG.describeSBN sbn'])))
80 :     fun union (NONE, _) = NONE
81 :     | union (_, NONE) = NONE
82 :     | union (SOME f, SOME f') = SOME (SymbolSet.union (f, f'))
83 :     in
84 :     if DG.sbeq (sbn, sbn') then
85 :     ((union (f, f'), sbn), DAEnv.LAYER (e, e'))
86 :     else (complain (); x)
87 :     end
88 : blume 283 val i_union = SymbolMap.unionWithi i_error
89 :     val gi_union = SymbolMap.unionWith #1
90 : blume 270 fun ld_error (s, f1, f2) =
91 : blume 275 (error (concat (describeSymbol
92 : blume 280 (s, [" defined in ", SmlInfo.spec f1,
93 :     " and also in ", SmlInfo.spec f2])));
94 : blume 275 f1)
95 : blume 269 val ld_union = SymbolMap.unionWithi ld_error
96 :     in
97 : blume 283 COLLECTION { imports = i_union (#imports c1, #imports c2),
98 :     gimports = gi_union (#gimports c1, #gimports c2),
99 : blume 269 smlfiles = #smlfiles c1 @ #smlfiles c2,
100 : blume 294 localdefs = ld_union (#localdefs c1, #localdefs c2),
101 : blume 301 subgroups = #subgroups c1 @ #subgroups c2,
102 :     reqpriv = StringSet.union (#reqpriv c1, #reqpriv c2) }
103 : blume 269 end
104 :    
105 : blume 299 fun expandOne (gp, rparse) arg = let
106 :     val primconf = #primconf (#param gp)
107 : blume 297 val { sourcepath, group, class } = arg
108 : blume 336 val class = Option.map (String.map Char.toLower) class
109 : blume 299 val error = GroupReg.error (#groupreg gp) group
110 : blume 274 fun noPrimitive () = let
111 : blume 294 fun e0 s = error EM.COMPLAIN s EM.nullErrorBody
112 :     fun w0 s = error EM.WARN s EM.nullErrorBody
113 : blume 277 val expansions = PrivateTools.expand e0 (sourcepath, class)
114 : blume 283 fun exp2coll (PrivateTools.GROUP p) = let
115 : blume 348 val g as GG.GROUP { exports = i, kind, required, ... } =
116 : blume 301 rparse p
117 : blume 348 val gi = case kind of GG.NOLIB => i | _ => SymbolMap.empty
118 : blume 283 in
119 :     COLLECTION { imports = i, gimports = gi, smlfiles = [],
120 : blume 294 localdefs = SymbolMap.empty,
121 : blume 380 subgroups = [g],
122 : blume 305 reqpriv = required }
123 : blume 283 end
124 : blume 274 | exp2coll (PrivateTools.SMLSOURCE src) = let
125 : blume 387 val { sourcepath = p, history = h, sh_spec = s } = src
126 : blume 301 val i = SmlInfo.info gp
127 : blume 297 { sourcepath = p,
128 :     group = group,
129 : blume 387 sh_spec = s,
130 : blume 326 split = true }
131 : blume 301 val exports =
132 :     case SmlInfo.exports gp i of
133 :     NONE => SS.empty
134 :     | SOME ex => (if SS.isEmpty ex then
135 :     w0 ("no module exports from " ^
136 : blume 354 SrcPath.descr p)
137 : blume 301 else ();
138 :     ex)
139 : blume 274 fun addLD (s, m) = SymbolMap.insert (m, s, i)
140 : blume 286 val ld = SS.foldl addLD SymbolMap.empty exports
141 : blume 274 in
142 : blume 283 COLLECTION { imports = SymbolMap.empty,
143 :     gimports = SymbolMap.empty,
144 : blume 274 smlfiles = [i],
145 : blume 294 localdefs = ld,
146 : blume 301 subgroups = [],
147 :     reqpriv = StringSet.empty }
148 : blume 274 end
149 :     val collections = map exp2coll expansions
150 : blume 277 fun combine (c1, c2) = sequential (c2, c1, e0)
151 : blume 274 in
152 :     foldl combine empty collections
153 :     end
154 :     in
155 :     if isSome class then noPrimitive ()
156 : blume 354 else case Primitive.fromString primconf (SrcPath.specOf sourcepath) of
157 : blume 274 SOME p => let
158 : blume 286 val exports = Primitive.exports primconf p
159 : blume 309 val env = Primitive.da_env primconf p
160 : blume 278 fun addFN (s, m) = let
161 : blume 282 val fsbn = (NONE, DG.SB_BNODE (DG.PNODE p))
162 : blume 278 in
163 : blume 282 SymbolMap.insert (m, s, (fsbn, env))
164 : blume 278 end
165 : blume 286 val imp = SS.foldl addFN SymbolMap.empty exports
166 : blume 270 in
167 : blume 283 COLLECTION { imports = imp,
168 :     gimports = SymbolMap.empty,
169 : blume 270 smlfiles = [],
170 : blume 294 localdefs = SymbolMap.empty,
171 : blume 301 subgroups = [],
172 :     reqpriv = Primitive.reqpriv p }
173 : blume 270 end
174 : blume 274 | NONE => noPrimitive ()
175 : blume 270 end
176 :    
177 : blume 364 fun build (COLLECTION c, fopt, gp) =
178 :     BuildDepend.build (c, fopt, gp)
179 : blume 280
180 : blume 294 fun subgroups (COLLECTION { subgroups = sg, ... }) = sg
181 :    
182 : blume 336 local
183 :     fun symenv_look (gp: GeneralParams.info) (c: collection) s =
184 :     SymVal.look (#symenv (#param gp)) s
185 :     in
186 :     fun num_look gp c s = getOpt (symenv_look gp c s, 0)
187 :     fun cm_look gp c s = isSome (symenv_look gp c s)
188 :     end
189 : blume 269
190 : blume 283 fun ml_look (COLLECTION { imports, localdefs, ... }) s =
191 :     isSome (SymbolMap.find (imports, s)) orelse
192 : blume 269 isSome (SymbolMap.find (localdefs, s))
193 : blume 267 end

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