void AddForwardReference(List <ManagedClass> forwardRefs, TypeRefDefinition type, HeaderDefinition header)
        {
            if (type.IsBasic)
            {
                return;
            }

            switch (type.Kind)
            {
            case TypeKind.Pointer:
            case TypeKind.LValueReference:
                AddForwardReference(forwardRefs, type.Referenced, header);
                return;
            }

            var target = type.Target;

            if (target == null)
            {
                return;
            }
            if (target.IsExcluded || target.MarshalAsStruct || target.Header == header)
            {
                return;
            }

            var targetManaged = DotNetParser.GetManaged(target);

            if (!forwardRefs.Contains(targetManaged))
            {
                forwardRefs.Add(targetManaged);
            }
        }
        public void CppTemplate()
        {
            var project = new WrapperProject();
            project.NamespaceName = "CppTemplate";
            project.ProjectFilePath = "CppTemplate/cpp_template.xml";
            project.SourceRootFolders.Add(".");
            project.ReadCpp();
            project.Save();

            var parser = new DotNetParser(project);
            parser.Parse();

            project.CProjectPath = "CppTemplate_wrap";
            project.CsProjectPath = "CppTemplate_wrap";
            var writer = new PInvokeWriter(parser);
            writer.Output();

            var cmake = new CMakeWriter(parser);
            cmake.Output();

            Assert.AreEqual(1, project.HeaderDefinitions.Count);
            Assert.AreEqual(4, project.ClassDefinitions.Count);
            /*
            var cppClass1 = project.ClassDefinitions.First().Value;
            Assert.AreEqual("CppClass1", cppClass1.Name);
            Assert.AreEqual("CppClass1", cppClass1.ManagedName);
            Assert.AreEqual(2, cppClass1.Methods.Count);
            Assert.AreEqual("Empty", cppClass1.Methods[1].ManagedName);*/
        }
Esempio n. 3
0
        public ExtensionsWriter(DotNetParser parser)
            : base(parser)
        {
            _extensionClassesInternal.Add("Matrix3x3", "BulletSharp.Math.Matrix");
            _extensionClassesInternal.Add("Quaternion", "BulletSharp.Math.Quaternion");
            _extensionClassesInternal.Add("Transform", "BulletSharp.Math.Matrix");
            _extensionClassesInternal.Add("Vector3", "BulletSharp.Math.Vector3");

            _extensionClassesExternal.Add("Matrix3x3", "OpenTK.Matrix4");
            _extensionClassesExternal.Add("Quaternion", "OpenTK.Quaternion");
            _extensionClassesExternal.Add("Transform", "OpenTK.Matrix4");
            _extensionClassesExternal.Add("Vector3", "OpenTK.Vector3");

            _returnTypeConversion.Add("Matrix3x3", ".ToOpenTK()");
            _returnTypeConversion.Add("Quaternion", ".ToOpenTK()");
            _returnTypeConversion.Add("Transform", ".ToOpenTK()");
            _returnTypeConversion.Add("Vector3", ".ToOpenTK()");

            OpenFile(null, WriteTo.Buffer);
        }
        public ExtensionsWriter(DotNetParser parser)
            : base(parser)
        {
            _extensionClassesInternal.Add("Matrix3x3", "BulletSharp.Math.Matrix");
            _extensionClassesInternal.Add("Quaternion", "BulletSharp.Math.Quaternion");
            _extensionClassesInternal.Add("Transform", "BulletSharp.Math.Matrix");
            _extensionClassesInternal.Add("Vector3", "BulletSharp.Math.Vector3");

            _extensionClassesExternal.Add("Matrix3x3", "OpenTK.Matrix4");
            _extensionClassesExternal.Add("Quaternion", "OpenTK.Quaternion");
            _extensionClassesExternal.Add("Transform", "OpenTK.Matrix4");
            _extensionClassesExternal.Add("Vector3", "OpenTK.Vector3");

            _returnTypeConversion.Add("Matrix3x3", ".ToOpenTK()");
            _returnTypeConversion.Add("Quaternion", ".ToOpenTK()");
            _returnTypeConversion.Add("Transform", ".ToOpenTK()");
            _returnTypeConversion.Add("Vector3", ".ToOpenTK()");

            OpenFile(null, WriteTo.Buffer);
        }
        public void Cpp1()
        {
            var project = new WrapperProject();
            project.NamespaceName = "Cpp1";
            project.ProjectFilePath = "Cpp1/cpp1.xml";
            project.SourceRootFolders.Add(".");
            project.ReadCpp();
            project.Save();

            var parser = new DotNetParser(project);
            parser.Parse();

            project.CProjectPath = "Cpp1_wrap";
            project.CsProjectPath = "Cpp1_wrap";
            var writer = new PInvokeWriter(parser);
            writer.Output();

            Assert.AreEqual(1, project.HeaderDefinitions.Count);
            Assert.AreEqual(1, parser.Classes.Count);
            var cppClass1 = parser.Classes.First().Value;
            Assert.AreEqual("CppClass1", cppClass1.Name);
            Assert.AreEqual(2, cppClass1.Methods.Count);
            Assert.AreEqual("Empty", cppClass1.Methods[1].Name);
        }
        // If the type is defined in a conditionally compiled header, return the condition string.
        private string GetTypeConditional(TypeRefDefinition type)
        {
            var target = type.Target;

            if (target == null && type.Referenced != null)
            {
                target = type.Referenced.Target;
            }

            if (target == null)
            {
                return(null);
            }

            string headerConditional;
            string targetHeaderName = DotNetParser.GetManaged(target.Header).Name;

            if (headerConditionals.TryGetValue(targetHeaderName, out headerConditional))
            {
                return(headerConditional);
            }

            return(null);
        }
Esempio n. 7
0
        static void OutputSolution(TargetVS targetVS, DotNetParser parser)
        {
            string targetVersionString;
            switch (targetVS)
            {
                case TargetVS.VS2008:
                    targetVersionString = "2008";
                    break;
                case TargetVS.VS2010:
                    targetVersionString = "2010";
                    break;
                case TargetVS.VS2012:
                    targetVersionString = "2012";
                    break;
                case TargetVS.VS2013:
                    targetVersionString = "2013";
                    break;
                case TargetVS.VS2015:
                    targetVersionString = "2015";
                    break;
                default:
                    throw new NotImplementedException();
            }

            string slnRelDir = (targetVS == TargetVS.VS2010) ? "" : "..\\";
            string rootFolder = slnRelDir + "src\\";

            var confs = new List<ProjectConfiguration>
            {
                new ProjectConfiguration("Axiom", true, "GRAPHICS_AXIOM",
                    slnRelDir + "..\\Axiom-SDK-0.8.3376.12322\\bin\\Net35"),
                new ProjectConfiguration("Axiom", false, "GRAPHICS_AXIOM",
                    slnRelDir + "..\\Axiom-SDK-0.8.3376.12322\\bin\\Net35"),
                new ProjectConfiguration("Generic", true, "GRAPHICS_GENERIC"),
                new ProjectConfiguration("Generic", false, "GRAPHICS_GENERIC"),
                new ProjectConfiguration("Mogre", true, "GRAPHICS_MOGRE", "C:\\MogreSDK\\bin\\Debug"),
                new ProjectConfiguration("Mogre", false, "GRAPHICS_MOGRE", "C:\\MogreSDK\\bin\\Release")
            };
            if (targetVS != TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("MonoGame", true, "GRAPHICS_MONOGAME", "$(ProgramFiles)\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\;$(ProgramFiles(x86))\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\"));
                confs.Add(new ProjectConfiguration("MonoGame", false, "GRAPHICS_MONOGAME", "$(ProgramFiles)\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\;$(ProgramFiles(x86))\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\"));
            }
            if (targetVS != TargetVS.VS2008 && targetVS != TargetVS.VS2010)
            {
                confs.Add(new ProjectConfiguration("Numerics", true, "GRAPHICS_NUMERICS"));
                confs.Add(new ProjectConfiguration("Numerics", false, "GRAPHICS_NUMERICS"));
            }
            if (targetVS == TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("OpenTK", true, "GRAPHICS_OPENTK", "$(USERPROFILE)\\My Documents\\OpenTK\\1.1\\Binaries\\OpenTK\\Release"));
                confs.Add(new ProjectConfiguration("OpenTK", false, "GRAPHICS_OPENTK", "$(USERPROFILE)\\My Documents\\OpenTK\\1.1\\Binaries\\OpenTK\\Release"));
                confs.Add(new ProjectConfiguration("SharpDX", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net20"));
                confs.Add(new ProjectConfiguration("SharpDX", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net20"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net20"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net20"));
                confs.Add(new ProjectConfiguration("SlimDX", true, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net20\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net20\\"));
                confs.Add(new ProjectConfiguration("SlimDX", false, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net20\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net20\\"));
            }
            else
            {
                confs.Add(new ProjectConfiguration("OpenTK", true, "GRAPHICS_OPENTK")
                {
                    ConditionalRef = "OpenTK",
                    ConditionalRefAssembly = "OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4"
                });
                confs.Add(new ProjectConfiguration("OpenTK", false, "GRAPHICS_OPENTK")
                {
                    ConditionalRef = "OpenTK",
                    ConditionalRefAssembly = "OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4"
                });
                confs.Add(new ProjectConfiguration("SharpDX", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net40"));
                confs.Add(new ProjectConfiguration("SharpDX", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net40"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net40"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net40"));
                confs.Add(new ProjectConfiguration("SlimDX", true, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net40\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net40\\"));
                confs.Add(new ProjectConfiguration("SlimDX", false, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net40\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net40\\"));
            }
            //confs.Add(new ProjectConfiguration("SlimMath", true, "GRAPHICS_SLIMMATH", slnRelDir + "..\\SlimMath\\SlimMath\\bin\\Release"));
            //confs.Add(new ProjectConfiguration("SlimMath", false, "GRAPHICS_SLIMMATH", slnRelDir + "..\\SlimMath\\SlimMath\\bin\\Debug"));
            if (targetVS != TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("Windows API Code Pack", true, "GRAPHICS_WAPICODEPACK", slnRelDir + "..\\Windows API Code Pack 1.1\\binaries\\DirectX"));
                confs.Add(new ProjectConfiguration("Windows API Code Pack", false, "GRAPHICS_WAPICODEPACK", slnRelDir + "..\\Windows API Code Pack 1.1\\binaries\\DirectX"));
            }
            /*
            confs.Add(new ProjectConfiguration("XNA 3.1", true, "GRAPHICS_XNA31", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\"));
            confs.Add(new ProjectConfiguration("XNA 3.1", false, "GRAPHICS_XNA31", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\"));
            if (targetVS != TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("XNA 4.0", true, "GRAPHICS_XNA40", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\"));
                confs.Add(new ProjectConfiguration("XNA 4.0", false, "GRAPHICS_XNA40", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\"));
            }
            */

            var project = parser.Project;
            var filterWriter = new FilterWriter(project.NamespaceName);
            var sourceFilter = new Filter("Source Files", "4FC737F1-C7A5-4376-A066-2A32D752A2FF", "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx");
            var headerFilter = new Filter("Header Files", "93995380-89BD-4b04-88EB-625FBE52EBFB", "h;hh;hpp;hxx;hm;inl;inc;xsd");
            var resourceFilter = new Filter("Resource Files", "67DA6AB6-F800-4c08-8B7A-83BB121AAD01", "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
            filterWriter.RootFilter.Add(sourceFilter);
            filterWriter.RootFilter.Add(headerFilter);
            filterWriter.RootFilter.Add(resourceFilter);

            sourceFilter.AddFile("", rootFolder + "Stdafx");
            sourceFilter.AddFile("", rootFolder + "AssemblyInfo");
            sourceFilter.AddFile("", rootFolder + "Collections");
            sourceFilter.AddFile("", rootFolder + "Math");
            sourceFilter.AddFile("", rootFolder + "StringConv");
            sourceFilter.AddFile("", rootFolder + "DataStream");
            sourceFilter.AddFile("", rootFolder + "Matrix");
            sourceFilter.AddFile("", rootFolder + "Quaternion");
            sourceFilter.AddFile("", rootFolder + "Utilities");
            sourceFilter.AddFile("", rootFolder + "Vector3");
            sourceFilter.AddFile("", rootFolder + "Vector4");

            headerFilter.AddFile("", rootFolder + "Stdafx");
            headerFilter.AddFile("", rootFolder + "Collections");
            headerFilter.AddFile("", rootFolder + "Enums");
            headerFilter.AddFile("", rootFolder + "ITrackingDisposable");
            headerFilter.AddFile("", rootFolder + "Math");
            headerFilter.AddFile("", rootFolder + "StringConv");
            headerFilter.AddFile("", rootFolder + "Version");
            headerFilter.AddFile("", rootFolder + "DataStream");
            headerFilter.AddFile("", rootFolder + "Matrix");
            headerFilter.AddFile("", rootFolder + "Quaternion");
            headerFilter.AddFile("", rootFolder + "Utilities");
            headerFilter.AddFile("", rootFolder + "Vector3");
            headerFilter.AddFile("", rootFolder + "Vector4");

            foreach (ManagedHeader header in parser.Headers.Values)
            {
                if (header.Classes.Count == 0) continue;

                sourceFilter.AddFile(header.Native.Filename, rootFolder + header.Name);
                headerFilter.AddFile(header.Native.Filename, rootFolder + header.Name);
            }

            sourceFilter.AddFile("BulletCollision/CollisionDispatch/", rootFolder + "InternalEdgeUtility");
            sourceFilter.AddFile("BulletCollision/CollisionShapes/", rootFolder + "BulletMaterial");
            sourceFilter.AddFile("BulletCollision/NarrowPhaseCollision/", rootFolder + "SimplexSolverInterface");
            sourceFilter.AddFile("LinearMath/", rootFolder + "DebugDraw");
            sourceFilter.AddFile("SoftBody/", rootFolder + "SoftBodySolver");
            headerFilter.AddFile("BulletCollision/CollisionDispatch/", rootFolder + "InternalEdgeUtility");
            headerFilter.AddFile("BulletCollision/CollisionShapes/", rootFolder + "BulletMaterial");
            headerFilter.AddFile("BulletCollision/NarrowPhaseCollision/", rootFolder + "SimplexSolverInterface");
            headerFilter.AddFile("LinearMath/", rootFolder + "DebugDraw");
            headerFilter.AddFile("BulletDynamics/Character/", rootFolder + "ICharacterController");
            headerFilter.AddFile("LinearMath/", rootFolder + "IDebugDraw");
            headerFilter.AddFile("SoftBody/", rootFolder + "SoftBodySolver");

            resourceFilter.AddFile("", rootFolder + "Resources.rc");

            filterWriter.RootFilter.Sort();

            string bulletRoot = "..\\bullet3";

            /*
            foreach (string sourceRootFolder in project.SourceRootFolders)
            {
                string sourceRootFolderRel = WrapperProject.MakeRelativePath(project.ProjectFilePath, sourceRootFolder);
                sourceRootFolderRel.ToString();
            }
            */

            var slnWriter = new SlnWriter(filterWriter, project.NamespaceName)
            {
                IncludeDirectories = string.Format("{0}\\src;{0}\\Extras\\HACD;{0}\\Extras\\Serialize\\BulletWorldImporter;{0}\\Extras\\Serialize\\BulletXmlWorldImporter;", slnRelDir + bulletRoot),
                FilterWriter = filterWriter
            };
            if (targetVS == TargetVS.VS2008)
            {
                slnWriter.LibraryDirectoriesRelease = slnRelDir + bulletRoot + "\\msvc\\2008\\lib\\MinSizeRel";
                slnWriter.LibraryDirectoriesDebug = slnRelDir + bulletRoot + "\\msvc\\2008\\lib\\Debug";
            }
            else
            {
                slnWriter.LibraryDirectoriesRelease = slnRelDir + bulletRoot + "\\msvc\\" + targetVersionString + "\\lib\\MinSizeRel;";
                slnWriter.LibraryDirectoriesDebug = slnRelDir + bulletRoot + "\\msvc\\" + targetVersionString + "\\lib\\Debug;";
            }
            slnWriter.Output(targetVS, confs, "sln" + targetVersionString);
        }
Esempio n. 8
0
        static void OutputSolution(TargetVS targetVS, DotNetParser parser)
        {
            string targetVersionString;

            switch (targetVS)
            {
            case TargetVS.VS2008:
                targetVersionString = "2008";
                break;

            case TargetVS.VS2010:
                targetVersionString = "2010";
                break;

            case TargetVS.VS2012:
                targetVersionString = "2012";
                break;

            case TargetVS.VS2013:
                targetVersionString = "2013";
                break;

            case TargetVS.VS2015:
                targetVersionString = "2015";
                break;

            default:
                throw new NotImplementedException();
            }

            string slnRelDir  = (targetVS == TargetVS.VS2010) ? "" : "..\\";
            string rootFolder = slnRelDir + "src\\";

            var confs = new List <ProjectConfiguration>
            {
                new ProjectConfiguration("Axiom", true, "GRAPHICS_AXIOM",
                                         slnRelDir + "..\\Axiom-SDK-0.8.3376.12322\\bin\\Net35"),
                new ProjectConfiguration("Axiom", false, "GRAPHICS_AXIOM",
                                         slnRelDir + "..\\Axiom-SDK-0.8.3376.12322\\bin\\Net35"),
                new ProjectConfiguration("Generic", true, "GRAPHICS_GENERIC"),
                new ProjectConfiguration("Generic", false, "GRAPHICS_GENERIC"),
                new ProjectConfiguration("Mogre", true, "GRAPHICS_MOGRE", "C:\\MogreSDK\\bin\\Debug"),
                new ProjectConfiguration("Mogre", false, "GRAPHICS_MOGRE", "C:\\MogreSDK\\bin\\Release")
            };

            if (targetVS != TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("MonoGame", true, "GRAPHICS_MONOGAME", "$(ProgramFiles)\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\;$(ProgramFiles(x86))\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\"));
                confs.Add(new ProjectConfiguration("MonoGame", false, "GRAPHICS_MONOGAME", "$(ProgramFiles)\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\;$(ProgramFiles(x86))\\MonoGame\\v3.0\\Assemblies\\WindowsGL\\"));
            }
            if (targetVS != TargetVS.VS2008 && targetVS != TargetVS.VS2010)
            {
                confs.Add(new ProjectConfiguration("Numerics", true, "GRAPHICS_NUMERICS"));
                confs.Add(new ProjectConfiguration("Numerics", false, "GRAPHICS_NUMERICS"));
            }
            if (targetVS == TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("OpenTK", true, "GRAPHICS_OPENTK", "$(USERPROFILE)\\My Documents\\OpenTK\\1.1\\Binaries\\OpenTK\\Release"));
                confs.Add(new ProjectConfiguration("OpenTK", false, "GRAPHICS_OPENTK", "$(USERPROFILE)\\My Documents\\OpenTK\\1.1\\Binaries\\OpenTK\\Release"));
                confs.Add(new ProjectConfiguration("SharpDX", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net20"));
                confs.Add(new ProjectConfiguration("SharpDX", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net20"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net20"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net20"));
                confs.Add(new ProjectConfiguration("SlimDX", true, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net20\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net20\\"));
                confs.Add(new ProjectConfiguration("SlimDX", false, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net20\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net20\\"));
            }
            else
            {
                confs.Add(new ProjectConfiguration("OpenTK", true, "GRAPHICS_OPENTK")
                {
                    ConditionalRef         = "OpenTK",
                    ConditionalRefAssembly = "OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4"
                });
                confs.Add(new ProjectConfiguration("OpenTK", false, "GRAPHICS_OPENTK")
                {
                    ConditionalRef         = "OpenTK",
                    ConditionalRefAssembly = "OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4"
                });
                confs.Add(new ProjectConfiguration("SharpDX", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net40"));
                confs.Add(new ProjectConfiguration("SharpDX", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-net40"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", true, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net40"));
                confs.Add(new ProjectConfiguration("SharpDX Signed", false, "GRAPHICS_SHARPDX", slnRelDir + "..\\SharpDX\\Bin\\DirectX11-Signed-net40"));
                confs.Add(new ProjectConfiguration("SlimDX", true, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net40\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net40\\"));
                confs.Add(new ProjectConfiguration("SlimDX", false, "GRAPHICS_SLIMDX", "$(PROGRAMFILES)\\SlimDX SDK (January 2012)\\Bin\\net40\\;$(PROGRAMFILES(x86))\\SlimDX SDK (June 2010)\\Bin\\net40\\"));
            }
            //confs.Add(new ProjectConfiguration("SlimMath", true, "GRAPHICS_SLIMMATH", slnRelDir + "..\\SlimMath\\SlimMath\\bin\\Release"));
            //confs.Add(new ProjectConfiguration("SlimMath", false, "GRAPHICS_SLIMMATH", slnRelDir + "..\\SlimMath\\SlimMath\\bin\\Debug"));
            if (targetVS != TargetVS.VS2008)
            {
                confs.Add(new ProjectConfiguration("Windows API Code Pack", true, "GRAPHICS_WAPICODEPACK", slnRelDir + "..\\Windows API Code Pack 1.1\\binaries\\DirectX"));
                confs.Add(new ProjectConfiguration("Windows API Code Pack", false, "GRAPHICS_WAPICODEPACK", slnRelDir + "..\\Windows API Code Pack 1.1\\binaries\\DirectX"));
            }

            /*
             * confs.Add(new ProjectConfiguration("XNA 3.1", true, "GRAPHICS_XNA31", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\"));
             * confs.Add(new ProjectConfiguration("XNA 3.1", false, "GRAPHICS_XNA31", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v3.1\\References\\Windows\\x86\\"));
             * if (targetVS != TargetVS.VS2008)
             * {
             *  confs.Add(new ProjectConfiguration("XNA 4.0", true, "GRAPHICS_XNA40", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\"));
             *  confs.Add(new ProjectConfiguration("XNA 4.0", false, "GRAPHICS_XNA40", "$(ProgramFiles)\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\;$(ProgramFiles(x86))\\Microsoft XNA\\XNA Game Studio\\v4.0\\References\\Windows\\x86\\"));
             * }
             */

            var project        = parser.Project;
            var filterWriter   = new FilterWriter(project.NamespaceName);
            var sourceFilter   = new Filter("Source Files", "4FC737F1-C7A5-4376-A066-2A32D752A2FF", "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx");
            var headerFilter   = new Filter("Header Files", "93995380-89BD-4b04-88EB-625FBE52EBFB", "h;hh;hpp;hxx;hm;inl;inc;xsd");
            var resourceFilter = new Filter("Resource Files", "67DA6AB6-F800-4c08-8B7A-83BB121AAD01", "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");

            filterWriter.RootFilter.Add(sourceFilter);
            filterWriter.RootFilter.Add(headerFilter);
            filterWriter.RootFilter.Add(resourceFilter);

            sourceFilter.AddFile("", rootFolder + "Stdafx");
            sourceFilter.AddFile("", rootFolder + "AssemblyInfo");
            sourceFilter.AddFile("", rootFolder + "Collections");
            sourceFilter.AddFile("", rootFolder + "Math");
            sourceFilter.AddFile("", rootFolder + "StringConv");
            sourceFilter.AddFile("", rootFolder + "DataStream");
            sourceFilter.AddFile("", rootFolder + "Matrix");
            sourceFilter.AddFile("", rootFolder + "Quaternion");
            sourceFilter.AddFile("", rootFolder + "Utilities");
            sourceFilter.AddFile("", rootFolder + "Vector3");
            sourceFilter.AddFile("", rootFolder + "Vector4");

            headerFilter.AddFile("", rootFolder + "Stdafx");
            headerFilter.AddFile("", rootFolder + "Collections");
            headerFilter.AddFile("", rootFolder + "Enums");
            headerFilter.AddFile("", rootFolder + "ITrackingDisposable");
            headerFilter.AddFile("", rootFolder + "Math");
            headerFilter.AddFile("", rootFolder + "StringConv");
            headerFilter.AddFile("", rootFolder + "Version");
            headerFilter.AddFile("", rootFolder + "DataStream");
            headerFilter.AddFile("", rootFolder + "Matrix");
            headerFilter.AddFile("", rootFolder + "Quaternion");
            headerFilter.AddFile("", rootFolder + "Utilities");
            headerFilter.AddFile("", rootFolder + "Vector3");
            headerFilter.AddFile("", rootFolder + "Vector4");

            foreach (ManagedHeader header in parser.Headers.Values)
            {
                if (header.Classes.Count == 0)
                {
                    continue;
                }

                sourceFilter.AddFile(header.Native.Filename, rootFolder + header.Name);
                headerFilter.AddFile(header.Native.Filename, rootFolder + header.Name);
            }

            sourceFilter.AddFile("BulletCollision/CollisionDispatch/", rootFolder + "InternalEdgeUtility");
            sourceFilter.AddFile("BulletCollision/CollisionShapes/", rootFolder + "BulletMaterial");
            sourceFilter.AddFile("BulletCollision/NarrowPhaseCollision/", rootFolder + "SimplexSolverInterface");
            sourceFilter.AddFile("LinearMath/", rootFolder + "DebugDraw");
            sourceFilter.AddFile("SoftBody/", rootFolder + "SoftBodySolver");
            headerFilter.AddFile("BulletCollision/CollisionDispatch/", rootFolder + "InternalEdgeUtility");
            headerFilter.AddFile("BulletCollision/CollisionShapes/", rootFolder + "BulletMaterial");
            headerFilter.AddFile("BulletCollision/NarrowPhaseCollision/", rootFolder + "SimplexSolverInterface");
            headerFilter.AddFile("LinearMath/", rootFolder + "DebugDraw");
            headerFilter.AddFile("BulletDynamics/Character/", rootFolder + "ICharacterController");
            headerFilter.AddFile("LinearMath/", rootFolder + "IDebugDraw");
            headerFilter.AddFile("SoftBody/", rootFolder + "SoftBodySolver");

            resourceFilter.AddFile("", rootFolder + "Resources.rc");

            filterWriter.RootFilter.Sort();

            string bulletRoot = "..\\bullet3";

            /*
             * foreach (string sourceRootFolder in project.SourceRootFolders)
             * {
             *  string sourceRootFolderRel = WrapperProject.MakeRelativePath(project.ProjectFilePath, sourceRootFolder);
             *  sourceRootFolderRel.ToString();
             * }
             */

            var slnWriter = new SlnWriter(filterWriter, project.NamespaceName)
            {
                IncludeDirectories = string.Format("{0}\\src;{0}\\Extras\\HACD;{0}\\Extras\\Serialize\\BulletWorldImporter;{0}\\Extras\\Serialize\\BulletXmlWorldImporter;", slnRelDir + bulletRoot),
                FilterWriter       = filterWriter
            };

            if (targetVS == TargetVS.VS2008)
            {
                slnWriter.LibraryDirectoriesRelease = slnRelDir + bulletRoot + "\\msvc\\2008\\lib\\MinSizeRel";
                slnWriter.LibraryDirectoriesDebug   = slnRelDir + bulletRoot + "\\msvc\\2008\\lib\\Debug";
            }
            else
            {
                slnWriter.LibraryDirectoriesRelease = slnRelDir + bulletRoot + "\\msvc\\" + targetVersionString + "\\lib\\MinSizeRel;";
                slnWriter.LibraryDirectoriesDebug   = slnRelDir + bulletRoot + "\\msvc\\" + targetVersionString + "\\lib\\Debug;";
            }
            slnWriter.Output(targetVS, confs, "sln" + targetVersionString);
        }
 public PInvokeWriter(DotNetParser parser)
     : base(parser)
 {
 }
Esempio n. 10
0
        void WriteMethodDefinition(ManagedMethod method, int numParameters, int overloadIndex, int level,
                                   ManagedParameter outValueParameter)
        {
            var nativeMethod = method.Native;

            if (nativeMethod.IsConstructor)
            {
                if (method.Parent.BaseClass == null)
                {
                    Write("_native = ");
                }
                Write($"{GetFullNameC(method.Parent.Native)}_new");
            }
            else
            {
                if (!nativeMethod.IsVoid)
                {
                    if (outValueParameter != null)
                    {
                        // Temporary variable
                        WriteLine(string.Format("{0} {1};",
                                                DotNetParser.GetManaged(outValueParameter.Native.Type.Referenced.Target).Name,
                                                outValueParameter.Name));
                        WriteTabs(level + 2);
                    }
                    else
                    {
                        Write($"return {BulletParser.GetTypeMarshalConstructorStartCS(nativeMethod)}");
                    }
                }

                Write($"{GetFullNameC(method.Parent.Native)}_{method.Native.Name}");
            }

            if (overloadIndex != 0)
            {
                Write((overloadIndex + 1).ToString());
            }

            Write('(');

            var parameters = method.Parameters.Take(numParameters)
                             .Select(p => GetParameterMarshal(p));

            if (outValueParameter != null)
            {
                parameters = parameters.Concat(new[] { $"out {outValueParameter.Name }" });
            }

            // The first parameter is the instance pointer (if not constructor or static method)
            if (!nativeMethod.IsConstructor && !nativeMethod.IsStatic)
            {
                parameters = new[] { "_native" }.Concat(parameters);
            }

            Write(ListToLines(parameters, WriteTo.CS, level + 2));

            if (nativeMethod.IsConstructor && method.Parent.BaseClass != null)
            {
                Write(")");
                if (method.Parent.BaseClass.Native.HasPreventDelete)
                {
                    Write(", false");
                }
                WriteLine(")");
                WriteLine(level + 1, "{");
            }
            else
            {
                if (!nativeMethod.IsConstructor && !nativeMethod.IsVoid)
                {
                    Write(BulletParser.GetTypeMarshalConstructorEndCS(nativeMethod));
                }
                WriteLine(");");
            }

            // Cache property values
            if (nativeMethod.IsConstructor)
            {
                var methodParent = method.Parent;
                while (methodParent != null)
                {
                    foreach (var cachedProperty in methodParent.CachedProperties.OrderBy(p => p.Key))
                    {
                        foreach (var param in method.Parameters)
                        {
                            if (param.Name.ToLower().Equals(cachedProperty.Key.ToLower()) &&
                                GetName(param.Native.Type).Equals(GetName(cachedProperty.Value.Property.Type)))
                            {
                                WriteLine(level + 2,
                                          $"{cachedProperty.Value.CacheFieldName} = {param.Name};");
                            }
                        }
                    }
                    methodParent = methodParent.BaseClass;
                }
            }

            // Return temporary variable
            if (outValueParameter != null)
            {
                WriteLine(level + 2, $"return {outValueParameter.Name};");
            }
        }
Esempio n. 11
0
 public PInvokeWriter(DotNetParser parser)
     : base(parser)
 {
 }
 public CppCliWriter(DotNetParser parser)
     : base(parser)
 {
 }
Esempio n. 13
0
        public override void Output()
        {
            var headers = DotNetParser.Headers.Values;

            if (headers.Count != 0)
            {
                Directory.CreateDirectory(Project.CppCliProjectPathFull);
            }

            foreach (var header in headers)
            {
                string headerFilename = Path.Combine(Project.CppCliProjectPathFull, header.Name + ".h");
                OpenFile(headerFilename, WriteTo.Header);
                WriteLine("#pragma once");
                WriteLine();

                // Write includes
                if (header.Native.Includes.Count != 0)
                {
                    foreach (var include in header.Native.Includes)
                    {
                        string includeName = DotNetParser.GetManaged(include).Name;
                        WriteLine($"#include \"{includeName}.h\"");
                    }
                    WriteLine();
                }

                // Write namespace
                WriteLine($"namespace {Project.NamespaceName}");
                WriteLine("{");
                hasHeaderWhiteSpace = true;

                // Find forward references
                var forwardRefs = new List <ManagedClass>();
                foreach (var c in header.Classes)
                {
                    FindForwardReferences(forwardRefs, c);
                }

                // Remove redundant forward references (header file already included)
                forwardRefs.RemoveAll(fr => header.Native.Includes.Contains(fr.Header.Native));
                forwardRefs.Sort((r1, r2) => r1.Name.CompareTo(r2.Name));

                // Write forward references
                var forwardRefHeaders = new List <ManagedHeader>();
                foreach (ManagedClass c in forwardRefs)
                {
                    WriteLine(1, $"ref class {c.Name};");
                    if (!forwardRefHeaders.Contains(c.Header))
                    {
                        forwardRefHeaders.Add(c.Header);
                    }
                    hasHeaderWhiteSpace = false;
                }
                forwardRefHeaders.Add(header);
                forwardRefHeaders.Sort((r1, r2) => r1.Name.CompareTo(r2.Name));


                string sourceFilename = Path.Combine(Project.CppCliProjectPathFull, header.Name + ".cpp");
                OpenFile(sourceFilename, WriteTo.Source);
                WriteLine("#include \"StdAfx.h\"");
                WriteLine();

                string headerConditional;
                if (headerConditionals.TryGetValue(header.Name, out headerConditional))
                {
                    WriteLine($"#ifndef {headerConditional}");
                    WriteLine();
                }

                // Write statements to include forward referenced types
                if (forwardRefHeaders.Count != 0)
                {
                    foreach (var refHeader in forwardRefHeaders)
                    {
                        bool hasHeaderConditional = false;
                        if (headerConditionals.ContainsKey(refHeader.Name))
                        {
                            hasHeaderConditional = true;
                            if (headerConditionals.ContainsKey(header.Name) &&
                                headerConditionals[refHeader.Name] == headerConditionals[header.Name])
                            {
                                hasHeaderConditional = false;
                            }
                        }
                        if (hasHeaderConditional)
                        {
                            Write("#ifndef ");
                            WriteLine(headerConditionals[refHeader.Name]);
                        }
                        WriteLine($"#include \"{refHeader.Name}.h\"");
                        if (hasHeaderConditional)
                        {
                            WriteLine("#endif");
                        }
                    }
                    hasSourceWhiteSpace = false;
                }

                // Write classes
                var currentAccess = RefAccessSpecifier.Public;
                WriteClasses(header.Classes, ref currentAccess, 0);

                if (headerConditionals.ContainsKey(header.Name))
                {
                    WriteLine();
                    WriteLine("#endif");
                }

                WriteLine("};", WriteTo.Header);
                CloseFile(WriteTo.Header);
                CloseFile(WriteTo.Source);
            }

            Console.WriteLine("Write complete");
        }
Esempio n. 14
0
 public CppCliWriter(DotNetParser parser)
     : base(parser)
 {
 }