コード例 #1
0
ファイル: Program.cs プロジェクト: zhuyue1314/CodeContracts
 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);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: zhuyue1314/CodeContracts
        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?
        }
コード例 #3
0
ファイル: TypeVerifier.cs プロジェクト: ugurak/nemerle
        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);
        }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #9
0
            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);
                }
            }
コード例 #10
0
ファイル: Util.cs プロジェクト: dsgouda/buildtools
 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;
 }
コード例 #11
0
ファイル: Util.cs プロジェクト: dsgouda/buildtools
 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;
 }
コード例 #12
0
ファイル: Util.cs プロジェクト: dsgouda/buildtools
 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;
 }
コード例 #13
0
ファイル: Util.cs プロジェクト: dsgouda/buildtools
 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;
 }
コード例 #14
0
ファイル: Util.cs プロジェクト: dsgouda/buildtools
 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;
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: asvishnyakov/CodeContracts
 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;
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: asvishnyakov/CodeContracts
    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?
    }