コード例 #1
0
    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
コード例 #2
0
    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
コード例 #3
0
ファイル: Converter.py プロジェクト: vishnur/ufora
    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
コード例 #4
0
    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
コード例 #5
0
    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
コード例 #6
0
ファイル: Converter.py プロジェクト: vishnur/ufora
    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