Exemplo n.º 1
0
        public static void WriteClass(TypeDefinition def, ITextOutput output)
        {
            if (def.IsInterface || Helper.isClassAsEnum(def))
            {
                return;
            }
            WriteHeadStart(def.Name, output);
            output.WriteLine();
            output.WriteLine("#include <QuantKit/" + def.Name + ".h>");
            output.WriteLine();
            var info = InfoUtil.Info(def);

            if (info.IsBaseClassInModule)
            {
                output.WriteLine("#include <QSharedData>");
                output.WriteLine();
            }
            WriteIncludeBody(def, output);


            WriteClassBody(def, output);



            WriteHeadEnd(def.Name, output);
        }
Exemplo n.º 2
0
        static void WriteMethodHead(MethodDefinition def, ITextOutput output, bool isDeclaration)
        {
            if (def.IsConstructor && def.IsStatic)
            {
                return;
            }

            var  info = InfoUtil.Info(def);
            bool isCopyConstructor = info != null && info.isCopyConstructor;

            if (def.IsConstructor)
            {
                if (def.Parameters.Count() == 1 && !isCopyConstructor)
                {
                    output.Write("explicit ");
                }
                output.Write(def.DeclaringType.Name);
            }
            else
            {
                output.Write(info.ReturnTypeName);
                output.Write(" ");
                output.Write(info.Name);
            }
            output.Write("(");
            WriteParameters(def, output, isDeclaration);
            output.Write(")");

            /*if (modifiers.HasFlag(Modifiers.Override))
             * {
             *  output.Write(" Q_DECL_OVERRIDE");
             * }*/
        }
Exemplo n.º 3
0
        static void WriteForward(TypeDefinition def, ITextOutput output)
        {
            List <string> elist;
            List <string> mlist;
            List <string> clist;

            BuildIncludeList(def, out elist, out clist, out mlist);
            var info = InfoUtil.Info(def);

            if (info != null)
            {
                foreach (var m in clist)
                {
                    if (m != def.Name)
                    {
                        output.WriteLine("class " + m + ";");
                        //output.WriteLine("#include <QuantKit/" + m + ".h>");
                    }
                }
                if (clist.Count() > 0)
                {
                    output.WriteLine();
                }
            }
        }
Exemplo n.º 4
0
        static void WriteMethodHead(MethodDefinition def, ITextOutput output, bool isDeclaration)
        {
            if (def.IsConstructor && def.IsStatic)
            {
                return;
            }

            var  info = InfoUtil.Info(def);
            bool isCopyConstructor = info != null && info.isCopyConstructor;

            if (def.IsConstructor)
            {
                if (def.Parameters.Count() == 1 && !isCopyConstructor)
                {
                    output.Write("explicit ");
                }
                output.Write(def.DeclaringType.Name + "Private");
            }
            else
            {
                //if (info.modifiers.HasFlag(Modifiers.Virtual))
                //    output.Write("virtual ");
                output.Write(info.ReturnTypeName);
                output.Write(" ");
                output.Write(info.Name);
            }
            output.Write("(");
            WriteParameters(def, output, false);
            output.Write(")");
        }
Exemplo n.º 5
0
        static void WriteIncludeBody(TypeDefinition def, ITextOutput output)
        {
            List <string> externalList;
            List <string> moduleEnumOrInterfaceList;
            List <string> classList;

            BuildIncludeList(def, out externalList, out classList, out moduleEnumOrInterfaceList);

            var info = InfoUtil.Info(def);

            // include base private header file
            if (info.BaseTypeInModule != null)
            {
                output.WriteLine("#include \"" + info.BaseTypeInModule.Name + CppLanguage.HxxFileExtension + "\"");
            }

            foreach (var m in classList)
            {
                if (m != def.Name)
                {
                    output.WriteLine("#include \"" + m + CppLanguage.HxxFileExtension + "\"");
                    //output.WriteLine("#include <QuantKit/" + m + ".h>");
                }
            }
        }
Exemplo n.º 6
0
        static void WriteFieldMethodBody(FieldDefinition def, ITextOutput output, bool isRead)
        {
            var info = InfoUtil.Info(def);

            if (!isRead)
            {
                output.WriteLine("{");
                output.Indent();
                output.Write("d_ptr->");
                output.Write(info.GetterMethodName);
                output.WriteLine("(value);");
                output.Unindent();
                output.WriteLine("}");
            }
            else
            {
                output.WriteLine("{");
                output.Indent();
                string value = Util.GetDefaultValue(def.FieldType);
                output.WriteLine("return d_ptr->");
                output.Write(info.SetterMethodName);
                output.WriteLine("()");
                output.Unindent();
                output.WriteLine("}");
            }
        }
Exemplo n.º 7
0
        static void WriteMethod(MethodDefinition m, ITextOutput output)
        {
            if (m.IsConstructor && m.IsStatic)
            {
                return;
            }
            var info = InfoUtil.Info(m);

            if (m.DeclaringType.IsInterface || info.modifiers.HasFlag(Modifiers.Virtual) || info.modifiers.HasFlag(Modifiers.Override))
            {
                output.Write("virtual ");
            }

            WriteMethodHead(m, output, true);

            if (m.IsGetter)
            {
                output.Write(" const");
            }

            if (m.DeclaringType != null && m.DeclaringType.IsInterface)
            {
                output.WriteLine(" = 0;");
            }
            else
            {
                output.WriteLine(";");
            }
        }
Exemplo n.º 8
0
        public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options)
        {
            WriteCommentLine(output, TypeToString(ev.DeclaringType, includeNamespace: true));
            PreProcess(ev.Module);
            var info = InfoUtil.Info(ev);

            GenerateCode(info.Declaration, output);
        }
Exemplo n.º 9
0
        public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options)
        {
            WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true));
            PreProcess(property.Module);
            var info = InfoUtil.Info(property);

            GenerateCode(info.Declaration, output);
        }
Exemplo n.º 10
0
        public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
        {
            WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true));
            PreProcess(method.Module);
            var info = InfoUtil.Info(method);

            GenerateCode(info.Declaration, output);
        }
Exemplo n.º 11
0
        /*static void BuildIncludeList(TypeDefinition def, out List<string> externalList, out List<string> moduleClassList, out List<string> moduleEnumOrInterfaceList)
         * {
         *  List<string> elist = new List<string>();
         *  List<string> mlist = new List<string>();
         *  List<string> clist = new List<string>();
         *  bool hasBaseType = def.BaseType != null && def.BaseType.Name != "Object";
         *  if (hasBaseType)
         *      mlist.Add(def.BaseType.Name); // basetype must be include file
         *  if (def.HasInterfaces)
         *  {
         *      foreach (var i in def.Interfaces)
         *      {
         *          if (i.Module == def.Module)
         *              mlist.Add(i.Name);
         *          else
         *              elist.Add(i.Name);
         *      }
         *  }
         *  foreach (var m in def.Methods)
         *  {
         *      Util.AddInclude(def.Namespace, m.ReturnType, elist, clist, mlist);
         *      foreach (var p in m.Parameters)
         *          Util.AddInclude(def.Namespace, p.ParameterType, elist, clist, mlist);
         *      //special for currencyId
         *      foreach (var p in m.Parameters)
         *      {
         *          if (p.Name == "currencyId" && p.HasConstant && p.Constant != null)
         *              mlist.Add("CurrencyId");
         *      }
         *  }
         *  foreach (var f in def.Fields)
         *  {
         *      Util.AddInclude(def.Namespace, f.FieldType, elist, clist, mlist);
         *  }
         *
         *  externalList = elist.Distinct<string>().ToList();
         *  moduleClassList = clist.Distinct<string>().ToList();
         *  moduleEnumOrInterfaceList = mlist.Distinct<string>().ToList();
         * }
         *
         * static void WriteIncludeBody(TypeDefinition def, TypeDeclaration decl, ITextOutput output)
         * {
         *  List<string> externalList;
         *  List<string> moduleEnumOrInterfaceList;
         *  List<string> classList;
         *
         *  BuildIncludeList(def, out externalList, out classList, out moduleEnumOrInterfaceList);
         *
         *  foreach (var m in classList)
         *  {
         *      if (m != def.Name)
         *      {
         *          output.WriteLine("#include <QuantKit/" + m + ".h>");
         *      }
         *  }
         *
         *  var tevent = Util.GetTypeDefinition(def.Module, "Event");
         *  if (tevent == def || Util.isInhertFrom(def, tevent))
         *  {
         *      if (classList.Count() > 0)
         *          output.WriteLine();
         *      output.WriteLine("#include <QuantKit/EventType.h>");
         *  }
         * }*/

        /*static void process_getTypeId(MethodDefinition m, ITextOutput output)
         * {
         *  var decl = Util.getMethodDeclaration(m);
         *  var rlist = decl.Descendants.OfType<ReturnStatement>().ToList();
         *  if (rlist.Count() > 0)
         *  {
         *      var pexpr = rlist[0].Descendants.OfType<PrimitiveExpression>().ToList();
         *      if (pexpr.Count() > 0)
         *      {
         *          var v = pexpr[0].Value;
         *          output.Indent();
         *
         *          output.Unindent();
         *      }
         *
         *  }
         *
         * }*/
        static void WriteMethod(MethodDefinition m, ITextOutput output)
        {
            if (m.IsConstructor && m.IsStatic)
            {
                return;
            }
            if (m.DeclaringType != null && m.DeclaringType.IsInterface)
            {
                return;
            }

            var info = InfoUtil.Info(m);

            WriteMethodHead(m, output, true);
            if (m.IsGetter)
            {
                output.Write(" const");
            }
            output.WriteLine();
            output.WriteLine("{");
            // special process getTypeId

            if (info.Name == "getTypeId")
            {
                output.Indent();
                string rvalue;
                if (m.Name == "get_TypeId")
                {
                    rvalue = "EventType::" + m.DeclaringType.Name;
                }
                output.Unindent();
            }
            else
            {
                //output.Indent();
                foreach (var s in info.MethodBody)
                {
                    output.WriteLine(s);
                }
                //output.Unindent();
            }

            /*if (m.ReturnType.MetadataType != MetadataType.Void)
             * {
             *  output.Indent();
             *  string rvalue;
             *  if (m.Name == "get_TypeId")
             *      rvalue = "EventType::" + m.DeclaringType.Name;
             *  else
             *      rvalue = Util.GetDefaultValue(m.ReturnType);
             *  output.WriteLine("return " + rvalue + ";");
             *  output.Unindent();
             * }*/
            output.WriteLine("}");
        }
Exemplo n.º 12
0
 public void PreProcess(ModuleDefinition module)
 {
     //TODO find public && internal field reference
     if (!needPreProcess)
     {
         return;
     }
     InfoUtil.BuildModuleDict(module);
     Helper.BuildEventTypeTable(module);
     needPreProcess = false;
 }
Exemplo n.º 13
0
 internal void inValidCache()
 {
     foreach (var t in Module.Types)
     {
         var info = InfoUtil.Info(t);
         if (info != null)
         {
             info.inValidCache();
         }
     }
 }
Exemplo n.º 14
0
 internal void post()
 {
     ScanCode();
     foreach (var t in Module.Types)
     {
         var info = InfoUtil.Info(t);
         if (info != null)
         {
             info.post();
         }
     }
 }
Exemplo n.º 15
0
        static void WriteCtor(MethodDefinition m, ITextOutput output)
        {
            if (m.IsConstructor && m.IsStatic)
            {
                return;
            }
            if (m.DeclaringType != null && m.DeclaringType.IsInterface)
            {
                return;
            }

            var info = InfoUtil.Info(m);

            WriteMethodHead(m, output, true);
            output.WriteLine();
            var clist = info.CtorInitBody;

            if (clist.Count() > 0)
            {
                output.Indent();
                foreach (var s in clist)
                {
                    output.WriteLine(s);
                }
                output.Unindent();
            }
            output.WriteLine("{");
            // special process getTypeId

            if (info.Name == "getTypeId")
            {
                output.Indent();
                string rvalue;
                if (m.Name == "get_TypeId")
                {
                    rvalue = "EventType::" + m.DeclaringType.Name;
                }
                output.Unindent();
            }
            else
            {
                output.Indent();
                foreach (var s in info.MethodBody)
                {
                    output.WriteLine(s);
                }
                output.Unindent();
            }
            output.WriteLine("}");
        }
Exemplo n.º 16
0
        public static void WriteEnum(TypeDefinition def, ITextOutput output)
        {
            if (RenameUtil.EnumRenameDict.ContainsKey(def.FullName))
            {
                def.Name = RenameUtil.EnumRenameDict[def.FullName];
            }
            WriteHeadStart(def.Name, output);
            WriteNamespaceStart(def.Namespace, output);
            var info = InfoUtil.Info(def);

            WriteEnumBody(info, output);
            WriteNamespaceEnd(def.Namespace, output);
            WriteHeadEnd(def.Name, output);
        }
Exemplo n.º 17
0
        static void WriteMethod(MethodDefinition def, ITextOutput output)
        {
            if (def.IsConstructor && def.IsStatic)
            {
                return;
            }
            if (def.DeclaringType != null && def.DeclaringType.IsInterface)
            {
                return;
            }

            var info = InfoUtil.Info(def);

            if (def.IsConstructor)
            {
                output.Write(def.DeclaringType.Name + "::" + def.DeclaringType.Name);
            }
            else
            {
                output.Write(info.ReturnTypeName);
                output.Write(" ");
                output.Write(def.DeclaringType.Name + "::" + info.Name);
            }
            output.Write("(");
            WriteParameters(def, output, false);
            output.Write(")");
            if (def.IsGetter)
            {
                output.Write(" const");
            }

            output.WriteLine();
            output.WriteLine("{");
            if (!def.IsConstructor)
            {
                output.Indent();
                if (def.ReturnType.MetadataType != MetadataType.Void)
                {
                    output.Write("return ");
                }
                output.Write("d_ptr->");
                output.Write(info.Name);
                output.Write("(");
                WriteParameterNames(def, output);
                output.WriteLine(");");
                output.Unindent();
            }
            output.WriteLine("}");
        }
Exemplo n.º 18
0
        void special_init()
        {
            List <CtorInitInfo> ctorInitList = new List <CtorInitInfo>();

            // is sample member init
            foreach (var minit in this.method_body)
            {
                var vlist = minit.Replace(";", "").Split('=');
                if (vlist.Count() == 2)
                {
                    var variable = vlist[0].Trim();
                    var expr     = vlist[1].Trim();
                    foreach (var f in this.def.DeclaringType.Fields)
                    {
                        if (variable == f.Name)
                        {
                            var cinfo = new CtorInitInfo();
                            cinfo.field    = f;
                            cinfo.initExpr = expr;
                            cinfo.expr     = minit;
                            ctorInitList.Add(cinfo);
                            break;
                        }
                    }
                }
            }
            foreach (var cinfo in ctorInitList)
            {
                this.method_body.Remove(cinfo.expr);
            }

            // reorder list by filed order
            this.initList.Clear();
            foreach (var field in this.def.DeclaringType.Fields)
            {
                var info = InfoUtil.Info(field);
                if (info.modifiers.HasFlag(Modifiers.Const))
                {
                    continue;
                }
                foreach (var cinfo in ctorInitList)
                {
                    if (field == cinfo.field)
                    {
                        this.initList.Add(cinfo);
                    }
                }
            }
        }
Exemplo n.º 19
0
        internal void post()
        {
            foreach (var t in this.def.Module.Types)
            {
                if (t == this.def)
                {
                    continue;
                }
                if (Util.isInhertFrom(t, this.def))
                {
                    this.DerivedClasses.Add(t);
                }
            }

            foreach (var f in this.def.Fields)
            {
                FieldInfo info = InfoUtil.Info(f);
                if (info != null)
                {
                    info.post();
                }
            }
            foreach (var p in this.def.Properties)
            {
                PropertyInfo info = InfoUtil.Info(p);
                if (info != null)
                {
                    info.post();
                }
            }

            foreach (var m in this.def.Methods)
            {
                var info = InfoUtil.Info(m);
                if (info != null)
                {
                    info.post();
                }
            }
            foreach (var e in this.def.Events)
            {
                var info = InfoUtil.Info(e);
                if (info != null)
                {
                    info.post();
                }
            }
        }
Exemplo n.º 20
0
        public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
        {
            PreProcess(type.Module);
            var info = InfoUtil.Info(type);

            GenerateCode(info.Declaration, output);

            /*AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: type);
             * codeDomBuilder.AddType(type);
             * codeDomBuilder.RunTransformations(transformAbortCondition);
             * //RunTransformsAndGenerateCode(codeDomBuilder, output, options);
             * GenerateCplusplusCode(codeDomBuilder, output, OnlyIncludeNameSpace);*/
            WriteHppCode(type, output);
            WriteHxxCode(type, output);
            WriteCppCode(type, output);
        }
Exemplo n.º 21
0
        static void FindFieldAccess(TypeDefinition def, List <FieldDefinition> GetAndSet, List <FieldDefinition> onlyGet, List <FieldDefinition> onlySet)
        {
            List <FieldDefinition> gets = new List <FieldDefinition>();
            List <FieldDefinition> sets = new List <FieldDefinition>();

            foreach (var f in def.Fields)
            {
                var info = InfoUtil.Info(f);
                if (info != null)
                {
                    if (info.ReadByOther.Count() > 0 || info.AssignByOther.Count() > 0)
                    {
                        if (info.DeclareProperty == null)
                        {
                            gets.Add(f);
                        }
                    }

                    if (info.AssignByOther.Count() > 0)
                    {
                        if (info.DeclareProperty == null)
                        {
                            sets.Add(f);
                        }
                    }
                }
            }

            foreach (var f in gets)
            {
                if (sets.Contains(f))
                {
                    GetAndSet.Add(f);
                    sets.Remove(f);
                }
                else
                {
                    onlyGet.Add(f);
                }
            }

            foreach (var f in sets)
            {
                onlySet.Add(f);
            }
        }
Exemplo n.º 22
0
 static void WriteFields(TypeDefinition def, ITextOutput output)
 {
     if (def.Fields.Count() > 0)
     {
         output.WriteLine("public:");
         output.Indent();
         foreach (var f in def.Fields)
         {
             var info = InfoUtil.Info(f);
             output.Write(info.FieldTypeName);
             output.Write(" ");
             output.Write(f.Name);
             output.WriteLine(";");
         }
         output.Unindent();
         output.WriteLine();
     }
 }
Exemplo n.º 23
0
        public static bool IsNeedWriteHxx(TypeDefinition def, string @namespace = null)
        {
            var info = InfoUtil.Info(def);

            if (def != null && (@namespace == null || (@namespace != null && def.Namespace == @namespace)))
            {
                if (def.IsEnum || def.IsInterface || isSkipClass(def))
                {
                    return(false);
                }
                if (def.Name == "EventType" || def.Name == "CurrencyId")
                {
                    return(false);
                }
                if (info != null && !info.HasDerivedClass)
                {
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 24
0
        static void WriteFieldAsMethod(FieldDefinition field, ITextOutput output, bool isGetter)
        {
            var info = InfoUtil.Info(field);

            if (info == null)
            {
                Console.WriteLine("Error");
                return;
            }

            /*var name = field.Name;
             * if (field.Name.StartsWith("m_"))
             *  name = field.Name.Remove(0, 2);*/

            if (isGetter)
            {
                bool   isValueType;
                string type = Util.TypeString(field.FieldType, out isValueType);
                output.Write(type);
                output.Write(" ");
                //output.Write("get");
                //output.Write(Util.upperFirstChar(name));
                output.Write(info.GetterMethodName);
                output.WriteLine("() const;");
            }
            else
            {
                bool   isValueType;
                string type = Util.TypeString(field.FieldType, out isValueType);
                output.Write("void ");
                //output.Write(Util.upperFirstChar(name));
                //output.Write("(");
                output.Write(info.SetterMethodName);
                output.Write("(");
                output.Write(type);
                output.WriteLine(" value);");
            }
        }
Exemplo n.º 25
0
        static void WriteMethodHead(MethodDefinition def, ITextOutput output, bool isDeclaration)
        {
            if (def.IsConstructor && def.IsStatic)
            {
                return;
            }

            var info = InfoUtil.Info(def);

            if (def.IsConstructor)
            {
                output.Write(def.DeclaringType.Name + "::" + def.DeclaringType.Name);
            }
            else
            {
                output.Write(info.ReturnTypeName);
                output.Write(" ");
                output.Write(def.DeclaringType.Name + "::" + info.Name);
            }
            output.Write("(");
            WriteParameters(def, output, false);
            output.Write(")");
        }
Exemplo n.º 26
0
        internal void inValidCache()
        {
            foreach (var f in this.def.Fields)
            {
                FieldInfo info = InfoUtil.Info(f);
                if (info != null)
                {
                    info.inValidCache();
                }
            }
            foreach (var p in this.def.Properties)
            {
                PropertyInfo info = InfoUtil.Info(p);
                if (info != null)
                {
                    info.inValidCache();
                }
            }

            foreach (var m in this.def.Methods)
            {
                var info = InfoUtil.Info(m);
                if (info != null)
                {
                    info.inValidCache();
                }
            }
            foreach (var e in this.def.Events)
            {
                var info = InfoUtil.Info(e);
                if (info != null)
                {
                    info.inValidCache();
                }
            }
            this.decl = null;
        }
Exemplo n.º 27
0
        static void WriteFieldAsMethod(FieldDefinition field, ITextOutput output, bool isGetter)
        {
            var info = InfoUtil.Info(field);

            if (isGetter)
            {
                bool   isValueType;
                string type = Util.TypeString(field.FieldType, out isValueType);
                output.Write(type);
                output.Write(" ");
                output.Write(info.GetterMethodName);
                output.WriteLine("() const");
            }
            else
            {
                bool   isValueType;
                string type = Util.TypeString(field.FieldType, out isValueType);
                output.Write("void ");
                output.Write(info.SetterMethodName);
                output.Write("(");
                output.Write(type);
                output.WriteLine(" value)");
            }
        }
Exemplo n.º 28
0
        public static void WriteClass(TypeDefinition def, ITextOutput output)
        {
            if (def.IsInterface || Helper.isClassAsEnum(def))
            {
                return;
            }
            output.WriteLine("#include <QuantKit/" + def.Name + ".h>");
            output.WriteLine();
            WriteIncludeBody(def, output);
            var  info         = InfoUtil.Info(def);
            bool isFinalClass = info != null && !info.HasDerivedClass;

            if (!CppLanguage.IsNeedWriteHxx(def))
            {
                if (info.BaseTypeInModule != null)
                {
                    output.WriteLine("#include \"" + info.BaseTypeInModule.Name + CppLanguage.HxxFileExtension + "\"");
                }
                var tevent = Util.GetTypeDefinition(def.Module, "Event");
                if (tevent == def || Util.isInhertFrom(def, tevent))
                {
                    if (!CppLanguage.IsNeedWriteHxx(def))
                    {
                        output.WriteLine("#include <QuantKit/EventType.h>");
                    }
                }
                Hxx.WriteClassBody(def, output);
            }
            else
            {
                output.WriteLine("#include \"" + def.Name + CppLanguage.HxxFileExtension + "\"");
            }
            //output.WriteLine("#include <QuantKit/" + def.Name + CppLanguage.HxxFileExtension + ">");
            //output.WriteLine();
            //WriteIncludeBody(def, output);
            output.WriteLine();
            output.WriteLine("using namespace QuantKit;");
            //output.WriteLine("using namespace QuantKit::Internal;");
            output.WriteLine();
            //WriteNamespaceStart(def.Namespace, output);
            //output.WriteLine("namespace Internal {");
            //output.WriteLine();
            Cxx.WritePrivateClassBody(def, output);

            //output.WriteLine("} // namespace Internal");
            output.WriteLine();

            output.WriteLine("// Pubic API ");
            output.WriteLine();

            WriteProxyClassBody(def, output);

            if (!def.IsInterface && !Helper.isClassAsEnum(def))
            {
                output.WriteLine();
                output.WriteLine("QDataStream& " + def.Name + "::operator<<(QDataStream &stream, const " + def.Name + " &" + def.Name.ToLower() + ")");
                output.WriteLine("{");
                output.Indent();
                output.WriteLine("return stream << " + def.Name.ToLower() + ".toString();");
                output.Unindent();
                output.WriteLine("}");
            }

            output.WriteLine();
            //WriteNamespaceEnd(def.Namespace, output);
        }
Exemplo n.º 29
0
        static void WriteClassBody(TypeDefinition def, ITextOutput output)
        {
            if (def.Name == "CurrencyId")
            {
                Helper.WriteCurrencyIdInclude(def, output);
                return;
            }
            if (def.Name == "EventType")
            {
                Helper.WriteEventTypeInclude(def, output);
                return;
            }

            List <MethodDefinition> ctorSections     = new List <MethodDefinition>();
            List <MethodDefinition> publicSections   = new List <MethodDefinition>();
            List <MethodDefinition> protectedSection = new List <MethodDefinition>();
            List <MethodDefinition> privateSection   = new List <MethodDefinition>();

            ConvertToSection(def, ctorSections, publicSections, protectedSection, privateSection);

            List <FieldDefinition> GetAndSet = new List <FieldDefinition>();
            List <FieldDefinition> OnlyGet   = new List <FieldDefinition>();
            List <FieldDefinition> OnlySet   = new List <FieldDefinition>();

            FindFieldAccess(def, GetAndSet, OnlyGet, OnlySet);

            WriteClassHead(def, output);
            output.WriteLine();
            output.WriteLine("{");

            /* write ctor section */
            if (ctorSections.Count() > 0)
            {
                output.WriteLine("public:");
                output.Indent();

                var tinfo = InfoUtil.Info(def);
                //if (tinfo != null && tinfo.NullConstructor == null)
                //    WriteDefaultNullConstructor(def, output);
                if (tinfo != null && tinfo.CopyConstructor == null)
                {
                    WriteDefaultCopyConstructor(def, output);
                }
                foreach (var m in ctorSections)
                {
                    WriteMethod(m, output);
                }
                WriteAddCppMethod(def, output);
                output.Unindent();
                if (publicSections.Count() > 0)// || protectedSection.Count() > 0 || privateSection.Count() > 0)
                {
                    output.WriteLine();
                }
            }

            /* write public method */
            if (publicSections.Count() > 0)
            {
                output.WriteLine("public:");
                output.Indent();
                /* write filed as method */
                for (int i = 0; i < GetAndSet.Count(); ++i)
                {
                    var f = GetAndSet[i];
                    WriteFieldAsMethod(f, output, true);
                    WriteFieldAsMethod(f, output, false);
                    if (i < GetAndSet.Count() - 1)
                    {
                        output.WriteLine();
                    }
                }
                if (GetAndSet.Count() > 0 && OnlySet.Count() > 0)
                {
                    output.WriteLine();
                }

                for (int i = 0; i < OnlySet.Count(); ++i)
                {
                    var f = OnlySet[i];
                    WriteFieldAsMethod(f, output, true);
                    WriteFieldAsMethod(f, output, false);
                    if (i < OnlySet.Count() - 1)
                    {
                        output.WriteLine();
                    }
                }

                if (OnlyGet.Count() > 0 && (GetAndSet.Count() > 0 || OnlySet.Count() > 0))
                {
                    output.WriteLine();
                }
                for (int i = 0; i < OnlyGet.Count(); ++i)
                {
                    var f = OnlyGet[i];
                    WriteFieldAsMethod(f, output, true);
                    if (i < OnlyGet.Count() - 1)
                    {
                        output.WriteLine();
                    }
                }

                if (publicSections.Count() > 0 && (GetAndSet.Count() > 0 || OnlySet.Count() > 0 || OnlyGet.Count() > 0))
                {
                    output.WriteLine();
                }

                foreach (var m in publicSections)
                {
                    WriteMethod(m, output);
                }
                output.Unindent();
                //if (protectedSection.Count() > 0 || privateSection.Count() > 0)
                //    output.WriteLine();
            }

            /* write protected section */
            var  cinfo          = InfoUtil.Info(def);
            bool hasChildClass  = cinfo != null && cinfo.HasDerivedClass;
            bool isDerivedClass = cinfo != null && cinfo.isDerivedClass;

            if (!def.IsInterface && !Helper.isClassAsEnum(def) && hasChildClass)//hasChildClass(def))
            {
                output.WriteLine();
                output.WriteLine("protected:");
                output.Indent();
                output.WriteLine(def.Name + "(" + def.Name + "Private& dd);");
                if (!isDerivedClass)
                {
                    output.WriteLine("QSharedDataPointer<" + def.Name + "Private> d_ptr;");
                }
                output.Unindent();
            }

            if (!def.IsInterface && !Helper.isClassAsEnum(def))
            {
                output.WriteLine();
                output.WriteLine("private:");
                output.Indent();
                //if (!hasChildClass(def))
                if (!hasChildClass && !isDerivedClass)
                {
                    output.WriteLine("QSharedDataPointer<" + def.Name + "Private> d_ptr;");
                    output.WriteLine();
                }
                output.WriteLine("friend QUANTKIT_EXPORT QDataStream &operator<<(QDataStream & stream, const " + def.Name + " &" + def.Name.ToLower() + ");");
                output.Unindent();
            }

            /*if (protectedSection.Count() > 0)
             * {
             *  output.WriteLine("protected:");
             *  output.Indent();
             *  foreach (var m in protectedSection)
             *  {
             *      WriteMethod(m, output);
             *  }
             *  output.Unindent();
             *  if (privateSection.Count() > 0)
             *      output.WriteLine();
             * }*/

            /* write private section */

            /*if (privateSection.Count() > 0)
             * {
             *  output.WriteLine("private:");
             *  output.Indent();
             *  foreach (var m in privateSection)
             *  {
             *      WriteMethod(m, output);
             *  }
             *  output.Unindent();
             * }*/

            output.WriteLine("};");
        }
Exemplo n.º 30
0
        public static void WriteClassBody(TypeDefinition def, ITextOutput output)
        {
            WriteNamespaceStart(def.Namespace, output);
            List <MethodDefinition> ctorSections     = new List <MethodDefinition>();
            List <MethodDefinition> publicSections   = new List <MethodDefinition>();
            List <MethodDefinition> protectedSection = new List <MethodDefinition>();
            List <MethodDefinition> privateSection   = new List <MethodDefinition>();

            ConvertToSection(def, ctorSections, publicSections, protectedSection, privateSection);

            List <FieldDefinition> GetAndSet = new List <FieldDefinition>();
            List <FieldDefinition> OnlyGet   = new List <FieldDefinition>();
            List <FieldDefinition> OnlySet   = new List <FieldDefinition>();

            FindFieldAccess(def, GetAndSet, OnlyGet, OnlySet);

            var info     = InfoUtil.Info(def);
            var baseType = info.BaseTypeInModule;

            if (baseType != null)
            {
                output.Write("class " + def.Name + "Private : public " + baseType.Name + "Private");
            }
            else
            {
                output.Write("class " + def.Name + "Private : public QSharedData");
            }
            output.WriteLine();
            output.WriteLine("{");
            WriteFields(def, output);
            /* write ctor section */
            if (ctorSections.Count() > 0)
            {
                output.WriteLine("public:");
                output.Indent();

                foreach (var m in ctorSections)
                {
                    WriteMethod(m, output);
                }
                WriteAddCppMethod(def, output);
                output.Unindent();
                if (publicSections.Count() > 0 || protectedSection.Count() > 0 || privateSection.Count() > 0)
                {
                    output.WriteLine();
                }
            }

            /* write public method */
            if (publicSections.Count() > 0)
            {
                output.WriteLine("public:");
                output.Indent();
                /* write filed as method */
                for (int i = 0; i < GetAndSet.Count(); ++i)
                {
                    var f = GetAndSet[i];
                    WriteFieldAsMethod(f, output, true);
                    WriteFieldAsMethod(f, output, false);
                    if (i < GetAndSet.Count() - 1)
                    {
                        output.WriteLine();
                    }
                }
                if (GetAndSet.Count() > 0 && OnlySet.Count() > 0)
                {
                    output.WriteLine();
                }

                for (int i = 0; i < OnlySet.Count(); ++i)
                {
                    var f = OnlySet[i];
                    WriteFieldAsMethod(f, output, true);
                    WriteFieldAsMethod(f, output, false);
                    if (i < OnlySet.Count() - 1)
                    {
                        output.WriteLine();
                    }
                }

                if (OnlyGet.Count() > 0 && (GetAndSet.Count() > 0 || OnlySet.Count() > 0))
                {
                    output.WriteLine();
                }
                for (int i = 0; i < OnlyGet.Count(); ++i)
                {
                    var f = OnlyGet[i];
                    WriteFieldAsMethod(f, output, true);
                    if (i < OnlyGet.Count() - 1)
                    {
                        output.WriteLine();
                    }
                }

                if (publicSections.Count() > 0 && (GetAndSet.Count() > 0 || OnlySet.Count() > 0 || OnlyGet.Count() > 0))
                {
                    output.WriteLine();
                }

                foreach (var m in publicSections)
                {
                    WriteMethod(m, output);
                }
                output.Unindent();
                if (protectedSection.Count() > 0 || privateSection.Count() > 0)
                {
                    output.WriteLine();
                }
            }

            /* write protected section */
            if (!def.IsInterface && !Helper.isClassAsEnum(def) && hasChildClass(def))
            {
                if (protectedSection.Count() > 0)
                {
                    output.WriteLine("//protected");
                    output.Indent();
                    foreach (var m in protectedSection)
                    {
                        WriteMethod(m, output);
                    }
                    output.Unindent();
                    if (privateSection.Count() > 0)
                    {
                        output.WriteLine();
                    }
                }
            }

            if (!def.IsInterface && !Helper.isClassAsEnum(def))
            {
                if (privateSection.Count() > 0)
                {
                    output.WriteLine("//private:");
                    output.Indent();
                    foreach (var m in privateSection)
                    {
                        WriteMethod(m, output);
                    }
                    output.Unindent();
                }
            }
            output.WriteLine("};");
            WriteNamespaceEnd(def.Namespace, output);
        }