123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Queries are a generic mechanism for extracting information from abstract
domains without being coupled to their internal representation.
*)openLatticeopenContextopenMopsa_utilsopenAst.VaropenAst.Addrtype('a,_)query=..typequery_pool={pool_join:'a'r.('a,'r)query->'r->'r->'r;pool_meet:'a'r.('a,'r)query->'r->'r->'r;}letsimple_pool=ref{pool_join=(fun___->raiseNot_found);pool_meet=(fun___->raiseNot_found);}typelattice_query_pool={pool_join:'a'r.'actx->'alattice->('a,'r)query->'r->'r->'r;pool_meet:'a'r.'actx->'alattice->('a,'r)query->'r->'r->'r;}letlattice_pool=ref{pool_join=(fun_____->raiseNot_found);pool_meet=(fun_____->raiseNot_found);}letjoin_query?(ctx=None)?(lattice=None)qab=try!simple_pool.pool_joinqabwithNot_found->matchctx,latticewith|Somectx,Somelattice->begintry!lattice_pool.pool_joinctxlatticeqabwithNot_found->Exceptions.panic"join_query: query not found"end|_->Exceptions.panic"join_query: query not found"letmeet_query?(ctx=None)?(lattice=None)qab=try!simple_pool.pool_meetqabwithNot_found->matchctx,latticewith|Somectx,Somelattice->begintry!lattice_pool.pool_meetctxlatticeqabwithNot_found->Exceptions.panic"meet_query: query not found"end|_->Exceptions.panic"meet_query: query not found"typequery_info={join:'a'r.query_pool->('a,'r)query->'r->'r->'r;meet:'a'r.query_pool->('a,'r)query->'r->'r->'r;}letregister_queryinfo=letold_pool=!simple_poolinsimple_pool:={pool_join=(funqab->info.joinold_poolqab);pool_meet=(funqab->info.meetold_poolqab);}typelattice_query_info={join:'a'r.lattice_query_pool->'actx->'alattice->('a,'r)query->'r->'r->'r;meet:'a'r.lattice_query_pool->'actx->'alattice->('a,'r)query->'r->'r->'r;}letregister_lattice_queryinfo=letold_pool=!lattice_poolinlattice_pool:={pool_join=(functxlatticeqab->info.joinold_poolctxlatticeqab);pool_meet=(functxlatticeqab->info.meetold_poolctxlatticeqab);}type('a,_)query+=|Q_defined_variables:stringoption->('a,varlist)query|Q_allocated_addresses:('a,addrlist)query|Q_variables_linked_to:Ast.Expr.expr->('a,Ast.Var.VarSet.t)querylet()=register_query{join=(letf:typear.query_pool->(a,r)query->r->r->r=funnextqueryab->matchquerywith|Q_defined_variables_->a@b|Q_allocated_addresses->a@b|Q_variables_linked_to_->Ast.Var.VarSet.unionab|_->next.pool_joinqueryabinf);meet=(letf:typear.query_pool->(a,r)query->r->r->r=funnextqueryab->matchquerywith|Q_allocated_addresses->assertfalse|Q_variables_linked_to_->Ast.Var.VarSet.interab|_->next.pool_meetqueryabinf);}