private List <SymbolsViewerSymbol> InternalFindReferences(string fname, PascalABCCompiler.SyntaxTree.expression expr, int line, int col, bool for_refact)
        {
            List <PascalABCCompiler.Parsers.Position> lst = new List <PascalABCCompiler.Parsers.Position>();
            List <SymbolsViewerSymbol> svs_lst            = new List <SymbolsViewerSymbol>();

            try
            {
                CodeCompletion.DomConverter dc = CodeCompletion.CodeCompletionController.comp_modules[fname] as CodeCompletion.DomConverter;
                IBaseScope fnd_scope           = null;
                IBaseScope cur_sc = null;
                if (dc != null)
                {
                    fnd_scope = dc.GetSymDefinition(expr, line, col, keyword);
                    cur_sc    = dc.FindScopeByLocation(line, col);
                }
                if (fnd_scope != null)
                {
                    foreach (string FileName in CodeCompletionParserController.open_files.Keys)
                    {
                        CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
                        string text = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
                        PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text);
                        if (cu != null)
                        {
                            dc = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter;
                            CodeCompletion.ReferenceFinder rf = null;
                            if (dc != null && dc.visitor.entry_scope != null)
                            {
                                rf = new CodeCompletion.ReferenceFinder(fnd_scope, dc.visitor.entry_scope, cu, FileName, for_refact);
                                lst.AddRange(rf.FindPositions());
                            }
                        }
                    }
                    PascalABCCompiler.Parsers.Position p = fnd_scope.GetPosition();
                    bool need_add_def = !for_refact; // true
                    if (p.file_name != null && need_add_def)
                    {
                        svs_lst.Add(new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(p.file_name, p.line, p.column, p.end_line, p.end_column), ImagesProvider.GetPictureNum(fnd_scope.SymbolInfo)));
                    }
                    foreach (PascalABCCompiler.Parsers.Position pos in lst)
                    {
                        if (pos.file_name != null)
                        {
                            svs_lst.Add(new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(pos.file_name, pos.line, pos.column, pos.end_line, pos.end_column), ImagesProvider.IconNumberGotoText));
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
            GC.Collect();
            return(svs_lst);
            //return svs_lst.ToArray();
        }
        public List <SymbolsViewerSymbol> Rename(string expr, string name, string fileName, int line, int column, ref string new_val)
        {
            if (rf == null)
            {
                rf = new RenameForm();
                Form1StringResources.SetTextForAllControls(rf);
            }
            rf.EditValue = name.Trim(' ');
            DialogResult dr = rf.ShowDialog();

            if (dr == DialogResult.OK)
            {
                new_val = rf.EditValue;
                List <SymbolsViewerSymbol> refers = FindReferences(expr, fileName, line, column, true);
                if (refers == null)
                {
                    return(null);
                }
                return(refers);
            }
            return(null);
        }
        private List<SymbolsViewerSymbol> InternalFindReferences(string fname, PascalABCCompiler.SyntaxTree.expression expr, int line, int col, bool for_refact)
        {
            List<PascalABCCompiler.Parsers.Position> lst = new List<PascalABCCompiler.Parsers.Position>();
            List<SymbolsViewerSymbol> svs_lst = new List<SymbolsViewerSymbol>();
            try
            {
                CodeCompletion.DomConverter dc = CodeCompletion.CodeCompletionController.comp_modules[fname] as CodeCompletion.DomConverter;
                IBaseScope fnd_scope = null;
                IBaseScope cur_sc = null;
                if (dc != null)
                {
                    fnd_scope = dc.GetSymDefinition(expr, line, col, keyword);
                    cur_sc = dc.FindScopeByLocation(line, col);
                }
                if (fnd_scope != null)
                {
                    foreach (string FileName in CodeCompletionParserController.open_files.Keys)
                    {
                        CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
                        string text = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
                        PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text);
                        if (cu != null)
                        {
                            dc = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter;
                            CodeCompletion.ReferenceFinder rf = null;
                            if (dc != null && dc.stv.entry_scope != null)
                            {
                                rf = new CodeCompletion.ReferenceFinder(fnd_scope, dc.stv.entry_scope, cu, FileName, for_refact);
                                lst.AddRange(rf.FindPositions());
                            }
                        }
                    }
                    PascalABCCompiler.Parsers.Position p = fnd_scope.GetPosition();
                    bool need_add_def = true;
                    if (for_refact)
                    foreach (PascalABCCompiler.Parsers.Position pos in lst)
                        if (p.file_name == pos.file_name && p.line == pos.line && p.column == pos.column && p.end_line == pos.end_line && p.end_column == pos.end_column)
                        {
                            need_add_def = false;
                            break;
                        }
                    if (p.file_name != null && need_add_def)       
                        svs_lst.Add(new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(p.file_name, p.line, p.column, p.end_line, p.end_column), ImagesProvider.GetPictureNum(fnd_scope.SymbolInfo)));
                    foreach (PascalABCCompiler.Parsers.Position pos in lst)
                    {
                        if (pos.file_name != null)
                            svs_lst.Add(new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(pos.file_name, pos.line, pos.column, pos.end_line, pos.end_column), ImagesProvider.IconNumberGotoText));
                    }
                }
            }
            catch (Exception e)
            {

            }
            GC.Collect();
            return svs_lst;
            //return svs_lst.ToArray();
        }
 public List<SymbolsViewerSymbol> Rename(string expr, string name, string fileName, int line, int column, ref string new_val)
 {
     if (rf == null)
     {
         rf = new RenameForm();
         Form1StringResources.SetTextForAllControls(rf);
     }
     rf.EditValue = name.Trim(' ');
     DialogResult dr = rf.ShowDialog();
     if (dr == DialogResult.OK)
     {
         new_val = rf.EditValue;
         List<SymbolsViewerSymbol> refers = FindReferences(expr, fileName, line, column, true);
         if (refers == null) return null;
         return refers;
     }
     return null;
 }