public void ReplaceName(PascalABCCompiler.SyntaxTree.ident id, string new_name, string[] lines)
        {
            PascalABCCompiler.SyntaxTree.SourceContext sc = id.source_context;
            int    type_name_num = sc.begin_position.line_num - 1;
            int    bcol          = sc.begin_position.column_num;
            int    ecol          = sc.end_position.column_num;
            string s             = lines[type_name_num].Remove(bcol - 1, ecol - bcol + 1);

            lines[type_name_num] = s.Insert(bcol - 1, new_name);
        }
Exemple #2
0
        public static void RenameUnit(string FileName, string new_val)
        {
            if (CodeCompletion.CodeCompletionController.CurrentParser == null)
            {
                return;
            }
            ccp = new CodeCompletionProvider();
            IDocument doc = null;

            CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
            string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;

            PascalABCCompiler.SyntaxTree.compilation_unit cu       = controller.ParseOnlySyntaxTree(FileName, text);
            PascalABCCompiler.SyntaxTree.ident            unitName = null;
            if (cu is PascalABCCompiler.SyntaxTree.unit_module)
            {
                unitName = (cu as PascalABCCompiler.SyntaxTree.unit_module).unit_name.idunit_name;
            }
            else if (cu is PascalABCCompiler.SyntaxTree.program_module)
            {
                if ((cu as PascalABCCompiler.SyntaxTree.program_module).program_name == null)
                {
                    return;
                }
                unitName = (cu as PascalABCCompiler.SyntaxTree.program_module).program_name.prog_name;
            }

            List <SymbolsViewerSymbol> refers = ccp.Rename(unitName.name, unitName.name, FileName, unitName.source_context.begin_position.line_num, unitName.source_context.begin_position.column_num);

            if (refers == null || new_val == null)
            {
                return;
            }
            int addit = 0;

            PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0);
            string file_name = null;

            VisualPABCSingleton.MainForm.StopTimer();
            WorkbenchServiceFactory.CodeCompletionParserController.StopParseThread();
            foreach (IFileInfo fi in ProjectFactory.Instance.CurrentProject.SourceFiles)
            {
                WorkbenchServiceFactory.CodeCompletionParserController.RegisterFileForParsing(fi.Path);
            }
            WorkbenchServiceFactory.CodeCompletionParserController.ParseInThread();
            foreach (SymbolsViewerSymbol svs in refers)
            {
                if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line)
                {
                    addit = 0;
                }
                else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column)
                {
                    addit = 0;
                }
                if (svs.SourceLocation.FileName != file_name)
                {
                    CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName);
                    if (cfdoc == null)
                    {
                        continue;
                    }
                    doc       = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document;
                    file_name = svs.SourceLocation.FileName;
                }
                tmp = svs.SourceLocation;
                TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1, svs.SourceLocation.BeginPosition.Line - 1);
                //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column);
                int offset = doc.PositionToOffset(tl_beg);
                //addit += new_val.Length - unitName.name.Length;
                doc.Replace(offset, unitName.name.Length, new_val);
                doc.CommitUpdate();
            }
            WorkbenchServiceFactory.CodeCompletionParserController.RunParseThread();
            VisualPABCSingleton.MainForm.StartTimer();
        }
Exemple #3
0
        private static SyntaxTree.statement_list AssignArrs(SyntaxTree.array_type ArrFrom, SyntaxTree.addressed_value IdFrom, SyntaxTree.addressed_value IdTo)
        {
            SyntaxTree.statement_list OuterSTL = new PascalABCCompiler.SyntaxTree.statement_list();
            SyntaxTree.statement_list InnerSTL = OuterSTL;
            List<List<SyntaxTree.diapason>> DiapasonsList = get_list_of_diapasons(ArrFrom);
            List<List<SyntaxTree.ident>> IdentsList = new List<List<PascalABCCompiler.SyntaxTree.ident>>();
            int VarNum = 0;
            if (DiapasonsList == null)
                DiapasonsList = new List<List<PascalABCCompiler.SyntaxTree.diapason>>();
            foreach (List<SyntaxTree.diapason> Diapasons in DiapasonsList)
            {
                bool IsDynamicArray = false;
                List<SyntaxTree.method_call> Lens = new List<PascalABCCompiler.SyntaxTree.method_call>();
                if ((Diapasons.Count == 0) || (Diapasons[0] == null))
                {
                    //массив динамический, нужно делать setlength
                    IsDynamicArray = true;
                    SyntaxTree.procedure_call SetLenPC = new PascalABCCompiler.SyntaxTree.procedure_call();
                    SyntaxTree.method_call SetLenMC = new PascalABCCompiler.SyntaxTree.method_call();
                    SetLenMC.dereferencing_value = new SyntaxTree.ident("SetLength");
                    SetLenPC.func_name = SetLenMC;
                    SyntaxTree.expression_list SetLenParamsExl = new PascalABCCompiler.SyntaxTree.expression_list();
                    SetLenMC.parameters = SetLenParamsExl;

                    //индексное выражение для массива-приемника
                    SyntaxTree.addressed_value IndexerTo = IdTo;
                    foreach (List<SyntaxTree.ident> Idents in IdentsList)
                    {
                        SyntaxTree.indexer InnerInd = new PascalABCCompiler.SyntaxTree.indexer();
                        InnerInd.dereferencing_value = IndexerTo;
                        SyntaxTree.expression_list IndexersExl = new PascalABCCompiler.SyntaxTree.expression_list();
                        foreach (SyntaxTree.ident Ident in Idents)
                            IndexersExl.expressions.Add(new SyntaxTree.ident(Ident.name));
                        InnerInd.indexes = IndexersExl;
                        IndexerTo = InnerInd;
                    }

                    //индексное выражение для массива-источника
                    SyntaxTree.addressed_value IndexerFrom = IdFrom;
                    foreach (List<SyntaxTree.ident> Idents in IdentsList)
                    {
                        SyntaxTree.indexer InnerInd = new PascalABCCompiler.SyntaxTree.indexer();
                        InnerInd.dereferencing_value = IndexerFrom;
                        SyntaxTree.expression_list IndexersExl = new PascalABCCompiler.SyntaxTree.expression_list();
                        foreach (SyntaxTree.ident Ident in Idents)
                            IndexersExl.expressions.Add(new SyntaxTree.ident(Ident.name));
                        InnerInd.indexes = IndexersExl;
                        IndexerFrom = InnerInd;
                    }

                    SetLenParamsExl.expressions.Add(IndexerTo);

                    //List<SyntaxTree.method_call> Lengths = new List<PascalABCCompiler.SyntaxTree.method_call>();
                    if (Diapasons.Count == 0)
                    {
                        SyntaxTree.method_call LengthMC = new PascalABCCompiler.SyntaxTree.method_call();
                        LengthMC.dereferencing_value = new SyntaxTree.ident("Length");
                        SyntaxTree.expression_list LenMCExl = new PascalABCCompiler.SyntaxTree.expression_list();
                        LengthMC.parameters = LenMCExl;
                        LenMCExl.expressions.Add(IndexerFrom);
                        SetLenParamsExl.expressions.Add(LengthMC);
                        Lens.Add(LengthMC);
                    }
                    else
                    {
                        for (int i = 0; i < Diapasons.Count; ++i)
                        {
                            SyntaxTree.method_call LengthMC = new PascalABCCompiler.SyntaxTree.method_call();
                            LengthMC.dereferencing_value = new SyntaxTree.ident("Length");
                            SyntaxTree.expression_list LenMCExl = new PascalABCCompiler.SyntaxTree.expression_list();
                            LengthMC.parameters = LenMCExl;
                            LenMCExl.expressions.Add(IndexerFrom);
                            LenMCExl.expressions.Add(new SyntaxTree.int32_const(i));
                            SetLenParamsExl.expressions.Add(LengthMC);
                            Lens.Add(LengthMC);
                        }
                    }
                    InnerSTL.subnodes.Add(SetLenPC);
                }
                //к этому моменту вызов SetLength с параметрами сформирован
                //в Lens содержатся вызовы length по нужной размерности если массив динамический
                //теперь нужно создать циклы for и список переменных, по которым идут циклы
                List<SyntaxTree.ident> LoopIdents = new List<SyntaxTree.ident>();
                for (int i = 0; i < Math.Max(Diapasons.Count, 1); ++i)
                {
                    SyntaxTree.for_node ForNode = new PascalABCCompiler.SyntaxTree.for_node();
                    SyntaxTree.ident LoopVar = new PascalABCCompiler.SyntaxTree.ident("$i" + (VarNum++).ToString());
                    LoopIdents.Add(LoopVar);
                    ForNode.loop_variable = LoopVar;
                    ForNode.create_loop_variable = true;
                    if (IsDynamicArray)
                    {
                        ForNode.initial_value = new SyntaxTree.int32_const(0);
                        ForNode.finish_value = new PascalABCCompiler.SyntaxTree.bin_expr(Lens[i], new SyntaxTree.int32_const(1), PascalABCCompiler.SyntaxTree.Operators.Minus);
                    }
                    else
                    {
                        ForNode.initial_value = Diapasons[i].left;
                        ForNode.finish_value = Diapasons[i].right;
                    }
                    InnerSTL.subnodes.Add(ForNode);
                    ForNode.statements = new PascalABCCompiler.SyntaxTree.statement_list();
                    InnerSTL = ForNode.statements as SyntaxTree.statement_list;
                }
                IdentsList.Add(LoopIdents);
            }

            // к этому моменту создано гнездо циклов с установкой длины динамических массивов и перебором
            // вообще всех массивов. Осталось создать самое внутреннее присваивание
            SyntaxTree.addressed_value AssignIndexerFrom = IdFrom;
            SyntaxTree.addressed_value AssignIndexerTo = IdTo;
            foreach (List<SyntaxTree.ident> AssignIdents in IdentsList)
            {
                SyntaxTree.indexer FromIndexer = new PascalABCCompiler.SyntaxTree.indexer();
                SyntaxTree.indexer ToIndexer = new PascalABCCompiler.SyntaxTree.indexer();
                FromIndexer.dereferencing_value = AssignIndexerFrom;
                ToIndexer.dereferencing_value = AssignIndexerTo;

                SyntaxTree.expression_list Exl = new PascalABCCompiler.SyntaxTree.expression_list();
                foreach (SyntaxTree.ident id in AssignIdents)
                    Exl.expressions.Add(id);
                FromIndexer.indexes = Exl;
                ToIndexer.indexes = Exl;

                AssignIndexerFrom = FromIndexer;
                AssignIndexerTo = ToIndexer;
            }
            SyntaxTree.assign Assign = new PascalABCCompiler.SyntaxTree.assign();
            Assign.from = AssignIndexerFrom;
            Assign.to = AssignIndexerTo;
            Assign.operator_type = PascalABCCompiler.SyntaxTree.Operators.Assignment;
            InnerSTL.subnodes.Add(Assign);

            return OuterSTL;
        }