Ejemplo n.º 1
0
        private TriggerAnnotation Annotate(Expression expr)
        {
            TriggerAnnotation cached;

            if (cache.annotations.TryGetValue(expr, out cached))
            {
                return(cached);
            }

            TriggerAnnotation annotation = null; // TODO: Using ApplySuffix fixes the unresolved members problem in GenericSort

            if (expr is LetExpr)
            {
                var le = (LetExpr)expr;
                if (le.LHSs.All(p => p.Var != null) && le.Exact)
                {
                    // Inline the let expression before doing trigger selection.
                    annotation = Annotate(Translator.InlineLet(le));
                }
            }

            if (annotation == null)
            {
                expr.SubExpressions.Iter(e => Annotate(e));

                if (IsPotentialTriggerCandidate(expr))
                {
                    annotation = AnnotatePotentialCandidate(expr);
                }
                else if (expr is QuantifierExpr)
                {
                    annotation = AnnotateQuantifier((QuantifierExpr)expr);
                }
                else if (expr is LetExpr)
                {
                    annotation = AnnotateLetExpr((LetExpr)expr);
                }
                else if (expr is IdentifierExpr)
                {
                    annotation = AnnotateIdentifier((IdentifierExpr)expr);
                }
                else if (expr is ApplySuffix)
                {
                    annotation = AnnotateApplySuffix((ApplySuffix)expr);
                }
                else if (expr is MatchExpr)
                {
                    annotation = AnnotateMatchExpr((MatchExpr)expr);
                }
                else if (expr is ComprehensionExpr)
                {
                    annotation = AnnotateComprehensionExpr((ComprehensionExpr)expr);
                }
                else if (expr is ConcreteSyntaxExpression ||
                         expr is LiteralExpr ||
                         expr is ThisExpr ||
                         expr is BoxingCastExpr ||
                         expr is MultiSetFormingExpr ||
                         expr is SeqConstructionExpr)
                {
                    annotation = AnnotateOther(expr, false);
                }
                else
                {
                    annotation = AnnotateOther(expr, true);
                }
            }

            TriggerUtils.DebugTriggers("{0} ({1})\n{2}", Printer.ExprToString(expr), expr.GetType(), annotation);
            cache.annotations[expr] = annotation;
            return(annotation);
        }