Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private AssociativeNode RewriteIdentifierListNode(AssociativeNode identifierList)
        {
            var identListNode = identifierList as IdentifierListNode;

            string partialName = identListNode != null?
                                 CoreUtils.GetIdentifierExceptMethodName(identListNode) : identifierList.Name;

            var resolvedName = elementResolver.LookupResolvedName(partialName);

            if (string.IsNullOrEmpty(resolvedName))
            {
                // If namespace resolution map does not contain entry for partial name,
                // back up on compiler to resolve the namespace from partial name
                var matchingClasses = CoreUtils.GetResolvedClassName(classTable, identifierList);

                if (matchingClasses.Length == 1)
                {
                    resolvedName = matchingClasses[0];
                    var assemblyName = CoreUtils.GetAssemblyFromClassName(classTable, resolvedName);

                    elementResolver.AddToResolutionMap(partialName, resolvedName, assemblyName);
                }
            }
            if (string.IsNullOrEmpty(resolvedName))
            {
                return(identifierList);
            }

            var newIdentList = CoreUtils.CreateNodeFromString(resolvedName);

            Validity.Assert(newIdentList is IdentifierListNode);

            // 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);

            Validity.Assert(lNode is IdentifierListNode);

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

            return(lastIdentList);
        }