private static void WriteXmlInstruction(XmlTextWriter xmltw, AbstractInstruction cinst) { switch (cinst.Name()) { case "call": case "execute": case "bcall": xmltw.WriteStartElement(cinst.Name()); xmltw.WriteAttributeString("name", cinst.ToString().Split(new char[] { ' ' })[1]); xmltw.WriteEndElement(); break; case "fcall": FCallInstruction fcinst = (FCallInstruction)cinst; xmltw.WriteStartElement(cinst.Name()); xmltw.WriteAttributeString("assembly", fcinst._assemblyName); xmltw.WriteAttributeString("class", fcinst._classType); xmltw.WriteAttributeString("method", fcinst._methodName); xmltw.WriteAttributeString("predicate", fcinst._predicateName); break; default: WriteXmlInstructionArguments(xmltw, cinst); break; } }
private static void WriteXmlInstructionArguments(XmlTextWriter xmltw, AbstractInstruction cinst) { switch (cinst.NumberOfArguments()) { case 0: xmltw.WriteStartElement(cinst.Name()); xmltw.WriteEndElement(); break; case 1: xmltw.WriteStartElement(cinst.Name()); xmltw.WriteAttributeString("arg1", cinst.ToString().Split(new char[] { ' ' })[1]); xmltw.WriteEndElement(); break; case 2: xmltw.WriteStartElement(cinst.Name()); if (cinst.Name() == "put_structure") { string args = cinst.ToString().Split(new char[] { ' ' })[1]; xmltw.WriteAttributeString("arg1", args.Split(new char[] { ',' })[0]); xmltw.WriteAttributeString("arg2", args.Split(new char[] { ',' })[1]); xmltw.WriteEndElement(); } else { if (cinst.ToString().IndexOf('"') != -1) { // put_constant "Hello, World", X0 string instStr = cinst.ToString(); string arg1 = instStr.Substring(instStr.IndexOf('"'), instStr.LastIndexOf('"') - instStr.IndexOf('"') + 1); string arg2 = instStr.Substring(instStr.LastIndexOf('"') + 2); xmltw.WriteAttributeString("arg1", arg1); xmltw.WriteAttributeString("arg2", arg2); xmltw.WriteEndElement(); } else if (cinst.ToString().IndexOf('\'') != -1) { // put_constant 'Hello, World', X0 string instStr = cinst.ToString(); string arg1 = instStr.Substring(instStr.IndexOf('\''), instStr.LastIndexOf('\'') - instStr.IndexOf('\'') + 1); string arg2 = instStr.Substring(instStr.LastIndexOf('\'') + 2); xmltw.WriteAttributeString("arg1", arg1); xmltw.WriteAttributeString("arg2", arg2); xmltw.WriteEndElement(); } else { string args = cinst.ToString().Split(new char[] { ' ' })[1]; xmltw.WriteAttributeString("arg1", args.Split(new char[] { ',' })[0]); xmltw.WriteAttributeString("arg2", args.Split(new char[] { ',' })[1]); xmltw.WriteEndElement(); } } break; } }
private bool CompareInstructions(AbstractInstruction i1, AbstractInstruction i2) { return i1.ToString() == i2.ToString(); }