public StatementProcessor(MethodDescriptor m,
                                  PropGraphNodeDescriptor rv, PropGraphNodeDescriptor thisRef,
                                  IEnumerable <PropGraphNodeDescriptor> parameters)
        //    ,
        //    ICodeProvider codeProvider)
        {
            // this.containerEntity = containerEntity;
            this.ReturnVariable    = rv;
            this.Method            = m;
            this.ParameterNodes    = parameters;
            this.ThisRef           = thisRef;
            this.PropagationGraph  = new PropagationGraph();
            this.InstantiatedTypes = new HashSet <TypeDescriptor>();
            this.RemovedTypes      = new HashSet <TypeDescriptor>();

            if (rv != null)
            {
                PropagationGraph.AddRet(rv);
            }
            if (thisRef != null)
            {
                PropagationGraph.Add(thisRef);
            }

            foreach (var parameter in this.ParameterNodes)
            {
                if (parameter != null)
                {
                    PropagationGraph.Add(parameter);
                }
            }
            //this.dispatcher = dispatcher;
        }
 public void RegisterRemoveAssignment(PropGraphNodeDescriptor lhs, PropGraphNodeDescriptor rhs)
 {
     if (lhs != null && rhs != null)
     {
         var typesToDelete = PropagationGraph.TypesInEdge(rhs, lhs);
         PropagationGraph.RemoveTypes(lhs, typesToDelete);
         PropagationGraph.AddToDeletionWorkList(lhs);
     }
 }
        public void RegisterRemoveTypes(PropGraphNodeDescriptor lhs, IEnumerable <TypeDescriptor> types)
        {
            if (lhs != null)
            {
                this.RemovedTypes.UnionWith(types);

                PropagationGraph.RemoveTypes(lhs, types);
                PropagationGraph.AddToDeletionWorkList(lhs);
            }
        }
        public void RegisterRemoveNewExpressionAssignment(PropGraphNodeDescriptor lhs)
        {
            if (lhs != null)
            {
                var types = PropagationGraph.GetTypes(lhs);

                this.RemovedTypes.UnionWith(types);

                PropagationGraph.RemoveTypes(lhs, types);
                PropagationGraph.AddToDeletionWorkList(lhs);
            }
        }
        /// <summary>
        ///  In the incremental analysis we want to use this commands over an existing propagation graph
        /// </summary>
        /// <param name="propagationGraph"></param>
        public StatementProcessor(MethodDescriptor method, VariableNode rv,
                                  VariableNode thisRef, IList <PropGraphNodeDescriptor> parameters,
                                  PropagationGraph propagationGraph)
        {
            this.PropagationGraph = propagationGraph;
            this.ReturnVariable   = rv;
            this.Method           = method;
            this.ParameterNodes   = parameters;
            this.ThisRef          = thisRef;

            this.InstantiatedTypes = new HashSet <TypeDescriptor>();
            this.RemovedTypes      = new HashSet <TypeDescriptor>();
        }
        public void RegisterRemoveType(PropGraphNodeDescriptor lhs, TypeDescriptor type)
        {
            if (lhs != null)
            {
                var types = new HashSet <TypeDescriptor>();
                types.Add(type);

                this.RemovedTypes.Add(type);

                PropagationGraph.RemoveTypes(lhs, types);
                PropagationGraph.AddToDeletionWorkList(lhs);
            }
        }
        public void RegisterAssignment(PropGraphNodeDescriptor lhs, PropGraphNodeDescriptor rhs)
        {
            if (lhs != null && rhs != null)
            {
                PropagationGraph.AddEdge(rhs, lhs);

                if (!rhs.Type.IsConcreteType)
                {
                    PropagationGraph.Add(rhs, rhs.Type);
                    PropagationGraph.AddToWorkList(rhs);
                }
            }
        }
        /// <summary>
        /// We use this mapping as a cache of already computed callees info
        /// </summary>
        //public MethodEntityProcessor EntityProcessor { get; private set; }
        //public ISet<E> NodesProcessing = new HashSet<E>();
        //public ISet<CallConext<M,E>> NodesProcessing = new HashSet<CallConext<M,E>>();
        /// <summary>
        /// A method entity is built using the methods interface (params, return) and the propagation graph that is 
        /// initially populated with the variables, parameters and calls of the method 
        /// </summary>
        /// <param name="methodDescriptor"></param>
        /// <param name="mid"></param>
        /// <param name="propGraph"></param>
        /// <param name="instantiatedTypes"></param>
        public MethodEntity(MethodDescriptor methodDescriptor,
			MethodInterfaceData mid,
			PropagationGraph propGraph,
			IEnumerable<TypeDescriptor> instantiatedTypes)
            : base()
        {
            this.MethodDescriptor = methodDescriptor;
            this.EntityDescriptor = EntityFactory.Create(methodDescriptor);
            this.MethodInterfaceData = mid;

            this.PropGraph = propGraph;
            this.InstantiatedTypes = new HashSet<TypeDescriptor>(instantiatedTypes);
        }
 public MethodEntity(MethodDescriptor methodDescriptor,
                     MethodInterfaceData mid,
                     PropagationGraph propGraph,
                     IEntityDescriptor descriptor,
                     IEnumerable <TypeDescriptor> instantiatedTypes,
                     IDictionary <AnonymousMethodDescriptor, MethodEntity> anonymousMethods,
                     CodeGraphModel.DeclarationAnnotation declarationInfo,
                     CodeGraphModel.SymbolReference referenceInfo)
     : this(methodDescriptor, mid, propGraph, descriptor, instantiatedTypes)
 {
     this.anonymousMethods = anonymousMethods;
     this.DeclarationInfo  = declarationInfo;
     this.ReferenceInfo    = referenceInfo;
 }
        public void RegisterPropertyCall(MethodDescriptor callee, PropGraphNodeDescriptor receiver, IList <PropGraphNodeDescriptor> arguments,
                                         VariableNode lhs, AnalysisCallNode callNode)
        {
            Contract.Requires(callNode != null);
            Contract.Requires(callee != null);

            var callExp = new MethodCallInfo(this.Method, callNode, callee, receiver, arguments, lhs, false);

            RegisterInvocation(arguments, callNode, callExp);

            if (receiver != null)
            {
                PropagationGraph.AddEdge(receiver, callNode);
            }
        }
        /// <summary>
        /// We use this mapping as a cache of already computed callees info
        /// </summary>
        //public MethodEntityProcessor EntityProcessor { get; private set; }
        //public ISet<E> NodesProcessing = new HashSet<E>();
        //public ISet<CallConext<M,E>> NodesProcessing = new HashSet<CallConext<M,E>>();
        /// <summary>
        /// A method entity is built using the methods interface (params, return) and the propagation graph that is 
        /// initially populated with the variables, parameters and calls of the method 
        /// </summary>
        /// <param name="methodDescriptor"></param>
        /// <param name="mid"></param>
        /// <param name="propGraph"></param>
        /// <param name="instantiatedTypes"></param>
        public MethodEntity(MethodDescriptor methodDescriptor,
            MethodInterfaceData mid,
            PropagationGraph propGraph,
            IEntityDescriptor descriptor,
            IEnumerable<TypeDescriptor> instantiatedTypes,
            bool canBeAnalyzed = true)
            : base()
        {
            this.MethodDescriptor = methodDescriptor;
            this.EntityDescriptor = descriptor; // EntityFactory.Create(methodDescriptor);
            this.MethodInterfaceData = mid;

            this.propGraph = propGraph;
            this.InstantiatedTypes = new HashSet<TypeDescriptor>(instantiatedTypes);
            this.CanBeAnalized = canBeAnalyzed;
        }
        /// <summary>
        /// We use this mapping as a cache of already computed callees info
        /// </summary>
        //public MethodEntityProcessor EntityProcessor { get; private set; }

        //public ISet<E> NodesProcessing = new HashSet<E>();
        //public ISet<CallConext<M,E>> NodesProcessing = new HashSet<CallConext<M,E>>();

        /// <summary>
        /// A method entity is built using the methods interface (params, return) and the propagation graph that is
        /// initially populated with the variables, parameters and calls of the method
        /// </summary>
        /// <param name="methodDescriptor"></param>
        /// <param name="mid"></param>
        /// <param name="propGraph"></param>
        /// <param name="instantiatedTypes"></param>
        public MethodEntity(MethodDescriptor methodDescriptor,
                            MethodInterfaceData mid,
                            PropagationGraph propGraph,
                            IEntityDescriptor descriptor,
                            IEnumerable <TypeDescriptor> instantiatedTypes,
                            bool canBeAnalyzed = true)
        {
            this.MethodDescriptor    = methodDescriptor;
            this.EntityDescriptor    = descriptor; // EntityFactory.Create(methodDescriptor);
            this.MethodInterfaceData = mid;

            this.propGraph         = propGraph;
            this.CanBeAnalized     = canBeAnalyzed;
            this.InstantiatedTypes = new HashSet <TypeDescriptor>(instantiatedTypes);
            this.anonymousMethods  = new Dictionary <AnonymousMethodDescriptor, MethodEntity>();
        }
        //public void RegisterVirtualDelegateCall(MethodDescriptor callee, VariableNode receiver,
        //                                    IList<AnalysisNode> arguments,
        //                                    VariableNode lhs, DelegateVariableNode delegateVariableNode)
        //{
        //    Contract.Requires(receiver != null);
        //    Contract.Requires(arguments != null);
        //    Contract.Requires(lhs != null);
        //    Contract.Requires(callee != null);
        //    Contract.Requires(delegateVariableNode != null);

        //    var callExp = new DelegateCallInfo(this.Method, delegateVariableNode, receiver, arguments, lhs);
        //    this.PropagationGraph.AddEdge(receiver, delegateVariableNode);

        //    RegisterInvocation(arguments, delegateVariableNode, callExp);
        //}


        private void RegisterInvocation(IList <PropGraphNodeDescriptor> arguments,
                                        AnalysisCallNode invocationNode,
                                        CallInfo callExp)
        {
            Contract.Requires(callExp != null);
            Contract.Requires(arguments != null);
            Contract.Requires(invocationNode != null);

            this.PropagationGraph.AddCall(callExp, invocationNode);
            this.PropagationGraph.AddToWorkList(invocationNode);

            foreach (var a in arguments)
            {
                if (a != null)
                {
                    PropagationGraph.AddEdge(a, invocationNode);
                }
            }
        }
        public void RegisterConstructorCall(MethodDescriptor callee, IList <PropGraphNodeDescriptor> arguments,
                                            VariableNode lhs, AnalysisCallNode callNode)
        {
            Contract.Requires(callee != null);
            Contract.Requires(callNode != null);
            Contract.Requires(arguments != null);
            //var argumentValues = arguments.Select(a => a!=null?worker.GetTypes(a):new HashSet<Type>());

            var callExp = new MethodCallInfo(this.Method, callNode, callee, lhs, arguments, lhs, true);

            PropagationGraph.AddCall(callExp, callNode);
            PropagationGraph.AddToWorkList(callNode);

            foreach (var argument in arguments)
            {
                if (argument != null)
                {
                    PropagationGraph.AddEdge(argument, callNode);
                }
            }
        }
 public void RegisterLocalVariable(PropGraphNodeDescriptor v)
 {
     PropagationGraph.Add(v);
 }
        /// <summary>
        ///  In the incremental analysis we want to use this commands over an existing propagation graph
        /// </summary>
        /// <param name="propagationGraph"></param>
        public StatementProcessor(MethodDescriptor method, VariableNode rv,
            VariableNode thisRef, IList<PropGraphNodeDescriptor> parameters,
            PropagationGraph propagationGraph)
        {
            this.PropagationGraph = propagationGraph;
            this.ReturnVariable = rv;
            this.Method = method;
            this.ParameterNodes = parameters;
            this.ThisRef = thisRef;

            this.InstantiatedTypes = new HashSet<TypeDescriptor>();
            this.RemovedTypes = new HashSet<TypeDescriptor>();
        }
 //internal void RegisterDelegateAssignment(DelegateVariableNode lhs, MethodDescriptor m)
 internal void RegisterDelegateAssignment(VariableNode lhs, MethodDescriptor m)
 {
     PropagationGraph.AddDelegate(lhs, m);
     PropagationGraph.AddToWorkList(lhs);
 }
        public void RegisterCallLHS(AnalysisCallNode callNode, VariableNode lhs)
        {
            var callExp = PropagationGraph.GetInvocationInfo(callNode);

            callExp.LHS = lhs;
        }
 public void RegisterRet(PropGraphNodeDescriptor rn)
 {
     PropagationGraph.AddEdge(rn, this.ReturnVariable);
 }