Esempio n. 1
0
        protected override void ProcessMethod(MethodDefinition method)
        {
            if (!method.HasBody || method.IsCompilerControlled)
            {
                return;
            }

            try
            {
                MethodEditor.SimplifyMacros(method.Body);

                _collectionsStep.Process(method);

                if (!HasFieldAccesses(method))
                {
                    return;
                }

                InstrumentFieldAccesses(method);

                PatchBaseConstructorInvocationOrderIfRequired(method);
            }
            finally
            {
                MethodEditor.OptimizeMacros(method.Body);
            }
        }
Esempio n. 2
0
 private void InsertActivateCall(MethodEditor cil, Instruction insertionPoint,
                                 Instruction loadReferenceInstruction, ActivationPurpose activationPurpose)
 {
     cil.InsertBefore(insertionPoint, loadReferenceInstruction);
     cil.InsertBefore(insertionPoint, cil.Create(OpCodes.Ldc_I4, (int)activationPurpose));
     cil.InsertBefore(insertionPoint, cil.Create(OpCodes.Callvirt, ActivateMethodRef()));
 }
Esempio n. 3
0
        private static VariableDefinition SaveStackTop(MethodEditor cil, Instruction instruction)
        {
            VariableDefinition oldStackTop = cil.AddVariable(Resolve(instruction).FieldType);

            cil.InsertBefore(GetInsertionPoint(instruction), cil.Create(OpCodes.Stloc, oldStackTop));

            return(oldStackTop);
        }
Esempio n. 4
0
        private void ProcessFieldSetter(Instruction instruction, MethodEditor cil)
        {
            VariableDefinition oldStackTop = SaveStackTop(cil, instruction);

            Instruction insertionPoint = GetInsertionPoint(instruction);

            InsertActivateCall(cil, insertionPoint, ActivationPurpose.Write);
            cil.InsertBefore(insertionPoint, cil.Create(OpCodes.Ldloc, oldStackTop));
        }
Esempio n. 5
0
        private void InstrumentFieldAccesses(MethodDefinition method)
        {
            MethodEditor editor = new MethodEditor(method);

            foreach (Instruction instruction in FieldAccesses(method.Body))
            {
                ProcessFieldAccess(editor, instruction);
            }
        }
Esempio n. 6
0
 private void ProcessFieldAccess(MethodEditor cil, Instruction instruction)
 {
     if (IsFieldGetter(instruction))
     {
         ProcessFieldGetter(instruction, cil);
     }
     else
     {
         ProcessFieldSetter(instruction, cil);
     }
 }
Esempio n. 7
0
        private void InsertActivateCall(MethodEditor cil, Instruction insertionPoint, ActivationPurpose activationPurpose)
        {
            Instruction previous = insertionPoint.Previous;

            if (previous.OpCode == OpCodes.Ldarg)
            {
                Instruction newLoadInstruction = cil.Create(previous.OpCode, (ParameterDefinition)previous.Operand);
                InsertActivateCall(cil,
                                   previous,
                                   newLoadInstruction,
                                   activationPurpose);
            }
            else
            {
                InsertActivateCall(cil,
                                   insertionPoint,
                                   cil.Create(OpCodes.Dup),
                                   activationPurpose);
            }
        }
Esempio n. 8
0
        private void ProcessFieldGetter(Instruction instruction, MethodEditor cil)
        {
            Instruction insertionPoint = GetInsertionPoint(instruction);

            InsertActivateCall(cil, insertionPoint, ActivationPurpose.Read);
        }