public virtual void HandleViolation(ISymbolTable context, IProblemPipe problemPipe)
 {
     if (_problemMetadata != null)
       {
     problemPipe.AddProblem (_problemMetadata);
       }
 }
Beispiel #2
0
        public void Build_ReturnsAllStatementHandlersNeededByBlockParser()
        {
            MockRepository     mocks              = new MockRepository();
            IBlacklistManager  blacklistManager   = mocks.Stub <IBlacklistManager>();
            IProblemPipe       problemPipe        = mocks.Stub <IProblemPipe>();
            BlockParserContext blockParserContext = new BlockParserContext(
                problemPipe,
                Fragment.CreateNamed("returnFragmentType"),
                new List <ReturnCondition>(),
                blacklistManager,
                delegate { });
            StatementHandlerDictionaryBuilder builder = new StatementHandlerDictionaryBuilder(blockParserContext);

            Dictionary <Type, IStatementHandler> handlers = builder.Build();
            bool assignmentStatementSupported             = handlers.ContainsKey(typeof(AssignmentStatement));
            bool branchSupported = handlers.ContainsKey(typeof(Branch));
            bool expressionStatementSupported = handlers.ContainsKey(typeof(ExpressionStatement));
            bool returnNodeSupported          = handlers.ContainsKey(typeof(ReturnNode));
            bool switchInstructionSupported   = handlers.ContainsKey(typeof(SwitchInstruction));

            bool necessaryHandlersSupported = assignmentStatementSupported &&
                                              branchSupported &&
                                              expressionStatementSupported &&
                                              returnNodeSupported &&
                                              switchInstructionSupported;

            bool correctHandlerCount = handlers.Keys.Count == 5;

            Assert.That(necessaryHandlersSupported && correctHandlerCount, Is.True);
        }
        private void HandleFragmentConflict(ISymbolTable context, IProblemPipe problemPipe)
        {
            if (ProblemMetadata != null)
            problemPipe.AddProblem (_problemMetadata);

              context.MakeUnsafe (_symbol);
        }
 public virtual void HandleViolation(ISymbolTable context, IProblemPipe problemPipe)
 {
     if (_problemMetadata != null)
     {
         problemPipe.AddProblem(_problemMetadata);
     }
 }
Beispiel #5
0
        public MethodGraphBuilder(Method method, IBlacklistManager blacklistManager, IProblemPipe problemPipe, Fragment returnFragment)
            : this(method, blacklistManager, problemPipe)
        {
            ArgumentUtility.CheckNotNull("returnFragment", returnFragment);

            _returnFragment = returnFragment;
        }
 public BlockParserContext(IProblemPipe problemPipe, Fragment returnFragmentType, List <ReturnCondition> returnConditions, IBlacklistManager blacklistManager, BlockParser.InspectCallback inspect)
 {
     _problemPipe        = problemPipe;
     _returnFragmentType = returnFragmentType;
     _returnConditions   = returnConditions;
     _blacklistManager   = blacklistManager;
     _inspect            = inspect;
 }
 public BlockParserContext(IProblemPipe problemPipe, Fragment returnFragmentType, List<ReturnCondition> returnConditions, IBlacklistManager blacklistManager, BlockParser.InspectCallback inspect)
 {
     _problemPipe = problemPipe;
       _returnFragmentType = returnFragmentType;
       _returnConditions = returnConditions;
       _blacklistManager = blacklistManager;
       _inspect = inspect;
 }
        private void HandleFragmentConflict(ISymbolTable context, IProblemPipe problemPipe)
        {
            if (ProblemMetadata != null)
            {
                problemPipe.AddProblem(_problemMetadata);
            }

            context.MakeUnsafe(_symbol);
        }
 public BlockParser(
 IBlacklistManager blacklistManager, IProblemPipe problemPipe, Fragment returnFragmentType, List<ReturnCondition> returnConditions)
 {
     _blacklistManager = ArgumentUtility.CheckNotNull ("blacklistManager", blacklistManager);
       _problemPipe = ArgumentUtility.CheckNotNull ("typeParser", problemPipe);
       _returnFragmentType = returnFragmentType;
       _returnConditions = returnConditions;
       BlockParserContext blockParserContext = new BlockParserContext (
       _problemPipe, _returnFragmentType, _returnConditions, _blacklistManager, Inspect
       );
       StatementHandlerDictionaryBuilder handlerBuilder = new StatementHandlerDictionaryBuilder (blockParserContext);
       _statementHandlers = handlerBuilder.Build();
       _methodCallAnalyzer = new MethodCallAnalyzer (_problemPipe);
 }
        public override void HandleViolation(ISymbolTable context, IProblemPipe problemPipe)
        {
            if (!IsViolated (context))
            return;

              bool symbolIsUndefined = context.Contains (_symbol) && context.GetFragmentType (_symbol).Undefined;
              if (symbolIsUndefined)
              {
            SetSymbolFragmentType(context);
              }
              else
              {
            HandleFragmentConflict (context, problemPipe);
              }
        }
        public void HandleViolation_ProblemMetadataGivenButNoViolation_NoProblemAdded()
        {
            var expectedFragment = Fragment.CreateNamed(c_expectedType);
            var givenFragment    = Fragment.CreateNamed(c_expectedType);

            IPreCondition preCondition = new CustomInferencePreCondition(c_symbol, expectedFragment, _problemMetadata);
            var           context      = new SymbolTable(_blacklistManager);

            context.MakeSafe(c_symbol, givenFragment);
            IProblemPipe problemPipe = MockRepository.GenerateMock <IProblemPipe>();

            preCondition.HandleViolation(context, problemPipe);

            problemPipe.AssertWasNotCalled(pipe => pipe.AddProblem(Arg <ProblemMetadata> .Is.Anything));
        }
Beispiel #12
0
        public BlockParser(
            IBlacklistManager blacklistManager, IProblemPipe problemPipe, Fragment returnFragmentType, List <ReturnCondition> returnConditions)
        {
            _blacklistManager   = ArgumentUtility.CheckNotNull("blacklistManager", blacklistManager);
            _problemPipe        = ArgumentUtility.CheckNotNull("typeParser", problemPipe);
            _returnFragmentType = returnFragmentType;
            _returnConditions   = returnConditions;
            BlockParserContext blockParserContext = new BlockParserContext(
                _problemPipe, _returnFragmentType, _returnConditions, _blacklistManager, Inspect
                );
            StatementHandlerDictionaryBuilder handlerBuilder = new StatementHandlerDictionaryBuilder(blockParserContext);

            _statementHandlers  = handlerBuilder.Build();
            _methodCallAnalyzer = new MethodCallAnalyzer(_problemPipe);
        }
        public void HandleViolation_ViolationNotProvoked_KeepsSymbolFragment()
        {
            var expectedFragment = Fragment.CreateNamed(c_expectedType);
            var givenFragment    = expectedFragment;

            IPreCondition preCondition = new CustomInferencePreCondition(c_symbol, expectedFragment, _problemMetadata);
            var           context      = new SymbolTable(_blacklistManager);

            context.MakeSafe(c_symbol, givenFragment);
            IProblemPipe problemPipe = MockRepository.GenerateMock <IProblemPipe>();

            preCondition.HandleViolation(context, problemPipe);

            bool symbolFragmentKept = context.GetFragmentType(c_symbol) == expectedFragment;

            Assert.That(symbolFragmentKept, Is.True);
        }
        public override void HandleViolation(ISymbolTable context, IProblemPipe problemPipe)
        {
            if (!IsViolated(context))
            {
                return;
            }

            bool symbolIsUndefined = context.Contains(_symbol) && context.GetFragmentType(_symbol).Undefined;

            if (symbolIsUndefined)
            {
                SetSymbolFragmentType(context);
            }
            else
            {
                HandleFragmentConflict(context, problemPipe);
            }
        }
Beispiel #15
0
        public MethodGraphBuilder(Method method, IBlacklistManager blacklistManager, IProblemPipe problemPipe)
        {
            ArgumentUtility.CheckNotNull("method", method);
            _blacklistManager = ArgumentUtility.CheckNotNull("blacklistManager", blacklistManager);
            _problemPipe      = ArgumentUtility.CheckNotNull("problemPipe", problemPipe);
            bool isInterfaceMethod = method.Body.Statements == null;

            if (!isInterfaceMethod)
            {
                _methodBody = method.Body;
                _referenceAndOutConditions = ReferenceAndOutConditions(method);
                _result = null;
            }
            else
            {
                _result = new MethodGraph(-1, new Dictionary <int, BasicBlock>());
            }
            _returnFragment = FragmentUtility.ReturnFragmentType(method);
        }
 public void PassProblem(
 MethodCall methodCall, List<IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
 {
     Method calleeMethod = IntrospectionUtility.ExtractMethod (methodCall);
       if(_coveredMethods.Contains(calleeMethod.FullName))
       {
     foreach (var operand in methodCall.Operands)
     {
       string nestedVariableName;
       if (OperandIsVariableFromPrecedingBlock (operand, symbolTable, out nestedVariableName))
       {
     preConditions.Add (new AssignabilityPreCondition (nestedVariableName, problemMetadata.ExpectedFragment, problemMetadata));
       }
       else
       {
     problemPipe.AddProblem (problemMetadata);
       }
     }
       }
 }
Beispiel #17
0
 public ProblemDuplicateFilter(IProblemPipe problemDestination)
 {
     _problemDestination = problemDestination;
     _filteredIds        = new List <int>();
 }
Beispiel #18
0
 public MethodGraphAnalyzer(IProblemPipe problemPipe)
 {
     _problemPipe = ArgumentUtility.CheckNotNull("problemPipe", problemPipe);
 }
 public void PassProblem(
 MethodCall methodCall, List<IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
 {
     Method calleeMethod = IntrospectionUtility.ExtractMethod (methodCall);
       ICustomInference matchingRule = MatchingAnalyzeRule (calleeMethod);
       if (matchingRule != null)
       {
     matchingRule.PassProblem (methodCall, preConditions, problemMetadata, symbolTable, problemPipe);
       }
 }
Beispiel #20
0
 public TypeParser(IBlacklistManager blacklistManager)
     : base("TypeParser")
 {
     _problemFilter = new ProblemDuplicateFilter (this);
       _blacklistManager = blacklistManager;
 }
Beispiel #21
0
 public TypeParser(IBlacklistManager blacklistManager)
     : base("TypeParser")
 {
     _problemFilter    = new ProblemDuplicateFilter(this);
     _blacklistManager = blacklistManager;
 }
 public void SetUp()
 {
     _mocks = new MockRepository();
     _problemDestination = _mocks.StrictMock <IProblemPipe>();
 }
 public void SetUp()
 {
     _mocks = new MockRepository();
       _problemDestination = _mocks.StrictMock<IProblemPipe>();
 }
 public ProblemDuplicateFilter(IProblemPipe problemDestination)
 {
     _problemDestination = problemDestination;
       _filteredIds = new List<int>();
 }
 public void PassProblem(MethodCall methodCall, List<IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
 {
     throw new NotImplementedException();
 }
        public void PassProblem(
            MethodCall methodCall, List <IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
        {
            Method calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);

            if (_coveredMethods.Contains(calleeMethod.FullName))
            {
                foreach (var operand in methodCall.Operands)
                {
                    string nestedVariableName;
                    if (OperandIsVariableFromPrecedingBlock(operand, symbolTable, out nestedVariableName))
                    {
                        preConditions.Add(new AssignabilityPreCondition(nestedVariableName, problemMetadata.ExpectedFragment, problemMetadata));
                    }
                    else
                    {
                        problemPipe.AddProblem(problemMetadata);
                    }
                }
            }
        }
 public MethodCallAnalyzer(IProblemPipe problemPipe)
 {
     _problemPipe = problemPipe;
       _customInferenceController = new CustomInferenceController();
 }
Beispiel #28
0
 public MethodCallAnalyzer(IProblemPipe problemPipe)
 {
     _problemPipe = problemPipe;
     _customInferenceController = new CustomInferenceController();
 }
        public void PassProblem(
            MethodCall methodCall, List <IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
        {
            Method           calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);
            ICustomInference matchingRule = MatchingAnalyzeRule(calleeMethod);

            if (matchingRule != null)
            {
                matchingRule.PassProblem(methodCall, preConditions, problemMetadata, symbolTable, problemPipe);
            }
        }
 public void PassProblem(MethodCall methodCall, List <IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
 {
     throw new NotImplementedException();
 }
 public MethodGraphAnalyzer(IProblemPipe problemPipe)
 {
     _problemPipe = ArgumentUtility.CheckNotNull ("problemPipe", problemPipe);
 }