From 2486d1d419141c11317f5675f9b78e224beff428 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Dec 2016 21:55:55 +0200 Subject: [PATCH 01/12] Shortened the generated C# code for patching v-tables. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpSources.cs | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index db4f50e3..1ac93648 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -1448,18 +1448,14 @@ namespace CppSharp.Generators.CSharp WriteStartBraceIndent(); WriteLine("_Thunks = new void*[{0}];", wrappedEntries.Count); - var uniqueEntries = new HashSet(); - for (int i = 0; i < wrappedEntries.Count; i++) { var entry = wrappedEntries[i]; var method = entry.Method; var name = GetVTableMethodDelegateName(method); - var instance = name + "Instance"; - if (uniqueEntries.Add(entry)) - WriteLine("{0} += {1}Hook;", instance, name); - WriteLine("_Thunks[{0}] = Marshal.GetFunctionPointerForDelegate({1}).ToPointer();", - i, instance); + WriteLine($@"_Thunks[{i}] = Marshal.GetFunctionPointerForDelegate(new { + GetDelegateName(method, @class.TranslationUnit.Module.OutputNamespace) + }({name}Hook)).ToPointer();"); } WriteCloseBraceIndent(); @@ -1499,19 +1495,20 @@ namespace CppSharp.Generators.CSharp AllocateNewVTablesItanium(@class, wrappedEntries, destructorOnly); } - private void SaveOriginalVTablePointers(Class @class) + private void SaveOriginalVTablePointers(Class @class, bool cast = false) { var suffix = Helpers.GetSuffixForInternal(@class); + var pointer = cast ? $@"(({Helpers.InternalStruct}{ + Helpers.GetSuffixForInternal(@class)}*) native)" : "native"; if (Context.ParserOptions.IsMicrosoftAbi) WriteLine("__OriginalVTables = new void*[] {{ {0} }};", string.Join(", ", - @class.Layout.VTablePointers.Select(v => string.Format( - "(({0}{1}*) native)->{2}.ToPointer()", - Helpers.InternalStruct, suffix, v.Name)))); + @class.Layout.VTablePointers.Select(v => + $"{pointer}->{v.Name}.ToPointer()"))); else WriteLine( - "__OriginalVTables = new void*[] {{ (({0}{1}*) native)->{2}.ToPointer() }};", - Helpers.InternalStruct, suffix, @class.Layout.VTablePointers[0].Name); + $@"__OriginalVTables = new void*[] {{ {pointer}->{ + @class.Layout.VTablePointers[0].Name}.ToPointer() }};"); } private void AllocateNewVTablesMS(Class @class, IList wrappedEntries, @@ -1726,11 +1723,6 @@ namespace CppSharp.Generators.CSharp var vTableMethodDelegateName = GetVTableMethodDelegateName(method); - WriteLine("private static {0} {1}Instance;", - GetDelegateName(method, @class.TranslationUnit.Module.OutputNamespace), - vTableMethodDelegateName); - NewLine(); - WriteLine("private static {0} {1}Hook({2})", retType, vTableMethodDelegateName, string.Join(", ", @params)); WriteStartBraceIndent(); @@ -2071,7 +2063,7 @@ namespace CppSharp.Generators.CSharp } if (@class.IsAbstractImpl || hasVTables) - SaveOriginalVTablePointers(@class); + SaveOriginalVTablePointers(@class, true); if (setupVTables) { From 22bd02c8497cb97e0f35bfd43303b7bec441c0b3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Dec 2016 22:44:13 +0200 Subject: [PATCH 02/12] Revert "Shortened the generated C# code for patching v-tables." This reverts commit 2486d1d419141c11317f5675f9b78e224beff428. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpSources.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 1ac93648..620be3de 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -1448,14 +1448,18 @@ namespace CppSharp.Generators.CSharp WriteStartBraceIndent(); WriteLine("_Thunks = new void*[{0}];", wrappedEntries.Count); + var uniqueEntries = new HashSet(); + for (int i = 0; i < wrappedEntries.Count; i++) { var entry = wrappedEntries[i]; var method = entry.Method; var name = GetVTableMethodDelegateName(method); - WriteLine($@"_Thunks[{i}] = Marshal.GetFunctionPointerForDelegate(new { - GetDelegateName(method, @class.TranslationUnit.Module.OutputNamespace) - }({name}Hook)).ToPointer();"); + var instance = name + "Instance"; + if (uniqueEntries.Add(entry)) + WriteLine("{0} += {1}Hook;", instance, name); + WriteLine("_Thunks[{0}] = Marshal.GetFunctionPointerForDelegate({1}).ToPointer();", + i, instance); } WriteCloseBraceIndent(); @@ -1723,6 +1727,11 @@ namespace CppSharp.Generators.CSharp var vTableMethodDelegateName = GetVTableMethodDelegateName(method); + WriteLine("private static {0} {1}Instance;", + GetDelegateName(method, @class.TranslationUnit.Module.OutputNamespace), + vTableMethodDelegateName); + NewLine(); + WriteLine("private static {0} {1}Hook({2})", retType, vTableMethodDelegateName, string.Join(", ", @params)); WriteStartBraceIndent(); From 66c3acc2f6a0257cfba1bf3ba95a3ee5e174b876 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 21 Dec 2016 23:18:55 +0200 Subject: [PATCH 03/12] Fixed a bug when determining if a type is external to the current module. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/CheckIgnoredDecls.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index 0ad6dcc7..8fded460 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -409,10 +409,9 @@ namespace CppSharp.Passes if (declaration.TranslationUnit.Module.Libraries.Any(l => Context.Symbols.Libraries.First( lib => lib.FileName == l).Dependencies.Any( - module.Libraries.Contains))) - { + d => module != declaration.TranslationUnit.Module && + module.Libraries.Contains(d)))) return true; - } } return false; } From 24decfa11f64e40abd99017d60b01a384adfaf91 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Tue, 10 Jan 2017 16:22:15 +0000 Subject: [PATCH 04/12] Remove outdated Clang example. --- examples/Clang/Clang.cs | 91 ----------------------- examples/Clang/Properties/AssemblyInfo.cs | 36 --------- 2 files changed, 127 deletions(-) delete mode 100644 examples/Clang/Clang.cs delete mode 100644 examples/Clang/Properties/AssemblyInfo.cs diff --git a/examples/Clang/Clang.cs b/examples/Clang/Clang.cs deleted file mode 100644 index 8274c673..00000000 --- a/examples/Clang/Clang.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Cxxi.Generators; -using Cxxi.Passes; -using Cxxi.Templates; -using Generator = Cxxi.Generators.Generator; - -namespace Cxxi -{ - /// - /// Transform the Clang library declarations to something more .NET friendly. - /// - class Clang : ILibrary - { - public void Preprocess(LibraryHelpers g) - { - //g.SetNameOfEnumWithMatchingItem("SDL_LOG_CATEGORY_CUSTOM", "LogCategory"); - - // Clean up types - g.FindClass("CXString").IsOpaque = true; - g.FindClass("CXSourceLocation").IsOpaque = true; - g.FindClass("CXSourceRange").IsOpaque = true; - g.FindClass("CXCursor").IsOpaque = true; - g.FindClass("CXType").IsOpaque = true; - g.FindClass("CXToken").IsOpaque = true; - g.FindClass("CXIdxLoc").IsOpaque = true; - g.FindClass("CXTranslationUnitImpl").IsOpaque = true; - } - - public void Postprocess(LibraryHelpers g) - { - g.FindEnum("CompletionContext").SetFlags(); - g.FindClass("String").Name = "CXString"; - //gen.SetNameOfEnumWithName("LOG_CATEGORY", "LogCategory"); - } - - public void Postprocess(Generators.Generator generator) - { - - } - - public void SetupPasses(PassBuilder p) - { - p.RemovePrefix("CX"); - p.RemovePrefix("clang_"); - p.RenameWithPattern("^_", string.Empty, RenameTargets.Any); - - // Clean up enums - p.RemovePrefixEnumItem("ChildVisit_"); - p.RemovePrefixEnumItem("Comment_"); - p.RemovePrefixEnumItem("Availability_"); - p.RemovePrefixEnumItem("GlobalOpt_"); - p.RemovePrefixEnumItem("Diagnostic_"); - p.RemovePrefixEnumItem("LoadDiag_"); - p.RemovePrefixEnumItem("TranslationUnit_"); - p.RemovePrefixEnumItem("SaveTranslationUnit_"); - p.RemovePrefixEnumItem("SaveError_"); - p.RemovePrefixEnumItem("TranslationUnit_"); - p.RemovePrefixEnumItem("Reparse_"); - p.RemovePrefixEnumItem("TUResourceUsage_"); - p.RemovePrefixEnumItem("Cursor_"); - p.RemovePrefixEnumItem("Linkage_"); - p.RemovePrefixEnumItem("Language_"); - p.RemovePrefixEnumItem("Type_"); - p.RemovePrefixEnumItem("CallingConv_"); - p.RemovePrefixEnumItem("CommentInlineCommandRenderKind_"); - p.RemovePrefixEnumItem("CommentParamPassDirection_"); - p.RemovePrefixEnumItem("NameRange_"); - p.RemovePrefixEnumItem("Token_"); - p.RemovePrefixEnumItem("CompletionChunk_"); - p.RemovePrefixEnumItem("CodeComplete_"); - p.RemovePrefixEnumItem("CompletionContext_"); - p.RemovePrefixEnumItem("Visit_"); - p.RemovePrefixEnumItem("IdxEntity_"); - p.RemovePrefixEnumItem("IdxEntityLang_"); - p.RemovePrefixEnumItem("IdxAttr_"); - p.RemovePrefixEnumItem("IdxObjCContainer_"); - p.RemovePrefixEnumItem("IdxEntityRef_"); - p.RemovePrefixEnumItem("IndexOpt_"); - p.RemovePrefixEnumItem("IdxObjCContainer_"); - } - - public void GenerateStart(TextTemplate template) - { - throw new System.NotImplementedException(); - } - - public void GenerateAfterNamespaces(TextTemplate template) - { - throw new System.NotImplementedException(); - } - } -} diff --git a/examples/Clang/Properties/AssemblyInfo.cs b/examples/Clang/Properties/AssemblyInfo.cs deleted file mode 100644 index 5d5e7c96..00000000 --- a/examples/Clang/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Clang")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Clang")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e7c52cd3-e09e-43ba-91e4-82bc31315f7c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] From 2a58d5158614a911901636e51603f210c16953ba Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Tue, 10 Jan 2017 16:22:28 +0000 Subject: [PATCH 05/12] Clean option setup in SDL example. --- examples/SDL/SDL.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/SDL/SDL.cs b/examples/SDL/SDL.cs index e872fdfc..b0114377 100644 --- a/examples/SDL/SDL.cs +++ b/examples/SDL/SDL.cs @@ -9,13 +9,14 @@ namespace CppSharp { public void Setup(Driver driver) { - var parserOptions = driver.ParserOptions; var options = driver.Options; options.LibraryName = "SDL"; options.Headers.Add("SDL.h"); + options.OutputDir = "SDL"; + + var parserOptions = driver.ParserOptions; var sdlPath = Path.Combine(GetExamplesDirectory("SDL"), "SDL-2.0/include"); parserOptions.AddIncludeDirs(sdlPath); - options.OutputDir = "SDL"; } public void SetupPasses(Driver driver) From 853fba5ef97bef1a093601556b171c6b4238c1c0 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 10 Jan 2017 23:26:40 +0200 Subject: [PATCH 06/12] Fixed the auto-compilation to work with a custom output directory. --- src/Generator/Driver.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index cba68bea..6fbff2ca 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -383,13 +383,14 @@ namespace CppSharp public void CompileCode(AST.Module module) { - var assemblyFile = string.IsNullOrEmpty(module.LibraryName) ? - "out.dll" : module.LibraryName + ".dll"; + var assemblyFile = Path.Combine(Options.OutputDir, + string.IsNullOrEmpty(module.LibraryName) ? + "out.dll" : module.LibraryName + ".dll"); - var docFile = Path.ChangeExtension(Path.GetFileName(assemblyFile), ".xml"); + var docFile = Path.ChangeExtension(assemblyFile, ".xml"); var compilerOptions = new StringBuilder(); - compilerOptions.Append(" /doc:" + docFile); + compilerOptions.Append($" /doc:\"{docFile}\""); compilerOptions.Append(" /debug:pdbonly"); compilerOptions.Append(" /unsafe"); @@ -404,7 +405,7 @@ namespace CppSharp if (module != Options.SystemModule) compilerParameters.ReferencedAssemblies.Add( - string.Format("{0}.dll", Options.SystemModule.LibraryName)); + Path.Combine(Options.OutputDir, $"{Options.SystemModule.LibraryName}.dll")); // add a reference to System.Core compilerParameters.ReferencedAssemblies.Add(typeof(Enumerable).Assembly.Location); From f2a7c4cbbc84de49bb362349bdd0f5f033534dee Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 10 Jan 2017 23:45:48 +0200 Subject: [PATCH 07/12] Deleted some unused code. --- src/Generator/Utils/FileHashes.cs | 52 ------------------------------- src/Generator/Utils/Glob.cs | 34 -------------------- 2 files changed, 86 deletions(-) delete mode 100644 src/Generator/Utils/FileHashes.cs delete mode 100644 src/Generator/Utils/Glob.cs diff --git a/src/Generator/Utils/FileHashes.cs b/src/Generator/Utils/FileHashes.cs deleted file mode 100644 index 187d7dcd..00000000 --- a/src/Generator/Utils/FileHashes.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; - -[Serializable] -class FileHashes -{ - private string serializedFile; - private Dictionary fileHashes = new Dictionary(); - - public bool UpdateHash(string file, int hash) - { - if(!fileHashes.ContainsKey(file)) - { - fileHashes.Add(file, hash); - Save(this, serializedFile); - return true; - } - - var oldHash = fileHashes[file]; - fileHashes[file] = hash; - Save(this, serializedFile); - - return oldHash != hash; - } - - public static FileHashes Load(string file) - { - var stream = File.Open(file, FileMode.OpenOrCreate); - var bformatter = new BinaryFormatter(); - - FileHashes obj; - if(stream.Length>0) - obj = (FileHashes)bformatter.Deserialize(stream); - else - obj = new FileHashes(); - obj.serializedFile = file; - stream.Close(); - - return obj; - } - - public static void Save(FileHashes obj, string file) - { - Stream stream = File.Open(file, FileMode.Create); - BinaryFormatter bformatter = new BinaryFormatter(); - - bformatter.Serialize(stream, obj); - stream.Close(); - } -} \ No newline at end of file diff --git a/src/Generator/Utils/Glob.cs b/src/Generator/Utils/Glob.cs deleted file mode 100644 index 30e19b44..00000000 --- a/src/Generator/Utils/Glob.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -public static class Glob -{ - static public string[] GetFiles(string[] patterns) - { - List filelist = new List(); - foreach (string pattern in patterns) - filelist.AddRange(GetFiles(pattern)); - string[] files = new string[filelist.Count]; - filelist.CopyTo(files, 0); - return files; - } - - static public string[] GetFiles(string patternlist) - { - List filelist = new List(); - foreach (string pattern in - patternlist.Split(Path.GetInvalidPathChars())) - { - string dir = Path.GetDirectoryName(pattern); - if (String.IsNullOrEmpty(dir)) dir = - Directory.GetCurrentDirectory(); - filelist.AddRange(Directory.GetFiles( - Path.GetFullPath(dir), - Path.GetFileName(pattern))); - } - string[] files = new string[filelist.Count]; - filelist.CopyTo(files, 0); - return files; - } -} \ No newline at end of file From e61a7b745361a1632ffcd349c8a69458619efd22 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Wed, 11 Jan 2017 18:10:01 +0000 Subject: [PATCH 08/12] Fixed type printing code to work handle non-C++ global qualified names correctly. --- src/AST/CppTypePrinter.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AST/CppTypePrinter.cs b/src/AST/CppTypePrinter.cs index 26da4ec3..2ebed004 100644 --- a/src/AST/CppTypePrinter.cs +++ b/src/AST/CppTypePrinter.cs @@ -151,7 +151,7 @@ namespace CppSharp.AST FunctionType func; return decl.Type.IsPointerTo(out func) ? VisitDeclaration(decl) : decl.Type.Visit(this); } - return GetDeclName(typedef.Declaration); + return GetDeclName(typedef.Declaration, PrintScopeKind); } public virtual string VisitAttributedType(AttributedType attributed, TypeQualifiers quals) @@ -290,9 +290,9 @@ namespace CppSharp.AST throw new System.NotImplementedException(); } - public virtual string GetDeclName(Declaration declaration) + public virtual string GetDeclName(Declaration declaration, CppTypePrintScopeKind scope) { - switch (PrintScopeKind) + switch (scope) { case CppTypePrintScopeKind.Local: return PrintLogicalNames ? declaration.LogicalOriginalName @@ -301,8 +301,8 @@ namespace CppSharp.AST return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName : declaration.QualifiedOriginalName; case CppTypePrintScopeKind.GlobalQualified: - return "::" + (PrintLogicalNames ? declaration.QualifiedLogicalOriginalName - : declaration.QualifiedOriginalName); + var qualifier = PrintFlavorKind == CppTypePrintFlavorKind.Cpp ? "::" : string.Empty; + return qualifier + GetDeclName(declaration, CppTypePrintScopeKind.Qualified); } throw new NotSupportedException(); @@ -310,7 +310,7 @@ namespace CppSharp.AST public virtual string VisitDeclaration(Declaration decl) { - return GetDeclName(decl); + return GetDeclName(decl, PrintScopeKind); } public virtual string VisitClassDecl(Class @class) From 18cc5ed24a578f1596cf766a0653d778ceb326ae Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 11 Jan 2017 21:26:32 +0200 Subject: [PATCH 09/12] Removed the manual padding of fields with type array. This used to work around a bug in Mono which has now been fixed. --- .../Generators/CSharp/CSharpSources.cs | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 620be3de..023d681d 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -802,26 +802,6 @@ namespace CppSharp.Generators.CSharp } PopBlock(NewLineKind.BeforeNextBlock); - - // Workaround a bug in Mono when handling fixed arrays in P/Invoke declarations. - // https://bugzilla.xamarin.com/show_bug.cgi?id=33571 - if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant && - arrayType.Size > 0) - { - for (var i = 1; i < arrayType.Size; ++i) - { - var dummy = new LayoutField - { - Offset = (uint) (field.Offset + i * arrayType.ElementSize / 8), - QualifiedType = new QualifiedType(arrayType.Type), - Name = string.Format("{0}_{1}_{2}", Helpers.DummyIdentifier, - safeIdentifier, i), - FieldPtr = field.FieldPtr - }; - - GenerateClassInternalsField(dummy); - } - } } private void GenerateClassField(Field field, bool @public = false) From 70492c248f1c1f1d0d74bd6f5cc2ef0598096f4b Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 11 Jan 2017 22:33:12 +0200 Subject: [PATCH 10/12] Deleted two unused variables. --- src/Generator/BindingContext.cs | 2 -- src/Generator/Generators/CSharp/CSharpSources.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Generator/BindingContext.cs b/src/Generator/BindingContext.cs index 690b706d..77582857 100644 --- a/src/Generator/BindingContext.cs +++ b/src/Generator/BindingContext.cs @@ -24,8 +24,6 @@ namespace CppSharp.Generators public Dictionary Delegates { get; private set; } - private static readonly Dictionary libraryMappings = new Dictionary(); - public BindingContext(IDiagnostics diagnostics, DriverOptions options, ParserOptions parserOptions = null) { diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 023d681d..2ddbd8b0 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2656,7 +2656,6 @@ namespace CppSharp.Generators.CSharp if (construct == null) { var @class = retClass.OriginalClass ?? retClass; - var specialization = @class as ClassTemplateSpecialization; WriteLine("var {0} = new {1}.{2}{3}();", Helpers.ReturnIdentifier, @class.Visit(TypePrinter), Helpers.InternalStruct, Helpers.GetSuffixForInternal(@class)); From 22c80b3fe1c042ab26b07a10891684b2f980eed3 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Wed, 11 Jan 2017 21:56:12 +0000 Subject: [PATCH 11/12] Improve CheckIgnoredDecls.IsTypeExternal to deal with declarations with no namespaces. --- src/Generator/Passes/CheckIgnoredDecls.cs | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index 8fded460..38ed5fac 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -403,16 +403,22 @@ namespace CppSharp.Passes private bool IsTypeExternal(Module module, Type type) { Declaration declaration; - if ((type.GetFinalPointee() ?? type).TryGetDeclaration(out declaration)) - { - declaration = declaration.CompleteDeclaration ?? declaration; - if (declaration.TranslationUnit.Module.Libraries.Any(l => - Context.Symbols.Libraries.First( - lib => lib.FileName == l).Dependencies.Any( - d => module != declaration.TranslationUnit.Module && - module.Libraries.Contains(d)))) - return true; - } + if (!(type.GetFinalPointee() ?? type).TryGetDeclaration(out declaration)) + return false; + + declaration = declaration.CompleteDeclaration ?? declaration; + if (declaration.Namespace == null || declaration.TranslationUnit.Module == null) + return false; + + // Check if there’s another module which wraps libraries with dependencies on + // the ones in the current module. + if (declaration.TranslationUnit.Module.Libraries.Any(l => + Context.Symbols.Libraries.First( + lib => lib.FileName == l).Dependencies.Any( + d => module != declaration.TranslationUnit.Module && + module.Libraries.Contains(d)))) + return true; + return false; } From 66a2a54aebcc6197c1bacf84b0aa5105b86e3f27 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Wed, 11 Jan 2017 22:35:39 +0000 Subject: [PATCH 12/12] Clean up the diagnostic in FieldToProperty pass. --- src/Generator/Passes/FieldToPropertyPass.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Generator/Passes/FieldToPropertyPass.cs b/src/Generator/Passes/FieldToPropertyPass.cs index 82de5cd7..cf0a3ddb 100644 --- a/src/Generator/Passes/FieldToPropertyPass.cs +++ b/src/Generator/Passes/FieldToPropertyPass.cs @@ -51,8 +51,7 @@ namespace CppSharp.Passes @class.Properties.Add(prop); - Diagnostics.Debug("Property created from field: {0}::{1}", @class.Name, - field.Name); + Diagnostics.Debug($"Property created from field: {field.QualifiedName}"); return false; }