示例#1
0
        internal bool TryResolveExtendedName(ImmutableContextBase context, FullSymbol enclosingName, FullSymbol requestedName, out ModuleBinding result)
        {
            // Semantically nested namespaces forms hierarchical structure, when nested namespace is stored in the outer namespace.
            // For performance reasons, file module stores all names in one big map with combined keys.
            // This means that when looking for A.B we should look at the current scope for A, then need to combine A and B
            // and look for A.B in the file module.
            // This means that extended (or partial) names are only allowed if the enclosing name is valid.
            // In this case we will combine requested name with the enclosing one and look in the current file module.
            result = null;

            if (!enclosingName.IsValid)
            {
                return(false);
            }

            if (m_partialSymbolsCache.Value.TryGetValue(requestedName, out result))
            {
                return(true);
            }

            var extendedFullName = enclosingName.Combine(context.FrontEndContext.SymbolTable, requestedName);

            // Now trying to resolve extended name in the current file.
            result = GetNamespaceBinding(context, extendedFullName, recurs: false);

            // If resolution was successful, saving it in the cache.
            if (result != null)
            {
                m_partialSymbolsCache.Value.GetOrAdd(requestedName, result);
                return(true);
            }

            return(false);
        }
示例#2
0
        public void Combine()
        {
            var        idt = new SymbolTable();
            FullSymbol a1  = FullSymbol.Create(idt, @"C");
            SymbolAtom p1  = SymbolAtom.Create(idt.StringTable, "A");
            FullSymbol a2  = a1.Combine(idt, p1);

            XAssert.AreEqual(@"C.A", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            a2 = a1.Combine(idt, p1);
            XAssert.AreEqual(@"C.X.A", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            SymbolAtom p2 = SymbolAtom.Create(idt.StringTable, "B");

            a2 = a1.Combine(idt, p1, p2);
            XAssert.AreEqual(@"C.X.A.B", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            p2 = SymbolAtom.Create(idt.StringTable, "B");
            SymbolAtom p3 = SymbolAtom.Create(idt.StringTable, "C");

            a2 = a1.Combine(idt, p1, p2, p3);
            XAssert.AreEqual(@"C.X.A.B.C", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C");
            PartialSymbol rp = PartialSymbol.Create(idt.StringTable, @"A.B");

            a2 = a1.Combine(idt, rp);
            XAssert.AreEqual(@"C.A.B", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            rp = PartialSymbol.Create(idt.StringTable, @"A.B");
            a2 = a1.Combine(idt, rp);
            XAssert.AreEqual(@"C.X.A.B", a2.ToString(idt));
        }