Пример #1
0
        public void FindAllInAreaList(string name, Scope[] arr, bool StopIfFind, bool NotOnlyInNetScopes, List <SymbolInfo> Result)
        {
            if (arr == null)
            {
                return;
            }

            int add = Result.Count;
            HashSet <Assembly> assm_cache = new HashSet <Assembly>();

            foreach (Scope sc in arr)
            {
                if (sc is DotNETScope)
                {
                    if (sc is PascalABCCompiler.NetHelper.NetScope)
                    {
                        PascalABCCompiler.NetHelper.NetScope netScope = sc as PascalABCCompiler.NetHelper.NetScope;
                        if (PascalABCCompiler.NetHelper.NetHelper.PABCSystemType == null || netScope.Assembly != PascalABCCompiler.NetHelper.NetHelper.PABCSystemType.Assembly)
                        {
                            if (!assm_cache.Contains(netScope.Assembly))
                            {
                                assm_cache.Add(netScope.Assembly);
                            }
                            else if (netScope.used_namespaces.Count == 0)
                            {
                                continue;
                            }
                        }
                    }
                    AddToSymbolInfo(Result, (DotNETScope)sc, name);
                    if (Result.Count > add && StopIfFind)
                    {
                        return;
                    }
                }
                else
                if (NotOnlyInNetScopes && sc != null)
                {
                    var tn = sc.Symbols.Find(name);
                    if (tn != null)
                    {
                        AddToSymbolInfo(tn.InfoList, Result);
                        if (Result.Count > add && StopIfFind)
                        {
                            return;
                        }
                    }
                }
            }
        }
        internal SymbolTable.Scope[] build_referenced_units(unit_node_list referenced_units, bool try_get_system_module)
        {
            List<SymbolTable.Scope> used_units = new List<SymbolTable.Scope>();
            Dictionary<System.Reflection.Assembly, dot_net_unit_node> assembly_references_dict = new Dictionary<System.Reflection.Assembly, dot_net_unit_node>();
            for (int i = 0; i < referenced_units.Count; i++)
            {
                if (referenced_units[i] is dot_net_unit_node)
                    if (!assembly_references_dict.ContainsKey((referenced_units[i] as dot_net_unit_node).dotNetScope._assembly))
                        assembly_references_dict.Add((referenced_units[i] as dot_net_unit_node).dotNetScope._assembly, referenced_units[i] as dot_net_unit_node);
            }
            dot_net_unit_node[] assembly_references = new dot_net_unit_node[assembly_references_dict.Values.Count];
            assembly_references_dict.Values.CopyTo(assembly_references, 0);
            List<NetHelper.NetScope> def_scopes = new List<NetHelper.NetScope>();
            if (SemanticRules.AllowGlobalVisibilityForPABCDll)
            {
                for (int i = 0; i < assembly_references.Length; i++)
                {
                    if (assembly_references[i].dotNetScope.entry_type != null)
                        def_scopes.Add(assembly_references[i].dotNetScope);
                }
            }
            //used_units.Add(_system_unit.scope);
            for (int i = 0; i < referenced_units.Count; i++)
            {
                if (!(referenced_units[i] is dot_net_unit_node))
                {
                    if (referenced_units[i] is namespace_unit_node)
                    {
                        for (int j = 0; j < assembly_references.Length; j++)
                        {
                            using_namespace_list unl = new using_namespace_list();
                            unl.AddElement((referenced_units[i] as namespace_unit_node).namespace_name);
                            NetHelper.NetScope ns = new PascalABCCompiler.NetHelper.NetScope(unl, assembly_references[j].dotNetScope._assembly, SymbolTable);
                            used_units.Add(ns);
                        }
                        if (_compiled_unit != null)
                            _compiled_unit.used_namespaces.Add((referenced_units[i] as namespace_unit_node).namespace_name.namespace_name);
                    }
                    else
                    {
                        common_unit_node cun = _referenced_units[i] as common_unit_node;
                        if (cun != null)
                        {
                            if (try_get_system_module && cun.IsSystemUnit)
                            {
                                get_system_module(cun);
                                for (int j = 0; j < def_scopes.Count; j++)
                                {
                                    used_units.Add(new PascalABCCompiler.NetHelper.NetScope(interface_using_list, def_scopes[j]._assembly, SymbolTable));
                                }
                            }
                            used_units.Add(cun.scope);
                        }
                        else
                        {
                            throw new CompilerInternalError("Unexpected unit type.");
                        }
                    }
                }
                else
                {
                    dot_net_unit_node dun = referenced_units[i] as dot_net_unit_node;
                    if (dun.dotNetScope.entry_type != null && dun.dotNetScope.entry_type.Name == "PABCRtl")
                    {
                        if (try_get_system_module)
                        {
                            from_pabc_dll = true;
                            get_system_module_from_dll(dun);
                        }
                    }
                }
            }
            List<SymTable.Scope> fetched_used_units = new List<SymTable.Scope>();
            Dictionary<System.Reflection.Assembly, PascalABCCompiler.NetHelper.NetScope> assm_cache = new Dictionary<System.Reflection.Assembly, PascalABCCompiler.NetHelper.NetScope>();
            for (int i = 0; i < used_units.Count; i++)
            {
                PascalABCCompiler.NetHelper.NetScope net_scope = used_units[i] as PascalABCCompiler.NetHelper.NetScope;
                if (net_scope != null)
                {
                    PascalABCCompiler.NetHelper.NetScope existing_scope = null;
                    if (assm_cache.TryGetValue(net_scope.Assembly, out existing_scope))
                    {
                        /*if (net_scope.used_namespaces)
                        {
                            foreach (using_namespace un in net_scope.used_namespaces)
                            {
                                if (un.namespace_name)
                            }
                        }*/
                        existing_scope.used_namespaces.AddRange(net_scope.used_namespaces);
                    }
                    else
                    {
                        if (NetHelper.NetHelper.PABCSystemType == null || net_scope.Assembly != NetHelper.NetHelper.PABCSystemType.Assembly)
                            assm_cache.Add(net_scope.Assembly, net_scope);
                        fetched_used_units.Add(net_scope);
                    }
                }
                else
                    fetched_used_units.Add(used_units[i]);
            }
            used_units = fetched_used_units;
            //Если компилими implementation то в начало кладем все что было в interface
            for (int i = 0; i < assembly_references.Length; i++)
            {
                used_units.Add(new PascalABCCompiler.NetHelper.NetScope(interface_using_list, (assembly_references[i] as dot_net_unit_node).dotNetScope._assembly, SymbolTable));
            }
            used_units.Add(_system_unit.scope);

            return used_units.ToArray();
        }