Example #1
0
 private void DefineAllTypes(CodeWriter writer)
 {
     writer.Write("#pragma once");
     writer.NewLine();
     writer.Write("#include <e/system/basic_type.h>");
     ReferenceEocLibs(writer);
     using (writer.NewNamespace(TypeNamespace))
     {
         using (writer.NewNamespace("eoc_internal"))
         {
             EocStruct.DefineRawName(this, writer, EocStructs);
             EocObjectClass.DefineRawName(this, writer, EocObjectClasses);
         }
         EocStruct.DefineName(this, writer, EocStructs);
         EocObjectClass.DefineName(this, writer, EocObjectClasses);
         using (writer.NewNamespace("eoc_internal"))
         {
             EocStruct.DefineRawStructInfo(this, writer, EocStructs);
             EocObjectClass.DefineRawObjectClass(this, writer, EocObjectClasses);
         }
     }
     using (writer.NewNamespace("e::system"))
     {
         EocStruct.DefineStructMarshaler(this, writer, EocStructs);
     }
 }
Example #2
0
 public static void Implement(ProjectConverter P, CodeWriter writer, SortedDictionary <int, EocDll> map)
 {
     writer.Write("#include \"dll.h\"");
     writer.NewLine();
     writer.Write("#include <e/system/dll_core.h>");
     writer.NewLine();
     writer.Write("#include <e/system/methodptr_caller.h>");
     using (writer.NewNamespace(P.DllNamespace))
     {
         var moduleMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
         var funcMap   = new Dictionary <Tuple <string, string>, string>();
         var eocDlls   = map.Values.ToList();
         for (int i = 0, j = 0, k = 0; i < eocDlls.Count; i++)
         {
             var item = eocDlls[i];
             if (!moduleMap.TryGetValue(item.LibraryName, out var dllIdInCpp))
             {
                 dllIdInCpp = (j++).ToString();
                 moduleMap.Add(item.LibraryName, dllIdInCpp);
             }
             var dllEntryPointPair = new Tuple <string, string>(dllIdInCpp, item.EntryPoint);
             if (!funcMap.ContainsKey(dllEntryPointPair))
             {
                 funcMap.Add(dllEntryPointPair, (k++).ToString());
             }
         }
         using (writer.NewNamespace("eoc_module"))
         {
             foreach (var item in moduleMap)
             {
                 writer.NewLine();
                 writer.Write($"eoc_DefineMoudleLoader({item.Value}, \"{item.Key}\");");
             }
         }
         using (writer.NewNamespace("eoc_func"))
         {
             foreach (var item in funcMap)
             {
                 var entryPointExpr = item.Key.Item2;
                 if (entryPointExpr.StartsWith("#"))
                 {
                     entryPointExpr = $"reinterpret_cast<const char *>({Convert.ToInt32(entryPointExpr.Substring(1))})";
                 }
                 else
                 {
                     entryPointExpr = $"\"{entryPointExpr}\"";
                 }
                 writer.NewLine();
                 writer.Write($"eoc_DefineFuncPtrGetter({item.Value}, {P.DllNamespace}::eoc_module::GetMoudleHandle_{item.Key.Item1}(), {entryPointExpr});");
             }
         }
         foreach (var item in eocDlls)
         {
             item.ImplementItem(writer, moduleMap, funcMap);
         }
     }
 }
Example #3
0
        public void ImplementRawObjectClass(CodeWriter writer)
        {
            writer.Write("#include \"../../../stdafx.h\"");
            using (writer.NewNamespace(P.TypeNamespace))
            {
                bool hasInitMethod    = Method.Where(x => x.MethodItem.Name == "_初始化").FirstOrDefault() != null;
                bool hasDestroyMethod = Method.Where(x => x.MethodItem.Name == "_销毁").FirstOrDefault() != null;
                using (writer.NewNamespace("eoc_internal"))
                {
                    writer.NewLine();
                    writer.Write($"{RawName}::{RawName}()");
                    if (RawInfo.Variables.Length != 0)
                    {
                        writer.Write(": ");
                        P.InitMembersInConstructor(writer, RawInfo.Variables);
                    }
                    using (writer.NewBlock())
                    {
                        if (hasInitMethod)
                        {
                            writer.NewLine();
                            writer.Write("this->_初始化();");
                        }
                    }
                    writer.NewLine();
                    writer.Write($"{RawName}::~{RawName}()");
                    using (writer.NewBlock())
                    {
                        if (hasDestroyMethod)
                        {
                            writer.NewLine();
                            writer.Write("this->_销毁();");
                        }
                    }

                    writer.NewLine();
                    writer.Write($"{RawName}::{RawName}(const {RawName}&) = default;");

                    writer.NewLine();
                    writer.Write($"e::system::basic_object* {RawName}::clone()");
                    using (writer.NewBlock())
                    {
                        writer.NewLine();
                        writer.Write($"return new {RawName}(*this);");
                    }

                    foreach (var item in Method)
                    {
                        item.ImplementItem(writer);
                    }
                }
            }
        }
Example #4
0
        public void ImplementRawObjectClass(CodeWriter writer)
        {
            writer.Write("#include \"../../../stdafx.h\"");
            using (writer.NewNamespace(P.TypeNamespace))
            {
                var initMethod    = Method.Values.Where(x => x.MethodItem.Name == "_初始化").FirstOrDefault();
                var destroyMethod = Method.Values.Where(x => x.MethodItem.Name == "_销毁").FirstOrDefault();
                using (writer.NewNamespace("eoc_internal"))
                {
                    writer.NewLine();
                    writer.Write($"{RawName}::{RawName}()");
                    if (MemberInfoMap.Count != 0)
                    {
                        writer.Write(": ");
                        P.InitMembersInConstructor(writer, MemberInfoMap.Values);
                    }
                    using (writer.NewBlock())
                    {
                        if (initMethod != null)
                        {
                            writer.NewLine();
                            writer.Write($"this->{initMethod.Name}();");
                        }
                    }
                    writer.NewLine();
                    writer.Write($"{RawName}::~{RawName}()");
                    using (writer.NewBlock())
                    {
                        if (destroyMethod != null)
                        {
                            writer.NewLine();
                            writer.Write($"this->{destroyMethod.Name}();");
                        }
                    }

                    writer.NewLine();
                    writer.Write($"{RawName}::{RawName}(const {RawName}&) = default;");

                    writer.NewLine();
                    writer.Write($"e::system::basic_object* {RawName}::clone()");
                    using (writer.NewBlock())
                    {
                        writer.NewLine();
                        writer.Write($"return new {RawName}(*this);");
                    }

                    foreach (var item in Method.Values)
                    {
                        item.ImplementNormalItem(writer);
                    }
                }
            }
        }
Example #5
0
 public static void Implement(ProjectConverter P, CodeWriter writer, EocDll[] eocDlls)
 {
     writer.Write("#include \"dll.h\"");
     writer.NewLine();
     writer.Write("#include <e/system/dll_core.h>");
     writer.NewLine();
     writer.Write("#include <e/system/methodptr_caller.h>");
     using (writer.NewNamespace(P.DllNamespace))
     {
         var moduleMap = new Dictionary <string, string>();
         var funcMap   = new Dictionary <Tuple <string, string>, string>();
         for (int i = 0, j = 0, k = 0; i < eocDlls.Length; i++)
         {
             var item = eocDlls[i];
             if (!moduleMap.TryGetValue(item.LibraryName, out var dllIdInCpp))
             {
                 dllIdInCpp = (j++).ToString();
                 moduleMap.Add(item.LibraryName, dllIdInCpp);
             }
             var dllEntryPointPair = new Tuple <string, string>(dllIdInCpp, item.EntryPoint);
             if (!funcMap.ContainsKey(dllEntryPointPair))
             {
                 funcMap.Add(dllEntryPointPair, (k++).ToString());
             }
         }
         using (writer.NewNamespace("eoc_module"))
         {
             foreach (var item in moduleMap)
             {
                 writer.NewLine();
                 writer.Write($"eoc_DefineMoudleLoader({item.Value}, \"{item.Key}\");");
             }
         }
         using (writer.NewNamespace("eoc_func"))
         {
             foreach (var item in funcMap)
             {
                 writer.NewLine();
                 writer.Write($"eoc_DefineFuncPtrGetter({item.Value}, {P.DllNamespace}::eoc_module::GetMoudleHandle_{item.Key.Item1}(), \"{item.Key.Item2}\");");
             }
         }
         foreach (var item in eocDlls)
         {
             item.ImplementItem(writer, moduleMap, funcMap);
         }
     }
 }
Example #6
0
 public void Implement(CodeWriter writer)
 {
     writer.Write("#include \"../../../stdafx.h\"");
     using (writer.NewNamespace(P.CmdNamespace))
     {
         if (RawInfo.Variables.Length > 0)
         {
             using (writer.NewNamespace(Name))
             {
                 P.DefineVariable(writer, new string[] { "static" }, RawInfo.Variables);
             }
         }
         foreach (var item in Method)
         {
             item.ImplementItem(writer);
         }
     }
 }
Example #7
0
 public static void Implement(ProjectConverter P, CodeWriter writer, EocGlobalVariable[] collection)
 {
     writer.Write("#include \"global.h\"");
     using (writer.NewNamespace(P.GlobalNamespace))
     {
         foreach (var item in collection)
         {
             item.ImplementItem(writer);
         }
     }
 }
Example #8
0
 public static void Define(ProjectConverter P, CodeWriter writer, EocGlobalVariable[] collection)
 {
     writer.Write("#pragma once");
     writer.NewLine();
     writer.Write("#include \"type.h\"");
     using (writer.NewNamespace(P.GlobalNamespace))
     {
         foreach (var item in collection)
         {
             item.DefineItem(writer);
         }
     }
 }
Example #9
0
 public static void Define(ProjectConverter P, CodeWriter writer, SortedDictionary <int, EocConstant> map)
 {
     writer.Write("#pragma once");
     writer.NewLine();
     writer.Write("#include <e/system/basic_type.h>");
     using (writer.NewNamespace(P.ConstantNamespace))
     {
         foreach (var item in map.Values)
         {
             item.DefineItem(writer);
         }
     }
 }
Example #10
0
 public void Define(CodeWriter writer)
 {
     writer.Write("#pragma once");
     writer.NewLine();
     writer.Write("#include \"../type.h\"");
     using (writer.NewNamespace(P.CmdNamespace))
     {
         foreach (var item in Method)
         {
             item.DefineItem(writer);
         }
     }
 }