Example #1
0
        private bool TryShortenClassName(IdentifierListNode node, out AssociativeNode shortNameNode)
        {
            shortNameNode = null;

            string qualifiedName = CoreUtils.GetIdentifierExceptMethodName(node);

            // if it is a global method with no class
            if (string.IsNullOrEmpty(qualifiedName))
            {
                return(false);
            }

            // Make sure qualifiedName is not a property
            var matchingClasses = classTable.GetAllMatchingClasses(qualifiedName);

            if (matchingClasses.Length == 0)
            {
                return(false);
            }

            string className = qualifiedName.Split('.').Last();

            var symbol = new ProtoCore.Namespace.Symbol(qualifiedName);

            if (!symbol.Matches(node.ToString()))
            {
                return(false);
            }

            shortNameNode = CreateNodeFromShortName(className, qualifiedName);
            return(shortNameNode != null);
        }
Example #2
0
        private IdentifierListNode GenerateNewIdentifierList(string newNodeName, FunctionCallNode funcCall)
        {
            var newNode = CoreUtils.CreateNodeFromString(newNodeName);

            if (newNode == null)
            {
                return(null);
            }

            // append argument list from original method to newNode
            var newMethodName = ((IdentifierListNode)newNode).RightNode.Name;

            var newMethod = new FunctionCallNode
            {
                Function        = AstFactory.BuildIdentifier(newMethodName),
                FormalArguments = funcCall.FormalArguments
            };
            var newIdentList = new IdentifierListNode
            {
                LeftNode  = ((IdentifierListNode)newNode).LeftNode,
                RightNode = newMethod,
                Optr      = Operator.dot
            };

            return(newIdentList);
        }
Example #3
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            // If node is a reserved method call, skip rewriting it.
            if (ReservedMethods.Any(reservedMethod => node.ToString().Contains(reservedMethod)))
            {
                return(node);
            }

            // First pass attempt to resolve the node before traversing it deeper
            AssociativeNode newIdentifierListNode = null;

            if (IsMatchingResolvedName(node, out newIdentifierListNode))
            {
                return(newIdentifierListNode);
            }

            var rightNode = node.RightNode;
            var leftNode  = node.LeftNode;

            rightNode = rightNode.Accept(this);
            leftNode  = leftNode.Accept(this);

            node = new IdentifierListNode
            {
                LeftNode  = leftNode,
                RightNode = rightNode,
                Optr      = Operator.dot
            };

            return(RewriteIdentifierListNode(node));
        }
Example #4
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            if (node == null)
            {
                return(null);
            }

            var    leftNodeName  = node.LeftNode.ToString();
            var    rightNode     = node.RightNode as FunctionCallNode;
            string rightNodeName = string.Empty;

            if (rightNode != null)
            {
                rightNodeName = rightNode.Function.Name;
            }
            var    oldNodeName = leftNodeName + '.' + rightNodeName;
            string newNodeName;

            if (!priorNames.TryGetValue(oldNodeName, out newNodeName))
            {
                return(node);
            }

            OnLogWarning(oldNodeName, newNodeName);

            return(GenerateNewIdentifierList(newNodeName, rightNode));
        }
Example #5
0
        public override bool VisitIdentifierListNode(IdentifierListNode node)
        {
            if (node == null)
            {
                return(false);
            }

            if (node.LeftNode is IdentifierNode || node.LeftNode is IdentifierListNode)
            {
                if (node.RightNode is FunctionCallNode || node.RightNode is IdentifierNode)
                {
                    var lhs = node.LeftNode.ToString();
                    if (core.ClassTable.IndexOf(lhs) < 0)
                    {
                        node.LeftNode.Accept(this);
                    }

                    if (!(node.RightNode is IdentifierNode))
                    {
                        node.RightNode.Accept(this);
                    }

                    return(true);
                }
            }
            return(base.VisitIdentifierListNode(node));
        }
Example #6
0
        private static AssociativeNode RewriteIdentifierListNode(AssociativeNode identifier, Queue <string> resolvedNames)
        {
            var resolvedName = resolvedNames.Dequeue();

            // if resolved name is null or empty, return the identifier list node as is
            if (string.IsNullOrEmpty(resolvedName))
            {
                return(identifier);
            }

            var newIdentList = CoreUtils.CreateNodeFromString(resolvedName);

            Validity.Assert(newIdentList is IdentifierListNode);

            var             identListNode = identifier as IdentifierListNode;
            AssociativeNode rightNode     = identListNode != null ? identListNode.RightNode : identifier;

            // The last ident list for the functioncall or identifier rhs
            var lastIdentList = new IdentifierListNode
            {
                LeftNode  = newIdentList,
                RightNode = rightNode,
                Optr      = Operator.dot
            };

            return(lastIdentList);
        }
Example #7
0
        public static AssociativeNode CreateNodeByCombiningIdentifiers(IList <AssociativeNode> nodeList)
        {
            int count = nodeList.Count;

            if (count == 0)
            {
                return(null);
            }

            if (count == 1)
            {
                return(nodeList[0]);
            }

            var newIdentList = new IdentifierListNode
            {
                LeftNode  = nodeList[0],
                RightNode = nodeList[1],
                Optr      = Operator.dot
            };

            for (var n = 2; n < count; ++n)
            {
                var subIdentList = new IdentifierListNode
                {
                    LeftNode  = newIdentList,
                    RightNode = nodeList[n],
                    Optr      = Operator.dot
                };
                newIdentList = subIdentList;
            }

            return(newIdentList);
        }
Example #8
0
        /// <summary>
        /// Given a name or string of names, this creates an IdentifierNode or IdentifierListNode
        /// e.g. Creates an IdentifierNode from A and IdentifierListNode from A.B
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static AssociativeNode CreateNodeFromString(string name)
        {
            string[] strIdentList = name.Split('.');

            if (strIdentList.Length == 1)
            {
                return(new IdentifierNode(strIdentList[0]));
            }

            var newIdentList = new IdentifierListNode
            {
                LeftNode  = new IdentifierNode(strIdentList[0]),
                RightNode = new IdentifierNode(strIdentList[1]),
                Optr      = Operator.dot
            };

            for (var n = 2; n < strIdentList.Length; ++n)
            {
                var subIdentList = new IdentifierListNode
                {
                    LeftNode  = newIdentList,
                    RightNode = new IdentifierNode(strIdentList[n]),
                    Optr      = Operator.dot
                };
                newIdentList = subIdentList;
            }

            return(newIdentList);
        }
Example #9
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            node.LeftNode = node.LeftNode.Accept(this);

            var rightNode = node.RightNode;

            while (rightNode != null)
            {
                if (rightNode is FunctionCallNode)
                {
                    var funcCall = rightNode as FunctionCallNode;
                    funcCall.FormalArguments = VisitNodeList(funcCall.FormalArguments);
                    if (funcCall.ArrayDimensions != null)
                    {
                        funcCall.ArrayDimensions = funcCall.ArrayDimensions.Accept(this) as ArrayNode;
                    }
                    break;
                }
                else if (rightNode is IdentifierListNode)
                {
                    rightNode = (rightNode as IdentifierListNode).RightNode;
                }
                else
                {
                    break;
                }
            }

            return(node);
        }
Example #10
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            if (node == null)
            {
                return(null);
            }

            // First pass attempt to resolve the node class name
            // and shorten it before traversing it deeper
            AssociativeNode shortNameNode;

            if (TryShortenClassName(node, out shortNameNode))
            {
                return(shortNameNode);
            }

            var rightNode = node.RightNode;
            var leftNode  = node.LeftNode;

            rightNode = rightNode.Accept(this);
            var newLeftNode = leftNode.Accept(this);

            node = new IdentifierListNode
            {
                LeftNode  = newLeftNode,
                RightNode = rightNode,
                Optr      = Operator.dot
            };
            return(leftNode != newLeftNode ? node : RewriteNodeWithShortName(node));
        }
Example #11
0
            public override bool VisitIdentifierListNode(IdentifierListNode node)
            {
                if (forDefinition)
                {
                    return(false);
                }

                return(node.LeftNode.Accept(this) || node.RightNode.Accept(this));
            }
Example #12
0
        private bool Test_GetIdentifierStringUntilFirstParenthesis(string input, string expected)
        {
            List <AssociativeNode> astList   = ProtoCore.Utils.CoreUtils.BuildASTList(core, input);
            IdentifierListNode     identList = (astList[0] as BinaryExpressionNode).RightNode as IdentifierListNode;

            // Verify expected string
            string identListString = ProtoCore.Utils.CoreUtils.GetIdentifierStringUntilFirstParenthesis(identList);

            return(identListString.Equals(expected));
        }
Example #13
0
        /// <summary>
        /// Retrieves the string format of the identifier list from left to right, leaving out any symbols after the last identifier.
        /// Given: A.B()
        ///     Return: "A.B"
        /// Given: A.B.C()[0]
        ///     Return: "A.B.C"
        /// Given: A.B().C
        ///     Return: "A.B"
        /// Given: A.B[0].C
        ///     Return: "A.B[0].C"
        /// </summary>
        /// <param name="identList"></param>
        /// <returns></returns>
        public static string GetIdentifierStringUntilFirstParenthesis(IdentifierListNode identList)
        {
            Validity.Assert(null != identList);
            string identListString = identList.ToString();
            int    removeIndex     = identListString.IndexOf('(');

            if (removeIndex > 0)
            {
                identListString = identListString.Remove(removeIndex);
            }
            return(identListString);
        }
Example #14
0
        private AssociativeNode RewriteIdentifierListNode(AssociativeNode identifierList)
        {
            var resolvedName = ResolveClassName(identifierList);

            if (string.IsNullOrEmpty(resolvedName))
            {
                return(identifierList);
            }

            var identListNode = identifierList as IdentifierListNode;

            var newIdentList = CoreUtils.CreateNodeFromString(resolvedName);

            if (newIdentList == null)
            {
                return(null);
            }

            // If the original input node matches with the resolved name, simply return
            // the identifier list constructed from the resolved name
            var symbol = new Symbol(resolvedName);

            if (symbol.Matches(identifierList.ToString()))
            {
                return(newIdentList);
            }

            // Remove partialName from identListNode and replace with newIdentList
            AssociativeNode leftNode  = identListNode != null ? identListNode.LeftNode : identifierList;
            AssociativeNode rightNode = identListNode != null ? identListNode.RightNode : identifierList;

            var intermediateNodes = new List <AssociativeNode>();

            while (leftNode is IdentifierListNode && !symbol.Matches(leftNode.ToString()))
            {
                intermediateNodes.Insert(0, ((IdentifierListNode)leftNode).RightNode);
                leftNode = ((IdentifierListNode)leftNode).LeftNode;
            }
            intermediateNodes.Insert(0, newIdentList);

            var lNode = CoreUtils.CreateNodeByCombiningIdentifiers(intermediateNodes);

            // The last ident list for the functioncall or identifier rhs
            var lastIdentList = new IdentifierListNode
            {
                LeftNode  = lNode,
                RightNode = rightNode,
                Optr      = Operator.dot
            };

            return(lastIdentList);
        }
Example #15
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!InPorts[0].IsConnected && !InPorts[1].IsConnected && !InPorts[2].IsConnected)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            AssociativeNode rhs;

            if (IsPartiallyApplied)
            {
                var connectedInputs = Enumerable.Range(0, InPorts.Count)
                                      .Where(index => InPorts[index].IsConnected)
                                      .Select(x => new IntNode(x) as AssociativeNode)
                                      .ToList();
                var arguments = AstFactory.BuildExprList(inputAstNodes);


                var functionNode = new IdentifierListNode
                {
                    LeftNode  = new IdentifierNode("DSCore.Math"),
                    RightNode = new IdentifierNode("Equals")
                };
                IntNode paramNumNode = new IntNode(3);
                var     positionNode = AstFactory.BuildExprList(connectedInputs);

                var inputParams = new List <AssociativeNode>
                {
                    functionNode,
                    paramNumNode,
                    positionNode,
                    arguments,
                    AstFactory.BuildBooleanNode(true)
                };

                rhs = AstFactory.BuildFunctionCall("__CreateFunctionObject", inputParams);
            }
            else
            {
                UseLevelAndReplicationGuide(inputAstNodes);

                rhs = AstFactory.BuildFunctionCall(new Func <double, double, double, bool>(DSCore.Math.Equals),
                                                   inputAstNodes);
            }

            return(new[]
            {
                AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), rhs)
            });
        }
Example #16
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            var rightNode = node.RightNode;
            var leftNode  = node.LeftNode;

            rightNode = rightNode.Accept(this);
            leftNode  = leftNode.Accept(this);

            node = new IdentifierListNode
            {
                LeftNode  = leftNode,
                RightNode = rightNode,
                Optr      = Operator.dot
            };
            return(RewriteIdentifierListNode(node));
        }
Example #17
0
            public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
            {
                if ((node.LeftNode is IdentifierNode || node.LeftNode is IdentifierListNode) &&
                    node.RightNode is FunctionCallNode)
                {
                    var fullName = node.LeftNode.ToString();
                    if (core.ClassTable.IndexOf(fullName) >= 0 && fullName.Contains("."))
                    {
                        node.LeftNode = AstFactory.BuildIdentifier(fullName.Split('.').Last());
                    }

                    node.RightNode.Accept(this);
                }

                return(node);
            }
Example #18
0
 void identifierList(out Node node)
 {
     node = null;
     NameReference(out node);
     while (la.kind == 37)
     {
         Get();
         Node rnode = null;
         NameReference(out rnode);
         IdentifierListNode bnode = new IdentifierListNode();
         bnode.LeftNode  = node;
         bnode.Optr      = Operator.dot;
         bnode.RightNode = rnode;
         node            = bnode;
     }
 }
Example #19
0
        private bool IsMatchingResolvedName(IdentifierListNode identifierList, out AssociativeNode newIdentList)
        {
            newIdentList = null;
            var resolvedName = ResolveClassName(identifierList);

            if (string.IsNullOrEmpty(resolvedName))
            {
                return(false);
            }

            newIdentList = CoreUtils.CreateNodeFromString(resolvedName);

            var symbol = new Symbol(resolvedName);

            return(symbol.Matches(identifierList.ToString()));
        }
Example #20
0
 public override void VisitIdentifierListNode(IdentifierListNode node)
 {
     if ((node.LeftNode is IdentifierNode ||
          node.RightNode is IdentifierListNode) &&
         node.RightNode is FunctionCallNode)
     {
         var lhs = node.LeftNode.ToString();
         if (core.ClassTable.IndexOf(lhs) < 0)
         {
             node.LeftNode.Accept(this);
         }
         node.RightNode.Accept(this);
         return;
     }
     base.VisitIdentifierListNode(node);
 }
Example #21
0
 private string GetTopLevelVariable(AssociativeNode astNode)
 {
     if (astNode is ProtoCore.AST.AssociativeAST.IdentifierNode)
     {
         ProtoCore.AST.AssociativeAST.IdentifierNode identifierNode = (ProtoCore.AST.AssociativeAST.IdentifierNode)astNode;
         return(((ProtoCore.AST.AssociativeAST.IdentifierNode)astNode).Value);
     }
     else if (astNode is IdentifierListNode)
     {
         IdentifierListNode identListNode = (IdentifierListNode)astNode;
         return(GetTopLevelVariable(identListNode.LeftNode));
     }
     else
     {
         throw new InvalidOperationException("Input is not IdentifierNode or IdentifierListNode");
     }
 }
Example #22
0
        public void VisitTypedIdentifierNodeTest()
        {
            //Arrange
            var engine = CurrentDynamoModel.EngineController;
            ShortestQualifiedNameReplacer replacer = new ShortestQualifiedNameReplacer(engine.LibraryServices.LibraryManagementCore.ClassTable, null);
            TypedIdentifierNode           node     = null;
            IdentifierListNode            node2    = null;

            //Act
            //We need to pass null to both functions in order to reach a specific piece of code wihout coverage
            var response  = replacer.VisitTypedIdentifierNode(node);
            var response2 = replacer.VisitIdentifierListNode(node2);

            //Assert
            //Checking that both functions returned null
            Assert.IsNull(response);
            Assert.IsNull(response2);
        }
Example #23
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            var newLeftNode = node.LeftNode.Accept(this);

            if (newLeftNode != node.LeftNode)
            {
                node.LeftNode = newLeftNode;
            }

            var newRightNode = node.RightNode.Accept(this);

            if (newRightNode != node.RightNode)
            {
                node.RightNode = newRightNode;
            }

            return(node);
        }
Example #24
0
            public override bool VisitIdentifierListNode(IdentifierListNode node)
            {
                if (node.LeftNode is IdentifierNode || node.LeftNode is IdentifierListNode)
                {
                    if (node.RightNode is FunctionCallNode || node.RightNode is IdentifierNode)
                    {
                        node.LeftNode.Accept(this);

                        if (!(node.RightNode is IdentifierNode))
                        {
                            node.RightNode.Accept(this);
                        }

                        return(true);
                    }
                }

                return(base.VisitIdentifierListNode(node));
            }
Example #25
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (IsPartiallyApplied)
            {
                var connectedInput = Enumerable.Range(0, InPorts.Count)
                                     .Where(index => InPorts[index].IsConnected)
                                     .Select(x => new IntNode(x) as AssociativeNode)
                                     .ToList();

                var paramNumNode = new IntNode(InPorts.Count);
                var positionNode = AstFactory.BuildExprList(connectedInput);
                var arguments    = AstFactory.BuildExprList(inputAstNodes);
                var functionNode = new IdentifierListNode
                {
                    LeftNode  = new IdentifierNode("DSCore.List"),
                    RightNode = new IdentifierNode("__Create")
                };
                var inputParams = new List <AssociativeNode>
                {
                    functionNode,
                    paramNumNode,
                    positionNode,
                    arguments,
                    AstFactory.BuildBooleanNode(false)
                };

                return(new[]
                {
                    AstFactory.BuildAssignment(
                        GetAstIdentifierForOutputIndex(0),
                        AstFactory.BuildFunctionCall("__CreateFunctionObject", inputParams))
                });
            }

            return(new[]
            {
                AstFactory.BuildAssignment(
                    GetAstIdentifierForOutputIndex(0),
                    AstFactory.BuildExprList(inputAstNodes))
            });
        }
Example #26
0
        private IdentifierListNode RewriteNodeWithShortName(IdentifierListNode node)
        {
            // Get class name from AST
            string qualifiedName = CoreUtils.GetIdentifierExceptMethodName(node);

            // if it is a global method
            if (string.IsNullOrEmpty(qualifiedName))
            {
                return(node);
            }

            // Make sure qualifiedName is not a property
            var lNode           = node.LeftNode;
            var matchingClasses = classTable.GetAllMatchingClasses(qualifiedName);

            while (matchingClasses.Length == 0 && lNode is IdentifierListNode)
            {
                qualifiedName   = lNode.ToString();
                matchingClasses = classTable.GetAllMatchingClasses(qualifiedName);
                lNode           = ((IdentifierListNode)lNode).LeftNode;
            }
            qualifiedName = lNode.ToString();
            string className = qualifiedName.Split('.').Last();

            var newIdentList = CreateNodeFromShortName(className, qualifiedName);

            if (newIdentList == null)
            {
                return(node);
            }

            // Replace class name in input node with short name (newIdentList)
            node = new IdentifierListNode
            {
                LeftNode  = newIdentList,
                RightNode = node.RightNode,
                Optr      = Operator.dot
            };
            return(node);
        }
        public override AssociativeNode VisitIdentifierNode(IdentifierNode node)
        {
            var name = node.ToString();

            string[] strIdentList = name.Split('.');

            // return IdentifierNode if identifier string is not separated by '.'
            if (strIdentList.Length == 1)
            {
                return(new IdentifierNode(strIdentList[0]));
            }

            // create IdentifierListNode from string such that
            // RightNode is IdentifierNode representing classname
            // and LeftNode is IdentifierNode representing one or more namespaces.
            var           rightNode = new IdentifierNode(strIdentList.Last());
            StringBuilder bld       = new StringBuilder();

            for (int i = 0; i < strIdentList.Length - 1; i++)
            {
                if (!string.IsNullOrEmpty(bld.ToString()))
                {
                    bld.Append(".");
                }
                bld.Append(strIdentList[i]);
            }
            var leftNode = new IdentifierNode(bld.ToString());

            var identListNode = new IdentifierListNode
            {
                LeftNode  = leftNode,
                RightNode = rightNode,
                Optr      = Operator.dot
            };

            return(identListNode.Accept(this));
        }
Example #28
0
        public override AssociativeNode VisitIdentifierListNode(IdentifierListNode node)
        {
            // First pass attempt to resolve the node before traversing it deeper
            AssociativeNode newIdentifierListNode = null;

            if (IsMatchingResolvedName(node, out newIdentifierListNode))
            {
                return(newIdentifierListNode);
            }

            var rightNode = node.RightNode;
            var leftNode  = node.LeftNode;

            rightNode = rightNode.Accept(this);
            leftNode  = leftNode.Accept(this);

            node = new IdentifierListNode
            {
                LeftNode  = leftNode,
                RightNode = rightNode,
                Optr      = Operator.dot
            };
            return(RewriteIdentifierListNode(node));
        }
Example #29
0
        /// <summary>
        /// Retrieves the string format of the identifier list from left to right, leaving out any symbols after the last identifier.
        /// Given: A.B()
        ///     Return: "A"
        /// Given: A.B.C()[0]
        ///     Return: "A.B"
        /// Given: A.B().C
        ///     Return: "A"
        /// Given: A.B[0].C
        ///     Return: "A.B[0].C"
        /// Given: A().B (global function)
        ///     Return: empty string
        /// Given: A.B[0].C()
        ///     Return: "A.B[0]"
        /// </summary>
        /// <param name="identList"></param>
        /// <returns></returns>
        public static string GetIdentifierExceptMethodName(IdentifierListNode identList)
        {
            Validity.Assert(null != identList);

            var leftNode  = identList.LeftNode;
            var rightNode = identList.RightNode;

            var intermediateNodes = new List <AssociativeNode>();

            if (!(rightNode is FunctionCallNode))
            {
                intermediateNodes.Insert(0, rightNode);
            }

            while (leftNode is IdentifierListNode)
            {
                rightNode = ((IdentifierListNode)leftNode).RightNode;
                if (rightNode is FunctionCallNode)
                {
                    intermediateNodes.Clear();
                }
                else
                {
                    intermediateNodes.Insert(0, rightNode);
                }
                leftNode = ((IdentifierListNode)leftNode).LeftNode;
            }
            if (leftNode is FunctionCallNode)
            {
                intermediateNodes.Clear();
                return("");
            }
            intermediateNodes.Insert(0, leftNode);

            return(CreateNodeByCombiningIdentifiers(intermediateNodes).ToString());
        }
Example #30
0
 public WithoutParenthesisLambdaParametersNode(IdentifierListNode p0)
 {
     m_p0 = p0;
 }
Example #31
0
 public WithParenthesisLambdaParametersNode(OpeningParToken p0, IdentifierListNode p1, ClosingParToken p2)
 {
     m_p0 = p0;
     m_p1 = p1;
     m_p2 = p2;
 }
Example #32
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.UseLevelAndReplicationGuide(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.UseLevelAndReplicationGuide(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.UseLevelAndReplicationGuide(inputAstNodes);
                    rhs = AstFactory.BuildFunctionCall(function, inputAstNodes);
                }
                break;
            }

            return(rhs);
        }
Example #33
0
 public IdentifierListNode(IdentifierListNode rhs) : base(rhs)
 {
     Optr = rhs.Optr;
     LeftNode = ProtoCore.Utils.NodeUtils.Clone(rhs.LeftNode);
     RightNode = ProtoCore.Utils.NodeUtils.Clone(rhs.RightNode);
 }