コード例 #1
0
	def testUniqueVar(self):
		from iegen.util import get_unique_var

		self.failUnless('a'==get_unique_var('a',set()))
		self.failUnless('a'==get_unique_var('a',set(['b'])))
		self.failUnless('a'==get_unique_var('a',set(['b','c'])))
		self.failUnless('a0'==get_unique_var('a',set(['a'])))
		self.failUnless('a0'==get_unique_var('a',set(['a','b','c'])))
コード例 #2
0
	def inVarExp(self,node):
		if self.in_var_tuple:
			#Get a unique name for the current tuple variable
			new_var_name=get_unique_var(node.id,self.used_vars)

			#Add the variable name to the collection of used variable names
			self.used_vars.add(new_var_name)

			#If the unique name is different from the current name,
			# change the name in this tuple variable and add an equality constraint
			if new_var_name!=node.id:
				#Grab the old tuple variable name
				old_var_name=node.id

				#Update the current variable name to the new one
				node.id=new_var_name

				#Create an equality constraint: new_var_name=old_var_name
				self.new_equalities.append(Equality(NormExp([VarExp(1,old_var_name),VarExp(-1,new_var_name)],0)))

				#Note that we have changed the formula
				self.changed=True