diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 8ca07a0f..287fe4e4 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -132,6 +132,7 @@ namespace CppSharp TranslationUnitPasses.AddPass(new SortDeclarationsPass()); TranslationUnitPasses.AddPass(new ResolveIncompleteDeclsPass()); TranslationUnitPasses.AddPass(new CheckIgnoredDeclsPass()); + TranslationUnitPasses.AddPass(new FindSymbolsPass()); library.SetupPasses(this); diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index ceb82a2c..b7e4d70f 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2071,19 +2071,6 @@ namespace CppSharp.Generators.CSharp return name; } - bool FindMangledDeclLibrary(IMangledDecl decl, out NativeLibrary library) - { - string symbol; - if (!FindMangledDeclSymbol(decl, out symbol)) - { - library = null; - return false; - } - - Driver.LibrarySymbols.FindLibraryBySymbol(symbol, out library); - return true; - } - bool FindMangledDeclSymbol(IMangledDecl decl, out string symbol) { symbol = decl.Mangled; @@ -2112,10 +2099,9 @@ namespace CppSharp.Generators.CSharp if (Options.CheckSymbols) { NativeLibrary library; - FindMangledDeclLibrary(function, out library); + Driver.LibrarySymbols.FindLibraryBySymbol(function.Mangled, out library); - libName = (library != null) ? library.FileName : "SymbolNotFound"; - libName = Path.GetFileNameWithoutExtension(libName); + libName = Path.GetFileNameWithoutExtension(library.FileName); } if (libName != null && libName.Length > 3 && libName.StartsWith("lib")) { diff --git a/src/Generator/Passes/FindSymbolsPass.cs b/src/Generator/Passes/FindSymbolsPass.cs new file mode 100644 index 00000000..5e2ef008 --- /dev/null +++ b/src/Generator/Passes/FindSymbolsPass.cs @@ -0,0 +1,21 @@ +using CppSharp.AST; + +namespace CppSharp.Passes +{ + public class FindSymbolsPass : TranslationUnitPass + { + public override bool VisitFunctionDecl(Function function) + { + string symbol = function.Mangled; + if (!Driver.LibrarySymbols.FindSymbol(ref symbol)) + { + Driver.Diagnostics.EmitWarning(DiagnosticId.SymbolNotFound, + "Symbol not found: {0}", symbol); + function.ExplicityIgnored = true; + return false; + } + function.Mangled = symbol; + return base.VisitFunctionDecl(function); + } + } +}