Exemplo n.º 1
0
        protected override AssociativeNode GetFunctionApplication(NodeModel model, List <AssociativeNode> inputAstNodes)
        {
            if (!model.IsPartiallyApplied)
            {
                model.AppendReplicationGuides(inputAstNodes);
                return(AstFactory.BuildFunctionCall(Definition.FunctionName, inputAstNodes));
            }

            var count = Definition.DisplayParameters.Count();

            return(AstFactory.BuildFunctionObject(
                       Definition.FunctionName,
                       count,
                       Enumerable.Range(0, count).Where(model.HasInput),
                       inputAstNodes));
        }
Exemplo n.º 2
0
        protected override AssociativeNode GetFunctionApplication(NodeModel model, List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode rhs;

            string function = Definition.FunctionName;

            switch (Definition.Type)
            {
            case FunctionType.Constructor:
            case FunctionType.StaticMethod:
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.FunctionName)
                    };
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    model.AppendReplicationGuides(inputAstNodes);
                    rhs = AstFactory.BuildFunctionCall(
                        Definition.ClassName,
                        Definition.FunctionName,
                        inputAstNodes);
                }
                break;

            case FunctionType.StaticProperty:

                var staticProp = new IdentifierListNode
                {
                    LeftNode  = new IdentifierNode(Definition.ClassName),
                    RightNode = new IdentifierNode(Definition.FunctionName)
                };
                rhs = staticProp;
                break;

            case FunctionType.InstanceProperty:

                // Only handle getter here. Setter could be handled in CBN.
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.FunctionName)
                    };
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    rhs = new NullNode();
                    if (inputAstNodes != null && inputAstNodes.Count >= 1)
                    {
                        var thisNode = inputAstNodes[0];
                        if (thisNode != null && !(thisNode is NullNode))
                        {
                            var insProp = new IdentifierListNode
                            {
                                LeftNode  = inputAstNodes[0],
                                RightNode = new IdentifierNode(Definition.FunctionName)
                            };
                            rhs = insProp;
                        }
                    }
                }

                break;

            case FunctionType.InstanceMethod:
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierListNode
                    {
                        LeftNode  = new IdentifierNode(Definition.ClassName),
                        RightNode = new IdentifierNode(Definition.FunctionName)
                    };
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    rhs = new NullNode();
                    model.AppendReplicationGuides(inputAstNodes);

                    if (inputAstNodes != null && inputAstNodes.Count >= 1)
                    {
                        var thisNode = inputAstNodes[0];
                        inputAstNodes.RemoveAt(0);     // remove this pointer

                        if (thisNode != null && !(thisNode is NullNode))
                        {
                            var memberFunc = new IdentifierListNode
                            {
                                LeftNode  = thisNode,
                                RightNode =
                                    AstFactory.BuildFunctionCall(function, inputAstNodes)
                            };
                            rhs = memberFunc;
                        }
                    }
                }

                break;

            default:
                if (model.IsPartiallyApplied)
                {
                    var functionNode = new IdentifierNode(function);
                    rhs = CreateFunctionObject(model, functionNode, inputAstNodes);
                }
                else
                {
                    model.AppendReplicationGuides(inputAstNodes);
                    rhs = AstFactory.BuildFunctionCall(function, inputAstNodes);
                }
                break;
            }

            return(rhs);
        }