Example #1
0
 protected override void ResetValueTypeInstanceAnalysisData(IOperation operation)
 {
     if (AnalysisEntityFactory.TryCreate(operation, out AnalysisEntity analysisEntity))
     {
         ResetValueTypeInstanceAnalysisData(analysisEntity);
     }
 }
Example #2
0
        /// <summary>
        /// Transfers the analysis data rooted from <paramref name="assignedValueOperation"/> to <paramref name="targetAnalysisEntity"/>, for a value type assignment operation.
        /// This involves transfer of data for of all <see cref="AnalysisEntity"/> instances that share the same <see cref="AnalysisEntity.InstanceLocation"/> as the valueAnalysisEntity for the <paramref name="assignedValueOperation"/>
        /// to all <see cref="AnalysisEntity"/> instances that share the same <see cref="AnalysisEntity.InstanceLocation"/> as <paramref name="targetAnalysisEntity"/>.
        /// </summary>
        private void TransferValueTypeInstanceAnalysisDataForAssignment(AnalysisEntity targetAnalysisEntity, IOperation assignedValueOperation)
        {
            Debug.Assert(HasPointsToAnalysisResult);
            Debug.Assert(targetAnalysisEntity.Type.HasValueCopySemantics());

            IEnumerable <AnalysisEntity> dependentAnalysisEntities;

            if (AnalysisEntityFactory.TryCreate(assignedValueOperation, out AnalysisEntity valueAnalysisEntity))
            {
                dependentAnalysisEntities = GetChildAnalysisEntities(valueAnalysisEntity);
            }
            else
            {
                // For allocations.
                PointsToAbstractValue newValueLocation = GetPointsToAbstractValue(assignedValueOperation);
                if (newValueLocation.Kind == PointsToAbstractValueKind.NoLocation)
                {
                    return;
                }

                dependentAnalysisEntities = GetChildAnalysisEntities(newValueLocation);
            }

            foreach (AnalysisEntity dependentInstance in dependentAnalysisEntities)
            {
                // Clone the dependent instance but with with target as the root.
                AnalysisEntity newAnalysisEntity = AnalysisEntityFactory.CreateWithNewInstanceRoot(dependentInstance, targetAnalysisEntity);
                var            dependentValue    = GetAbstractValue(dependentInstance);
                SetAbstractValue(newAnalysisEntity, dependentValue);
            }
        }
Example #3
0
 protected override void SetAbstractValueForElementInitializer(IOperation instance, ImmutableArray <AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, TAbstractAnalysisValue value)
 {
     if (AnalysisEntityFactory.TryCreateForElementInitializer(instance, indices, elementType, out AnalysisEntity analysisEntity))
     {
         SetAbstractValueForAssignment(analysisEntity, initializer, value);
     }
 }
Example #4
0
 protected override void SetAbstractValueForAssignment(IOperation target, IOperation assignedValueOperation, TAbstractAnalysisValue assignedValue)
 {
     if (AnalysisEntityFactory.TryCreate(target, out AnalysisEntity targetAnalysisEntity))
     {
         SetAbstractValueForAssignment(targetAnalysisEntity, assignedValueOperation, assignedValue);
     }
 }
Example #5
0
 protected override void SetAbstractValueForSymbolDeclaration(ISymbol symbol, IOperation initializer, TAbstractAnalysisValue initializerValue)
 {
     if (AnalysisEntityFactory.TryCreateForSymbolDeclaration(symbol, out AnalysisEntity analysisEntity))
     {
         SetAbstractValueForAssignment(analysisEntity, initializer, initializerValue);
     }
 }
Example #6
0
        protected DataFlowOperationVisitor(
            AbstractValueDomain <TAbstractAnalysisValue> valueDomain,
            ISymbol owningSymbol,
            bool pessimisticAnalysis,
            DataFlowAnalysisResult <NullBlockAnalysisResult, NullAbstractValue> nullAnalysisResultOpt,
            DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> pointsToAnalysisResultOpt)
        {
            Debug.Assert(owningSymbol != null);
            Debug.Assert(owningSymbol.Kind == SymbolKind.Method ||
                         owningSymbol.Kind == SymbolKind.Field ||
                         owningSymbol.Kind == SymbolKind.Property ||
                         owningSymbol.Kind == SymbolKind.Event);

            ValueDomain                   = valueDomain;
            OwningSymbol                  = owningSymbol;
            PessimisticAnalysis           = pessimisticAnalysis;
            _nullAnalysisResultOpt        = nullAnalysisResultOpt;
            _pointsToAnalysisResultOpt    = pointsToAnalysisResultOpt;
            _valueCacheBuilder            = ImmutableDictionary.CreateBuilder <IOperation, TAbstractAnalysisValue>();
            _pendingArgumentsToReset      = new List <IArgumentOperation>();
            ThisOrMePointsToAbstractValue = GetThisOrMeInstancePointsToValue(owningSymbol.ContainingType);

            AnalysisEntityFactory = new AnalysisEntityFactory(
                (pointsToAnalysisResultOpt != null || IsPointsToAnalysis) ?
                GetPointsToAbstractValue :
                (Func <IOperation, PointsToAbstractValue>)null,
                owningSymbol.ContainingType);
        }
        protected override TAbstractAnalysisValue VisitAssignmentOperation(IAssignmentOperation operation, object argument)
        {
            var value = base.VisitAssignmentOperation(operation, argument);

            if (AnalysisEntityFactory.TryCreate(operation.Target, out AnalysisEntity targetEntity))
            {
                value = GetAbstractValue(targetEntity);
            }

            return(value);
        }
 protected AnalysisEntityDataFlowOperationVisitor(
     AbstractValueDomain <TAbstractAnalysisValue> valueDomain,
     INamedTypeSymbol containingTypeSymbol,
     DataFlowAnalysisResult <NullBlockAnalysisResult, NullAbstractValue> nullAnalysisResultOpt,
     DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> pointsToAnalysisResultOpt)
     : base(valueDomain, containingTypeSymbol, nullAnalysisResultOpt, pointsToAnalysisResultOpt)
 {
     AnalysisEntityFactory = new AnalysisEntityFactory(
         (pointsToAnalysisResultOpt != null || IsPointsToAnalysis) ?
         GetPointsToAbstractValue :
         (Func <IOperation, PointsToAbstractValue>)null,
         containingTypeSymbol);
 }
Example #9
0
 protected sealed override TAbstractAnalysisValue ComputeAnalysisValueForOutArgument(IArgumentOperation operation, TAbstractAnalysisValue defaultValue)
 {
     if (AnalysisEntityFactory.TryCreate(operation, out AnalysisEntity analysisEntity))
     {
         var value = ComputeAnalysisValueForOutArgument(analysisEntity, operation, defaultValue);
         SetAbstractValue(analysisEntity, value);
         return(GetAbstractValue(analysisEntity));
     }
     else
     {
         return(defaultValue);
     }
 }
Example #10
0
        protected override TAbstractAnalysisValue ComputeAnalysisValueForReferenceOperation(IOperation operation, TAbstractAnalysisValue defaultValue)
        {
            if (AnalysisEntityFactory.TryCreate(operation, out AnalysisEntity analysisEntity))
            {
                if (!HasAbstractValue(analysisEntity))
                {
                    SetAbstractValue(analysisEntity, defaultValue);
                }

                return(GetAbstractValue(analysisEntity));
            }
            else
            {
                return(defaultValue);
            }
        }
 protected DataFlowOperationVisitor(
     AbstractDomain <TAbstractAnalysisValue> valueDomain,
     INamedTypeSymbol containingTypeSymbol,
     DataFlowAnalysisResult <NullBlockAnalysisResult, NullAbstractValue> nullAnalysisResultOpt,
     DataFlowAnalysisResult <PointsToBlockAnalysisResult, PointsToAbstractValue> pointsToAnalysisResultOpt)
 {
     ValueDomain                   = valueDomain;
     _nullAnalysisResultOpt        = nullAnalysisResultOpt;
     _pointsToAnalysisResultOpt    = pointsToAnalysisResultOpt;
     _valueCacheBuilder            = ImmutableDictionary.CreateBuilder <IOperation, TAbstractAnalysisValue>();
     _pendingArgumentsToReset      = new List <IArgumentOperation>();
     ThisOrMePointsToAbstractValue = GetThisOrMeInstancePointsToValue(containingTypeSymbol);
     AnalysisEntityFactory         = new AnalysisEntityFactory(
         HasPointsToAnalysisResult ? GetPointsToAbstractValue : (Func <IOperation, PointsToAbstractValue>)null,
         containingTypeSymbol);
 }
Example #12
0
        public void OnEntry(BasicBlock entryBlock, TAnalysisData input)
        {
            CurrentBasicBlock   = entryBlock;
            CurrentAnalysisData = input;

            if (_lazyParameterEntities == null &&
                OwningSymbol is IMethodSymbol method &&
                method.Parameters.Length > 0)
            {
                var builder = ImmutableDictionary.CreateBuilder <IParameterSymbol, AnalysisEntity>();
                foreach (var parameter in method.Parameters)
                {
                    var result = AnalysisEntityFactory.TryCreateForSymbolDeclaration(parameter, out AnalysisEntity analysisEntity);
                    Debug.Assert(result);
                    builder.Add(parameter, analysisEntity);
                    SetValueForParameterOnEntry(parameter, analysisEntity);
                }

                _lazyParameterEntities = builder.ToImmutable();
            }
        }