Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public override Expr VisitForallExpr(ForallExpr node)
        {
            Contract.Requires(node != null);
            if (_templates.ContainsKey(node))
            {
                return(node);
            }
            _nestedBoundVariables.AddRange(node.Dummies);
            base.VisitForallExpr(node);
            var body            = node.Body;
            var bodyTemplate    = _templates[body];
            var trigger         = node.Triggers;
            var triggerNoBounds = trigger == null || !_templates[trigger].ContainsBoundVariables();

            if (bodyTemplate is TemplateNoBoundVariables bt && triggerNoBounds)
            {
                var newBody    = bt.GetReplacement();
                var newTrigger = ReplacementTrigger(trigger);
                _templates[node] = new TemplateNoBoundVariables(
                    new ForallExpr(node.tok, node.TypeParameters, node.Dummies, node.Attributes, newTrigger,
                                   newBody, node.Immutable)
                {
                    Type = node.Type
                });
            }
Exemplo n.º 3
0
 public override Expr VisitLiteralExpr(LiteralExpr node)
 {
     Contract.Requires(node != null);
     if (_templates.ContainsKey(node))
     {
         return(node);
     }
     base.VisitLiteralExpr(node);
     _templates[node] = new TemplateNoBoundVariables(node);
     return(node);
 }
Exemplo n.º 4
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);
        }