Beispiel #1
0
        public override Evaluation VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
        {
            //node.ArgumentList?.Accept(this);
            Evaluation     evaluation = node.Initializer?.Accept <Evaluation>(this); //TODO - choose ret
            EvaluationList accept     = node.ArgumentList.Accept <Evaluation>(this) as EvaluationList;


            node.Type?.Accept <Evaluation>(this);

            ITypeSymbol type = node.Type.GetSymbol(_comp) as ITypeSymbol;

            Instance instance = _callStack.Peek().CreateInstance(type, type.ToNodeKind());

            GraphBuilder <Evaluation> .From(_callStack.Peek().Node).Kind(EdgeKind.CreatesObject).To(instance.Node);

            InitializeInstance(instance);

            FunctionalFrame constructor = instance.InstanceHeap.CreateFrame(node.GetReference(), _comp, type.ToNodeKind());

            GraphBuilder <Evaluation> .From(instance.Node).Kind(EdgeKind.InvokesMember).To(constructor.Node);

            SimulateFrame(constructor, EvaluationUtil.From <Instance>(accept).ToArray());

            return(instance);
        }
Beispiel #2
0
        public void SimulateFrame(Frame frame, params Instance[] args)
        {
            if (frame == null)
            {
                throw new ArgumentNullException(nameof(frame));
            }

            //TODO - if a frame has already been simulated, connect the graph instead

            Log.Info("Simulating {0}", frame.ToString());

            FunctionalFrame functionalFrame = frame as FunctionalFrame;

            if (functionalFrame != null)
            {
                //TODO named args, parameterized args
                if (args != null && args.Length != functionalFrame.DeclaredArguments.Length)
                {
                    throw new ArgumentException("Unhandled argument length");
                }

                for (int i = 0; i < functionalFrame.DeclaredArguments.Length; i++)
                {
                    Identity newArgIdent       = functionalFrame.DeclaredArguments[i];
                    Instance incommingInstance = args[i];

                    GraphBuilder <Evaluation> .From(functionalFrame.Node).Kind(EdgeKind.Declares).To(incommingInstance.Node);

                    newArgIdent.IsDisposed = false;
                    incommingInstance.Identities.Push(newArgIdent);

                    functionalFrame.Instances.Add(incommingInstance);
                }
            }

            _callStack.Push(frame);

            foreach (SyntaxReference reference in frame.Symbol.DeclaringSyntaxReferences)
            {
                Visit(reference.GetSyntax());
            }

            if (functionalFrame != null)
            {
                foreach (Identity argument in functionalFrame.DeclaredArguments)
                {
                    argument.IsDisposed = true;
                }
            }

            _callStack.Pop();
        }