From a5b9c106818fda301e5182fb59b99a96439c9e17 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 28 Feb 2014 23:24:51 +0200 Subject: [PATCH] Reverted "Cleared up and fixed the exported symbols of libraries." Extended the symbols with stripped of the initial '_' ones. Signed-off-by: Dimitar Dobrev --- src/AST/SymbolContext.cs | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/AST/SymbolContext.cs b/src/AST/SymbolContext.cs index cb43ebc3..21b9f79d 100644 --- a/src/AST/SymbolContext.cs +++ b/src/AST/SymbolContext.cs @@ -41,13 +41,10 @@ namespace CppSharp.AST /// public Dictionary Symbols; - private readonly Dictionary compiledSymbols; - public SymbolContext() { Libraries = new List(); Symbols = new Dictionary(); - compiledSymbols = new Dictionary(); } public NativeLibrary FindOrCreateLibrary(string file) @@ -70,13 +67,11 @@ namespace CppSharp.AST foreach (var symbol in library.Symbols) { Symbols[symbol] = library; - if (!symbol.StartsWith("_imp_") && !symbol.StartsWith("__imp_") && - !symbol.StartsWith("_head") && !symbol.StartsWith("__head")) + if (symbol.StartsWith("__")) { - if (symbol.StartsWith("__")) - compiledSymbols[symbol.Substring(1)] = library; - else - compiledSymbols[symbol] = library; + string stripped = symbol.Substring(1); + if (!Symbols.ContainsKey(stripped)) + Symbols[stripped] = library; } } } @@ -85,12 +80,35 @@ namespace CppSharp.AST public bool FindSymbol(ref string symbol) { NativeLibrary lib; - return FindLibraryBySymbol(symbol, out lib); + + if (FindLibraryBySymbol(symbol, out lib)) + return true; + + // Check for C symbols with a leading underscore. + if (FindLibraryBySymbol("_" + symbol, out lib)) + { + symbol = "_" + symbol; + return true; + } + + if (FindLibraryBySymbol("_imp_" + symbol, out lib)) + { + symbol = "_imp_" + symbol; + return true; + } + + if (FindLibraryBySymbol("__imp_" + symbol, out lib)) + { + symbol = "__imp_" + symbol; + return true; + } + + return false; } public bool FindLibraryBySymbol(string symbol, out NativeLibrary library) { - return compiledSymbols.TryGetValue(symbol, out library); + return Symbols.TryGetValue(symbol, out library); } } }