Ejemplo n.º 1
0
        internal static void Analyze(CSharpCompilation compilation, MethodSymbol method, BoundNode node, DiagnosticBag diagnostics)
        {
            if (compilation.Feature("checkdispose") == null)
            {
                return;
            }

            Debug.Assert(diagnostics != null);
            var walker = new DisposeCheckerPass(compilation, method, node);

            try
            {
                bool badRegion = false;
                var  returns   = walker.Analyze(ref badRegion);
                Debug.Assert(!badRegion);
                walker.AnalyzeResult(returns);
                if (walker.Diagnostics != null)
                {
                    diagnostics.AddRange(walker.Diagnostics);
                }
            }
            finally
            {
                walker.Free();
            }
        }
Ejemplo n.º 2
0
        private static bool Analyze(
            CSharpCompilation compilation,
            MethodSymbol method,
            BoundBlock block,
            DiagnosticBag diagnostics)
        {
            var result = ControlFlowPass.Analyze(compilation, method, block, diagnostics);

            DataFlowPass.Analyze(compilation, method, block, diagnostics);
            DisposeCheckerPass.Analyze(compilation, method, block, diagnostics);
            return(result);
        }
Ejemplo n.º 3
0
            public Value(BoundExpression expr, DisposeCheckerPass pass)
            {
                Debug.Assert(expr.Kind != HijackedBoundKindForValueHolder);
                this.creations = new HashSet <BoundExpression>();
                expr           = SkipReferenceConversions(expr);
                switch (expr.Kind)
                {
                case HijackedBoundKindForValueHolder:
                {
                    var holder = (BoundValueHolder)expr;
                    var value  = holder.value;
                    creations = value.creations;
                }
                break;

                case BoundKind.ObjectCreationExpression:
                case BoundKind.NewT:
                    HashSet <DiagnosticInfo> useSiteDiagnostics = null;
                    if (Conversions.IsBaseInterface(pass.IDisposableType, expr.Type, ref useSiteDiagnostics))
                    {
                        creations.Add(expr);
                    }
                    break;

                case BoundKind.Local:
                {
                    var   local = (BoundLocal)expr;
                    Value value;
                    pass.State.variables.TryGetValue(local.LocalSymbol, out value);
                    if (value != null)
                    {
                        creations = value.creations;
                    }
                }
                break;

                case BoundKind.Parameter:
                {
                    var   parameter = (BoundParameter)expr;
                    Value value;
                    pass.State.variables.TryGetValue(parameter.ParameterSymbol, out value);
                    if (value != null)
                    {
                        creations = value.creations;
                    }
                }
                break;

                default:
                    break;
                }
            }
Ejemplo n.º 4
0
 public BoundValueHolder(BoundExpression expr, DisposeCheckerPass pass)
     : base(HijackedBoundKindForValueHolder, expr.Syntax, expr.Type)
 {
     Debug.Assert(expr.Kind != HijackedBoundKindForValueHolder);
     this.value = new Value(expr, pass);
 }