예제 #1
0
        public override void Visit(IMethodCall call)
        {
            var receiver = call.ThisArgument;
            var callee   = call.MethodToCall.ResolvedMethod;

            // Form comparability information for Collection classes
            if (!call.IsStaticCall && Names.NameTable.ContainsKey(receiver))
            {
                HandleCollectionMethod(call);
                HandleDictionaryMethod(call);
            }

            if (NameBuilder.IsSetter(callee))
            {
                // For setters, mark the property name as comparable with the argument
                Mark(Expand(new[] { call, call.Arguments.First() }));
            }

            if (!(callee is Dummy || callee.Name is Dummy))
            {
                namedCalls.Add(call);
            }

            if (!call.IsStaticCall)
            {
                PropogateTypeReference(call.ThisArgument, call);
            }
        }
예제 #2
0
        /// <summary>
        /// Tries to find the method that should be called.
        /// </summary>
        /// <param name="methodCall">The methodCall can be wrapped</param>
        /// <returns></returns>
        protected MethodInfo FindMethodInDomain(IMethodCall methodCall)
        {
            foreach (MethodInfo methodInfo in domainService.GetType().GetMethods())
            {
                if (methodCall.MethodName.ToLower() != methodInfo.Name.ToLower())
                {
                    continue;
                }

                List <ParameterInfo> parameterResult = methodInfo.GetParameters().ToList <ParameterInfo>();
                if ((parameterResult.Count != methodCall.Args.Count) &&
                    (HelpMethods.AddTrueForSpecified(parameterResult, methodInfo) != methodCall.Args.Count))
                {
                    continue;
                }

                if (!HelpMethods.TypesAreEqual(methodCall.Classes, parameterResult.ToArray <ParameterInfo>()))
                {
                    continue;
                }

                return(methodInfo);
            }

            return(null);
        }
예제 #3
0
 public TimerJob(IScheduledItem schedule, IMethodCall method, string proFileName)
 {
     Schedule        = schedule;
     Method          = method;
     _ExecuteHandler = new ExecuteHandler(ExecuteInternal);
     ProfileName     = proFileName;
 }
    public override void TraverseChildren(IMethodCall methodCall) {
      if (PhoneCodeHelper.instance().PhoneFeedbackToggled) {
        // check for handlers we do not wish to add feedback checks to
        if (methodCall.MethodToCall.Name.Value.StartsWith("add_")) {
          string eventName = methodCall.MethodToCall.Name.Value.Remove(0, "add_".Length);
          if (PhoneCodeHelper.IgnoredEvents.Contains(eventName)) {
            IMethodReference eventHandler = null;
            foreach (IExpression arg in methodCall.Arguments) {
              ICreateDelegateInstance createDelegate = arg as ICreateDelegateInstance;
              if (createDelegate == null)
                continue;

              ITypeReference typeRef = createDelegate.Type;
              if (!typeRef.isRoutedEventHandlerClass(host))
                continue;

              eventHandler = createDelegate.MethodToCallViaDelegate;
              break;
            }

            if (eventHandler != null) {
              INamespaceTypeReference namedType = eventHandler.ContainingType.ResolvedType as INamespaceTypeReference;
              if (namedType != null) {
                INamespaceTypeDefinition namedTypeDef = namedType.ResolvedType;
                if (namedTypeDef != null) {
                  PhoneCodeHelper.instance().ignoreEventHandler(namedTypeDef.ContainingUnitNamespace.Name + "." + namedTypeDef.Name + "." + eventHandler.Name);
                }
              }
            }
          }
        }
      }
    }
            public override void Visit(IMethodCall methodCall)
            {
                _log.Info("Visiting IMethodCall: " + methodCall);
                var defaultEqualsDefinition = TypeHelper.GetMethod(Host.PlatformType.SystemObject.ResolvedType.Members,
                                                                   Host.NameTable.GetNameFor("Equals"),
                                                                   Host.PlatformType.SystemObject);


                var methodDefinition = methodCall.MethodToCall.ResolvedMethod;
                var containingType   = methodCall.ThisArgument.Type.ResolvedType;

                _log.Info("IMethodCall is of " + methodDefinition);
                //Check if the type overrides the Equals method
                if (containingType != Host.PlatformType.SystemString &&
                    containingType != Host.PlatformType.SystemObject &&
                    !containingType.IsValueType &&
                    methodDefinition.Equals(defaultEqualsDefinition) && containingType.IsClass &&
                    containingType.BaseClasses.Any())
                {
                    var overridingMethod = TypeHelper.GetMethod(containingType.Members,
                                                                Host.NameTable.GetNameFor("Equals"),
                                                                Host.PlatformType.SystemObject);

                    if (overridingMethod.IsVirtual)
                    {
                        MarkMutationTarget(methodCall);
                    }
                }
            }
        private bool isKnownUIChanger(ITypeReference typeRef, IMethodCall call)
        {
            string methodName = call.MethodToCall.Name.Value;
            IEnumerable <String> methodsForType = PHONE_UI_CHANGER_METHODS[typeRef.ToString()];

            return(methodsForType != null && methodsForType.Contains(methodName));
        }
        public override void TraverseChildren(IMethodCall methodCall)
        {
            if (!IsSharpMockGenerated(methodCall))
            {
                var mutableMethodCall = methodCall as MethodCall;
                var method = mutableMethodCall.MethodToCall.AsReplaceable();

                log.WriteTrace("Finding replacement for {0}.{1}", method.DeclaringType.Name, method.Name);
                log.WriteTrace("  in '{0}' at '{1}'", method.DeclaringType.Assembly.Name, method.DeclaringType.Assembly.AssemblyPath);

                if (registry.IsRegistered(method))
                {
                    var replacementCall = registry.GetReplacement(method);
                    mutableMethodCall.MethodToCall = replacementCall;

                    if (!methodCall.IsStaticCall)
                    {
                        mutableMethodCall.Arguments.Insert(0, mutableMethodCall.ThisArgument);
                        mutableMethodCall.IsStaticCall = true;
                        mutableMethodCall.IsVirtualCall = false;
                        mutableMethodCall.ThisArgument = CodeDummy.Expression;
                    }

                    log.WriteTrace("  --REPLACEMENT FOUND--");
                }
                else
                {
                    log.WriteTrace("  --NOT FOUND--");
                }
            }
        }
            public override void Visit(IMethodCall methodCall)
            {
                _log.Info("Visiting IMethodCall: " + methodCall);
                var defaultEqualsDefinition = TypeHelper.GetMethod(Host.PlatformType.SystemObject.ResolvedType.Members,
                                                                  Host.NameTable.GetNameFor("Equals"),
                                                                  Host.PlatformType.SystemObject);


                var methodDefinition = methodCall.MethodToCall.ResolvedMethod;
                var containingType = methodCall.ThisArgument.Type.ResolvedType;
                _log.Info("IMethodCall is of " + methodDefinition);
                //Check if the type overrides the Equals method
                if (containingType != Host.PlatformType.SystemString &&
                        containingType != Host.PlatformType.SystemObject &&
                        !containingType.IsValueType &&
                    methodDefinition.Equals(defaultEqualsDefinition) && containingType.IsClass
                    && containingType.BaseClasses.Any())
                {
                    var overridingMethod = TypeHelper.GetMethod(containingType.Members,
                        Host.NameTable.GetNameFor("Equals"),
                        Host.PlatformType.SystemObject);

                    if (overridingMethod.IsVirtual)
                    {
                        MarkMutationTarget(methodCall);
                    }

                }
            }
            public override void Visit(IMethodCall methodCall)
            {
                
                var thisMethod = methodCall.MethodToCall.ResolvedMethod;
                var currentDefinition = thisMethod.ContainingTypeDefinition;
                //Find overloads in this class
                List<IMethodDefinition> allOverloadingMethods = 
                currentDefinition.GetMatchingMembersNamed(thisMethod.Name,
                    false, member => member is IMethodDefinition).Cast<IMethodDefinition>().ToList();


                var currentClass = currentDefinition;
                //Add overloads from base classes
                while (currentClass.BaseClasses.Any())
                {
                    allOverloadingMethods.AddRange(currentClass.BaseClasses.Single()
                        .ResolvedType.GetMatchingMembersNamed(thisMethod.Name,
                    false, member => member is IMethodDefinition).Cast<IMethodDefinition>());
                    currentClass = currentClass.BaseClasses.Single().ResolvedType;
                }

                allOverloadingMethods = allOverloadingMethods.Where(m =>
                    !TypeHelper.ParameterListsAreEquivalent(m.Parameters, thisMethod.Parameters)).ToList();


                if(allOverloadingMethods.Count > 0)
                {
                    MarkMutationTarget(methodCall, new MutationVariant("", allOverloadingMethods.First()));
                }
            
               // allOverloadingMethods = allOverloadingMethods.Where(m =>
              //      m.Parameters.Count() == thisMethod.Parameters.Count()).ToList();

              /*  foreach (var method in allOverloadingMethods)
                {
                    method.Parameters.Di
                }



                var types = thisMethod.Parameters.Select(p => p.Type);
                var sublist = types.ToList().ToSublist();
                
              //  sublist.
                //  new[]{4}.ToSublist().
                while(List.NextPermutation(sublist))
                {
                    
                }



                if (method.IsVirtual && method.ContainingTypeDefinition
                    .BaseClasses.Single()
                    .ResolvedType.GetMembersNamed(method.Name, false).Any())
                {
                    MarkMutationTarget(method);
                }*/
            }
예제 #10
0
            public override void Visit(IMethodCall methodCall)
            {
                var thisMethod        = methodCall.MethodToCall.ResolvedMethod;
                var currentDefinition = thisMethod.ContainingTypeDefinition;
                //Find overloads in this class
                List <IMethodDefinition> allOverloadingMethods =
                    currentDefinition.GetMatchingMembersNamed(thisMethod.Name,
                                                              false, member => member is IMethodDefinition).Cast <IMethodDefinition>().ToList();


                var currentClass = currentDefinition;

                //Add overloads from base classes
                while (currentClass.BaseClasses.Any())
                {
                    allOverloadingMethods.AddRange(currentClass.BaseClasses.Single()
                                                   .ResolvedType.GetMatchingMembersNamed(thisMethod.Name,
                                                                                         false, member => member is IMethodDefinition).Cast <IMethodDefinition>());
                    currentClass = currentClass.BaseClasses.Single().ResolvedType;
                }

                allOverloadingMethods = allOverloadingMethods.Where(m =>
                                                                    !TypeHelper.ParameterListsAreEquivalent(m.Parameters, thisMethod.Parameters)).ToList();


                if (allOverloadingMethods.Count > 0)
                {
                    MarkMutationTarget(methodCall, new MutationVariant("", allOverloadingMethods.First()));
                }

                // allOverloadingMethods = allOverloadingMethods.Where(m =>
                //      m.Parameters.Count() == thisMethod.Parameters.Count()).ToList();

                /*  foreach (var method in allOverloadingMethods)
                 * {
                 *    method.Parameters.Di
                 * }
                 *
                 *
                 *
                 * var types = thisMethod.Parameters.Select(p => p.Type);
                 * var sublist = types.ToList().ToSublist();
                 *
                 * //  sublist.
                 * //  new[]{4}.ToSublist().
                 * while(List.NextPermutation(sublist))
                 * {
                 *
                 * }
                 *
                 *
                 *
                 * if (method.IsVirtual && method.ContainingTypeDefinition
                 *    .BaseClasses.Single()
                 *    .ResolvedType.GetMembersNamed(method.Name, false).Any())
                 * {
                 *    MarkMutationTarget(method);
                 * }*/
            }
예제 #11
0
 public override void Visit(IMethodCall methodCall)
 {
     if (Process(methodCall))
     {
         visitor.Visit(methodCall);
     }
     base.Visit(methodCall);
 }
 public override IExpression Rewrite(IMethodCall methodCall)
 {
     _log.Info("Rewriting IMethodCall: " + methodCall+" Pass: "+MutationTarget.PassInfo);
     var equality = new Equality();
     equality.LeftOperand = methodCall.ThisArgument;
     equality.RightOperand = methodCall.Arguments.Single();
     equality.Type = Host.PlatformType.SystemBoolean;
     return equality;
 }
            public override void Visit(IMethodCall call)
            {
                var field = TryFindField(call, Parent.CurrentMethod);

                if (field != null)
                {
                    MarkMutationTarget(call);
                }
            }
            public override IExpression Rewrite(IMethodCall methodCall)
            {
                _log.Info("Rewriting IMethodCall: " + methodCall + " Pass: " + MutationTarget.PassInfo);
                var equality = new Equality();

                equality.LeftOperand  = methodCall.ThisArgument;
                equality.RightOperand = methodCall.Arguments.Single();
                equality.Type         = Host.PlatformType.SystemBoolean;
                return(equality);
            }
      private static IFieldDefinition TryFindField(IMethodCall call, IMethodDefinition currentMethod)
      {
          var targetType = call.ThisArgument.Type;
 
          var field = currentMethod.ContainingTypeDefinition.Fields
              .Where(f => f.IsStatic == currentMethod.IsStatic)
              .FirstOrDefault(f => isCompatibile(targetType, f.Type.ResolvedType)
                  && FieldIsNotThis(f, call.ThisArgument) && !call.MethodToCall.ResolvedMethod.IsConstructor);
          return field;
      }
        private static IFieldDefinition TryFindField(IMethodCall call, IMethodDefinition currentMethod)
        {
            var targetType = call.ThisArgument.Type;

            var field = currentMethod.ContainingTypeDefinition.Fields
                        .Where(f => f.IsStatic == currentMethod.IsStatic)
                        .FirstOrDefault(f => isCompatibile(targetType, f.Type.ResolvedType) &&
                                        FieldIsNotThis(f, call.ThisArgument) && !call.MethodToCall.ResolvedMethod.IsConstructor);

            return(field);
        }
        public bool isNavigationCall(IMethodCall call)
        {
            ITypeReference callType = call.MethodToCall.ContainingType;

            if (!callType.isNavigationServiceClass(host))
            {
                return(false);
            }

            return(NAV_CALLS.Contains(call.MethodToCall.Name.Value));
        }
            public override void Visit(IMethodCall methodCall)
            {
                var thisMethod = methodCall.MethodToCall.ResolvedMethod;

                var types = thisMethod.Parameters.Select(p => p.Type.ResolvedType).ToList();
                
                if (types.Distinct().Count() < thisMethod.Parameters.Count())
                {
                    MarkMutationTarget(methodCall);
                }
            }
 public override IExpression Rewrite(IMethodCall methodCall)
 {
     _log.Info("Rewrite IMethodCall: " + OperatorUtils.Formatter.Format(methodCall));
     var methodDefinition = TypeHelper.GetMethod(methodCall.MethodToCall.ContainingType.ResolvedType, 
         NameTable.GetNameFor(MutationTarget.PassInfo), methodCall.Arguments.Select(a => a.Type).ToArray());
     var newCall = new MethodCall(methodCall);
     newCall.MethodToCall = methodDefinition;//
  //   (IMethodReference)MutationTarget.StoredObjects.Values.Single();
     _log.Info("Returning MethodCall to: " + OperatorUtils.Formatter.Format(methodCall));
     return newCall;
 }
예제 #20
0
        public override void Visit(IMethodCall methodCall)
        {
            // I'm going to assume that if it is not a static call then the method makes use of the instance.
            if (!methodCall.IsStaticCall)
            {
                instanceIsUsed = true;
                return;
            }

            base.Visit(methodCall);
        }
        private bool IsSharpMockGenerated(IMethodCall methodCall)
        {
            foreach (var customAttribute in methodCall.MethodToCall.ResolvedMethod.Attributes)
            {
                if (customAttribute.Constructor.ResolvedMethod.Equals(reflector.From<SharpMockGeneratedAttribute>().GetConstructor(System.Type.EmptyTypes)))
                {
                    return true;
                }
            }

            return false;
        }
예제 #22
0
        public override void TraverseChildren(IMethodCall methodCall)
        {
            if (methodCall.IsStaticCall ||
                !methodCall.MethodToCall.ContainingType.ResolvedType.Equals(methodBeingTraversed.Container) ||
                methodCall.MethodToCall.Name.Value != "InitializeComponent" ||
                methodCall.Arguments.Any())
            {
                return;
            }

            initializationFound = true;
        }
예제 #23
0
        /// <summary>
        /// Copy constructor, used by the aggregate web method node
        /// </summary>
        /// <param name="methodCall"></param>
        public MethodCall(IMethodCall methodCall)
        {
            m_methodInfo = methodCall.MethodInfo;
            m_object     = Activator.CreateInstance(m_methodInfo.DeclaringType);

            m_inputType    = methodCall.InputType;
            m_inputSchemas = methodCall.InputSchemas;
            m_inputSchema  = m_inputSchemas[0];

            m_outputType    = methodCall.OutputType;
            m_outputSchemas = methodCall.OutputSchemas;
            m_outputSchema  = m_outputSchemas[0];
        }
            public override void Visit(IMethodCall call)
            {


                var field = TryFindField(call, Parent.CurrentMethod);

                if(field != null)
                {
                    MarkMutationTarget(call);
                }

               
            }
        /// <summary>
        /// checks whether a static URI root (a definite page base) can be extracted from the expression
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public static bool IsStaticURIRootExtractable(this IExpression expr, out string uri)
        {
            // Pre expr.type == string
            IMethodCall stringConcatExpr = expr as IMethodCall;

            uri = null;
            if (stringConcatExpr == null)
            {
                return(false);
            }

            if (stringConcatExpr.MethodToCall.Name.Value != "Concat")
            {
                return(false);
            }

            IList <string> constantStrings = new List <string>();

            // TODO this misses so many "static" strings, but let's start with this for now
            IExpression leftOp = stringConcatExpr.Arguments.FirstOrDefault();

            while (leftOp != null && leftOp is ICompileTimeConstant)
            {
                ICompileTimeConstant strConst = leftOp as ICompileTimeConstant;
                constantStrings.Add(strConst.Value as string);
                if (stringConcatExpr.Arguments.ToList()[1] is IMethodCall)
                {
                    stringConcatExpr = stringConcatExpr.Arguments.ToList()[1] as IMethodCall;
                    leftOp           = stringConcatExpr.Arguments.FirstOrDefault();
                }
                else if (stringConcatExpr.Arguments.ToList()[1] is ICompileTimeConstant)
                {
                    constantStrings.Add((stringConcatExpr.Arguments.ToList()[1] as ICompileTimeConstant).Value as string);
                    break;
                }
                else
                {
                    break;
                }
            }

            if (constantStrings.Count > 0)
            {
                uri = constantStrings.Aggregate((aggr, elem) => aggr + elem);
                return(Uri.IsWellFormedUriString(uri, UriKind.RelativeOrAbsolute));
            }
            else
            {
                return(false);
            }
        }
예제 #26
0
 public override void Visit(IMethodCall methodCall)
 {
     base.Visit(methodCall);
     ScannedMethodCalls++;
     if (_currentTestMethod != null )
     {
         if (_searcher.Matches(methodCall.MethodToCall))
         {
             _log.Debug("Adding test" + _currentTestMethod + " invoking method "
                 + methodCall.MethodToCall);
             _foundTests.Add(CciMethodMatcher.CreateIdentifier(_currentTestMethod));
         }
     }
 }
예제 #27
0
        public override void TraverseChildren(IMethodCall methodCall)
        {
            var mName = MemberHelper.GetMethodSignature(methodCall.MethodToCall);

            if (mName.Contains("System.Diagnostics.Contracts.Contract.ForAll"))
            {
                base.sourceEmitterOutput.Write("for all ");
                var n = methodCall.Arguments.Count();
                if (n == 2)
                {
                    var lambda = methodCall.Arguments.ElementAt(1) as IAnonymousDelegate;
                    if (lambda == null)
                    {
                        return;
                    }
                    sourceEmitterOutput.Write(lambda.Parameters.ElementAt(0).Name.Value);
                    sourceEmitterOutput.Write(" in ");
                    Traverse(methodCall.Arguments.ElementAt(0));
                    sourceEmitterOutput.Write(" ");
                    if (!PrintLambdaBody(lambda))
                    {
                        Traverse(lambda.Body);
                    }
                }
                else
                {
                    // n == 3
                    var lambda = methodCall.Arguments.ElementAt(2) as IAnonymousDelegate;
                    if (lambda == null)
                    {
                        return;
                    }
                    var paramName = lambda.Parameters.ElementAt(0).Name.Value;
                    sourceEmitterOutput.Write(paramName);
                    sourceEmitterOutput.Write(" where ");
                    Traverse(methodCall.Arguments.ElementAt(0));
                    sourceEmitterOutput.Write(" <= ");
                    sourceEmitterOutput.Write(paramName);
                    sourceEmitterOutput.Write(" < ");
                    Traverse(methodCall.Arguments.ElementAt(1));
                    sourceEmitterOutput.Write(" :: ");
                    if (!PrintLambdaBody(lambda))
                    {
                        Traverse(lambda.Body);
                    }
                }
                return;
            }
            base.TraverseChildren(methodCall);
        }
예제 #28
0
        public override void TraverseChildren(IMethodCall methodCall)
        {
            base.TraverseChildren(methodCall);
            var ps   = new List <IParameterTypeInformation>(methodCall.MethodToCall.Parameters);
            var args = new List <IExpression>(methodCall.Arguments);

            for (int i = 0, n = args.Count; i < n; i++)
            {
                Contract.Assume(args[i] != null);
                Contract.Assume(i < ps.Count);
                Contract.Assume(ps[i] != null);
                args[i] = Convert(args[i], ps[i].Type);
            }
            ((MethodCall)methodCall).Type = methodCall.MethodToCall.Type;
        }
            public override void Visit(IMethodCall methodCall)
            {
                

                if(IsPropertyAccessor(methodCall.MethodToCall.ResolvedMethod))
                {
                    IMethodDefinition accessor;
                    if(TryGetCompatibileAccessor(methodCall.MethodToCall.ResolvedMethod, out accessor))
                    {
                       // _log.Info("Marking IMethodCall: " + methodCall.MethodToCall.ResolvedMethod + " - " + methodCall.MethodToCall.ResolvedMethod.GetType());
                        MarkMutationTarget(methodCall, accessor.Name.Value.InList());
                    }

                }

            }
예제 #30
0
        public void PrintSubVI(int indnt, StreamWriter writer, IMethodCall node)
        {
            IEnumerable <INode> E = node.GetDfirRoot.BlockDiagram.GetAllNodes();

            indent(indnt, writer); writer.Write("<SubVI NodeId=\"" + node.UniqueId + "\" ParentId=\"" + node.ParentNode.UniqueId + "\">\n");
            foreach (var tmp in E)
            {
                if (shortName(tmp.GetType().ToString()) == "ExDataAccessor")
                {
                    IDataAccessor da = tmp as IDataAccessor;
                    ITerminal     t  = node.GetTerminalByUserVisibleName(da.Name, node.GetDfirRoot);
                    indent(indnt + 1, writer); writer.Write("<Pair TerminalId=\"" + t.UniqueId + "\" SubVIDataAccessorId=\"" + da.UniqueId + "\"/>\n");
                }
            }
            indent(indnt, writer); writer.Write("</SubVI>\n");
        }
        public override void TraverseChildren(IMethodCall methodCall)
        {
            var mutableMethodCall = methodCall as MethodCall;

            var callsToOverloads = reflector.From(typeof(Replace)).GetAllOverloadsOf("CallsTo");
            if (mutableMethodCall.MethodCallMatchesAnOverload(callsToOverloads))
            {
                var lambda = mutableMethodCall.Arguments[0] as AnonymousDelegate;

                var parser = new LambdaParser(lambda, host, log, registry);

                var replacement = parser.GetReplacementFactory();
                var registrar = replacement.GetRegistrar();

                registrar.RegisterReplacement();
            }

            base.TraverseChildren(methodCall);
        }
            public override void Visit(IMethodCall methodCall)
            {
              //  _log.Info("Visiting IMethodCall: " + methodCall);
              /*  TypeHelper.GetDefiningUnitReference(methodCall.MethodToCall.ContainingType.ResolvedType);
                Host.CoreAssemblySymbolicIdentity
                var namedTypeReference = methodCall.MethodToCall.ContainingType.ResolvedType as INamedTypeReference;
                if (namedTypeReference != null)
                {
                    namedTypeReference.
                }*/
                if(IsPropertyModifier(methodCall.MethodToCall.ResolvedMethod))
                {
                    IMethodReference accessor;
                    if(TryGetCompatibileModifier(methodCall.MethodToCall.ResolvedMethod, out accessor))
                    {
                        MarkMutationTarget(methodCall, accessor.Name.Value);//w MutationVariant(accessor.Name.Value, accessor));
                    }

                }

            }
            public override IExpression Rewrite(IMethodCall methodCall)
            {
                var newSeq = new List<List<Reposition>>();
                var thisMethod = methodCall.MethodToCall.ResolvedMethod;
                var types = thisMethod.Parameters.Select(p => p.Type.ResolvedType).ToList();
                var groups = types.Select( (t, i) => new{t,i}).GroupBy(a => a.t, a=>a.i);

                newSeq.AddRange(from @group in groups 
                                select @group.RotateRight(1).Select((i, index) => 
                                    new Reposition(i, @group.ElementAt(index))).ToList());

                var newArgs = new IExpression[types.Count];
                foreach (var repos in newSeq.Flatten())
                {
                    newArgs[repos.NewPos] = methodCall.Arguments.ElementAt(repos.OldPos);

                }
                return new MethodCall(methodCall)
                    {
                        Arguments = newArgs.ToList()
                    };
            }
            public override IExpression Rewrite(IMethodCall call)
            {
                var field = TryFindField(call, CurrentMethod);
                if (field != null)
                {
                    return new MethodCall(call)
                    {
                        ThisArgument = new BoundExpression()
                        {
                            Instance = new ThisReference()
                            {
                                Type = CurrentMethod.ContainingTypeDefinition
                            },
                            Type = field.Type,
                            Definition = field,

                        }
                    };
                }
                else
                {
                    return call;
                }
            }
예제 #35
0
 public void Visit(IMethodCall methodCall)
 {
     this.traverser.Traverse(methodCall);
 }
예제 #36
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodCall"></param>
 internal ConstructorOrMethodCall(IMethodCall methodCall)
     : base(methodCall)
 {
     Contract.Requires(methodCall != null);
       this.arguments = new List<IExpression>(methodCall.Arguments);
       this.methodToCall = methodCall.MethodToCall;
 }
예제 #37
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="methodCall"></param>
 public MethodCall(IMethodCall methodCall)
     : base(methodCall)
 {
     this.isVirtualCall = methodCall.IsVirtualCall;
       this.isTailCall = methodCall.IsTailCall;
       this.isStaticCall = methodCall.IsStaticCall;
       if (!methodCall.IsStaticCall) {
     this.thisArgument = methodCall.ThisArgument;
       } else
     this.thisArgument = CodeDummy.Expression;
       //^ assume false; //invariant involves properties
 }
예제 #38
0
 /// <summary>
 /// Traverses the children of the method call.
 /// </summary>
 public virtual void TraverseChildren(IMethodCall methodCall)
 {
     Contract.Requires(methodCall != null);
       this.TraverseChildren((IExpression)methodCall);
       if (this.StopTraversal) return;
       if (!methodCall.IsStaticCall && !methodCall.IsJumpCall) {
     this.Traverse(methodCall.ThisArgument);
     if (this.StopTraversal) return;
       }
       this.Traverse(methodCall.MethodToCall);
       if (this.StopTraversal) return;
       this.Traverse(methodCall.Arguments);
 }
예제 #39
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="methodCall"></param>
    /// <remarks>Stub, This one really needs comments!</remarks>
    public override void Visit(IMethodCall methodCall) {

      #region Translate In Parameters


      Bpl.ExprSeq inexpr = new Bpl.ExprSeq();

      #region Create the 'this' argument for the function call
      this.Visit(methodCall.ThisArgument);
      inexpr.Add(this.TranslatedExpressions.Pop());
      #endregion

      Dictionary<IParameterDefinition, Bpl.Expr> p2eMap = new Dictionary<IParameterDefinition, Bpl.Expr>();
      IEnumerator<IParameterDefinition> penum = methodCall.MethodToCall.ResolvedMethod.Parameters.GetEnumerator();
      penum.MoveNext();
      foreach (IExpression exp in methodCall.Arguments) {
        if (penum.Current == null) {
          throw new TranslationException("More Arguments than Parameters in functioncall");
        }
        this.Visit(exp);
        Bpl.Expr e = this.TranslatedExpressions.Pop();

        p2eMap.Add(penum.Current, e);
        if (!penum.Current.IsOut) {
          inexpr.Add(e);
        }
        
        penum.MoveNext();
      }
      #endregion

      Bpl.IToken cloc = methodCall.Token();

      // meeting a constructor is always something special
      if (methodCall.MethodToCall.ResolvedMethod.IsConstructor) {
        // Todo: do something with the constructor call
      } else {
        // Todo: if there is no stmttraverser we are visiting a contract and should use a boogie function instead of procedure!

        #region Translate Out vars
        Bpl.IdentifierExprSeq outvars = new Bpl.IdentifierExprSeq();

        foreach (KeyValuePair<IParameterDefinition, Bpl.Expr> kvp in p2eMap) {
          if (kvp.Key.IsOut || kvp.Key.IsByReference) {
            Bpl.IdentifierExpr iexp = kvp.Value as Bpl.IdentifierExpr;
            if (iexp == null) {
              throw new TranslationException("Trying to pass complex expression as out in functioncall");
            }
            outvars.Add(iexp);
          }
        }
        #endregion

        if (methodCall.Type.ResolvedType.TypeCode != PrimitiveTypeCode.Void) {
          Bpl.Variable v = this.sink.CreateFreshLocal(methodCall.Type.ResolvedType);
          outvars.Add(new Bpl.IdentifierExpr(cloc, v));
          TranslatedExpressions.Push(new Bpl.IdentifierExpr(cloc, v));
        }
        string methodname = TranslationHelper.CreateUniqueMethodName(methodCall.MethodToCall.ResolvedMethod);

        this.StmtTraverser.StmtBuilder.Add(new Bpl.CallCmd(cloc, methodname, inexpr, outvars));
        
      }

    }
예제 #40
0
 public void Visit(IMethodCall methodCall)
 {
     throw new NotImplementedException();
 }
예제 #41
0
 /// <summary>
 /// Traverses the children of the method call.
 /// </summary>
 public override void TraverseChildren(IMethodCall methodCall)
 {
     base.TraverseChildren(methodCall);
       if (this.StopTraversal) return;
       if (this.contractProvider == null) return;
       IEnumerable<IEnumerable<IExpression>>/*?*/ triggers = this.contractProvider.GetTriggersFor(methodCall);
       if (triggers != null)
     this.Traverse(triggers);
 }
 public override IExpression Rewrite(IMethodCall methodCall) {
   var mutableMethodCall = methodCall as MethodCall;
   if (mutableMethodCall != null) {
     if (mutableMethodCall.Arguments.Count == 1) {
       var tokenOf = mutableMethodCall.Arguments[0] as TokenOf;
       if (tokenOf != null) {
         var typeRef = tokenOf.Definition as ITypeReference;
         if (typeRef != null && methodCall.MethodToCall.InternedKey == this.GetTypeFromHandle.InternedKey) {
           return new TypeOf() { Locations = mutableMethodCall.Locations, Type = methodCall.Type, TypeToGet = typeRef };
         }
       }
     }
   }
   return base.Rewrite(methodCall);
 }
예제 #43
0
 /// <summary>
 /// Performs some computation with the given method call.
 /// </summary>
 /// <param name="methodCall"></param>
 public virtual void Visit(IMethodCall methodCall)
 {
     this.Visit((IExpression)methodCall);
 }
예제 #44
0
 public void Visit(IMethodCall methodCall)
 {
     Contract.Requires(methodCall != null);
       throw new NotImplementedException();
 }
 public override void TraverseChildren(IMethodCall methodCall) {
   NameFormattingOptions options = NameFormattingOptions.None;
   bool delegateInvocation = false;
   if (!methodCall.IsStaticCall && !methodCall.IsJumpCall) {
     IAddressOf/*?*/ addressOf = methodCall.ThisArgument as IAddressOf;
     if (addressOf != null) {
       this.Traverse(addressOf.Expression);
     } else {
       this.Traverse(methodCall.ThisArgument);
       var methodReference = methodCall.MethodToCall;
       delegateInvocation = methodReference.Name.Value == "Invoke" && methodReference.ContainingType.ResolvedType.IsDelegate;
     }
     if (!delegateInvocation) this.PrintToken(CSharpToken.Dot);
     options |= NameFormattingOptions.OmitContainingNamespace | NameFormattingOptions.OmitContainingType;
   } else {
     // it is a static call, so see if it is an operator
     var methodDefinition = methodCall.MethodToCall.ResolvedMethod;
     if (IsOperator(methodDefinition) && !IsConversionOperator(methodDefinition)) {
       var opName = MapOperatorNameToCSharp(methodDefinition);
       if (opName.Length >= 9) {
         opName = opName.Substring(9);
       }
       if (methodDefinition.ParameterCount == 1) {
         this.sourceEmitterOutput.Write(opName);
         this.Traverse(methodCall.Arguments.ElementAt(0));
       } else {
         this.Traverse(methodCall.Arguments.ElementAt(0));
         this.sourceEmitterOutput.Write(" ");
         this.sourceEmitterOutput.Write(opName);
         this.sourceEmitterOutput.Write(" ");
         this.Traverse(methodCall.Arguments.ElementAt(1));
       }
       return;
     }
   }
   if (!delegateInvocation)
     this.PrintMethodReferenceName(methodCall.MethodToCall, options);
   if (methodCall.MethodToCall.Name.Value.StartsWith("get_")) {
     if (methodCall.MethodToCall.ParameterCount > 0) {
       this.sourceEmitterOutput.Write("[");
       this.Traverse(methodCall.Arguments);
       this.sourceEmitterOutput.Write("]");
     }
   } else if (methodCall.MethodToCall.Name.Value.StartsWith("set_") && methodCall.MethodToCall.ParameterCount > 0) {
     var argList = new List<IExpression>(methodCall.Arguments);
     if (argList.Count > 1) {
       this.sourceEmitterOutput.Write("[");
       for (int i = 0, n = argList.Count-1; i < n; i++) {
         if (i > 0) this.sourceEmitterOutput.Write(", ");
         this.Traverse(argList[i]);
       }
       this.sourceEmitterOutput.Write("]");
     }
     this.sourceEmitterOutput.Write(" = ");
     this.Traverse(argList[argList.Count-1]);
   } else 
     this.PrintArgumentList(methodCall.Arguments, methodCall.MethodToCall.Parameters);
 }
예제 #46
0
 public override void TraverseChildren(IMethodCall methodCall) {
   var mName = MemberHelper.GetMethodSignature(methodCall.MethodToCall);
   if (mName.Contains("System.Diagnostics.Contracts.Contract.ForAll")) {
     base.sourceEmitterOutput.Write("for all ");
     var n = methodCall.Arguments.Count();
     if (n == 2) {
       var lambda = methodCall.Arguments.ElementAt(1) as IAnonymousDelegate;
       sourceEmitterOutput.Write(lambda.Parameters.ElementAt(0).Name.Value);
       sourceEmitterOutput.Write(" in ");
       Traverse(methodCall.Arguments.ElementAt(0));
       sourceEmitterOutput.Write(" ");
       if (!PrintLambdaBody(lambda))
         Traverse(lambda.Body);
     } else {
       // n == 3
       var lambda = methodCall.Arguments.ElementAt(2) as IAnonymousDelegate;
       var paramName = lambda.Parameters.ElementAt(0).Name.Value;
       sourceEmitterOutput.Write(paramName);
       sourceEmitterOutput.Write(" where ");
       Traverse(methodCall.Arguments.ElementAt(0));
       sourceEmitterOutput.Write(" <= ");
       sourceEmitterOutput.Write(paramName);
       sourceEmitterOutput.Write(" < ");
       Traverse(methodCall.Arguments.ElementAt(1));
       sourceEmitterOutput.Write(" :: ");
       if (!PrintLambdaBody(lambda))
         Traverse(lambda.Body);
     }
     return;
   }
   base.TraverseChildren(methodCall);
 }
예제 #47
0
 public virtual void onASTElement(IMethodCall methodCall) { }
예제 #48
-1
파일: TimerJob.cs 프로젝트: ruslanlyalko/DA
 public TimerJob(IScheduledItem schedule, IMethodCall method, string proFileName)
 {
     Schedule = schedule;
     Method = method;
     _ExecuteHandler = new ExecuteHandler(ExecuteInternal);
        ProfileName = proFileName;
 }