Generate a new version of the variable v and return it

v The variable for which we generate a name counter The key is the variable, the value the number of assignment into the variable expr The AST node in which the assignment of v is made ssa The instance of SSA

Property definitions

nitc :: ssa $ APropdef :: generate_name
	# Generate a new version of the variable `v` and return it
	# *`v` The variable for which we generate a name
	# *`counter` The key is the variable, the value the number of assignment into the variable
	# *`expr` The AST node in which the assignment of v is made
	# *`ssa` The instance of SSA
	fun generate_name(v: Variable, counter: HashMap[Variable, Int], expr: ANode, ssa: SSA): Variable
	do
		var original_variable = v.original_variable.as(not null)

		var i = counter[original_variable]

		var new_version: Variable

		# Create a new version of Variable
		if original_variable isa PhiFunction then
			var block = original_variable.block
			new_version = new PhiFunction(original_variable.name + i.to_s, block)
			new_version.dependences.add_all(original_variable.dependences)
			ssa.phi_functions.add(new_version)
		else
			new_version = new Variable(original_variable.name + i.to_s)
			new_version.declared_type = expr.as(AVarFormExpr).variable.declared_type
			variables.add(new_version)
		end

		# Recopy the fields into the new version
		new_version.location = expr.location
		new_version.original_variable = original_variable

		# Push a new version on the stack
		original_variable.stack.add(new_version)
		counter[v] = i + 1

		return new_version
	end
src/ssa.nit:375,2--409,4

nitc :: compilation $ APropdef :: generate_name
	# Redef to add the same position to a new version of a Variable than the original variable
	redef fun generate_name(v, counter, expr, ssa)
	do
		var new_version = super

		# All versions of a variable have the same position in the environment
		new_version.position = v.original_variable.position

		return new_version
	end
src/vm/compilation.nit:50,2--59,4