def _reduceFreeVariableMemberAccessChains(self, expr, freeVariableMemberAccessChainToImplValMap): """ given an expression `expr` and mapping `freeVariableMemberAccessChainToImplValMap`, replace the occurences of the keys of the mapping in expr with fresh variable names. Returns the new expression, and a mapping from the replacing variables to their corresponding (implval) values. """ renamedVariableMapping = {} for chain, implval in freeVariableMemberAccessChainToImplValMap.iteritems(): assert isinstance(chain, str) chain = chain.split('.') if len(chain) == 1: renamedVariableMapping[chain[0]] = implval else: newName = Expression.freshVarname( '_'.join(chain), set(expr.mentionedVariables) ) renamedVariableMapping[newName] = implval expr = expr.rebindFreeVariableMemberAccessChain( chain, newName ) return expr, renamedVariableMapping
def computeRenamedObjectMapping(self, objectIdToForaFunctionExpression): renamedObjectMapping = dict() mentionedVariables = set() for objectId, foraFunctionExpression in objectIdToForaFunctionExpression.iteritems( ): mentionedVariables.update( foraFunctionExpression.mentionedVariables) renamedObjectMapping[objectId] = Expression.freshVarname( "_%s_" % objectId, mentionedVariables) return renamedObjectMapping
def computeRenamedObjectMapping(self, objectIdToForaFunctionExpression): renamedObjectMapping = dict() mentionedVariables = set() for objectId, foraFunctionExpression in objectIdToForaFunctionExpression.iteritems(): mentionedVariables.update(foraFunctionExpression.mentionedVariables) renamedObjectMapping[objectId] = Expression.freshVarname( "_%s_" % objectId, mentionedVariables ) return renamedObjectMapping
def specializeFreeVariableMemberAccessChains( self, expr, freeVariableMemberAccessChainToImplValMap): renamedVariableMapping = {} for chain, implval in freeVariableMemberAccessChainToImplValMap.iteritems( ): assert isinstance(chain, str) chain = chain.split('.') if len(chain) == 1: renamedVariableMapping[chain[0]] = implval else: newName = Expression.freshVarname('_'.join(chain), set(expr.mentionedVariables)) renamedVariableMapping[newName] = implval expr = expr.rebindFreeVariableMemberAccessChain(chain, newName) return expr, renamedVariableMapping
def _computeRenamedObjectMapping(self, objectIdToForaFunctionExpression): """ Given a map: objectId -> functionExpression, return a map: objectId -> varName where each varName is essentially the hash of the corresponding functionExpression """ renamedObjectMapping = dict() mentionedVariables = set() for objectId, foraFunctionExpression in objectIdToForaFunctionExpression.iteritems(): mentionedVariables.update(foraFunctionExpression.mentionedVariables) renamedObjectMapping[objectId] = Expression.freshVarname( "_%s_" % foraFunctionExpression.hash(), mentionedVariables ) return renamedObjectMapping
def specializeFreeVariableMemberAccessChains(self, expr, freeVariableMemberAccessChainToImplValMap): renamedVariableMapping = {} for chain, implval in freeVariableMemberAccessChainToImplValMap.iteritems(): assert isinstance(chain, str) chain = chain.split('.') if len(chain) == 1: renamedVariableMapping[chain[0]] = implval else: newName = Expression.freshVarname('_'.join(chain), set(expr.mentionedVariables)) renamedVariableMapping[newName] = implval expr = expr.rebindFreeVariableMemberAccessChain( chain, newName ) return expr, renamedVariableMapping