Пример #1
0
        internal void LookupResolvedNameAndRewriteAst(ElementResolver elementResolver,
                                                      ref AssociativeNode astNode)
        {
            Debug.Assert(elementResolver != null);

            // Get partial class identifier/identifier lists
            var classIdentifiers = GetClassIdentifiers(astNode);

            var resolvedNames = new Queue <string>();

            foreach (var identifier in classIdentifiers)
            {
                string partialName    = string.Empty;
                var    identifierList = identifier as IdentifierListNode;
                if (identifierList != null)
                {
                    partialName = CoreUtils.GetIdentifierExceptMethodName(identifierList);
                }
                else
                {
                    partialName = identifier.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, CoreUtils.CreateNodeFromString(partialName));

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

                        elementResolver.AddToResolutionMap(partialName, resolvedName, assemblyName);
                    }
                    else
                    {
                        // Class name could not be resolved - Possible namespace conflict
                        // This will be reported subsequently in the pre-compilation stage if there's a conflict
                        // Enter an empty resolved name to the list and continue
                        resolvedNames.Enqueue(string.Empty);
                        continue;
                    }
                }
                resolvedNames.Enqueue(resolvedName);
            }

            if (resolvedNames.Any())
            {
                RewriteAstWithResolvedName(ref astNode, resolvedNames);
            }
        }
Пример #2
0
        private string ResolveClassName(AssociativeNode identifierList)
        {
            var identListNode = identifierList as IdentifierListNode;

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

            if (string.IsNullOrEmpty(partialName))
            {
                return(String.Empty);
            }

            var resolvedName = elementResolver.LookupResolvedName(partialName);

            if (!string.IsNullOrEmpty(resolvedName))
            {
                return(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 classNode         = classTable.ClassNodes.FirstOrDefault(x => x.Name == resolvedName);
                var isHiddenInLibrary = classNode.ClassAttributes?.HiddenInLibrary ?? false;
                // Do not add a hidden class to element resolver.
                if (!isHiddenInLibrary)
                {
                    var assemblyName = CoreUtils.GetAssemblyFromClassName(classTable, resolvedName);
                    elementResolver.AddToResolutionMap(partialName, resolvedName, assemblyName);
                }
            }
            else if (matchingClasses.Length > 1)
            {
                OnLogSymbolConflictWarning(partialName, matchingClasses);
            }
            return(resolvedName);
        }
Пример #3
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);
        }