Beispiel #1
0
        public override AssociativeNode VisitTypedIdentifierNode(TypedIdentifierNode node)
        {
            // If type is primitive type
            if (node.datatype.UID != (int)PrimitiveType.InvalidType &&
                node.datatype.UID < (int)PrimitiveType.MaxPrimitive)
            {
                return(node);
            }

            var identListNode = CoreUtils.CreateNodeFromString(node.TypeAlias);

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

            // Rewrite node with resolved name
            if (identListNode is IdentifierNode)
            {
                identListNode = RewriteIdentifierListNode(identListNode);
            }
            else
            {
                identListNode = identListNode.Accept(this);
            }

            var identListString = identListNode.ToString();
            var type            = new Type
            {
                Name = identListString,
                UID  = classTable.IndexOf(identListString),
                rank = node.datatype.rank
            };

            var typedNode = new TypedIdentifierNode
            {
                Name      = node.Name,
                Value     = node.Name,
                datatype  = type,
                TypeAlias = node.TypeAlias
            };

            NodeUtils.CopyNodeLocation(typedNode, node);
            return(typedNode);
        }
Beispiel #2
0
        private void DfsTraverse(ref AssociativeNode astNode, ICollection <AssociativeNode> classIdentifiers,
                                 Queue <string> resolvedNames)
        {
            if (astNode is BinaryExpressionNode)
            {
                var             bnode     = astNode as BinaryExpressionNode;
                AssociativeNode leftNode  = bnode.LeftNode;
                AssociativeNode rightNode = bnode.RightNode;
                DfsTraverse(ref leftNode, classIdentifiers, resolvedNames);
                DfsTraverse(ref rightNode, classIdentifiers, resolvedNames);

                bnode.LeftNode  = leftNode;
                bnode.RightNode = rightNode;
            }
            else if (astNode is FunctionCallNode)
            {
                var fCall = astNode as FunctionCallNode;
                for (int n = 0; n < fCall.FormalArguments.Count; ++n)
                {
                    AssociativeNode argNode = fCall.FormalArguments[n];
                    DfsTraverse(ref argNode, classIdentifiers, resolvedNames);
                    fCall.FormalArguments[n] = argNode;
                }
            }
            else if (astNode is ExprListNode)
            {
                var exprList = astNode as ExprListNode;
                for (int n = 0; n < exprList.list.Count; ++n)
                {
                    AssociativeNode exprNode = exprList.list[n];
                    DfsTraverse(ref exprNode, classIdentifiers, resolvedNames);
                    exprList.list[n] = exprNode;
                }
            }
            else if (astNode is InlineConditionalNode)
            {
                var             inlineNode = astNode as InlineConditionalNode;
                AssociativeNode condition  = inlineNode.ConditionExpression;
                AssociativeNode trueBody   = inlineNode.TrueExpression;
                AssociativeNode falseBody  = inlineNode.FalseExpression;

                DfsTraverse(ref condition, classIdentifiers, resolvedNames);
                DfsTraverse(ref trueBody, classIdentifiers, resolvedNames);
                DfsTraverse(ref falseBody, classIdentifiers, resolvedNames);

                inlineNode.ConditionExpression = condition;
                inlineNode.FalseExpression     = falseBody;
                inlineNode.TrueExpression      = trueBody;
            }
            else if (astNode is TypedIdentifierNode)
            {
                var typedNode = astNode as TypedIdentifierNode;

                // If type is primitive type
                if (typedNode.datatype.UID != (int)PrimitiveType.kInvalidType &&
                    typedNode.datatype.UID < (int)PrimitiveType.kMaxPrimitives)
                {
                    return;
                }

                var identListNode = CoreUtils.CreateNodeFromString(typedNode.TypeAlias);

                // Rewrite node with resolved name
                if (resolvedNames.Any())
                {
                    if (identListNode is IdentifierNode)
                    {
                        identListNode = RewriteIdentifierListNode(identListNode, resolvedNames);
                    }
                    else
                    {
                        DfsTraverse(ref identListNode, classIdentifiers, resolvedNames);
                    }

                    var    identListString = identListNode.ToString();
                    int    indx            = identListString.LastIndexOf('.');
                    string name            = indx >= 0 ? identListString.Remove(indx) : identListString;

                    var type = new Type
                    {
                        Name = name,
                        UID  = classTable.IndexOf(name),
                        rank = typedNode.datatype.rank
                    };

                    typedNode = new TypedIdentifierNode
                    {
                        Name     = astNode.Name,
                        Value    = astNode.Name,
                        datatype = type
                    };

                    NodeUtils.CopyNodeLocation(typedNode, astNode);
                    astNode = typedNode;
                }
                else if (identListNode is IdentifierNode)
                {
                    classIdentifiers.Add(identListNode);
                }
                else
                {
                    DfsTraverse(ref identListNode, classIdentifiers, resolvedNames);
                }
            }
            else if (astNode is IdentifierListNode)
            {
                var identListNode = astNode as IdentifierListNode;
                var rightNode     = identListNode.RightNode;

                if (rightNode is FunctionCallNode)
                {
                    DfsTraverse(ref rightNode, classIdentifiers, resolvedNames);
                }
                if (resolvedNames.Any())
                {
                    astNode = RewriteIdentifierListNode(identListNode, resolvedNames);
                }
                else
                {
                    classIdentifiers.Add(identListNode);
                }
            }
        }