コード例 #1
0
        private void EnqueueStartNode()
        {
            var initialProgramState = new ProgramState();
            foreach (var parameter in declarationParameters)
            {
                var sv = SymbolicValue.Create(parameter.Type);
                initialProgramState = initialProgramState.StoreSymbolicValue(parameter, sv);
                initialProgramState = SetNonNullConstraintIfValueType(parameter, sv, initialProgramState);
            }

            EnqueueNewNode(new ProgramPoint(cfg.EntryBlock), initialProgramState);
        }
コード例 #2
0
        private ProgramState VisitVariableDesignation(VariableDesignationSyntaxWrapper variableDesignation, ProgramState programState, bool singleVariable)
        {
            var newProgramState = programState;

            if (DiscardDesignationSyntaxWrapper.IsInstance(variableDesignation))
            {
                // Push value for the discard, it will be popped when visiting the block for the
                // corresponding case statement.
                newProgramState = newProgramState.PushValue(SymbolicValue.Create());
            }
            else if (SingleVariableDesignationSyntaxWrapper.IsInstance(variableDesignation))
            {
                // "x is string s" is equivalent to "s = x"; both symbolic values should remain on stack
                var singleVariableDesignation = (SingleVariableDesignationSyntaxWrapper)variableDesignation;

                // associate variable with new SV
                var variableSymbol   = SemanticModel.GetDeclaredSymbol(singleVariableDesignation);
                var newSymbolicValue = SymbolicValue.Create();
                newProgramState = SetNewSymbolicValueIfTracked(variableSymbol, newSymbolicValue, newProgramState);

                if (singleVariable)
                {
                    // When the pattern is "x is Type t" we know that "t != null", hence (SV != null)
                    newProgramState = newProgramState.PushValue(new ValueNotEqualsSymbolicValue(newSymbolicValue, SymbolicValue.Null));
                }
            }
            else if (ParenthesizedVariableDesignationSyntaxWrapper.IsInstance(variableDesignation))
            {
                var parenthesizedVariableDesignation = (ParenthesizedVariableDesignationSyntaxWrapper)variableDesignation;
                foreach (var variable in parenthesizedVariableDesignation.Variables)
                {
                    // the variables in the deconstruction should not receive "Not Null" constraint
                    newProgramState = VisitVariableDesignation(variable, newProgramState, singleVariable: false);
                }
            }
            else
            {
                throw new NotSupportedException($"{variableDesignation.SyntaxNode.Kind()}");
            }
            return(newProgramState);
        }
コード例 #3
0
        private ProgramState VisitIdentifier(IdentifierNameSyntax identifier, ProgramState programState)
        {
            var newProgramState = programState;
            var symbol          = SemanticModel.GetSymbolInfo(identifier).Symbol;
            var typeSymbol      = SemanticModel.GetTypeInfo(identifier).Type;
            var sv = newProgramState.GetSymbolValue(symbol);

            if (sv == null)
            {
                var fieldSymbol = symbol as IFieldSymbol;
                if (fieldSymbol != null) // TODO: Fix me when implementing SLVS-1130
                {
                    sv = fieldSymbol.CreateFieldSymbolicValue();
                    newProgramState = newProgramState.StoreSymbolicValue(symbol, sv);
                }
                else
                {
                    sv = SymbolicValue.Create(typeSymbol);
                }
            }
            newProgramState = newProgramState.PushValue(sv);

            var parenthesized = identifier.GetSelfOrTopParenthesizedExpression();
            var argument      = parenthesized.Parent as ArgumentSyntax;

            if (argument == null ||
                argument.RefOrOutKeyword.IsKind(SyntaxKind.None))
            {
                return(SetNonNullConstraintIfValueType(symbol, sv, newProgramState));
            }

            newProgramState = newProgramState.PopValue();
            sv = SymbolicValue.Create(typeSymbol);
            newProgramState = newProgramState.PushValue(sv);
            newProgramState = SetNonNullConstraintIfValueType(symbol, sv, newProgramState);
            return(SetNewSymbolicValueIfTracked(symbol, sv, newProgramState));
        }