1/* Part of Extended Tools for SWI-Prolog 2 3 Author: Edison Mera 4 E-mail: efmera@gmail.com 5 WWW: https://github.com/edisonm/xtools 6 Copyright (C): 2018, Process Design Center, Breda, The Netherlands. 7 All rights reserved. 8 9 Redistribution and use in source and binary forms, with or without 10 modification, are permitted provided that the following conditions 11 are met: 12 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright 17 notice, this list of conditions and the following disclaimer in 18 the documentation and/or other materials provided with the 19 distribution. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 POSSIBILITY OF SUCH DAMAGE. 33*/ 34 35:- module(assrt_metainference, [infer_meta_assertions/0]). 36 37:- use_module(library(apply)). 38:- use_module(library(lists)). 39:- use_module(library(pairs)). 40:- use_module(library(assertions)). 41:- use_module(library(transpose)). 42:- use_module(library(prolog_metainference), []). 43:- init_expansors. 44 45:- prolog_metainference:use_module(library(apply), [maplist/3]). 46 47applicable_type(calls). 48applicable_type(success). 49applicable_type(pred). 50applicable_type(prop). 51 52meta_prop(typeprops:goal(Var), 0, Var). 53meta_prop(typeprops:goal(N, Var), N, Var). 54meta_prop(typeprops:mod_qual(Var), :, Var).
63infer_meta_assertions :-
64 findall((M:F/A)-Meta,
65 ( asr_head_prop(Asr, CM, Head, Status, Type, _, _, _From),
66 memberchk(Status, [true, trust, check]),
67 applicable_type(Type),
68 functor(Head, F, A),
69 predicate_property(CM:Head, implementation_module(M)),
70 findall([Head, Arg, Spec],
71 ( member(Key, [comp, call, succ]),
72 meta_prop(Prop, Spec, Arg),
73 prop_asr(Key, Prop, _, Asr)
74 ), HeadArgSpecLL),
75 transpose(HeadArgSpecLL, [HeadL, ArgL, SpecL]),
76 maplist(=(Head), HeadL),
77 prolog_metainference:maplist(annotate, ArgL, SpecL),
78 prolog_metainference:meta_annotation(Head, Meta)
79 ), KeyMetaU),
80 keysort(KeyMetaU, KeyMetaL),
81 group_pairs_by_key(KeyMetaL, KeyMetaG),
82 forall(member((M:F/A)-MetaL1, KeyMetaG),
83 ( functor(Head, F, A),
84 ( predicate_property(M:Head, meta_predicate(Meta1))
85 ->MetaL = [Meta1|MetaL1]
86 ; MetaL = MetaL1
87 ),
88 prolog_metainference:combine_meta_args(MetaL, Meta),
89 assertz(prolog_metainference:inferred_meta_pred(Head, M, Meta))
90 ))