1- use std:: collections:: { HashMap } ;
2- use std:: fmt;
3- use crate :: ast:: { Decl , DeclX , Ident , SnapShots , Typ , TypX } ;
1+ use crate :: ast:: { Decl , DeclX , Ident , SnapShots , Typ , TypX } ;
42use crate :: context:: Context ;
3+ use std:: collections:: HashMap ;
4+ use std:: fmt;
55use z3:: ast:: { Bool , Dynamic , Int } ;
66//use z3::{FuncDecl, Sort};
77
88#[ derive( Debug ) ]
99pub struct Model < ' a > {
1010 z3_model : z3:: Model < ' a > ,
1111 id_snapshots : SnapShots ,
12- value_snapshots : HashMap < Ident , HashMap < Ident , String > >
12+ value_snapshots : HashMap < Ident , HashMap < Ident , String > > ,
1313}
1414
1515// TODO: Duplicated from smt_verify
@@ -25,21 +25,16 @@ fn new_const<'ctx>(context: &mut Context<'ctx>, name: &String, typ: &Typ) -> Dyn
2525 }
2626}
2727
28-
2928impl < ' a > Model < ' a > {
30- pub fn new ( model : z3:: Model < ' a > , snapshots : SnapShots ) -> Model < ' a > {
29+ pub fn new ( model : z3:: Model < ' a > , snapshots : SnapShots ) -> Model < ' a > {
3130 println ! ( "Creating a new model with {} snapshots" , snapshots. len( ) ) ;
32- Model {
33- z3_model : model,
34- id_snapshots : snapshots,
35- value_snapshots : HashMap :: new ( ) ,
36- }
31+ Model { z3_model : model, id_snapshots : snapshots, value_snapshots : HashMap :: new ( ) }
3732 }
3833
39- // pub fn save_snapshots(&self, snapshots: SnapShots) {
40- // self.snapshots = snapshots.clone();
41- // }
42- fn lookup_z3_var ( & self , var_name : & String , var_smt : & Dynamic ) -> String {
34+ // pub fn save_snapshots(&self, snapshots: SnapShots) {
35+ // self.snapshots = snapshots.clone();
36+ // }
37+ fn lookup_z3_var ( & self , var_name : & String , var_smt : & Dynamic ) -> String {
4338 if let Some ( x) = self . z3_model . eval ( var_smt) {
4439 if let Some ( b) = x. as_bool ( ) {
4540 format ! ( "{}" , b)
@@ -55,17 +50,19 @@ impl<'a> Model<'a> {
5550 }
5651 }
5752
58-
5953 /// Reconstruct an AIR-level model based on the Z3 model
6054 pub fn build ( & mut self , context : & mut Context , local_vars : Vec < Decl > ) {
61- println ! ( "Building the AIR model" ) ;
55+ println ! ( "Building the AIR model" ) ;
6256 for ( snap_id, id_snapshot) in & self . id_snapshots {
6357 let mut value_snapshot = HashMap :: new ( ) ;
6458 println ! ( "Snapshot {} has {} variables" , snap_id, id_snapshot. len( ) ) ;
6559 for ( var_id, var_count) in & * id_snapshot {
6660 let var_name = crate :: var_to_const:: rename_var ( & * var_id, * var_count) ;
6761 println ! ( "\t {}" , var_name) ;
68- let var_smt = context. vars . get ( & var_name) . unwrap_or_else ( || panic ! ( "internal error: variable {} not found" , var_name) ) ;
62+ let var_smt = context
63+ . vars
64+ . get ( & var_name)
65+ . unwrap_or_else ( || panic ! ( "internal error: variable {} not found" , var_name) ) ;
6966 let val = self . lookup_z3_var ( & var_name, var_smt) ;
7067 value_snapshot. insert ( var_id. clone ( ) , val) ;
7168 }
@@ -86,7 +83,7 @@ impl<'a> Model<'a> {
8683 }
8784 }
8885
89- pub fn query_variable ( & self , snapshot : Ident , name : Ident ) -> Option < String > {
86+ pub fn query_variable ( & self , snapshot : Ident , name : Ident ) -> Option < String > {
9087 Some ( self . value_snapshots . get ( & snapshot) ?. get ( & name) ?. to_string ( ) )
9188 }
9289}
@@ -103,4 +100,3 @@ impl<'a> fmt::Display for Model<'a> {
103100 Ok ( ( ) )
104101 }
105102}
106-
0 commit comments