コード例 #1
0
ファイル: DSHashTable.cs プロジェクト: hvp1953/pascalabcnet
        public HashTableNode Add(string name)
        {
            HashTableNode node = null;
            var           b    = dict.TryGetValue(name, out node);

            if (!b)
            {
                node       = new HashTableNode(name);
                dict[name] = node;
            }
            return(node);

            /*if (!dict.ContainsKey(name))
             * {
             *  var node = new HashTableNode(name);
             *  dict[name] = node;
             *  return node;
             * }
             * return dict[name];*/

            /*if (count / hash_size * 100 > SymbolTableConstants.HashTable_StartResise)
             *  Resize(hash_size + hash_size / 100 * SymbolTableConstants.HashTable_ProcResize);
             * int tn = GetHash(node.Name);
             * if (hash_arr[tn] == null)
             * {
             *  hash_arr[tn] = node;
             *  count++;
             * }
             * return hash_arr[tn];*/
        }
コード例 #2
0
        public HashTableNode Find(string name)
        {
            HashTableNode node = null;

            dict.TryGetValue(name, out node);
            return(node);
        }
コード例 #3
0
ファイル: DSHashTable.cs プロジェクト: CSRedRat/pascalabcnet
		private void Resize(int new_size)
		{
			HashTableNode[] ha=new HashTableNode[new_size];
			for (int i=0;i<new_size;i++) ha[i]=null;
			count=0;
			HashTableNode[] hat=hash_arr;
			hash_arr=ha;
			if (hat.Length>new_size) return;
			for (int i=0;i<hat.Length;i++)
				if (hat[i]!=null) Add(hat[i]);
		}
コード例 #4
0
        public HashTableNode Add(string name)
        {
            HashTableNode node = null;
            var           b    = dict.TryGetValue(name, out node);

            if (!b)
            {
                node       = new HashTableNode(name);
                dict[name] = node;
            }
            return(node);
        }
コード例 #5
0
ファイル: DSHashTable.cs プロジェクト: CSRedRat/pascalabcnet
		public int Add(HashTableNode node)
		{
			if (count/hash_size*100>SymbolTableConstants.HashTable_StartResise)
				Resize(hash_size+hash_size/100*SymbolTableConstants.HashTable_ProcResize);
			int tn=GetHash(node.Name);
            if (hash_arr[tn] == null)
            {
                hash_arr[tn] = node;
                count++;
            }
			return tn;
    	}
コード例 #6
0
        public int Add(HashTableNode node)
        {
            if (count / hash_size * 100 > SymbolTableConstants.HashTable_StartResise)
            {
                Resize(hash_size + hash_size / 100 * SymbolTableConstants.HashTable_ProcResize);
            }
            int tn = GetHash(node.Name);

            if (hash_arr[tn] == null)
            {
                hash_arr[tn] = node;
                count++;
            }
            return(tn);
        }
コード例 #7
0
ファイル: DSHashTable.cs プロジェクト: hvp1953/pascalabcnet
        public HashTableNode Find(string name)
        {
            HashTableNode node = null;

            dict.TryGetValue(name, out node);
            return(node);

            /*if (dict.ContainsKey(name))
             *  return dict[name];
             * else return null;*/

            /*int h = GetHash(name);
             * //if (hash_arr[h] != null)
             * //    return hash_arr[h];
             * return hash_arr[h];*/
        }
コード例 #8
0
 private void Resize(int new_size)
 {
     HashTableNode[] ha = new HashTableNode[new_size];
     for (int i = 0; i < new_size; i++)
     {
         ha[i] = null;
     }
     count = 0;
     HashTableNode[] hat = hash_arr;
     hash_arr = ha;
     if (hat.Length > new_size)
     {
         return;
     }
     for (int i = 0; i < hat.Length; i++)
     {
         if (hat[i] != null)
         {
             Add(hat[i]);
         }
     }
 }
コード例 #9
0
        private List <SymbolInfo> FindAll(Scope scope, string Name, bool OnlyInType, bool OnlyInThisClass, Scope FromScope)
        {
            if (OnlyInType && !(scope is ClassScope) && !(scope is SymbolTable.DotNETScope))
            {
                return(null);
            }
            //if (!CaseSensitive) Name=Name.ToLower();

            if (!scope.CaseSensitive)
            {
                Name = Name.ToLower();
            }
            CurrentScope = FromScope; //глобальные переменные могут привести к ошибкам при поиске и поторном вызове!

            List <SymbolInfo> Result = new List <SymbolInfo>();

            Scope Area = scope;

            Scope[] used_units = null;

            HashTableNode tn = null;

            if (!(scope is DotNETScope) && !Name.StartsWith("?"))
            {
                Scope CurrentArea = Area;
                while (CurrentArea != null)
                {
                    if (CurrentArea is UnitPartScope) //мы очутились в модуле
                    {
                        //мы в ImplementationPart?
                        if (CurrentArea is UnitImplementationScope)
                        {
                            used_units = (CurrentArea as UnitImplementationScope).TopScopeArray;
                            tn         = CurrentArea.Symbols.Find(Name);
                            if (tn != null) //что-то нашли!
                            {
                                AddToSymbolInfo(tn.InfoList, Result);
                            }
                            CurrentArea = CurrentArea.TopScope;
                        }
                        //сейча мы в InterfacePart
                        tn = CurrentArea.Symbols.Find(Name);
                        if (tn != null) //что-то нашли!
                        {
                            AddToSymbolInfo(tn.InfoList, Result);
                        }
                        //смотрим в модулях
                        FindAllInAreaList(Name, used_units, true, Result);
                        FindAllInAreaList(Name, (CurrentArea as UnitInterfaceScope).TopScopeArray, true, Result);

                        return(Result.Count > 0 ? Result : null);
                    }
                    else
                    if (CurrentArea is IInterfaceScope)
                    {
                        FindAllInClass(Name, CurrentArea, OnlyInThisClass, Result);

                        if (Result.Count > 0) //если что-то нашли то заканчиваем
                        {
                            return(Result);
                        }

                        //Зачем искать в интерфейсах?
                        //(ssyy) Не понимаю вопрос. Спросившему подумать, зачем в компиляторе нужен поиск.
                        FindAllInAreaList(Name, (CurrentArea as IInterfaceScope).TopInterfaceScopeArray, true, Result);

                        if (Result.Count > 0 || OnlyInType) //если что-то нашли то заканчиваем
                        {
                            return(Result.Count > 0 ? Result : null);
                        }
                    }
                    else
                    if (CurrentArea is ClassScope)                                  //мы очутились в классе
                    {
                        FindAllInClass(Name, CurrentArea, OnlyInThisClass, Result); //надо сделать поиск по его предкам

                        if (Result.Count > 0 || OnlyInType)                         //если что-то нашли то заканчиваем
                        {
                            return(Result.Count > 0 ? Result : null);
                        }
                        //иначе ищем дальше
                    }
                    else
                    if (CurrentArea is WithScope)//мы очутились в With
                    {
                        tn = CurrentArea.Symbols.Find(Name);
                        if (tn != null) //что-то нашли!
                        {
                            AddToSymbolInfo(tn.InfoList, Result);
                        }
                        if (Result.Count > 0) //если что-то нашли то заканчиваем
                        {
                            return(Result);
                        }
                        Scope[] wscopes = (CurrentArea as WithScope).WithScopes;
                        if (wscopes != null)
                        {
                            foreach (Scope wsc in wscopes)
                            {
                                FindAllInClass(Name, wsc, OnlyInThisClass, Result); //надо сделать поиск по его предкам

                                if (Result.Count > 0)                               //если что-то нашли то заканчиваем
                                {
                                    return(Result);
                                }
                            }
                        }
                    }
                    else
                    {
                        tn = CurrentArea.Symbols.Find(Name);
                        if (tn != null) //что-то нашли!
                        {
                            AddToSymbolInfo(tn.InfoList, Result);
                            return(Result.Count > 0 ? Result : null);
                        }
                        if (CurrentArea is ClassMethodScope)                                                           //мы очутились в методе класса
                        {
                            FindAllInClass(Name, (CurrentArea as ClassMethodScope).TopScope, OnlyInThisClass, Result); //надо сделать поиск по его классу

                            if (Result.Count > 0)                                                                      //если что-то нашли то заканчиваем
                            {
                                return(Result);
                            }
                            CurrentArea = (CurrentArea as ClassMethodScope).DefScope;
                            continue;
                        }
                    }
                    CurrentArea = CurrentArea.TopScope;//Пошли вверх
                }
            }

            //если нет такого ищем в областях .NET

            // SSM 21.01.16
            if (Name.StartsWith("?"))     // это значит, надо искать в областях .NET
            {
                Name = Name.Substring(1); // съели ? и ищем т.к. tn<0
            }
            // end SSM

            //ssyy
            Scope NextUnitArea = null;
            //\ssyy
            Scope an;

            tn = Area.Symbols.Find(Name);
            while (Area != null)
            {
                an = Area;
                if (an is DotNETScope)
                {
                    if (tn == null)
                    {
                        AddToSymbolInfo(Result, (DotNETScope)an, Name);
                    }
                    else
                    {
                        FindAllInClass(Name, Area, false, Result);
                    }
                }
                if (Result.Count > 0)
                {
                    return(Result);
                }
                if (an is UnitPartScope)
                {
                    if (an is UnitImplementationScope)
                    {
                        FindAllInAreaList(Name, (an as UnitImplementationScope).TopScopeArray, true, Result);
                        an = an.TopScope;
                    }

                    FindAllInAreaList(Name, (an as UnitInterfaceScope).TopScopeArray, false, Result);

                    if (Result.Count > 0)
                    {
                        return(Result);
                    }
                }
                if (an is WithScope)//мы очутились в Width
                {
                    FindAllInAreaList(Name, (an as WithScope).WithScopes, true, false, Result);

                    if (Result.Count > 0) //если что-то нашли то заканчиваем
                    {
                        return(Result);
                    }
                }
                if (an is ClassScope)
                {
                    Scope          unit_area = an.TopScope;
                    InterfaceScope IntScope  = an as InterfaceScope;
                    while (((ClassScope)an).BaseClassScope != null)
                    {
                        an = ((ClassScope)an).BaseClassScope;
                        if (an is DotNETScope)
                        {
                            AddToSymbolInfo(Result, (DotNETScope)an, Name);
                            if (Result.Count > 0) // || OnlyInType)
                            {
                                return(Result);
                            }
                            break;
                        }
                    }
                    //В предках ничего не нашли, ищем по интерфейсам...
                    if (IntScope != null)
                    {
                        FindAllInAreaList(Name, IntScope.TopInterfaceScopeArray, false, Result);
                        if (Result.Count > 0) //если что-то нашли то заканчиваем
                        {
                            return(Result);
                        }
                    }
                    if (OnlyInType)
                    {
                        return(Result.Count > 0 ? Result : null);
                    }

                    //ssyy
                    if (NextUnitArea != null)
                    {
                        Area = NextUnitArea;
                        //NextUnitArea = null;
                        continue;
                    }
                    else
                    {
                        //\ssyy
                        an = unit_area;
                    }
                }
                if (Result.Count > 0)
                {
                    return(Result);
                }


                if (an is ClassMethodScope)
                {
                    //ssyy
                    NextUnitArea = (an as ClassMethodScope).DefScope;
                    //\ssyy
                    Area = an.TopScope;
                }
                else
                {
                    Area = Area.TopScope;
                }
                //Area = Area.TopScope;
            }
            return(null);                //если такого нет то поиск окончен
        }