pub fn dummy_from_view(view: &BinaryIndexedView, default_loc: Loc) -> Result<Self> {
        let module_ident = match view {
            BinaryIndexedView::Script(..) => None,
            BinaryIndexedView::Module(..) => {
                let module_handle = view.module_handle_at(ModuleHandleIndex::new(0));
                let module_name = ModuleName(Symbol::from(
                    view.identifier_at(module_handle.name).as_str(),
                ));
                let address = *view.address_identifier_at(module_handle.address);
                Some(ModuleIdent::new(module_name, address))
            }
        };
        let mut empty_source_map = Self::new(default_loc, module_ident);

        match view {
            BinaryIndexedView::Script(script) => {
                empty_source_map.add_top_level_function_mapping(
                    FunctionDefinitionIndex(0_u16),
                    default_loc,
                    false,
                )?;
                empty_source_map
                    .function_map
                    .get_mut(&(0_u16))
                    .ok_or_else(|| {
                        format_err!("Unable to get function map while generating dummy")
                    })?
                    .dummy_function_map(
                        view,
                        &script.type_parameters,
                        script.parameters,
                        Some(script.code.clone()),
                        default_loc,
                    )?;
            }
            BinaryIndexedView::Module(module) => {
                for (function_idx, function_def) in module.function_defs.iter().enumerate() {
                    empty_source_map.add_top_level_function_mapping(
                        FunctionDefinitionIndex(function_idx as TableIndex),
                        default_loc,
                        false,
                    )?;
                    let function_handle = module.function_handle_at(function_def.function);
                    empty_source_map
                        .function_map
                        .get_mut(&(function_idx as TableIndex))
                        .ok_or_else(|| {
                            format_err!("Unable to get function map while generating dummy")
                        })?
                        .dummy_function_map(
                            view,
                            &function_handle.type_parameters,
                            function_handle.parameters,
                            function_def.code.clone(),
                            default_loc,
                        )?;
                }
            }
        };

        for (struct_idx, struct_def) in view.struct_defs().into_iter().flatten().enumerate() {
            empty_source_map.add_top_level_struct_mapping(
                StructDefinitionIndex(struct_idx as TableIndex),
                default_loc,
            )?;
            empty_source_map
                .struct_map
                .get_mut(&(struct_idx as TableIndex))
                .ok_or_else(|| format_err!("Unable to get struct map while generating dummy"))?
                .dummy_struct_map(view, struct_def, default_loc)?;
        }

        for const_idx in 0..view.constant_pool().len() {
            empty_source_map.add_const_mapping(
                ConstantPoolIndex(const_idx as TableIndex),
                ConstantName(Symbol::from(format!("CONST{}", const_idx))),
            )?;
        }

        Ok(empty_source_map)
    }
/// Create a 'dummy' source map for a compiled module or script. This is useful for e.g. disassembling
/// with generated or real names depending upon if the source map is available or not.
Create a 'dummy' source map for a compiled module or script. This is useful for e.g. disassembling
with generated or real names depending upon if the source map is available or not.
Create a ' dummy ' source map for a compiled module or script . This is useful for e . g . disassembling with generated or real names depending upon if the source map is available or not .
pub fn dummy_from_view(view: &BinaryIndexedView, default_loc: Loc) -> Result<Self> {
        let module_ident = match view {
            BinaryIndexedView::Script(..) => None,
            BinaryIndexedView::Module(..) => {
                let module_handle = view.module_handle_at(ModuleHandleIndex::new(0));
                let module_name = ModuleName(Symbol::from(
                    view.identifier_at(module_handle.name).as_str(),
                ));
                let address = *view.address_identifier_at(module_handle.address);
                Some(ModuleIdent::new(module_name, address))
            }
        };
        let mut empty_source_map = Self::new(default_loc, module_ident);
        match view {
            BinaryIndexedView::Script(script) => {
                empty_source_map.add_top_level_function_mapping(
                    FunctionDefinitionIndex(0_u16),
                    default_loc,
                    false,
                )?;
                empty_source_map
                    .function_map
                    .get_mut(&(0_u16))
                    .ok_or_else(|| {
                        format_err!("Unable to get function map while generating dummy")
                    })?
                    .dummy_function_map(
                        view,
                        &script.type_parameters,
                        script.parameters,
                        Some(script.code.clone()),
                        default_loc,
                    )?;
            }
            BinaryIndexedView::Module(module) => {
                for (function_idx, function_def) in module.function_defs.iter().enumerate() {
                    empty_source_map.add_top_level_function_mapping(
                        FunctionDefinitionIndex(function_idx as TableIndex),
                        default_loc,
                        false,
                    )?;
                    let function_handle = module.function_handle_at(function_def.function);
                    empty_source_map
                        .function_map
                        .get_mut(&(function_idx as TableIndex))
                        .ok_or_else(|| {
                            format_err!("Unable to get function map while generating dummy")
                        })?
                        .dummy_function_map(
                            view,
                            &function_handle.type_parameters,
                            function_handle.parameters,
                            function_def.code.clone(),
                            default_loc,
                        )?;
                }
            }
        };
        for (struct_idx, struct_def) in view.struct_defs().into_iter().flatten().enumerate() {
            empty_source_map.add_top_level_struct_mapping(
                StructDefinitionIndex(struct_idx as TableIndex),
                default_loc,
            )?;
            empty_source_map
                .struct_map
                .get_mut(&(struct_idx as TableIndex))
                .ok_or_else(|| format_err!("Unable to get struct map while generating dummy"))?
                .dummy_struct_map(view, struct_def, default_loc)?;
        }
        for const_idx in 0..view.constant_pool().len() {
            empty_source_map.add_const_mapping(
                ConstantPoolIndex(const_idx as TableIndex),
                ConstantName(Symbol::from(format!("CONST{}", const_idx))),
            )?;
        }
        Ok(empty_source_map)
    }
pub fn dummy_from_view ( view : & BinaryIndexedView , default_loc : Loc ) -> Result < Self > { let module_ident = match view { BinaryIndexedView :: Script ( .. ) => None , BinaryIndexedView :: Module ( .. ) => { let module_handle = view . module_handle_at ( ModuleHandleIndex :: new ( 0 ) ) ; let module_name = ModuleName ( Symbol :: from ( view . identifier_at ( module_handle . name ) . as_str ( ) , ) ) ; let address = * view . address_identifier_at ( module_handle . address ) ; Some ( ModuleIdent :: new ( module_name , address ) ) } } ; let mut empty_source_map = Self :: new ( default_loc , module_ident ) ; match view { BinaryIndexedView :: Script ( script ) => { empty_source_map . add_top_level_function_mapping ( FunctionDefinitionIndex ( 0_u16 ) , default_loc , false , ) ? ; empty_source_map . function_map . get_mut ( & ( 0_u16 ) ) . ok_or_else ( | | { format_err ! ( " " ) } ) ? . dummy_function_map ( view , & script . type_parameters , script . parameters , Some ( script . code . clone ( ) ) , default_loc , ) ? ; } BinaryIndexedView :: Module ( module ) => { for ( function_idx , function_def ) in module . function_defs . iter ( ) . enumerate ( ) { empty_source_map . add_top_level_function_mapping ( FunctionDefinitionIndex ( function_idx as TableIndex ) , default_loc , false , ) ? ; let function_handle = module . function_handle_at ( function_def . function ) ; empty_source_map . function_map . get_mut ( & ( function_idx as TableIndex ) ) . ok_or_else ( | | { format_err ! ( " " ) } ) ? . dummy_function_map ( view , & function_handle . type_parameters , function_handle . parameters , function_def . code . clone ( ) , default_loc , ) ? ; } } } ; for ( struct_idx , struct_def ) in view . struct_defs ( ) . into_iter ( ) . flatten ( ) . enumerate ( ) { empty_source_map . add_top_level_struct_mapping ( StructDefinitionIndex ( struct_idx as TableIndex ) , default_loc , ) ? ; empty_source_map . struct_map . get_mut ( & ( struct_idx as TableIndex ) ) . ok_or_else ( | | format_err ! ( " " ) ) ? . dummy_struct_map ( view , struct_def , default_loc ) ? ; } for const_idx in 0 .. view . constant_pool ( ) . len ( ) { empty_source_map . add_const_mapping ( ConstantPoolIndex ( const_idx as TableIndex ) , ConstantName ( Symbol :: from ( format ! ( " " const_idx ) ) ) , ) ? ; } Ok ( empty_source_map ) }
Create a 'dummy' source map for a compiled module or script.
Create a ' dummy ' source map for a compiled module or script .
view
&BinaryIndexedView
default_loc
Loc