| 1 | % (c) 2014-2022 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
| 2 | % Heinrich Heine Universitaet Duesseldorf | |
| 3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
| 4 | ||
| 5 | :- module(smtlib2_environment,[empty_env/1, | |
| 6 | add_identifier/4, | |
| 7 | ||
| 8 | add_assertion/3, | |
| 9 | get_assertions/2, | |
| 10 | push_assertion_stack/3, | |
| 11 | pop_assertion_stack/3, | |
| 12 | ||
| 13 | get_type/3, | |
| 14 | add_function/6, | |
| 15 | get_function/5, | |
| 16 | create_local_env/3, | |
| 17 | get_custom_types/2, | |
| 18 | is_custom_type/2, | |
| 19 | add_custom_type/3]). | |
| 20 | ||
| 21 | :- use_module(probsrc(module_information),[module_info/2]). | |
| 22 | :- module_info(group,smtlib). | |
| 23 | :- module_info(description,'The SMT-LIB 2 Interpreter - Environment'). | |
| 24 | ||
| 25 | :- use_module(library(lists)). | |
| 26 | :- use_module(library(avl)). | |
| 27 | ||
| 28 | % environment: env(Identifiers,Functions,Assertions,CustomTypes) | |
| 29 | % identifiers: avl tree of b(identifier(ID),Type,[]) stored at ID | |
| 30 | % functions: avl tree of function(Parameters,RetType,Definition) at ID | |
| 31 | % Assertions: Stack (List) of Lists of predicates | |
| 32 | % CustomTypes: List of custom types, i.e. deferred sets | |
| 33 | ||
| 34 | empty_env(env(IDs,Funs,[[]],[])) :- | |
| 35 | empty_avl(IDs), | |
| 36 | empty_avl(Funs). | |
| 37 | ||
| 38 | get_custom_types(env(_,_,_,Ct),Ct). | |
| 39 | is_custom_type(env(_,_,_,Cts),Ct) :- | |
| 40 | member(Ct,Cts). | |
| 41 | add_custom_type(env(IDs,Funs,As,Ct),ID,env(IDs,Funs,As,[ID|Ct])). | |
| 42 | ||
| 43 | create_local_env(env(IDs,Funs,As,Ct),LocalIDs,env(NIDs,Funs,As,Ct)) :- | |
| 44 | avl_store_all_ids(LocalIDs,IDs,NIDs). | |
| 45 | ||
| 46 | avl_store_all_ids([],A,A). | |
| 47 | avl_store_all_ids([b(identifier(ID),Type,[])|T],AIn,AOut) :- | |
| 48 | avl_store(ID,AIn,b(identifier(ID),Type,[]),ATemp), | |
| 49 | avl_store_all_ids(T,ATemp,AOut). | |
| 50 | ||
| 51 | add_function(env(IDs,Funs,As,Ct),ID,P,R,D,env(IDs,NFuns,As,Ct)) :- | |
| 52 | avl_store(ID,Funs,function(P,R,D),NFuns). | |
| 53 | get_function(ID,env(_,Funs,_,_),Params,Results,Definition) :- atomic(ID),!, | |
| 54 | avl_fetch(ID,Funs,function(Params,Results,Definition)). | |
| 55 | get_function(ID,env(_,Funs,_,_),Params,Results,Definition) :- | |
| 56 | print(var_get_function(ID)),nl, | |
| 57 | avl_member(ID,Funs,function(Params,Results,Definition)). | |
| 58 | ||
| 59 | pop_assertion_stack(Env,0,Env) :- !. | |
| 60 | pop_assertion_stack(env(IDs,Funs,[_|Ass],Types),Count,EnvOut) :- Count > 0, !, | |
| 61 | NCount is Count - 1, | |
| 62 | pop_assertion_stack(env(IDs,Funs,Ass,Types),NCount,EnvOut). | |
| 63 | ||
| 64 | push_assertion_stack(Env,0,Env) :- !. | |
| 65 | push_assertion_stack(env(IDs,Funs,Ass,Types),Count,EnvOut) :- Count > 0, !, | |
| 66 | NCount is Count - 1, | |
| 67 | pop_assertion_stack(env(IDs,Funs,[[]|Ass],Types),NCount,EnvOut). | |
| 68 | ||
| 69 | get_assertions(env(_,_,As,_),AllAssertions) :- append(As,AllAssertions). | |
| 70 | add_assertion(env(IDs,Funs,[CurrentAssertionSet|AssertionSets],Ct),Term,env(IDs,Funs,[NAs|AssertionSets],Ct)) :- | |
| 71 | NAs = [Term|CurrentAssertionSet]. | |
| 72 | ||
| 73 | add_identifier(env(IDs,Funs,As,Ct),ID,Type,env(NIDs,Funs,As,Ct)) :- | |
| 74 | avl_store(ID,IDs,b(identifier(ID),Type,[]),NIDs). | |
| 75 | ||
| 76 | get_type(Id,env(IDs,_,_,_),Type) :- atomic(Id),!, | |
| 77 | avl_fetch(Id,IDs,b(identifier(Id),Type,[])). | |
| 78 | get_type(Id,env(IDs,_,_,_),Type) :- | |
| 79 | print(var_get_type(Id)),nl, | |
| 80 | avl_member(Id,IDs,b(identifier(Id),Type,[])). |