internal MethodEntityProcessor(MethodEntity methodEntity, 
            IDispatcher dispatcher, ICodeProvider codeProvider, IEntityDescriptor entityDescriptor = null,
            bool verbose = false)
            : base(methodEntity, entityDescriptor, dispatcher)
        {
            Contract.Assert(methodEntity != null);

            this.MethodEntity = methodEntity;
            this.EntityDescriptor = entityDescriptor==null?methodEntity.EntityDescriptor
                                                          :entityDescriptor;
            this.Verbose = true; // verbose;
            // It gets a code provider for the method.
            if (codeProvider!=null || dispatcher is OrleansDispatcher)
            {
                this.codeProvider = codeProvider;
                 //this.codeProvider = ProjectGrainWrapper.CreateProjectGrainWrapperAsync(methodEntity.MethodDescriptor).Result;
                //SetCodeProviderAsync(methodEntity.MethodDescriptor);
            }
            else
            {
                var pair = ProjectCodeProvider.GetProjectProviderAndSyntaxAsync(methodEntity.MethodDescriptor).Result;
                if (pair != null)
                {
                    this.codeProvider = pair.Item1;
                }
            }
            // We use the codeProvider for Propagation and HandleCall and ReturnEvents (in the method DiffProp that uses IsAssignable)
            // We can get rid of this by passing codeProvider as parameter in this 3 methods
            this.MethodEntity.PropGraph.SetCodeProvider(this.codeProvider);
        }
        public MethodEntity ParseLibraryMethod()
        {
            if (this.RetVar != null)
            {
                this.StatementProcessor.RegisterNewExpressionAssignment(RetVar,
                                            new TypeDescriptor(RetVar.Type,false));
            }

            var descriptor = new MethodEntityDescriptor(this.MethodDescriptor); //EntityFactory.Create(this.MethodDescriptor, this.Dispatcher);
            var methodEntity = new MethodEntity(this.MethodDescriptor,
                                                    this.MethodInterfaceData,
                                                    this.PropGraph, descriptor,
                                                    this.InstantiatedTypes,
                                                    false);
            return methodEntity;
        }
        /// <summary>
        /// Copy the information regarding parameters and callers from one entity and other
        /// The PropGraph of the old entity is used but copied
        /// This is used when one method is updated to recompute the PropGraph using the original input values
        /// </summary>
        /// <param name="oldEntity"></param>
        internal void CopyInterfaceDataAndCallers(MethodEntity entity)
        {
            Contract.Requires(this.ParameterNodes != null);
            foreach (var parameter in this.ParameterNodes)
            {
                if (parameter != null)
                {
                    this.PropGraph.Add(parameter, entity.PropGraph.GetTypes(parameter));
                    this.PropGraph.AddToWorkList(parameter);
                }
            }
            if (this.ThisRef != null)
            {
                this.PropGraph.Add(this.ThisRef, entity.PropGraph.GetTypes(entity.ThisRef));
                this.PropGraph.AddToWorkList(this.ThisRef);
            }

            foreach (var callersContext in entity.Callers)
            {
                this.AddToCallers(callersContext);
            }
        }
 internal MethodEntityProcessor(MethodEntity methodEntity,
     IDispatcher dispatcher, IEntityDescriptor entityDescriptor = null,
     bool verbose = false)
     : this(methodEntity, dispatcher, null, entityDescriptor, verbose)
 {
 }