コード例 #1
0
        public override Expr VisitNAryExpr(NAryExpr node)
        {
            Contract.Requires(node != null);
            if (_templates.ContainsKey(node))
            {
                return(node);
            }
            base.VisitNAryExpr(node);
            var nodeArgs = node.Args;

            if (nodeArgs.Any(arg => _templates[arg].ContainsBoundVariables()))
            {
                var replacements = new List <Expr>();
                foreach (Expr arg in nodeArgs)
                {
                    replacements.AddRange(_templates[arg].GetReplacements());
                }

                _templates[node] = new TemplateWithBoundVariables(replacements);
            }
            else
            {
                var newArgs = from arg in nodeArgs select((TemplateNoBoundVariables)_templates[arg]).GetReplacement();

                var llReplacementExpr =
                    new NAryExpr(node.tok, node.Fun, newArgs.ToList(), node.Immutable)
                {
                    TypeParameters = node.TypeParameters
                };
                llReplacementExpr.Type = node.Type ?? node.ShallowType;
                _templates[node]       = new TemplateNoBoundVariables(llReplacementExpr);
            }

            return(node);
        }
コード例 #2
0
        public override Expr VisitIdentifierExpr(IdentifierExpr node)
        {
            Contract.Requires(node != null);
            if (_templates.ContainsKey(node))
            {
                return(node);
            }
            base.VisitIdentifierExpr(node);
            if (IsBound(node.Decl))
            {
                _templates[node] = new TemplateWithBoundVariables();
            }
            else
            {
                _templates[node] = _templates[node.Decl];
            }

            return(node);
        }
コード例 #3
0
        public override Expr VisitLetExpr(LetExpr node)
        {
            Contract.Requires(node != null);
            if (_templates.ContainsKey(node))
            {
                return(node);
            }
            _nestedBoundVariables.AddRange(node.Dummies);
            base.VisitLetExpr(node);
            var bodyTemplate = _templates[node.Body];
            var varBodies    = node.Rhss;

            if (bodyTemplate.ContainsBoundVariables() || varBodies.Any(body => _templates[body].ContainsBoundVariables()))
            {
                var replacements = new List <Expr>();
                foreach (Expr body in varBodies)
                {
                    replacements.AddRange(_templates[body].GetReplacements());
                }

                replacements.AddRange(bodyTemplate.GetReplacements());
                _templates[node] = new TemplateWithBoundVariables(replacements);
            }
            else
            {
                var newRhss = from arg in varBodies select((TemplateNoBoundVariables)_templates[arg]).GetReplacement();

                LambdaLiftingTemplate template = new TemplateNoBoundVariables(
                    new LetExpr(node.tok, node.Dummies, newRhss.ToList(),
                                node.Attributes,
                                ((TemplateNoBoundVariables)_templates[node.Body])
                                .GetReplacement())
                {
                    Type = node.Type
                });
                _templates[node] = template;
            }

            return(node);
        }