示例#1
0
文件: AST.cs 项目: chenzuo/blue
    // Before we can process the classes, we need to add all the namespaces
    public void ResolveNamespace(
        string stParentNamespace, 
        ISemanticResolver s,
        Scope scopeParent)
    {
        Debug.Assert(m_symbol == null);
        
        // We can have one namespaces spread across multiple blocks (NamespaceDecl).
        // All blocks share the same scope (something defined in any block is visible
        // to all blocks), but each block can have its own lexical parent & set
        // of using clause. 
#if true
        m_symbol = (UserNamespaceEntry) scopeParent.LookupSymbolInThisScopeOnly(Name);
        if (m_symbol == null)
        {
            // Create new namespace
            string stFullName;
            if (stParentNamespace == "")
                stFullName = this.Name;
            else 
                stFullName = stParentNamespace + "." + this.Name;

            m_symbol = new UserNamespaceEntry(this, stFullName);
            scopeParent.AddSymbol(m_symbol);                        
        }
        
        // The symbol has the scope with all the data. But each namespace decl creates
        // a proxy scope that links to the symbol's data (Because all blocks share that)
        // but has a tie to its own set of using clauses & lexical parent.
        m_context = m_symbol.ChildScope.CreateSharedScope(this, scopeParent);
        
        foreach(NamespaceDecl n in NestedNamespaces)
            n.ResolveNamespace(m_symbol.FullName, s, m_context);
#else        
        
        // Since we can have multiple disjoint namespace decls refer
        // to the same namespace, we have to check and see if this
        // symbol is already created.        
        m_symbol = (UserNamespaceEntry) s.GetCurrentScope().LookupSymbolInThisScopeOnly(Name);
        if (m_symbol == null) 
        {
            string stFullName;
            if (stParentNamespace == "")
                stFullName = this.Name;
            else 
                stFullName = stParentNamespace + "." + this.Name;

            m_symbol = new UserNamespaceEntry(this, stFullName);        
            s.GetCurrentScope().AddSymbol(m_symbol);
        }
        
        
        EnterNamespace(s);
        
        foreach(NamespaceDecl n in NestedNamespaces)
            n.ResolveNamespace(m_symbol.FullName, s, scopeParent);
            
        
        ExitNamespace(s);
#endif        
    }