Пример #1
0
        // Override handlers for situations where annotated locations may be involved in reflection access:
        // - assignments
        // - method calls
        // - value returned from a method

        public override void HandleAssignment(MultiValue source, MultiValue target, IOperation operation)
        {
            if (target.Equals(TopValue))
            {
                return;
            }

            // TODO: consider not tracking patterns unless the target is something
            // annotated with DAMT.
            TrimAnalysisPatterns.Add(
                new TrimAnalysisAssignmentPattern(source, target, operation),
                isReturnValue: false
                );
        }
        public override bool HandleCall(MethodBody callingMethodBody, MethodReference calledMethod, Instruction operation, ValueNodeList methodParams, out MultiValue methodReturnValue)
        {
            methodReturnValue = new ();

            var reflectionProcessed = _markStep.ProcessReflectionDependency(callingMethodBody, operation);

            if (reflectionProcessed)
            {
                return(false);
            }

            Debug.Assert(callingMethodBody.Method == _origin.Provider);
            var calledMethodDefinition = _context.TryResolve(calledMethod);

            if (calledMethodDefinition == null)
            {
                return(false);
            }

            _origin = _origin.WithInstructionOffset(operation.Offset);

            MultiValue instanceValue;
            ImmutableArray <MultiValue> arguments;

            if (calledMethodDefinition.HasImplicitThis())
            {
                instanceValue = methodParams[0];
                arguments     = methodParams.Skip(1).ToImmutableArray();
            }
            else
            {
                instanceValue = MultiValueLattice.Top;
                arguments     = methodParams.ToImmutableArray();
            }

            TrimAnalysisPatterns.Add(new TrimAnalysisMethodCallPattern(
                                         operation,
                                         calledMethod,
                                         instanceValue,
                                         arguments,
                                         _origin
                                         ));

            var diagnosticContext = new DiagnosticContext(_origin, diagnosticsEnabled: false, _context);

            return(HandleCall(
                       operation,
                       calledMethod,
                       instanceValue,
                       arguments,
                       diagnosticContext,
                       _reflectionMarker,
                       _context,
                       _markStep,
                       out methodReturnValue));
        }