예제 #1
0
        private string WorkWithAssignments(string text)
        {
            Func func;

            int lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                int        lastVarInitIndex = 0;
                Assignment assignment;

                while ((func = Programm.FindFunc(lastFuncIndex, text)) != null && (assignment = Programm.FindAssignment(lastVarInitIndex, func.GetBody())) != null)
                {
                    ItemForVar varibale = this._table.GetItem(assignment.GetVaribaleName(), func.GetName());
                    text = text.Remove(func.GetIndexFuncIntoText() + func.GetIndexBody() + assignment.GetIndexIntoText(), assignment.GetText().Length);
                    string newAssignment = this.GetFuncCallToWrite(varibale.GetIndex(), varibale.GetType(), assignment.GetRightText());
                    text = text.Insert(func.GetIndexFuncIntoText() + func.GetIndexBody() + assignment.GetIndexIntoText(), newAssignment);

                    lastVarInitIndex = assignment.GetIndexIntoText() + assignment.GetText().Length;
                }

                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }
            return(text);
        }
예제 #2
0
        private string WorkWithLocalVars(string text)
        {
            Func func;

            int lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                int               lastVaribaleIndex = 0;
                Varibale          varibale;
                List <ItemForVar> items = this._table.GetVarsByView(func.GetName());

                foreach (ItemForVar item in items)
                {
                    while ((varibale = Programm.FindVaribale(lastVaribaleIndex, item.GetName(), func.GetBody())) != null)
                    {
                        text = text.Remove(func.GetIndexFuncIntoText() + func.GetIndexBody() + varibale.GetIndexIntoText(), varibale.GetText().Length);
                        string newVaribale = this.GetFuncCallToRead(item.GetIndex(), item.GetType());
                        text = text.Insert(func.GetIndexFuncIntoText() + func.GetIndexBody() + varibale.GetIndexIntoText(), newVaribale);

                        lastVaribaleIndex = varibale.GetIndexIntoText() + varibale.GetText().Length;
                        func = Programm.FindFunc(lastFuncIndex, text);
                    }
                    lastVaribaleIndex = 0;
                }

                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            return(text);
        }
예제 #3
0
        private string WorkWithVarInit(string text)
        {
            Func func;

            int lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                int     lastVarInitIndex = 0;
                VarInit varInit;

                while ((func = Programm.FindFunc(lastFuncIndex, text)) != null && (varInit = Programm.FindVarInit(lastVarInitIndex, func.GetBody())) != null)
                {
                    ItemForVar item = varInit.GetItemForVar();
                    item.SetView(func.GetName());

                    this._table.AddVar(item);
                    text = text.Remove(func.GetIndexFuncIntoText() + func.GetIndexBody() + varInit.GetIndexIntoText(), varInit.GetText().Length);

                    lastVarInitIndex = varInit.GetIndexIntoText() + varInit.GetText().Length;
                }

                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            return(text);
        }
예제 #4
0
        private string WorkWithFuncsParams(string text)
        {
            Func func;

            int lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                int     lastVarInitIndex = 0;
                VarInit varInit;

                int paramIndex = 0;
                while ((varInit = Programm.FindVarInit(lastVarInitIndex, func.GetFuncParamsText())) != null)
                {
                    //this._params.Add(varInit.GetItemForVar()); // Запомнить, какие параметры каким функциям принадлежат
                    ItemForVar item = varInit.GetItemForVar();
                    item.SetView(func.GetName());
                    item.SetParamStatus(true);
                    item.SetParamIndex(paramIndex++);

                    this._table.AddVar(item);
                    lastVarInitIndex = varInit.GetIndexIntoText() + varInit.GetText().Length;
                }

                text = text.Remove(func.GetIndexFuncParams() + func.GetIndexFuncIntoText(), func.GetFuncParamsText().Length);

                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            return(text);
        }
예제 #5
0
        private string WorkWithFuncCall(string text)
        {
            List <string> funcsName = new List <string>();

            Func func;

            int lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                if (func.GetName() != "Main")
                {
                    funcsName.Add(func.GetName());
                }
                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                int      lastVarInitIndex = 0;
                FuncCall funcCall;

                while ((func = Programm.FindFunc(lastFuncIndex, text)) != null && (funcCall = Programm.FindFuncCall(lastVarInitIndex, func.GetBody())) != null)
                {
                    string newCall = "";
                    foreach (string funcName in funcsName)
                    {
                        if (funcCall.GetFuncName() == funcName)
                        {
                            text = text.Remove(func.GetIndexBody() + func.GetIndexFuncIntoText() + funcCall.GetIndexIntoText(), funcCall.GetText().Length);

                            foreach (ItemForVar item in this._table.GetVarParamsByView(funcCall.GetFuncName()))
                            {
                                newCall += this.GetFuncCallToWrite(item.GetIndex(), item.GetType(), funcCall.GetFuncParams()[item.GetParamsIndex()]) + "\n";
                            }
                            newCall += funcCall.GetFuncName() + "();\n";

                            text             = text.Insert(func.GetIndexBody() + func.GetIndexFuncIntoText() + funcCall.GetIndexIntoText(), newCall);
                            lastVarInitIndex = funcCall.GetIndexIntoText() + newCall.Length;

                            break;
                        }
                        else
                        {
                            lastVarInitIndex = funcCall.GetIndexIntoText() + funcCall.GetText().Length;
                        }
                    }
                }

                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            return(text);
        }
예제 #6
0
        private string WorkWithArrayAddWriteAndReadFunctions(string text)
        {
            Func func;

            if ((func = Programm.FindFunc(0, text)) != null)
            {
                int insertPos = func.GetIndexFuncIntoText();
                text = text.Insert(insertPos, this.GetReadFuncText());
                text = text.Insert(insertPos += this.GetReadFuncText().Length, this.GetReadStringFuncText());
                text = text.Insert(insertPos += this.GetReadStringFuncText().Length, this.GetWriteFuncText());
                text = text.Insert(insertPos += this.GetWriteFuncText().Length, this.GetArrayText());
            }

            return(text);
        }
예제 #7
0
        private string WorkWithConsts(string text)
        {
            Func     func;
            IntConst intConst = null;

            int lastIntConstIndex = 0;
            int lastFuncIndex     = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                lastIntConstIndex = 0;
                string callFuncToRead = "";
                while ((func = Programm.FindFunc(lastFuncIndex, text)) != null && (intConst = Programm.FindIntConst(lastIntConstIndex + callFuncToRead.Length, func.GetBody())) != null)
                {
                    int index       = this._table.AddVar(intConst.GetItemForVar());
                    int posIntoText = intConst.GetIndexIntoText() + func.GetIndexBody() + func.GetIndexFuncIntoText();

                    text           = text.Remove(posIntoText, intConst.GetLength());
                    callFuncToRead = this.GetFuncCallToRead(index, "int");
                    text           = text.Insert(posIntoText, callFuncToRead);

                    lastIntConstIndex = intConst.GetIndexIntoText();
                }
                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            StringConst stringConst = null;

            int lastStringConstIndex = 0;

            lastFuncIndex = 0;

            while ((func = Programm.FindFunc(lastFuncIndex, text)) != null)
            {
                lastStringConstIndex = 0;
                string callFuncToRead = "";
                while ((func = Programm.FindFunc(lastFuncIndex, text)) != null && (stringConst = Programm.FindStringConst(lastStringConstIndex + callFuncToRead.Length, func.GetBody())) != null)
                {
                    int index       = this._table.AddVar(stringConst.GetItemForVar());
                    int posIntoText = stringConst.GetIndexIntoText() + func.GetIndexBody() + func.GetIndexFuncIntoText();
                    // 2 кавычки
                    text = text.Remove(posIntoText, stringConst.GetLength() + 2);

                    callFuncToRead = this.GetFuncCallToRead(index, "string");

                    /*callFuncToRead = "(" + this.GetFuncCallToRead(index, "char");
                     *
                     * for (int i = 1; i < stringConst.GetLength(); i++)
                     * {
                     *  int indexOfChar = index + i;
                     *  callFuncToRead += "+"+this.GetFuncCallToRead(indexOfChar, "char");
                     * }
                     *
                     * callFuncToRead += ").ToString()";*/
                    text = text.Insert(posIntoText, callFuncToRead);

                    lastStringConstIndex = stringConst.GetIndexIntoText();
                }
                lastFuncIndex = func.GetIndexFuncIntoText() + func.GetFuncText().Length;
            }

            return(text);
        }