// will be called by VisitExpressionStatement
        public override Expression VisitExpression(Expression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            switch (expression.NodeType)
            {
            case NodeType.Dup:
                throw new ApplicationException("dup should not be an expression!");

            case NodeType.Pop:
                try
                {
                    decrement_depth();
                }
                catch (Exception excp)
                { // debug suport
                    Console.Out.WriteLine("negative stack depth in " + CodePrinter.ExpressionToString(expression));
                    throw excp;
                }
                return(PopTransformer(expression, depth + 1));

            default:
                // recursively visit the sub-expressions to search for dup and pop.
                return((Expression)base.VisitExpression(expression));
            }
        }
Exemple #2
0
        private void UpdateLines(int linenr, int length)
        {
            Notify(String.Format("Updatelines: {0} + {1}", linenr, length), NotificationType.Info, null);

            // Bepaal de plek waar we weer terug willen komen
            int         selstart = txtText.SelectionStart;
            int         sellen   = txtText.SelectionLength;
            CodePrinter cp       = new CodePrinter(txtText);

            this.Cursor = Cursors.WaitCursor;
            txtText.SuspendLayout();
            while (length > 0)
            {
                // Controleer de regels op syntax
                int p1 = txtText.GetFirstCharIndexFromLine(linenr);
                int p2 = txtText.GetFirstCharIndexFromLine(linenr + 1);

                string line = txtText.Lines[linenr];
                m_codelines[linenr] = CodeLine.BuildCodeLine(m_filename, linenr + 1, line);
                //... do vanalles
                //txtText.SelectionStart = p1;
                //txtText.SelectionLength = p2 - p1;
                txtText.Select(p1, p2 - p1 - 1);
                txtText.SelectedText = "";
                m_codelines[linenr].Accept(cp);
                //...
                length--;
                linenr++;
            }
            // zet de selection weer terug
            txtText.SelectionStart  = selstart;
            txtText.SelectionLength = sellen;
            txtText.ResumeLayout();
            this.Cursor = Cursors.Default;
        }
Exemple #3
0
        public void InitFrom()
        {
            this.IsUseWeight = Convert.ToBoolean(commonDAO.GetAppletConfigInt32("启用称重"));

            this._CodePrinter = new CodePrinter(printDocument1);

            // 获取全自动制样机
        }
Exemple #4
0
        public void InitFrom()
        {
            this.IsUseWeight = Convert.ToBoolean(commonDAO.GetAppletConfigInt32("启用称重"));

            this._CodePrinter = new CodePrinter(printDocument1);

            // 获取全自动制样机
            this.AutoMaker = commonDAO.GetCMEquipmentByMachineCode(commonDAO.GetAppletConfigString("全自动制样机编码"));
        }
        public void InitFrom()
        {
            this.IsUseWeight = Convert.ToBoolean(commonDAO.GetAppletConfigInt32("启用称重"));

            this._CodePrinter = new CodePrinter(printDocument1);

            // 获取全自动制样机
            this.AutoMaker = commonDAO.GetCMEquipmentByMachineCode(commonDAO.GetCommonAppletConfigString(CommonAppConfig.GetInstance().AppIdentifier + "对应制样机"));
        }
Exemple #6
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void InitFrom()
        {
            //superGridControl1.PrimaryGrid.ColumnAutoSizeMode = ColumnAutoSizeMode.AllCells;

            this._CodePrinter   = new CodePrinter(printDocument1);
            this._QRCodePrinter = new QRCodePrinter(printDocument1);

            LoadDetail();
        }
Exemple #7
0
        private static string EndFilterToString(EndFilter endfilter)
        {
            string exprString;

            if (endfilter.Value != null)
            {
                exprString = CodePrinter.expression2str(endfilter.Value);
            }
            else
            {
                exprString = "";
            }
            return("endfilter " + exprString);
        }
Exemple #8
0
        private void Bg_worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker   = sender as BackgroundWorker;
            List <object>    listData = e.Argument as List <object>;

            DataListPrinting     dataContext          = listData[0] as DataListPrinting;
            DataPaperSizeSetting dataPaperSizeSetting = listData[1] as DataPaperSizeSetting;

            dataContext.IsEnableAll = false;

            List <BarCodePrinting> listprinting = dataContext.ListPrinting;
            int i = 1, max = listprinting.Count;

            foreach (BarCodePrinting printing in listprinting)
            {
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    try
                    {
                        printing.LayoutPaper = LayoutConvert.Convert(printing);
                        CodePrinter codePrinter = new CodePrinter(new PrinterSet()
                        {
                            PrinterSettings = dataContext.Printer,
                            Landscape       = dataContext.Landscape,
                            PaperSize       = new PaperSize("Customs Paper Size", dataPaperSizeSetting.BarcodeSizeW, dataPaperSizeSetting.BarcodeSizeH),
                            BarCode         = printing,
                            Horizontal      = dataPaperSizeSetting.Horizo
                        });
                        codePrinter.CodePrinter_EndPrint += CodePrinter_CodePrinter_EndPrint;
                        codePrinter.Print();

                        autoReset.WaitOne();
                        worker.ReportProgress(Convert.ToInt32(((double)i / max) * 100));

                        printing.Per     = 100;
                        printing.Success = true;

                        Thread.Sleep(500);
                        i++;
                    }
                    catch { }
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void InitFrom()
        {
            this.IsUseWeight  = Convert.ToBoolean(commonDAO.GetAppletConfigInt32("启用称重"));
            this._CodePrinter = new CodePrinter(printDocument1);

            // 生成编码按钮
            GridButtonXEditControl btnNewCode = superGridControl1.PrimaryGrid.Columns["gclmNewCode"].EditControl as GridButtonXEditControl;

            btnNewCode.ColorTable = eButtonColor.BlueWithBackground;
            btnNewCode.Click     += new EventHandler(btnNewCode_Click);
            // 打印编码按钮
            GridButtonXEditControl btnPrintCode = superGridControl1.PrimaryGrid.Columns["gclmPrintCode"].EditControl as GridButtonXEditControl;

            btnNewCode.ColorTable = eButtonColor.BlueWithBackground;
            btnPrintCode.Click   += new EventHandler(btnPrintCode_Click);
        }
Exemple #10
0
        internal static string Print(WrapperGenPackage genPkg)
        {
            var codeGen = new CodePrinter();

            codeGen.PrintLine("// Generated by github.com/davyxu/PhotonSharp");
            codeGen.PrintLine("// DO NOT EDIT!!");

            codeGen.PrintLine("using Photon;");
            codeGen.PrintLine("using System;");
            codeGen.PrintLine();

            codeGen.PrintLine("namespace ", genPkg.Name);
            codeGen.PrintLine("{");
            codeGen.In();

            foreach (var cls in genPkg.Classes)
            {
                codeGen.PrintLine("[NativeWrapperClass(typeof(", cls.FullName, "))]");
                codeGen.PrintLine("public class ", cls.Name, "Wrapper");
                codeGen.PrintLine("{");
                codeGen.In();

                foreach (var prop in cls.Properties)
                {
                    GenProperty(codeGen, prop, cls);
                    codeGen.PrintLine();
                }

                foreach (var method in cls.Methods)
                {
                    GenStaticOrMethod(codeGen, method, cls);
                    codeGen.PrintLine();
                }

                codeGen.Out();
                codeGen.PrintLine("}");
            }



            codeGen.Out();
            codeGen.PrintLine("}");


            return(codeGen.ToString());
        }
Exemple #11
0
        /// <summary>
        /// Example use of the CodePrinter class: prints the code of all the methods
        /// from an application rooted in a specific assembly file.
        /// </summary>
        /// <param name="args">Root assembly of the analyzed program.</param>
        public static void TestMain(string[] args)
        {
            AssemblyNode an = AssemblyNode.GetAssembly(args[0]);

            if (an == null)
            {
                Console.WriteLine("assembly \"{0}\" not found", args[0]);
                Environment.Exit(1);
            }

            ClassHierarchy ch = new ClassHierarchy(args[0]); //DataStructUtil.singleton(an));

            foreach (Method method in ch.AllMethods())
            {
                CodePrinter.PrintMethod(Console.Out, method);
            }
        }
Exemple #12
0
        public void FinishLoading()
        {
            TemplateMain m = TemplateMain.Instance();

            m.Cursor              = Cursors.WaitCursor;
            m.StatusLabel.Text    = "Loading";
            m.StatusLabel.Visible = false;                   // wordt toch niet getoond...(?)
            m.StatusLabel.Invalidate();
            m.ProgressBar.Value   = 0;
            m.ProgressBar.Maximum = 100;
            m.ProgressBar.Visible = true;

            try
            {
                Parser p = new Parser();
                m_codelines = p.Load(m_templatefilename);
                CodePrinter cp = new CodePrinter(txtText);
                //BuildPossibleIdentifiersList(File.ReadAllLines(m_templatefilename));
                foreach (CodeLine c in m_codelines)
                {
                    m.ProgressBar.Value = (c.Linenr * 100 / m_codelines.Count);
                    c.Accept(cp);
                    cp.NextLine();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                m.ProgressBar.Visible = false;
                m.StatusLabel.Visible = false;
                m.Cursor = Cursors.Default;
            }

            /*
             * foreach (KnownVariable k in globalvars)
             * {
             *  lstAlleMogelijkheden.Items.Add(k);
             * }
             */
        }
Exemple #13
0
        private static string CatchToString(Catch c)
        {
            StringBuilder sb = new StringBuilder();

            if (c.Variable == null)
            {
                sb.Append("top_of_stack");
            }
            else
            {
                sb.Append(CodePrinter.expression2str(c.Variable));
            }
            sb.Append(" = catch(");
            if (c.Type != null)
            {
                sb.Append(c.Type.FullName);
            }
            sb.Append(")");
            return(sb.ToString());
        }
Exemple #14
0
        static void GenProperty(CodePrinter codeGen, WrapperGenProperty prop, WrapperGenClass cls)
        {
            codeGen.PrintLine("[NativeEntry(NativeEntryType.Property)]");
            codeGen.PrintLine("public static void ", prop.Name, "(object phoIns, ref object value, bool isGet )");
            codeGen.PrintLine("{");
            codeGen.In();

            codeGen.PrintLine("var phoClassIns = phoIns as ", cls.Name, ";");
            codeGen.PrintLine();

            if (prop.CanRead)
            {
                codeGen.PrintLine("if (isGet)");
                codeGen.PrintLine("{");
                codeGen.In();
                codeGen.PrintLine("value = Convertor.", prop.TypeString, "ToValue(phoClassIns.", prop.Name, ");");
                codeGen.Out();
                codeGen.PrintLine("}");
            }


            if (prop.CanWrite)
            {
                if (prop.CanRead)
                {
                    codeGen.PrintLine("else");
                }

                codeGen.PrintLine("{");
                codeGen.In();
                codeGen.PrintLine("phoClassIns.", prop.Name, " = Convertor.ValueTo", prop.TypeString, "(value);");
                codeGen.Out();
                codeGen.PrintLine("}");
            }


            codeGen.Out();
            codeGen.PrintLine("}");
        }
Exemple #15
0
 private static string bo2s(object block)
 {
     return(CodePrinter.b2s((Block)block));
 }
Exemple #16
0
        static void GenStaticOrMethod(CodePrinter codeGen, WrapperGenFunc func, WrapperGenClass cls)
        {
            if (func.Mode == WrapperFuncMode.ClassMethod)
            {
                codeGen.PrintLine("[NativeEntry(NativeEntryType.ClassMethod)]");
            }
            else
            {
                codeGen.PrintLine("[NativeEntry(NativeEntryType.StaticFunc)]");
            }



            codeGen.PrintLine("public static int ", func.Name, "( VMachine phoVM )");
            codeGen.PrintLine("{");
            codeGen.In();

            if (func.Mode == WrapperFuncMode.ClassMethod)
            {
                codeGen.PrintLine("var phoClassIns = phoVM.DataStack.GetNativeInstance<", cls.FullName, ">(0);");
                codeGen.PrintLine();
            }


            // 获取输入参数
            int argIndex = 1;

            foreach (var pm in func.InputParameters)
            {
                codeGen.PrintLine("var ", pm.Name, " = phoVM.DataStack.Get", pm.TypeString, "(", argIndex, ");");

                argIndex++;
            }

            if (argIndex > 1)
            {
                codeGen.PrintLine();
            }

            // 声明输出参数
            argIndex = 1;
            foreach (var pm in func.OutputParameters)
            {
                codeGen.PrintLine(pm.NativeTypeString, " ", pm.Name, " = default(", pm.NativeTypeString, ");");

                argIndex++;
            }

            // 调用本体函数
            codeGen.BeginLine();

            if (func.RetParameter.NativeTypeString != "Nil" &&
                func.RetParameter.NativeTypeString != "Void")
            {
                codeGen.Print("var phoRetArg = ");
            }


            if (func.Mode == WrapperFuncMode.ClassMethod)
            {
                codeGen.Print("phoClassIns.", func.Name, "( ");
            }
            else
            {
                codeGen.Print(cls.FullName, ".", func.Name, "( ");
            }


            // 传入输入参数
            argIndex = 1;
            foreach (var pm in func.InputParameters)
            {
                if (argIndex > 1)
                {
                    codeGen.Print(", ");
                }

                codeGen.Print(pm.Name);

                argIndex++;
            }

            // 传入输出参数
            foreach (var pm in func.OutputParameters)
            {
                if (argIndex > 1)
                {
                    codeGen.Print(", ");
                }

                codeGen.Print("out ", pm.Name);

                argIndex++;
            }

            codeGen.Print(" );\n");

            codeGen.EndLine();

            // 栈推入输出参数
            foreach (var pm in func.OutputParameters)
            {
                codeGen.PrintLine("phoVM.DataStack.Push", pm.TypeString, "( ", pm.Name, " );");

                argIndex++;
            }

            int totalRet = func.OutputParameters.Count;

            // 栈推入返回参数
            if (func.RetParameter.TypeString != "Nil")
            {
                codeGen.PrintLine("phoVM.DataStack.Push", func.RetParameter.TypeString, "( phoRetArg );");
                totalRet++;
            }



            // 返回返回值数量
            codeGen.PrintLine();

            codeGen.PrintLine("return ", totalRet, ";");


            codeGen.Out();
            codeGen.PrintLine("}");
        }
Exemple #17
0
 public void InitFrom()
 {
     this._CodePrinter = new CodePrinter(printDocument1);
 }