142 in (("codevals", code''), (ctxt', args')) end; |
142 in (("codevals", code''), (ctxt', args')) end; |
143 |
143 |
144 |
144 |
145 (* const expressions *) |
145 (* const expressions *) |
146 |
146 |
|
147 local |
|
148 |
|
149 fun consts_of thy some_thyname = |
|
150 let |
|
151 val this_thy = Option.map ThyInfo.get_theory some_thyname |> the_default thy; |
|
152 val raw_cs = Symtab.fold (fn (c, (_, NONE)) => cons c | _ => I) |
|
153 ((snd o #constants o Consts.dest o #consts o Sign.rep_sg) this_thy) []; |
|
154 val cs = map (CodeUnit.subst_alias thy) raw_cs; |
|
155 fun belongs_here thyname c = |
|
156 not (exists (fn thy' => Sign.declared_const thy' c) (Theory.parents_of this_thy)) |
|
157 in case some_thyname |
|
158 of NONE => cs |
|
159 | SOME thyname => filter (belongs_here thyname) cs |
|
160 end; |
|
161 |
|
162 fun read_const_expr thy "*" = ([], consts_of thy NONE) |
|
163 | read_const_expr thy s = if String.isSuffix ".*" s |
|
164 then ([], consts_of thy (SOME (unsuffix ".*" s))) |
|
165 else ([CodeUnit.read_const thy s], []); |
|
166 |
|
167 in |
|
168 |
|
169 fun read_const_exprs thy select exprs = |
|
170 case (pairself flat o split_list o map (read_const_expr thy)) exprs |
|
171 of (consts, []) => (false, consts) |
|
172 | (consts, consts') => (true, consts @ select consts'); |
|
173 |
|
174 end; (*local*) |
|
175 |
147 fun filter_generatable thy consts = |
176 fun filter_generatable thy consts = |
148 let |
177 let |
149 val (consts', funcgr) = CodeFuncgr.make_consts thy consts; |
178 val (consts', funcgr) = CodeFuncgr.make_consts thy consts; |
150 val (consts'', _) = generate thy funcgr (fold_map ooo perhaps_const) consts'; |
179 val (consts'', _) = generate thy funcgr (fold_map ooo perhaps_const) consts'; |
151 val consts''' = map_filter (fn (const, SOME _) => SOME const | (_, NONE) => NONE) |
180 val consts''' = map_filter (fn (const, SOME _) => SOME const | (_, NONE) => NONE) |
152 (consts' ~~ consts''); |
181 (consts' ~~ consts''); |
153 in consts''' end; |
182 in consts''' end; |
154 |
183 |
155 fun generate_const_exprs thy raw_cs = |
184 fun generate_const_exprs thy raw_cs = |
156 let |
185 let |
157 val (perm1, cs) = CodeUnit.read_const_exprs thy |
186 val (perm1, cs) = read_const_exprs thy |
158 (filter_generatable thy) raw_cs; |
187 (filter_generatable thy) raw_cs; |
159 val (perm2, cs') = case generate thy (CodeFuncgr.make thy cs) |
188 val (perm2, cs') = case generate thy (CodeFuncgr.make thy cs) |
160 (fold_map ooo ensure_const) cs |
189 (fold_map ooo ensure_const) cs |
161 of ([], _) => (true, NONE) |
190 of ([], _) => (true, NONE) |
162 | (cs, _) => (false, SOME cs); |
191 | (cs, _) => (false, SOME cs); |
234 val (permissive, cs) = generate_const_exprs thy raw_cs; |
263 val (permissive, cs) = generate_const_exprs thy raw_cs; |
235 val _ = code thy permissive cs seris; |
264 val _ = code thy permissive cs seris; |
236 in () end; |
265 in () end; |
237 |
266 |
238 fun code_thms_cmd thy = |
267 fun code_thms_cmd thy = |
239 code_thms thy o snd o CodeUnit.read_const_exprs thy (fst o CodeFuncgr.make_consts thy); |
268 code_thms thy o snd o read_const_exprs thy (fst o CodeFuncgr.make_consts thy); |
240 |
269 |
241 fun code_deps_cmd thy = |
270 fun code_deps_cmd thy = |
242 code_deps thy o snd o CodeUnit.read_const_exprs thy (fst o CodeFuncgr.make_consts thy); |
271 code_deps thy o snd o read_const_exprs thy (fst o CodeFuncgr.make_consts thy); |
243 |
272 |
244 fun code_props_cmd raw_cs seris thy = |
273 fun code_props_cmd raw_cs seris thy = |
245 let |
274 let |
246 val (_, all_cs) = generate_const_exprs thy ["*"]; |
275 val (_, all_cs) = generate_const_exprs thy ["*"]; |
247 val (permissive, cs) = generate_const_exprs thy raw_cs; |
276 val (permissive, cs) = generate_const_exprs thy raw_cs; |