Browse Source

Search for mangled symbols for functions in addition to variables.

pull/1/head
triton 12 years ago
parent
commit
d1c9737d0c
  1. 47
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

47
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -532,13 +532,9 @@ namespace CppSharp.Generators.CSharp
{ {
var @var = decl as Variable; var @var = decl as Variable;
var symbol = @var.Mangled; string symbol;
if (!Driver.LibrarySymbols.FindSymbol(ref symbol)) if (!FindMangledDeclSymbol(@var, out symbol))
{ return string.Empty;
Driver.Diagnostics.EmitError(DiagnosticId.SymbolNotFound,
"symbol \"{0}\" was not found", symbol);
throw new SymbolNotFoundException(symbol);
}
NativeLibrary library; NativeLibrary library;
Driver.LibrarySymbols.FindLibraryBySymbol(symbol, out library); Driver.LibrarySymbols.FindLibraryBySymbol(symbol, out library);
@ -1445,15 +1441,46 @@ namespace CppSharp.Generators.CSharp
return name; 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;
if (!Driver.LibrarySymbols.FindSymbol(ref symbol))
{
Driver.Diagnostics.EmitError(DiagnosticId.SymbolNotFound,
"Symbol not found: {0}", symbol);
symbol = null;
return false;
}
return true;
}
public void GenerateFunction(Function function, Class @class = null) public void GenerateFunction(Function function, Class @class = null)
{ {
if(function.Ignore) return; if(function.Ignore) return;
NativeLibrary library;
if (!FindMangledDeclLibrary(function, out library))
return;
GenerateDeclarationCommon(function); GenerateDeclarationCommon(function);
WriteLine("[SuppressUnmanagedCodeSecurity]"); WriteLine("[SuppressUnmanagedCodeSecurity]");
Write("[DllImport(\"{0}\", ", library.FileName);
Write("[DllImport(\"{0}.dll\", ", Library.SharedLibrary); WriteLine("CallingConvention = CallingConvention.{0},",
WriteLine("CallingConvention = CallingConvention.{0}, ",
Helpers.ToCSharpCallConv(function.CallingConvention)); Helpers.ToCSharpCallConv(function.CallingConvention));
WriteLineIndent("EntryPoint=\"{0}\")]", function.Mangled); WriteLineIndent("EntryPoint=\"{0}\")]", function.Mangled);

Loading…
Cancel
Save