Browse Source

Re-write code dealing with library symbol checking to respect the new symbol checking options.

pull/13/merge
triton 12 years ago
parent
commit
02be3857ed
  1. 50
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -605,23 +605,25 @@ namespace CppSharp.Generators.CSharp
WriteCloseBraceIndent(); WriteCloseBraceIndent();
} }
enum PropertyMethodKind private Tuple<string, string> GetDeclarationLibrarySymbol(IMangledDecl decl)
{ {
Getter, var library = Options.SharedLibraryName;
Setter var symbol = decl.Mangled;
}
private string GetVariableLocation(Variable @var) if (!Options.CheckSymbols)
{ goto Out;
string symbol;
if (!FindMangledDeclSymbol(@var, out symbol))
return string.Empty;
NativeLibrary library; if (!FindMangledDeclSymbol(decl, out symbol))
Driver.LibrarySymbols.FindLibraryBySymbol(symbol, out library); goto Out;
return string.Format("CppSharp.SymbolResolver.ResolveSymbol(\"{0}\", \"{1}\")", NativeLibrary nativeLib;
Path.GetFileNameWithoutExtension(library.FileName), symbol); if (!Driver.LibrarySymbols.FindLibraryBySymbol(symbol, out nativeLib))
goto Out;
library = nativeLib.FileName;
Out:
return Tuple.Create(Path.GetFileNameWithoutExtension(library), symbol);
} }
private void GeneratePropertySetter<T>(T decl, Class @class) private void GeneratePropertySetter<T>(T decl, Class @class)
@ -717,13 +719,16 @@ namespace CppSharp.Generators.CSharp
else if (decl is Variable) else if (decl is Variable)
{ {
var @var = decl as Variable; var @var = decl as Variable;
var location = GetVariableLocation(@var); var libSymbol = GetDeclarationLibrarySymbol(@var);
var typePrinter = TypePrinter as CSharpTypePrinter; var typePrinter = TypePrinter as CSharpTypePrinter;
typePrinter.PushContext(CSharpTypePrinterContextKind.Native); typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
var location = string.Format("CppSharp.SymbolResolver.ResolveSymbol(\"{0}\", \"{1}\")",
Path.GetFileNameWithoutExtension(libSymbol.Item1), libSymbol.Item2);
WriteLine("var {0} = ({1}*){2};", Helpers.GeneratedIdentifier("ptr"), WriteLine("var {0} = ({1}*){2};", Helpers.GeneratedIdentifier("ptr"),
@var.Type, location); @var.Type, libSymbol);
typePrinter.PopContext(); typePrinter.PopContext();
@ -1721,16 +1726,17 @@ namespace CppSharp.Generators.CSharp
GenerateDeclarationCommon(function); GenerateDeclarationCommon(function);
WriteLine("[SuppressUnmanagedCodeSecurity]"); WriteLine("[SuppressUnmanagedCodeSecurity]");
NativeLibrary library; string libName = Options.SharedLibraryName;
FindMangledDeclLibrary(function, out library);
var libName = (library != null) ? library.FileName : "SymbolNotFound"; if (Options.CheckSymbols)
{
NativeLibrary library;
FindMangledDeclLibrary(function, out library);
var index = libName.LastIndexOf('.'); libName = (library != null) ? library.FileName : "SymbolNotFound";
if (index >= 0) }
libName = libName.Slice(0, index);
Write("[DllImport(\"{0}\", ", libName); Write("[DllImport(\"{0}\", ", Path.GetFileNameWithoutExtension(libName));
var callConv = Helpers.ToCSharpCallConv(function.CallingConvention); var callConv = Helpers.ToCSharpCallConv(function.CallingConvention);
WriteLine("CallingConvention = CallingConvention.{0},", callConv); WriteLine("CallingConvention = CallingConvention.{0},", callConv);

Loading…
Cancel
Save