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 283 - (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 269
18 : blume 267 type collection
19 :    
20 : blume 283 type farlooker = AbsPath.t ->
21 :     { imports: impexp SymbolMap.map, gimports: impexp SymbolMap.map }
22 : blume 278
23 : blume 274 val empty : collection
24 :    
25 : blume 278 val expandOne : farlooker
26 : blume 275 -> { sourcepath: AbsPath.t, group: AbsPath.t, class: string option,
27 : blume 277 error : string -> (PrettyPrint.ppstream -> unit) -> unit }
28 : blume 270 -> collection
29 : blume 275 val sequential : collection * collection * (string -> unit) -> collection
30 : blume 267
31 : blume 283 val build : collection * SymbolSet.set option * (string -> unit)
32 :     -> impexp SymbolMap.map
33 : blume 280
34 : blume 268 val num_look : collection -> string -> int
35 : blume 278 val ml_look : collection -> symbol -> bool
36 : blume 268 val cm_look : collection -> string -> bool
37 : blume 267 end
38 :    
39 :     structure MemberCollection :> MEMBERCOLLECTION = struct
40 :    
41 : blume 269 structure DG = DependencyGraph
42 : blume 277 structure EM = GenericVC.ErrorMsg
43 : blume 278 structure CBE = GenericVC.BareEnvironment
44 : blume 267
45 : blume 270 type smlinfo = SmlInfo.info
46 : blume 275 type symbol = Symbol.symbol
47 : blume 283 type impexp = DG.impexp
48 : blume 267
49 : blume 269 datatype collection =
50 : blume 283 COLLECTION of { imports: impexp SymbolMap.map,
51 :     gimports: impexp SymbolMap.map,
52 : blume 269 smlfiles: smlinfo list,
53 :     localdefs: smlinfo SymbolMap.map }
54 :    
55 : blume 283 type farlooker = AbsPath.t ->
56 :     { imports: impexp SymbolMap.map, gimports: impexp SymbolMap.map }
57 : blume 278
58 : blume 274 val empty =
59 : blume 283 COLLECTION { imports = SymbolMap.empty,
60 :     gimports = SymbolMap.empty,
61 : blume 274 smlfiles = [],
62 :     localdefs = SymbolMap.empty }
63 :    
64 : blume 278 fun convertEnv cmenv = let
65 :     fun modulesOnly sl = let
66 :     fun addModule (sy, set) =
67 :     case Symbol.nameSpace sy of
68 :     (Symbol.STRspace | Symbol.SIGspace |
69 :     Symbol.FCTspace | Symbol.FSIGspace) =>
70 :     SymbolSet.add (set, sy)
71 :     | _ => set
72 :     in
73 :     foldl addModule SymbolSet.empty sl
74 :     end
75 :     fun cvt CBE.CM_NONE = NONE
76 :     | cvt (CBE.CM_ENV { look, symbols }) =
77 :     SOME (DG.FCTENV { looker = cvt o look,
78 :     domain = modulesOnly o symbols })
79 :     in
80 :     valOf (cvt cmenv)
81 :     end
82 :    
83 : blume 275 fun sequential (COLLECTION c1, COLLECTION c2, error) = let
84 :     fun describeSymbol (s, r) = let
85 :     val ns = Symbol.nameSpace s
86 :     in
87 :     Symbol.nameSpaceToString ns :: " " :: Symbol.name s :: r
88 :     end
89 : blume 283 fun i_error (s, x as (fn1, _), (fn2, _)) =
90 : blume 275 (error (concat (describeSymbol
91 : blume 282 (s, [" imported from ", DG.describeFarSBN fn1,
92 :     " and also from ", DG.describeFarSBN fn2])));
93 : blume 275 x)
94 : blume 283 val i_union = SymbolMap.unionWithi i_error
95 :     val gi_union = SymbolMap.unionWith #1
96 : blume 270 fun ld_error (s, f1, f2) =
97 : blume 275 (error (concat (describeSymbol
98 : blume 280 (s, [" defined in ", SmlInfo.spec f1,
99 :     " and also in ", SmlInfo.spec f2])));
100 : blume 275 f1)
101 : blume 269 val ld_union = SymbolMap.unionWithi ld_error
102 :     in
103 : blume 283 COLLECTION { imports = i_union (#imports c1, #imports c2),
104 :     gimports = gi_union (#gimports c1, #gimports c2),
105 : blume 269 smlfiles = #smlfiles c1 @ #smlfiles c2,
106 :     localdefs = ld_union (#localdefs c1, #localdefs c2) }
107 :     end
108 :    
109 : blume 275 fun expandOne gexports { sourcepath, group, class, error } = let
110 : blume 274 fun noPrimitive () = let
111 : blume 277 fun e0 s = error s EM.nullErrorBody
112 :     val expansions = PrivateTools.expand e0 (sourcepath, class)
113 : blume 283 fun exp2coll (PrivateTools.GROUP p) = let
114 :     val { imports = i, gimports = gi } = gexports p
115 :     in
116 :     COLLECTION { imports = i, gimports = gi, smlfiles = [],
117 :     localdefs = SymbolMap.empty }
118 :     end
119 : blume 274 | exp2coll (PrivateTools.SMLSOURCE src) = let
120 :     val { sourcepath = p, history = h, share = s } = src
121 : blume 276 val i = SmlInfo.info
122 : blume 274 Policy.default
123 : blume 275 { sourcepath = p, group = group,
124 :     error = error, history = h,
125 : blume 277 share = s }
126 : blume 274 val exports = SmlInfo.exports i
127 :     fun addLD (s, m) = SymbolMap.insert (m, s, i)
128 :     val ld = SymbolSet.foldl addLD SymbolMap.empty exports
129 :     in
130 : blume 283 COLLECTION { imports = SymbolMap.empty,
131 :     gimports = SymbolMap.empty,
132 : blume 274 smlfiles = [i],
133 :     localdefs = ld }
134 :     end
135 :     val collections = map exp2coll expansions
136 : blume 277 fun combine (c1, c2) = sequential (c2, c1, e0)
137 : blume 274 in
138 :     foldl combine empty collections
139 :     end
140 :     in
141 :     if isSome class then noPrimitive ()
142 :     else case Primitive.fromString (AbsPath.spec sourcepath) of
143 :     SOME p => let
144 : blume 270 val exports = Primitive.exports p
145 : blume 278 fun addFN (s, m) = let
146 :     val cmenv = Primitive.lookup p s
147 :     val env = convertEnv cmenv
148 : blume 282 val fsbn = (NONE, DG.SB_BNODE (DG.PNODE p))
149 : blume 278 in
150 : blume 282 SymbolMap.insert (m, s, (fsbn, env))
151 : blume 278 end
152 : blume 283 val imp = SymbolSet.foldl addFN SymbolMap.empty exports
153 : blume 270 in
154 : blume 283 COLLECTION { imports = imp,
155 :     gimports = SymbolMap.empty,
156 : blume 270 smlfiles = [],
157 :     localdefs = SymbolMap.empty }
158 :     end
159 : blume 274 | NONE => noPrimitive ()
160 : blume 270 end
161 :    
162 : blume 283 fun build (COLLECTION c, fopt, error) = BuildDepend.build (c, fopt, error)
163 : blume 280
164 : blume 268 fun num_look (c: collection) (s: string) = 0
165 : blume 269
166 : blume 268 fun cm_look (c: collection) (s: string) = false
167 : blume 269
168 : blume 283 fun ml_look (COLLECTION { imports, localdefs, ... }) s =
169 :     isSome (SymbolMap.find (imports, s)) orelse
170 : blume 269 isSome (SymbolMap.find (localdefs, s))
171 : blume 267 end

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