@@ -15,8 +15,8 @@ use crate::distinct_vec::DistinctVec;
1515use crate :: expr_loader:: ExprLoader ;
1616use crate :: lang:: Lang ;
1717use crate :: replay:: { Events , Replay } ;
18- use crate :: task:: { Action , Breakpoint , Call , CallArg , CoreTrace , Location , ProgramEvent , RRTicks , NO_INDEX , NO_PATH , NO_POSITION , CtLoadLocalsArguments , Variable } ;
19- use crate :: value:: { Type , Value } ;
18+ use crate :: task:: { Action , Breakpoint , Call , CallArg , CoreTrace , Location , ProgramEvent , RRTicks , NO_INDEX , NO_PATH , NO_POSITION , CtLoadLocalsArguments , VariableWithRecord } ;
19+ use crate :: value:: { Type , Value , ValueRecordWithType } ;
2020
2121const NEXT_INTERNAL_STEP_OVERS_LIMIT : usize = 1_000 ;
2222
@@ -795,6 +795,52 @@ impl DbReplay {
795795 DbReplay { db, step_id : StepId ( 0 ) , call_key : CallKey ( 0 ) , breakpoint_list, breakpoint_next_id : 0 }
796796 }
797797
798+ pub fn register_type ( & mut self , typ : TypeRecord ) -> TypeId {
799+ // for no checking for typ.name logic: eventually in ensure_type?
800+ self . db . types . push ( typ) ;
801+ TypeId ( self . db . types . len ( ) - 1 )
802+ }
803+
804+ pub fn to_value_record ( & mut self , v : ValueRecordWithType ) -> ValueRecord {
805+ match v {
806+ ValueRecordWithType :: Int { i, typ } => {
807+ let type_id = self . register_type ( typ) ;
808+ ValueRecord :: Int { i, type_id }
809+ } ,
810+ ValueRecordWithType :: Float { f, typ } => {
811+ let type_id = self . register_type ( typ) ;
812+ ValueRecord :: Float { f, type_id }
813+ }
814+ ValueRecordWithType :: Bool { b, typ } => {
815+ let type_id = self . register_type ( typ) ;
816+ ValueRecord :: Bool { b, type_id }
817+ }
818+ ValueRecordWithType :: String { text, typ } => {
819+ let type_id = self . register_type ( typ) ;
820+ ValueRecord :: String { text, type_id }
821+ }
822+ _ => todo ! ( )
823+ }
824+ }
825+
826+ pub fn to_value_record_with_type ( & mut self , v : & ValueRecord ) -> ValueRecordWithType {
827+ match v {
828+ ValueRecord :: Int { i, type_id } => {
829+ ValueRecordWithType :: Int { i : * i, typ : self . db . types [ * type_id] . clone ( ) }
830+ } ,
831+ ValueRecord :: Float { f, type_id } => {
832+ ValueRecordWithType :: Float { f : * f, typ : self . db . types [ * type_id] . clone ( ) }
833+ }
834+ ValueRecord :: Bool { b, type_id } => {
835+ ValueRecordWithType :: Bool { b : * b, typ : self . db . types [ * type_id] . clone ( ) }
836+ }
837+ ValueRecord :: String { text, type_id } => {
838+ ValueRecordWithType :: String { text : text. to_string ( ) , typ : self . db . types [ * type_id] . clone ( ) }
839+ }
840+ _ => todo ! ( )
841+ }
842+ }
843+
798844 pub fn step_id_jump ( & mut self , step_id : StepId ) {
799845 if step_id. 0 != NO_INDEX {
800846 self . step_id = step_id;
@@ -973,30 +1019,33 @@ impl Replay for DbReplay {
9731019 }
9741020 }
9751021
976- fn load_locals ( & mut self , _arg : CtLoadLocalsArguments ) -> Result < Vec < Variable > , Box < dyn Error > > {
977- let full_value_locals: Vec < Variable > = self . db . variables [ self . step_id ]
1022+ fn load_locals ( & mut self , _arg : CtLoadLocalsArguments ) -> Result < Vec < VariableWithRecord > , Box < dyn Error > > {
1023+ let variables_for_step = self . db . variables [ self . step_id ] . clone ( ) ;
1024+ let full_value_locals: Vec < VariableWithRecord > = variables_for_step
9781025 . iter ( )
979- . map ( |v| Variable {
1026+ . map ( |v| VariableWithRecord {
9801027 expression : self . db . variable_name ( v. variable_id ) . to_string ( ) ,
981- value : self . db . to_ct_value ( & v. value ) ,
1028+ value : self . to_value_record_with_type ( & v. value ) ,
1029+ // &self.db.to_ct_value(&v.value),
9821030 } )
9831031 . collect ( ) ;
9841032
9851033 // TODO: fix random order here as well: ensure order(or in final locals?)
986- let value_tracking_locals: Vec < Variable > = self . db . variable_cells [ self . step_id ]
1034+ let variable_cells_for_step = self . db . variable_cells [ self . step_id ] . clone ( ) ;
1035+ let value_tracking_locals: Vec < VariableWithRecord > = variable_cells_for_step
9871036 . iter ( )
9881037 . map ( |( variable_id, place) | {
9891038 let name = self . db . variable_name ( * variable_id) ;
9901039 info ! ( "log local {variable_id:?} {name} place: {place:?}" ) ;
9911040 let value = self . db . load_value_for_place ( * place, self . step_id ) ;
992- Variable {
1041+ VariableWithRecord {
9931042 expression : self . db . variable_name ( * variable_id) . to_string ( ) ,
994- value : self . db . to_ct_value ( & value) ,
1043+ value : self . to_value_record_with_type ( & value) ,
9951044 }
9961045 } )
9971046 . collect ( ) ;
9981047 // based on https://stackoverflow.com/a/56490417/438099
999- let mut locals: Vec < Variable > = full_value_locals. into_iter ( ) . chain ( value_tracking_locals) . collect ( ) ;
1048+ let mut locals: Vec < VariableWithRecord > = full_value_locals. into_iter ( ) . chain ( value_tracking_locals) . collect ( ) ;
10001049
10011050 locals. sort_by ( |left, right| Ord :: cmp ( & left. expression , & right. expression ) ) ;
10021051 // for now just removing duplicated variables/expressions: even if storing different values
@@ -1005,21 +1054,21 @@ impl Replay for DbReplay {
10051054 Ok ( locals)
10061055 }
10071056
1008- fn load_value ( & mut self , expression : & str ) -> Result < ValueRecord , Box < dyn Error > > {
1057+ fn load_value ( & mut self , expression : & str ) -> Result < ValueRecordWithType , Box < dyn Error > > {
10091058 // TODO: a more optimal way: cache a hashmap? or change structure?
10101059 // or again start directly loading available values matching all expressions in the same time?:
10111060 // taking a set of expressions: probably best(maybe add an additional load_values)
10121061 for variable in & self . db . variables [ self . step_id ] {
10131062 if self . db . variable_names [ variable. variable_id ] == expression {
1014- return Ok ( variable. value . clone ( ) )
1063+ return Ok ( self . to_value_record_with_type ( & variable. value . clone ( ) ) )
10151064 }
10161065 }
10171066 return Err ( format ! ( "variable {expression} not found on this step" ) . into ( ) )
10181067 }
10191068
1020- fn load_return_value ( & mut self ) -> Result < ValueRecord , Box < dyn Error > > {
1069+ fn load_return_value ( & mut self ) -> Result < ValueRecordWithType , Box < dyn Error > > {
10211070 // assumes self.load_location() has been ran, and that we have the current call key
1022- Ok ( self . db . calls [ self . call_key ] . return_value . clone ( ) )
1071+ Ok ( self . to_value_record_with_type ( & self . db . calls [ self . call_key ] . return_value . clone ( ) ) )
10231072 }
10241073
10251074 fn load_step_events ( & mut self , step_id : StepId , exact : bool ) -> Vec < DbRecordEvent > {
0 commit comments