public void ArrayConstructIsParsed() { MockRepository mocks = new MockRepository(); IBlacklistManager blacklistManager = mocks.Stub<IBlacklistManager>(); Dictionary<string, bool> locallyInitializedArrays = new Dictionary<string, bool>(); BlockParserContext blockParserContext = new BlockParserContext ( new ProblemPipeStub(), Fragment.CreateNamed ("returnFragmentType"), new List<ReturnCondition>(), blacklistManager, delegate { }); ArrayConstructStatementHandler handler = new ArrayConstructStatementHandler (blockParserContext); Method sampleMethod = IntrospectionUtility.MethodFactory<ArrayConstructStatementHandlerSample> ("LocallyInitializedArray"); Block sampleBlock = (Block) sampleMethod.Body.Statements[0]; Statement sample = sampleBlock.Statements[1]; ISymbolTable symbolTable = mocks.Stub<ISymbolTable>(); HandleContext context = new HandleContext ( sample, symbolTable, new List<IPreCondition>(), new List<string>(), new List<BlockAssignment>(), new List<int>(), locallyInitializedArrays, new Dictionary<string, bool>()); handler.Handle (context); bool locallyInitializedArrayAdded = locallyInitializedArrays.ContainsKey ("local$2") && locallyInitializedArrays["local$2"] == false; Assert.That (locallyInitializedArrayAdded, Is.True); }
public void Handle_WrongStatementType_ThrowsException() { MockRepository mocks = new MockRepository(); IBlacklistManager blacklistManager = mocks.Stub<IBlacklistManager>(); BlockParserContext blockParserContext = new BlockParserContext ( new ProblemPipeStub(), Fragment.CreateNamed ("returnFragmentType"), new List<ReturnCondition>(), blacklistManager, delegate { }); StatementHandlerBase<AssignmentStatement> handler = new AssignmentStatementHandlerController (blockParserContext); Method sampleMethod = IntrospectionUtility.MethodFactory<StatementHandlerBaseSample> ("ContainsReturnStatement"); Block sampleBlock = (Block) sampleMethod.Body.Statements[1]; Statement sample = sampleBlock.Statements[0]; ISymbolTable symbolTable = mocks.Stub<ISymbolTable>(); HandleContext context = new HandleContext ( sample, symbolTable, new List<IPreCondition>(), new List<string>(), new List<BlockAssignment>(), new List<int>(), new Dictionary<string, bool>(), new Dictionary<string, bool>()); handler.Handle (context); }
public void Handle(HandleContext context) { if (context.Statement is T) { HandleStatement(context); } else { throw new InjectionCopException("Expected to handle " + typeof(T).Name + " but got " + context.Statement.GetType().Name); } }
private void HandleVoidReturn(ReturnNode returnNode, HandleContext context) { foreach (var returnCondition in _blockParserContext.ReturnConditions) { Fragment blockInternalFragmentType = context.SymbolTable.GetFragmentType(returnCondition.Symbol); if (!FragmentUtility.FragmentTypesAssignable(blockInternalFragmentType, returnCondition.Fragment)) { ProcessBlockInternalPreConditionViolation( returnNode, returnCondition, blockInternalFragmentType, context); } } }
protected override void HandleStatement(HandleContext context) { ReturnNode returnNode = (ReturnNode)context.Statement; bool memberHasReturnType = returnNode.Expression != null; if (memberHasReturnType) { HandleReturnType(returnNode, context); } else { HandleVoidReturn(returnNode, context); } }
private void HandleReturnType(ReturnNode returnNode, HandleContext context) { _blockParserContext.Inspect(returnNode.Expression); string returnSymbol = IntrospectionUtility.GetVariableName(returnNode.Expression); if (returnSymbol != null) { ProblemMetadata problemMetadata = new ProblemMetadata( returnNode.UniqueKey, returnNode.SourceContext, _blockParserContext.ReturnFragmentType, context.SymbolTable.GetFragmentType(returnSymbol)); AssignabilityPreCondition returnBlockCondition = new AssignabilityPreCondition( returnSymbol, _blockParserContext.ReturnFragmentType, problemMetadata); context.PreConditions.Add(returnBlockCondition); context.PreConditions.AddRange(_blockParserContext.ReturnConditions); } }
public void HandleStatement_InitializationWithCapacityAndMaximum_VariableFragmentTypeIsNull() { Method sampleMethod = IntrospectionUtility.MethodFactory<StringBuilderConstructStatementHandlerSample> ("InitializationWithCapacityAndMaximum"); Block sampleBlock = (Block) sampleMethod.Body.Statements[0]; Statement sample = sampleBlock.Statements[1]; HandleContext context = new HandleContext ( sample, _symbolTable, new List<IPreCondition>(), new List<string>(), new List<BlockAssignment>(), new List<int>(), new Dictionary<string, bool>(), _stringBuilderFragmentTypesDefined); _handler.Handle (context); bool variableUndefined = _symbolTable.GetFragmentType ("local$0").Undefined; Assert.That (variableUndefined, Is.True); }
private void ProcessBlockInternalPreConditionViolation( ReturnNode returnNode, ReturnCondition returnCondition, Fragment blockInternalFragmentType, HandleContext context) { ProblemMetadata problemMetadata = new ProblemMetadata( returnNode.UniqueKey, returnNode.SourceContext, returnCondition.Fragment, blockInternalFragmentType); returnCondition.ProblemMetadata = problemMetadata; if (!context.AssignmentTargetVariables.Contains(returnCondition.Symbol)) { context.PreConditions.Add(returnCondition); } else { _blockParserContext.ProblemPipe.AddProblem(problemMetadata); } }
public void HandleStatement_NonStringBuilderAssignment_VariableNotMapped() { Method sampleMethod = IntrospectionUtility.MethodFactory<StringBuilderConstructStatementHandlerSample> ("NonStringBuilderAssignment"); Block sampleBlock = (Block) sampleMethod.Body.Statements[0]; Statement sample = sampleBlock.Statements[1]; HandleContext context = new HandleContext ( sample, _symbolTable, new List<IPreCondition>(), new List<string>(), new List<BlockAssignment>(), new List<int>(), new Dictionary<string, bool>(), _stringBuilderFragmentTypesDefined); _handler.Handle (context); bool variableAdded = _stringBuilderFragmentTypesDefined.ContainsKey ("local$0"); Assert.That (variableAdded, Is.False); }
public void HandleStatement_InitializationWithLiteral_VariableFragmentTypeIsLiteral() { Method sampleMethod = IntrospectionUtility.MethodFactory<StringBuilderConstructStatementHandlerSample> ("InitializationWithLiteral"); Block sampleBlock = (Block) sampleMethod.Body.Statements[0]; Statement sample = sampleBlock.Statements[1]; HandleContext context = new HandleContext ( sample, _symbolTable, new List<IPreCondition>(), new List<string>(), new List<BlockAssignment>(), new List<int>(), new Dictionary<string, bool>(), _stringBuilderFragmentTypesDefined); _handler.Handle (context); bool symbolTableEntryCorrect = _symbolTable.GetFragmentType("local$0") == Fragment.CreateLiteral(); Assert.That (symbolTableEntryCorrect, Is.True); }
protected override void HandleStatement(HandleContext context) { Branch branch = (Branch)context.Statement; context.Successors.Add(branch.Target.UniqueKey); }
protected override void HandleStatement(HandleContext context) { ExpressionStatement expressionStatement = (ExpressionStatement)context.Statement; _blockParserContext.Inspect(expressionStatement.Expression); }
protected override void HandleStatement(HandleContext context) { SwitchInstruction switchInstruction = (SwitchInstruction)context.Statement; context.Successors.AddRange(switchInstruction.Targets.Select(caseBlock => caseBlock.UniqueKey)); }
protected abstract void HandleStatement(HandleContext context);
private void Inspect(Block methodBodyBlock) { foreach (Statement statement in methodBodyBlock.Statements) { if (_statementHandlers.ContainsKey (statement.GetType())) { HandleContext context = new HandleContext ( statement, _symbolTableParser, _preConditions, _assignmentTargetVariables, _blockAssignments, _successors, _locallyInitializedArrays, _stringBuilderFragmentTypesDefined); _statementHandlers[statement.GetType()].Handle (context); } } }