def migrate(self, expression, name_migration_map=None):
if name_migration_map is None:<EOL><INDENT>name_migration_map = {}<EOL><DEDENT>object_migration_map = {}<EOL>foreign_vars = itertools.filterfalse(self.is_declared, get_variables(expression))<EOL>for foreign_var in foreign_vars:<EOL><INDENT>if foreign_var.name in name_migration_map:<EOL><INDENT>migrated_name = name_migration_map[foreign_var.name]<EOL>native_var = self.get_variable(migrated_name)<EOL>assert native_var is not None, "<STR_LIT>"<EOL>object_migration_map[foreign_var] = native_var<EOL><DEDENT>else:<EOL><INDENT>migrated_name = foreign_var.name<EOL>if migrated_name in self._declarations:<EOL><INDENT>migrated_name = self._make_unique_name(f'<STR_LIT>')<EOL><DEDENT>if isinstance(foreign_var, Bool):<EOL><INDENT>new_var = self.new_bool(name=migrated_name)<EOL><DEDENT>elif isinstance(foreign_var, BitVec):<EOL><INDENT>new_var = self.new_bitvec(foreign_var.size, name=migrated_name)<EOL><DEDENT>elif isinstance(foreign_var, Array):<EOL><INDENT>new_var = self.new_array(index_max=foreign_var.index_max, index_bits=foreign_var.index_bits, value_bits=foreign_var.value_bits, name=migrated_name).array<EOL><DEDENT>else:<EOL><INDENT>raise NotImplemented(f"<STR_LIT>")<EOL><DEDENT>object_migration_map[foreign_var] = new_var<EOL>name_migration_map[foreign_var.name] = new_var.name<EOL><DEDENT><DEDENT>migrated_expression = replace(expression, object_migration_map)<EOL>return migrated_expression<EOL>
Migrate an expression created for a different constraint set to self.
            Returns an expression that can be used with this constraintSet

            All the foreign variables used in the expression are replaced by
            variables of this constraint set. If the variable was replaced before
            the replacement is taken from the provided migration map.

            The migration mapping is updated with new replacements.

            :param expression: the potentially foreign expression
            :param name_migration_map: mapping of already migrated variables. maps from string name of foreign variable to its currently existing migrated string name. this is updated during this migration.
            :return: a migrated expression where all the variables are local. name_migration_map is updated