Exemple #1
0
 private static IMethodDefinition GetMethod(INamedTypeDefinition original, IMethodDefinition method)
 {
     foreach (var candidate in original.GetMembersNamed(method.Name, false))
     {
         IMethodDefinition candidateMethod = candidate as IMethodDefinition;
         if (candidateMethod == null)
         {
             continue;
         }
         if (candidateMethod.GenericParameterCount != method.GenericParameterCount)
         {
             continue;
         }
         if (candidateMethod.ParameterCount != method.ParameterCount)
         {
             continue;
         }
         if (!ParameterTypesMatch(candidateMethod.Parameters, method.Parameters))
         {
             continue;
         }
         if (!TypesMatchSyntactically(candidateMethod.Type, method.Type))
         {
             continue;
         }
         return(candidateMethod);
     }
     return(null);
 }
Exemple #2
0
        private void CheckSurface(ITypeDefinitionMember member, INamedTypeDefinition original)
        {
            Contract.Requires(original != null);

            // find member in original
            if (member is IFieldDefinition)
            {
                var field = (IFieldDefinition)member;
                if (!IsCompilerGeneratedType(field.Attributes))
                {
                    // compiler generated types are closure implementations
                    // they are not going to match up.
                    CheckSurface(field, original.GetMembersNamed(field.Name, false));
                }
            }
            else if (member is IMethodDefinition)
            {
                var method = (IMethodDefinition)member;
                if (!(IsCompilerGeneratedType(method.Attributes)))
                {
                    // compiler generated types are closure implementations
                    // they are not going to match up.
                    CheckSurface(method, GetMethod(original, method));
                }
            }
            else if (member is INestedTypeDefinition)
            {
                var nested = (INestedTypeDefinition)member;
                if (!IsCompilerGeneratedType(nested.Attributes))
                {
                    // compiler generated types are closure implementations
                    // they are not going to match up.
                    CheckSurface(nested, original.NestedTypes);
                }
            }
            else if (member is IPropertyDefinition)
            {
                var nested = (IPropertyDefinition)member;
                CheckSurface(nested, original.GetMembersNamed(nested.Name, false));
            }
            else if (member is IEventDefinition)
            {
                var nested = (IEventDefinition)member;
                CheckSurface(nested, original.GetMembersNamed(nested.Name, false));
            }
            // ignore other members?
        }
Exemple #3
0
        private T GetMember <T>(string name)
            where T : class, ITypeDefinitionMember
        {
            var member = type.GetMembersNamed(env.NameTable.GetNameFor(name), false).FirstOrDefault() as T;

            if (member == null)
            {
                throw new VerificationException("{1} {0} not found", name, typeof(T).Name);
            }
            return(member);
        }
Exemple #4
0
 public static IEventDefinition GetEvent(INamedTypeDefinition type, IEventDefinition evnt)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(evnt.Name, false))
     {
         IEventDefinition evntDef = member as IEventDefinition;
         if (evntDef != null)
         {
             return(evntDef);
         }
     }
     return(null);
 }
Exemple #5
0
 public static IFieldDefinition GetField(INamedTypeDefinition type, IName fieldName)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(fieldName, false))
     {
         IFieldDefinition fieldDef = member as IFieldDefinition;
         if (fieldDef != null)
         {
             return(fieldDef);
         }
     }
     return(null);
 }
Exemple #6
0
 public static IMethodDefinition GetMethod(INamedTypeDefinition type, IMethodReference methodRef)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(methodRef.Name, false))
     {
         IMethodDefinition methodDef = member as IMethodDefinition;
         if (methodDef != null && ParametersMatch(methodRef.Parameters, methodDef.Parameters))
         {
             return(methodDef);
         }
     }
     return(null);
 }
Exemple #7
0
 public static IPropertyDefinition GetProperty(INamedTypeDefinition type, IPropertyDefinition property)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(property.Name, false))
     {
         IPropertyDefinition prop = member as IPropertyDefinition;
         if (prop != null && ParametersMatch(property.Parameters, prop.Parameters))
         {
             return(prop);
         }
     }
     return(null);
 }
Exemple #8
0
 public static IPropertyDefinition GetProperty(INamedTypeDefinition type, IName propName)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(propName, false))
     {
         IPropertyDefinition prop = member as IPropertyDefinition;
         if (prop != null)
         {
             return(prop);
         }
     }
     return(null);
 }
            private IExpression ReplaceOperation <T>(T operation) where T : IExpression
            {
                var mcall = operation as MethodCall;

                if (mcall != null)
                {
                    if (mcall.MethodToCall.Name.Value == "Abs")
                    {
                        return(operation);
                    }
                }


                if (MutationTarget.PassInfo.IsIn("Abs", "NegAbs"))
                {
                    INamedTypeDefinition systemConsole = UnitHelper.FindType(NameTable, CoreAssembly, "System.Math");
                    IMethodDefinition    abs           = TypeHelper.GetMethod(systemConsole, NameTable.GetNameFor("Abs"), operation.Type);

                    var call = new MethodCall
                    {
                        IsStaticCall = true,
                        MethodToCall = abs,
                        Type         = abs.Type
                    };
                    call.Arguments.Add(operation);

                    IExpression result = call;

                    if (MutationTarget.PassInfo == "NegAbs")
                    {
                        result = new UnaryNegation
                        {
                            CheckOverflow = false,
                            Operand       = call,
                            Type          = operation.Type,
                        };
                    }
                    return(result);
                }
                else
                {
                    INamedTypeDefinition systemConsole = UnitHelper.FindType(NameTable, Module, "VisualMutatorGeneratedClass");
                    IMethodDefinition    failOnZero    = (IMethodDefinition)systemConsole.GetMembersNamed(NameTable.GetNameFor("FailOnZero"), false).Single();
                    var call = new MethodCall
                    {
                        IsStaticCall = true,
                        MethodToCall = failOnZero,
                        Type         = failOnZero.Type
                    };
                    call.Arguments.Add(operation);
                    return(call);
                }
            }
Exemple #10
0
 public static IEventDefinition GetEvent(INamedTypeDefinition type, IEventDefinition evnt)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(evnt.Name, false))
     {
         IEventDefinition evntDef = member as IEventDefinition;
         if (evntDef != null)
             return evntDef;
     }
     return null;
 }
Exemple #11
0
 public static IFieldDefinition GetField(INamedTypeDefinition type, IName fieldName)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(fieldName, false))
     {
         IFieldDefinition fieldDef = member as IFieldDefinition;
         if (fieldDef != null)
             return fieldDef;
     }
     return null;
 }
Exemple #12
0
 public static IMethodDefinition GetMethod(INamedTypeDefinition type, IMethodReference methodRef)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(methodRef.Name, false))
     {
         IMethodDefinition methodDef = member as IMethodDefinition;
         if (methodDef != null && ParametersMatch(methodRef.Parameters, methodDef.Parameters))
             return methodDef;
     }
     return null;
 }
Exemple #13
0
 public static IPropertyDefinition GetProperty(INamedTypeDefinition type, IPropertyDefinition property)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(property.Name, false))
     {
         IPropertyDefinition prop = member as IPropertyDefinition;
         if (prop != null && ParametersMatch(property.Parameters, prop.Parameters))
             return prop;
     }
     return null;
 }
Exemple #14
0
 public static IPropertyDefinition GetProperty(INamedTypeDefinition type, IName propName)
 {
     foreach (ITypeDefinitionMember member in type.GetMembersNamed(propName, false))
     {
         IPropertyDefinition prop = member as IPropertyDefinition;
         if (prop != null) return prop;
     }
     return null;
 }
Exemple #15
0
 private static IMethodDefinition GetMethod(INamedTypeDefinition original, IMethodDefinition method)
 {
   foreach (var candidate in original.GetMembersNamed(method.Name, false))
   {
     IMethodDefinition candidateMethod = candidate as IMethodDefinition;
     if (candidateMethod == null) continue;
     if (candidateMethod.GenericParameterCount != method.GenericParameterCount) continue;
     if (candidateMethod.ParameterCount != method.ParameterCount) continue;
     if (!ParameterTypesMatch(candidateMethod.Parameters, method.Parameters)) continue;
     if (!TypesMatchSyntactically(candidateMethod.Type, method.Type)) continue;
     return candidateMethod;
   }
   return null;
 }
Exemple #16
0
    private void CheckSurface(ITypeDefinitionMember member, INamedTypeDefinition original)
    {
      Contract.Requires(original != null);

      // find member in original
      if (member is IFieldDefinition) {
        var field = (IFieldDefinition)member;
        if (!IsCompilerGeneratedType(field.Attributes)) {
          // compiler generated types are closure implementations
          // they are not going to match up.
          CheckSurface(field, original.GetMembersNamed(field.Name, false));
        }
      }
      else if (member is IMethodDefinition) {
        var method = (IMethodDefinition)member;
        if (!(IsCompilerGeneratedType(method.Attributes))){
          // compiler generated types are closure implementations
          // they are not going to match up.
          CheckSurface(method, GetMethod(original, method));
        }
      }
      else if (member is INestedTypeDefinition) {
        var nested = (INestedTypeDefinition)member;
        if (!IsCompilerGeneratedType(nested.Attributes)) {
          // compiler generated types are closure implementations
          // they are not going to match up.
          CheckSurface(nested, original.NestedTypes);
        }
      }
      else if (member is IPropertyDefinition) {
        var nested = (IPropertyDefinition)member;
        CheckSurface(nested, original.GetMembersNamed(nested.Name, false));
      }
      else if (member is IEventDefinition) {
        var nested = (IEventDefinition)member;
        CheckSurface(nested, original.GetMembersNamed(nested.Name, false));
      }
      // ignore other members?
    }