private ProgramState VisitMemberAccess(MemberAccessExpressionSyntax memberAccess, ProgramState programState)
        {
            var           newProgramState = programState.PopValue(out var memberExpression);
            SymbolicValue sv = null;

            if (memberAccess.Name is IdentifierNameSyntax identifier)
            {
                var symbol = SemanticModel.GetSymbolInfo(identifier).Symbol;
                if (symbol is IFieldSymbol fieldSymbol && (memberAccess.IsOnThis() || fieldSymbol.IsConst))
                {
                    sv = newProgramState.GetSymbolValue(symbol);
                    if (sv == null)
                    {
                        sv = fieldSymbol.CreateFieldSymbolicValue();
                        newProgramState = newProgramState.StoreSymbolicValue(symbol, sv);
                    }
                }
            }
            if (sv == null)
            {
                sv = new MemberAccessSymbolicValue(memberExpression, memberAccess.Name.Identifier.ValueText);
            }

            newProgramState = SetNonNullConstraintIfValueType(memberAccess, sv, newProgramState);
            return(newProgramState.PushValue(sv));
        }
        public void Test_ToString()
        {
            var memberAccessSv = new MemberAccessSymbolicValue(new SymbolicValue(), "Foo");
            var toString       = memberAccessSv.ToString();

            toString.Should().StartWith("SV_");
            toString.Should().EndWith(".Foo");
        }
예제 #3
0
        private ProgramState VisitMemberAccess(MemberAccessExpressionSyntax memberAccess, ProgramState programState)
        {
            SymbolicValue memberExpression;
            var           newProgramState = programState.PopValue(out memberExpression);
            var           sv = new MemberAccessSymbolicValue(memberExpression, memberAccess.Name.Identifier.ValueText);

            var type = SemanticModel.GetTypeInfo(memberAccess).Type;

            if (IsNonNullableValueType(type))
            {
                newProgramState = sv.SetConstraint(ObjectConstraint.NotNull, newProgramState);
            }

            return(newProgramState.PushValue(sv));
        }