Ejemplo n.º 1
0
        private static SyntaxTree.statement_list CreateFinalPart(string ObjName, VarInfoContainer Vars)
        {
            SyntaxTree.statement_list stl = new PascalABCCompiler.SyntaxTree.statement_list();

            //создаем присваивания разделяемым переменным
            for (int i = 0; i < Vars.SharedVariables.Count; ++i)
            {
                string VarName = Vars.SharedVariables[i].name;
                if (LoopVariables.Contains(VarName.ToLower()))
                    continue;

                SyntaxTree.dot_node DotNode = new PascalABCCompiler.SyntaxTree.dot_node();
                DotNode.left = new SyntaxTree.ident(ObjName);
                DotNode.right = new SyntaxTree.ident(VarName);

                SyntaxTree.array_type arrType = ConvertToSyntaxType(Vars.SharedVariables[i].type as type_node) as SyntaxTree.array_type;
                if (arrType != null && !is_dyn_arr(arrType))
                {
                    stl.subnodes.Add(AssignArrs(arrType, DotNode, new SyntaxTree.ident(VarName)));
                }
                else
                {
                    SyntaxTree.assign Assign = new PascalABCCompiler.SyntaxTree.assign();
                    Assign.operator_type = PascalABCCompiler.SyntaxTree.Operators.Assignment;
                    Assign.to = new SyntaxTree.ident(VarName);
                    Assign.from = DotNode;
                    stl.subnodes.Add(Assign);
                }

            }

            //создаем присваивания переменным редукции
            for (int i = 0; i < Vars.ReductionVariables.Count; ++i)
            {
                string VarName = Vars.ReductionVariables[i].name;

                SyntaxTree.dot_node DotNode = new PascalABCCompiler.SyntaxTree.dot_node();
                DotNode.left = new SyntaxTree.ident(ObjName);
                DotNode.right = new SyntaxTree.ident("$" + VarName);

                SyntaxTree.array_type arrType = ConvertToSyntaxType(Vars.ReductionVariables[i].type as type_node) as SyntaxTree.array_type;
                if (arrType != null && !is_dyn_arr(arrType))
                {
                    stl.subnodes.Add(AssignArrs(arrType, DotNode, new SyntaxTree.ident(VarName)));
                }
                else
                {
                    SyntaxTree.assign Assign = new PascalABCCompiler.SyntaxTree.assign();
                    Assign.operator_type = PascalABCCompiler.SyntaxTree.Operators.Assignment;
                    Assign.to = new SyntaxTree.ident(VarName);
                    Assign.from = DotNode;
                    stl.subnodes.Add(Assign);
                }
            }

            return stl;
        }
Ejemplo n.º 2
0
        private static SyntaxTree.statement_list CreateInitPart(string ClassName, string ObjName, VarInfoContainer Vars)
        {
            SyntaxTree.statement_list stl = new PascalABCCompiler.SyntaxTree.statement_list();

            //Var Statement - объявление экземпляра обьекта-функции
            SyntaxTree.var_statement ClassVar = new PascalABCCompiler.SyntaxTree.var_statement();
            stl.subnodes.Add(ClassVar);
            SyntaxTree.var_def_statement ClassVarDef = new PascalABCCompiler.SyntaxTree.var_def_statement();
            ClassVar.var_def = ClassVarDef;
            SyntaxTree.ident_list ClassIdl = new PascalABCCompiler.SyntaxTree.ident_list();
            ClassVarDef.vars = ClassIdl;
            ClassIdl.idents.Add(new PascalABCCompiler.SyntaxTree.ident(ObjName));
            SyntaxTree.named_type_reference ClassTypeNTR = new PascalABCCompiler.SyntaxTree.named_type_reference();
            ClassVarDef.vars_type = ClassTypeNTR;
            ClassTypeNTR.names.Add(new PascalABCCompiler.SyntaxTree.ident(ClassName));
            SyntaxTree.new_expr ClassInitNE = new PascalABCCompiler.SyntaxTree.new_expr();
            ClassVarDef.inital_value = ClassInitNE;
            SyntaxTree.named_type_reference ClassInitNTR = new PascalABCCompiler.SyntaxTree.named_type_reference();
            ClassInitNE.type = ClassInitNTR;
            ClassInitNTR.names.Add(new PascalABCCompiler.SyntaxTree.ident(ClassName));

            //создаем присваивания разделяемым переменным
            for (int i = 0; i < Vars.SharedVariables.Count; ++i)
            {
                string VarName = Vars.SharedVariables[i].name;

                SyntaxTree.dot_node DotNode = new PascalABCCompiler.SyntaxTree.dot_node();
                DotNode.left = new SyntaxTree.ident(ObjName);
                DotNode.right = new SyntaxTree.ident(VarName);

                SyntaxTree.array_type arrType = ConvertToSyntaxType(Vars.SharedVariables[i].type as type_node) as SyntaxTree.array_type;
                if (arrType != null && !is_dyn_arr(arrType))
                {
                    stl.subnodes.Add(AssignArrs(arrType, new SyntaxTree.ident(VarName), DotNode));
                }
                else
                {
                    SyntaxTree.assign Assign = new PascalABCCompiler.SyntaxTree.assign();
                    Assign.operator_type = PascalABCCompiler.SyntaxTree.Operators.Assignment;
                    Assign.from = new SyntaxTree.ident(VarName);
                    Assign.to = DotNode;
                    stl.subnodes.Add(Assign);
                }
            }
            //создаем присваивания переменным редукции
            for (int i = 0; i < Vars.ReductionVariables.Count; ++i)
            {
                string VarName = Vars.ReductionVariables[i].name;

                SyntaxTree.dot_node DotNode = new PascalABCCompiler.SyntaxTree.dot_node();
                DotNode.left = new SyntaxTree.ident(ObjName);
                DotNode.right = new SyntaxTree.ident("$" + VarName);

                SyntaxTree.array_type arrType = ConvertToSyntaxType(Vars.ReductionVariables[i].type as type_node) as SyntaxTree.array_type;
                if (arrType != null && !is_dyn_arr(arrType))
                {
                    stl.subnodes.Add(AssignArrs(arrType, new SyntaxTree.ident(VarName), DotNode));
                }
                else
                {
                    SyntaxTree.assign Assign = new PascalABCCompiler.SyntaxTree.assign();
                    Assign.operator_type = PascalABCCompiler.SyntaxTree.Operators.Assignment;
                    Assign.from = new SyntaxTree.ident(VarName);
                    Assign.to = DotNode;
                    stl.subnodes.Add(Assign);
                }
            }
            return stl;
        }