public static AnalysisEntity Create(IInstanceReferenceOperation instanceReferenceOperation, PointsToAbstractValue instanceLocation)
        {
            Debug.Assert(instanceReferenceOperation != null);
            Debug.Assert(instanceLocation != null);

            return(new AnalysisEntity(instanceReferenceOperation, instanceLocation));
        }
            private bool ValidateExpression(IExpressionStatementOperation expressionStatement)
            {
                if (expressionStatement.Operation?.Kind != OperationKind.Invocation)
                {
                    return(false);
                }

                var invocation = (IInvocationOperation)expressionStatement.Operation;

                // Valid calls are either to Dispose(false), or to the Finalize method of the base type
                if (!_callDispose)
                {
                    bool result = IsDisposeBoolCall(invocation, _type, expectedValue: false);
                    if (result)
                    {
                        _callDispose = true;
                    }

                    return(result);
                }
                else if (_type.BaseType != null && invocation.Instance != null && invocation.Instance.Kind == OperationKind.InstanceReference)
                {
                    IMethodSymbol methodSymbol           = invocation.TargetMethod;
                    IInstanceReferenceOperation receiver = (IInstanceReferenceOperation)invocation.Instance;

                    return(methodSymbol.IsFinalizer() && Equals(receiver.Type.OriginalDefinition, _type.BaseType.OriginalDefinition));
                }

                return(false);
            }
Ejemplo n.º 3
0
            public override PointsToAbstractValue VisitInstanceReference(IInstanceReferenceOperation operation, object argument)
            {
                var        _ = base.VisitInstanceReference(operation, argument);
                IOperation currentInstanceOperation = operation.GetInstance();

                return(currentInstanceOperation != null?
                       GetCachedAbstractValue(currentInstanceOperation) :
                           ThisOrMePointsToAbstractValue);
            }
Ejemplo n.º 4
0
        private AnalysisEntity(IInstanceReferenceOperation instanceReferenceOperation, PointsToAbstractValue location)
        {
            Debug.Assert(instanceReferenceOperation != null);
            Debug.Assert(location != null);

            InstanceReferenceOperationSyntaxOpt = instanceReferenceOperation.Syntax;
            InstanceLocation = location;
            Type             = instanceReferenceOperation.Type;
            Indices          = ImmutableArray <AbstractIndex> .Empty;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the operation for the object being created that is being referenced by <paramref name="operation"/>.
        /// If the operation is referencing an implicit or an explicit this/base/Me/MyBase/MyClass instance, then we return "null".
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="isInsideObjectInitializer">Flag to indicate if the operation is a descendant of an <see cref="IObjectOrCollectionInitializerOperation"/> or an <see cref="IAnonymousObjectCreationOperation"/>.</param>
        /// <remarks>
        /// PERF: Note that the parameter <paramref name="isInsideObjectInitializer"/> is to improve performance by avoiding walking the entire IOperation parent for non-initializer cases.
        /// </remarks>
        public static IOperation GetInstance(this IInstanceReferenceOperation operation, bool isInsideObjectInitializer)
        {
            Debug.Assert(isInsideObjectInitializer ==
                         (operation.GetAncestor <IObjectOrCollectionInitializerOperation>(OperationKind.ObjectOrCollectionInitializer) != null ||
                          operation.GetAncestor <IAnonymousObjectCreationOperation>(OperationKind.AnonymousObjectCreation) != null));

            if (isInsideObjectInitializer)
            {
                for (IOperation current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent)
                {
                    switch (current.Kind)
                    {
                    // VB object initializer allows accessing the members of the object being created with "." operator.
                    // The syntax of such an IInstanceReferenceOperation points to the object being created.
                    // Check for such an  IObjectCreationOperation or IAnonymousObjectCreationOperation with matching syntax.
                    // For example, instance reference for members ".Field1" and ".Field2" in "New C() With { .Field1 = 0, .Field2 = .Field1 }".
                    case OperationKind.ObjectCreation:
                    case OperationKind.AnonymousObjectCreation:
                        if (current.Syntax == operation.Syntax)
                        {
                            return(current);
                        }

                        break;

                    // IInstanceReferenceOperation on left of an IMemberInitializerOperation refers to the ancestor IObjectCreationOperation/IAnonymousObjectCreationOperation/IMemberInitializerOperation.
                    // For example, implicit instance reference for member initializer "AnotherType" in "new C() { AnotherType = { IntField = 0 } };", where "AnotherType" is a member of named type kind.
                    case OperationKind.MemberInitializer:
                        var parentMemberInitializer = (IMemberInitializerOperation)current;
                        if (parentMemberInitializer.InitializedMember.DescendantsAndSelf().Contains(operation))
                        {
                            return(parentMemberInitializer.GetCreation());
                        }

                        break;

                    // IInstanceReferenceOperation on left of an ISimpleAssignmentOperation with an IObjectOrCollectionInitializerOperation parent refers to the parenting IObjectCreationOperation/IAnonymousObjectCreationOperation/IMemberInitializerOperation.
                    // For example, implicit instance reference for "IntField" in "new C() { IntField = 0 };".
                    case OperationKind.SimpleAssignment:
                        var parentSimpleAssignmentInitialier = (ISimpleAssignmentOperation)current;
                        if (parentSimpleAssignmentInitialier.Parent is IObjectOrCollectionInitializerOperation &&
                            parentSimpleAssignmentInitialier.Target.DescendantsAndSelf().Contains(operation))
                        {
                            return(parentSimpleAssignmentInitialier.Parent.Parent);
                        }

                        break;
                    }
                }
            }

            // For all other cases, IInstanceReferenceOperation refers to the implicit or explicit this/base/Me/MyBase/MyClass reference.
            // We return null for such cases.
            return(null);
        }
Ejemplo n.º 6
0
            public override PointsToAbstractValue VisitInstanceReference(IInstanceReferenceOperation operation, object argument)
            {
                var        _ = base.VisitInstanceReference(operation, argument);
                IOperation currentInstanceOperation = operation.GetInstance(IsInsideObjectInitializer);
                var        value = currentInstanceOperation != null?
                                   GetCachedAbstractValue(currentInstanceOperation) :
                                       ThisOrMePointsToAbstractValue;

                Debug.Assert(value.NullState == NullAbstractValue.NotNull);
                return(value);
            }
        /// <summary>
        /// Gets the operation for the object being created that is being referenced by <paramref name="operation"/>.
        /// If the operation is referencing an implicit or an explicit this/base/Me/MyBase/MyClass instance, then we return "null".
        /// </summary>
        public static IOperation GetInstance(this IInstanceReferenceOperation operation)
        {
            // VB object initializer allows accessing the members of the object being created with "." operator.
            // The syntax of such an IInstanceReferenceOperation points to the object being created.
            // Check for such an  IObjectCreationOperation or IAnonymousObjectCreationOperation with matching syntax.
            // For example, instance reference for members ".Field1" and ".Field2" in "New C() With { .Field1 = 0, .Field2 = .Field1 }".
            Func <IObjectCreationOperation, bool> isObjectCreation = creation => creation.Syntax == operation.Syntax;
            var objectCreation = operation.GetAncestor(OperationKind.ObjectCreation, isObjectCreation);

            if (objectCreation != null)
            {
                return(objectCreation);
            }

            Func <IAnonymousObjectCreationOperation, bool> isAnonymousObjectCreation = creation => creation.Syntax == operation.Syntax;
            var anonymousObjectCreation = operation.GetAncestor(OperationKind.AnonymousObjectCreation, isAnonymousObjectCreation);

            if (anonymousObjectCreation != null)
            {
                return(anonymousObjectCreation);
            }

            // IInstanceReferenceOperation on left of an IMemberInitializerOperation refers to the ancestor IObjectCreationOperation/IAnonymousObjectCreationOperation/IMemberInitializerOperation.
            // For example, implicit instance reference for member initializer "AnotherType" in "new C() { AnotherType = { IntField = 0 } };", where "AnotherType" is a member of named type kind.
            IMemberInitializerOperation parentMemberInitializer = operation.GetAncestor <IMemberInitializerOperation>(OperationKind.MemberInitializer);

            if (parentMemberInitializer != null &&
                parentMemberInitializer.InitializedMember.DescendantsAndSelf().Contains(operation))
            {
                return(parentMemberInitializer.GetCreation());
            }

            // IInstanceReferenceOperation on left of an ISimpleAssignmentOperation with an IObjectOrCollectionInitializerOperation parent refers to the parenting IObjectCreationOperation/IAnonymousObjectCreationOperation/IMemberInitializerOperation.
            // For example, implicit instance reference for "IntField" in "new C() { IntField = 0 };".
            ISimpleAssignmentOperation parentSimpleAssignmentInitialier = operation.GetAncestor <ISimpleAssignmentOperation>(OperationKind.SimpleAssignment);

            if (parentSimpleAssignmentInitialier != null &&
                parentSimpleAssignmentInitialier.Parent is IObjectOrCollectionInitializerOperation &&
                parentSimpleAssignmentInitialier.Target.DescendantsAndSelf().Contains(operation))
            {
                return(parentSimpleAssignmentInitialier.Parent.Parent);
            }

            // For all cases, IInstanceReferenceOperation refers to the implicit or explicit this/base/Me/MyBase/MyClass reference.
            // We return null for such cases.
            return(null);
        }
Ejemplo n.º 8
0
        public override MultiValue VisitInstanceReference(IInstanceReferenceOperation instanceRef, StateValue state)
        {
            if (instanceRef.ReferenceKind != InstanceReferenceKind.ContainingTypeInstance)
            {
                return(TopValue);
            }

            // The instance reference operation represents a 'this' or 'base' reference to the containing type,
            // so we get the annotation from the containing method.
            // TODO: Check whether the Context.OwningSymbol is the containing type in case we are in a lambda.
            if (instanceRef.Type != null && instanceRef.Type.IsTypeInterestingForDataflow())
            {
                return(new MethodThisParameterValue((IMethodSymbol)Context.OwningSymbol));
            }

            return(TopValue);
        }
Ejemplo n.º 9
0
 public static AnalysisEntity Create(IInstanceReferenceOperation instanceReferenceOperation, PointsToAbstractValue instanceLocation)
 {
     return(new AnalysisEntity(instanceReferenceOperation, instanceLocation));
 }
            public override NullAbstractValue VisitInstanceReference(IInstanceReferenceOperation operation, object argument)
            {
                var _ = base.VisitInstanceReference(operation, argument);

                return(NullAbstractValue.NotNull);
            }
Ejemplo n.º 11
0
 public override IOperation VisitInstanceReference(IInstanceReferenceOperation operation, object argument)
 {
     return(new InstanceReferenceExpression(operation.ReferenceKind, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
Ejemplo n.º 12
0
 public virtual void VisitInstanceReference(IInstanceReferenceOperation operation)
 {
     DefaultVisit(operation);
 }
Ejemplo n.º 13
0
 public override void VisitInstanceReference([NotNull] IInstanceReferenceOperation operation)
 {
     base.VisitInstanceReference(operation);
 }
Ejemplo n.º 14
0
 public override bool VisitInstanceReference([NotNull] IInstanceReferenceOperation operation1,
                                             [CanBeNull] IOperation argument)
 {
     return(argument is IInstanceReferenceOperation operation2 && AreBaseOperationsEqual(operation1, operation2));
 }
 private AnalysisEntity(IInstanceReferenceOperation instanceReferenceOperation, PointsToAbstractValue location)
     : this(symbolOpt : null, indices : ImmutableArray <AbstractIndex> .Empty, instanceReferenceOperationSyntaxOpt : instanceReferenceOperation.Syntax,
            location : location, type : instanceReferenceOperation.Type, parentOpt : null, isThisOrMeInstance : false)
 {
     Debug.Assert(instanceReferenceOperation != null);
 }
Ejemplo n.º 16
0
 public override void VisitInstanceReference(IInstanceReferenceOperation operation)
 {
     Assert.Equal(OperationKind.InstanceReference, operation.Kind);
     Assert.Empty(operation.Children);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="operation">IOperationインスタンス</param>
 /// <param name="container">イベントコンテナ</param>
 public InstanceReference(IInstanceReferenceOperation operation, EventContainer container) : base(container)
 {
     Expressions.Add(new Expression("this", Expression.GetSymbolTypeName(operation.Type)));
 }