/// <summary> /// Generates the instructions for the setup method. These instructions are the actual /// instructions for the setup method in DoNoConfuseMocksWithStubsTarget.cs /// </summary> /// <returns> /// A list of instructions that was empirically obtained from /// DoNotConfuseRhinoMocksStubsWithMocksTarget.cs /// </returns> private IList <CustomInstruction> GetListOfCustomInstructionForSetupMethod() { IList <CustomInstruction> instructionList = new List <CustomInstruction>(); // CIL Instruction 1. CustomInstruction instruction = new CustomInstruction(); instruction.Offset = 0; instruction.OpCode = OpCode._Locals; instruction.Value = "{Microsoft.FxCop.Sdk.LocalCollection}"; instructionList.Add(instruction); // CIL Instruction 2. instruction = new CustomInstruction(); instruction.Offset = 0; instruction.OpCode = OpCode.Nop; instruction.Value = null; instructionList.Add(instruction); // CIL Instruction 3. instruction = new CustomInstruction(); instruction.Offset = 1; instruction.OpCode = OpCode.Ldarg_0; instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget this}"; instructionList.Add(instruction); // CIL Instruction 4. instruction = new CustomInstruction(); instruction.Offset = 2; instruction.OpCode = OpCode.Ldc_I4_0; instruction.Value = 0; instructionList.Add(instruction); // CIL Instruction 5. instruction = new CustomInstruction(); instruction.Offset = 3; instruction.OpCode = OpCode.Newarr; // TODO: instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:System.Object}"; instructionList.Add(instruction); // CIL Instruction 6. instruction = new CustomInstruction(); instruction.Offset = 8; instruction.OpCode = OpCode.Call; // TODO: instruction.Value = "{Rhino.Mocks.MockRepository.GenerateStub<Srl.FxCop.CustomDeveloperTestRules.TestTargets.IBar>}"; instructionList.Add(instruction); // CIL Instruction 7. instruction = new CustomInstruction(); instruction.Offset = 13; instruction.OpCode = OpCode.Stfld; // TODO: instruction.Value = "{Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget._barStub}"; instructionList.Add(instruction); // CIL Instruction 8. instruction = new CustomInstruction(); instruction.Offset = 18; instruction.OpCode = OpCode.Ldarg_0; instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget this}"; instructionList.Add(instruction); // CIL Instruction 9. instruction = new CustomInstruction(); instruction.Offset = 19; instruction.OpCode = OpCode.Ldc_I4_0; instruction.Value = 0; instructionList.Add(instruction); // CIL Instruction 10. instruction = new CustomInstruction(); instruction.Offset = 20; instruction.OpCode = OpCode.Newarr; // TODO: instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:System.Object}"; instructionList.Add(instruction); // CIL Instruction 11. instruction = new CustomInstruction(); instruction.Offset = 25; instruction.OpCode = OpCode.Call; // TODO: instruction.Value = "{Rhino.Mocks.MockRepository.GenerateMock<Srl.FxCop.CustomDeveloperTestRules.TestTargets.IBar>}"; instructionList.Add(instruction); // CIL Instruction 12. instruction = new CustomInstruction(); instruction.Offset = 30; instruction.OpCode = OpCode.Stfld; // TODO: instruction.Value = "{Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget._barMock}"; instructionList.Add(instruction); // CIL Instruction 13. instruction = new CustomInstruction(); instruction.Offset = 35; instruction.OpCode = OpCode.Ldarg_0; instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget this}"; instructionList.Add(instruction); // CIL Instruction 14. instruction = new CustomInstruction(); instruction.Offset = 36; instruction.OpCode = OpCode.Ldc_I4_0; instruction.Value = 0; instructionList.Add(instruction); // CIL Instruction 15. instruction = new CustomInstruction(); instruction.Offset = 37; instruction.OpCode = OpCode.Newarr; // TODO: instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:System.Object}"; instructionList.Add(instruction); // CIL Instruction 16. instruction = new CustomInstruction(); instruction.Offset = 42; instruction.OpCode = OpCode.Call; // TODO: instruction.Value = "{Rhino.Mocks.MockRepository.GenerateStub<Srl.FxCop.CustomDeveloperTestRules.TestTargets.IBar>}"; instructionList.Add(instruction); // CIL Instruction 17. instruction = new CustomInstruction(); instruction.Offset = 47; instruction.OpCode = OpCode.Stfld; // TODO: instruction.Value = "{Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget._barStub2}"; instructionList.Add(instruction); // CIL Instruction 18. instruction = new CustomInstruction(); instruction.Offset = 52; instruction.OpCode = OpCode.Ldarg_0; instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget this}"; instructionList.Add(instruction); // CIL Instruction 19. instruction = new CustomInstruction(); instruction.Offset = 53; instruction.OpCode = OpCode.Ldc_I4_0; instruction.Value = 0; instructionList.Add(instruction); // CIL Instruction 20. instruction = new CustomInstruction(); instruction.Offset = 54; instruction.OpCode = OpCode.Newarr; // TODO: instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:System.Object}"; instructionList.Add(instruction); // CIL Instruction 21. instruction = new CustomInstruction(); instruction.Offset = 59; instruction.OpCode = OpCode.Call; // TODO: instruction.Value = "{Rhino.Mocks.MockRepository.GenerateMock<Srl.FxCop.CustomDeveloperTestRules.TestTargets.IBar>}"; instructionList.Add(instruction); // CIL Instruction 22. instruction = new CustomInstruction(); instruction.Offset = 64; instruction.OpCode = OpCode.Stfld; // TODO: instruction.Value = "{Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget._barMock2}"; instructionList.Add(instruction); // CIL Instruction 23. instruction = new CustomInstruction(); instruction.Offset = 69; instruction.OpCode = OpCode.Ret; instruction.Value = null; instructionList.Add(instruction); return(instructionList); }
/// <summary> /// Gets the instructions for the test CanRaiseProblemWhenALocalStubIsUsedAsAMock. /// </summary> /// <returns> /// A list of instructions that was empirically obtained from /// DoNotConfuseRhinoMocksStubsWithMocksTarget.cs /// </returns> private IList <CustomInstruction> GetInstructionsForCanRaiseProblemWhenALocalStubIsUsedAsAMock() { IList <CustomInstruction> instructionList = new List <CustomInstruction>(); // CIL Instruction 1. CustomInstruction instruction = new CustomInstruction(); instruction.Offset = 0; instruction.OpCode = OpCode._Locals; instruction.Value = "{Microsoft.FxCop.Sdk.LocalCollection}"; instructionList.Add(instruction); // CIL Instruction 2. instruction = new CustomInstruction(); instruction.Offset = 0; instruction.OpCode = OpCode.Nop; instruction.Value = null; instructionList.Add(instruction); // CIL Instruction 3. instruction = new CustomInstruction(); instruction.Offset = 1; instruction.OpCode = OpCode.Ldc_I4_0; instruction.Value = 0; instructionList.Add(instruction); // CIL Instruction 4. instruction = new CustomInstruction(); instruction.Offset = 2; instruction.OpCode = OpCode.Newarr; instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:System.Object}"; instructionList.Add(instruction); // CIL Instruction 5. instruction = new CustomInstruction(); instruction.Offset = 7; instruction.OpCode = OpCode.Call; instruction.Value = "{Rhino.Mocks.MockRepository.GenerateStub<Srl.FxCop.CustomDeveloperTestRules.TestTargets.IBar>}"; instructionList.Add(instruction); // CIL Instruction 6. instruction = new CustomInstruction(); instruction.Offset = 12; instruction.OpCode = OpCode.Stloc_0; instruction.Value = new CustomLocal() { Name = "localStub" }; instructionList.Add(instruction); // CIL Instruction 7. instruction = new CustomInstruction(); instruction.Offset = 13; instruction.OpCode = OpCode.Ldloc_0; instruction.Value = new CustomLocal() { Name = "localStub" }; instructionList.Add(instruction); // CIL Instruction 8. instruction = new CustomInstruction(); instruction.Offset = 14; instruction.OpCode = OpCode.Call; instruction.Value = "{Rhino.Mocks.RhinoMocksExtensions.VerifyAllExpectations}"; instructionList.Add(instruction); // CIL Instruction 9. instruction = new CustomInstruction(); instruction.Offset = 19; instruction.OpCode = OpCode.Nop; instruction.Value = null; instructionList.Add(instruction); // CIL Instruction 10. instruction = new CustomInstruction(); instruction.Offset = 20; instruction.OpCode = OpCode.Ret; instruction.Value = null; instructionList.Add(instruction); return(instructionList); }
/// <summary> /// Gets the instructions for the test CanRaiseProblemWhenAFieldStubIsUsedAsAMock. /// </summary> /// <returns> /// A list of instructions that was empirically obtained from /// DoNotConfuseRhinoMocksStubsWithMocksTarget.cs /// </returns> IList <CustomInstruction> GetInstructionsForCanRaiseProblemWhenAFieldStubIsUsedAsAMock() { IList <CustomInstruction> instructionList = new List <CustomInstruction>(); // CIL Instruction 1. CustomInstruction instruction = new CustomInstruction(); instruction.Offset = 0; instruction.OpCode = OpCode._Locals; // TODO: Replace with a custom type. instruction.Value = "{Microsoft.FxCop.Sdk.LocalCollection}"; instructionList.Add(instruction); // CIL Instruction 2. instruction = new CustomInstruction(); instruction.Offset = 0; instruction.OpCode = OpCode.Nop; instruction.Value = null; instructionList.Add(instruction); // CIL Instruction 3. instruction = new CustomInstruction(); instruction.Offset = 1; instruction.OpCode = OpCode.Ldarg_0; // TODO: Replace with a custom type. instruction.Value = "{Microsoft.FxCop.Sdk.ClassNode:Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget this}"; instructionList.Add(instruction); // CIL Instruction 4. instruction = new CustomInstruction(); instruction.Offset = 2; instruction.OpCode = OpCode.Ldfld; // TODO: Replace with a custom type. instruction.Value = "Srl.FxCop.CustomDeveloperTestRules.TestTargets.DoNotConfuseRhinoMocksStubsWithMocksTarget._barStub"; instructionList.Add(instruction); // CIL Instruction 5. instruction = new CustomInstruction(); instruction.Offset = 7; instruction.OpCode = OpCode.Call; // TODO: Replace with a custom type. instruction.Value = "{Rhino.Mocks.RhinoMocksExtensions.VerifyAllExpectations}"; instructionList.Add(instruction); // CIL Instruction 6. instruction = new CustomInstruction(); instruction.Offset = 12; instruction.OpCode = OpCode.Nop; instruction.Value = null; instructionList.Add(instruction); // CIL Instruction 7. instruction = new CustomInstruction(); instruction.Offset = 13; instruction.OpCode = OpCode.Ret; instruction.Value = null; instructionList.Add(instruction); return(instructionList); }
/* * Input: A Component, and a CustomInstruction that needs to be attached to this Component. * Output: True if the instruction was identified and we attempted to take action, False if we do not know how to carry out the merge. * */ public static bool MergeInstructionWithComponent(Component cp, CustomInstruction cinstr, Makefile mkfile) { if (cinstr.isCl()) { ClInstruction clInstr = (ClInstruction)cinstr; string target = ""; foreach (string clFile in clInstr.clFiles) { if (clFile.EndsWith(".c", StringComparison.CurrentCultureIgnoreCase) || clFile.EndsWith(".cpp", StringComparison.CurrentCultureIgnoreCase)) { cp.SourceFiles.Add(Path.GetFileNameWithoutExtension(clFile)); } if (clFile.Contains(".obj")) target = clFile; } foreach (string clLib in clInstr.clLibs) { cp.Link.Libs.Add(clLib); } if (cp.CompilerFlags == null) cp.CompilerFlags = new CompileFlags(mkfile); cp.CompilerFlags.ParseString(clInstr.clOptionsLiteral); foreach (string linkOption in clInstr.linkerOptions) { cp.Link.Options.Add(new KeyValuePair<string, string>(target, linkOption)); } mkfile.GenerateSourceFileNames(cp); return true; } else if (cinstr.isRc()) { RcInstruction rcInstr = (RcInstruction)cinstr; cp.SourceFiles.Add(rcInstr.rcScript); RcFlags rcFlags = new RcFlags(mkfile); rcFlags.ParseString(rcInstr.instruction_literal); cp.CustomFlags.Add(rcInstr.rcScript, rcFlags); mkfile.GenerateSourceFileNames(cp); } else { //We cannot identify the instruction, we will assume that it must be added as a prebuild step to the component. cp.PostBuildInstructions.Add(cinstr); } return false; }
/* * Given: * A CustomComponent that creates a .dll. This CustomComponent should have a link instruction. * Output: * A Component that can be used to generate a project for this .dll * * */ public static Component generateComponentFromRule(CustomComponent rule, Makefile mkfile) { Component result = new Component(rule.Name); result.Owner = mkfile; List<CustomInstruction> preBuildInstrs = new List<CustomInstruction>(); List<CustomInstruction> postBuildInstrs = new List<CustomInstruction>(); bool afterLinkInstruction = false; foreach (string instr in rule.CustomInstructions) { CustomInstruction cinstr = new CustomInstruction(instr); if (cinstr.isNmake()) { LinkInstruction linkInstr = new LinkInstruction(cinstr); result = resolveLinkInstruction(linkInstr,rule,mkfile); afterLinkInstruction = true; } else if (cinstr.isCl()) { ClInstruction compileInstruction = new ClInstruction(cinstr); foreach (string sourceFile in compileInstruction.clFiles) result.SourceFileNames.Add(sourceFile); } else if (!afterLinkInstruction) { preBuildInstrs.Add(cinstr); } else { postBuildInstrs.Add(cinstr); } } result.PreBuildInstructions = preBuildInstrs; result.PostBuildInstructions = postBuildInstrs; return result; }