public void BagSaveAndLoad1() { NativeProcedure p1 = new NativeProcedure("p1"); p1.Signature.ReturnType = new NativeBuiltinType(BuiltinType.NativeBoolean); NativeTypeDef td = new NativeTypeDef("LPWSTR", new NativePointer(BuiltinType.NativeWChar)); p1.Signature.Parameters.Add(new NativeParameter("param1", new NativeNamedType("LPWSTR", td))); Assert.Equal("boolean p1(LPWSTR param1)", p1.DisplayName); Assert.Equal("p1(Sig(boolean)(Sal)(param1(LPWSTR(LPWSTR(*(wchar))))(Sal)))", SymbolPrinter.Convert(p1)); var ns = new BasicSymbolStorage(); ns.AddProcedure(p1); ns.AddTypeDef(td); NativeSymbolBag bag = new NativeSymbolBag(ns); NativeProcedure ret1 = null; Assert.True(bag.TryGetGlobalSymbol("p1", out ret1)); bag.AddProcedure(ret1); Assert.True(bag.TryResolveSymbolsAndValues()); Assert.Equal(SymbolPrinter.Convert(p1), SymbolPrinter.Convert(ret1)); }
private static BasicSymbolStorage CreateInitialBasicSymbolStorage() { var ns = new BasicSymbolStorage(); // Add in the basic type defs ns.AddTypeDef(new NativeTypeDef("SIZE_T", new NativeBuiltinType(BuiltinType.NativeInt32, true))); ns.AddTypeDef(new NativeTypeDef("DWORD64", new NativeBuiltinType(BuiltinType.NativeInt64, true))); ns.AddTypeDef(new NativeTypeDef("HWND", new NativePointer(BuiltinType.NativeVoid))); ns.AddTypeDef(new NativeTypeDef("HMENU", new NativePointer(BuiltinType.NativeVoid))); ns.AddTypeDef(new NativeTypeDef("HACCEL", new NativePointer(BuiltinType.NativeVoid))); ns.AddTypeDef(new NativeTypeDef("HBRUSH", new NativePointer(BuiltinType.NativeVoid))); ns.AddTypeDef(new NativeTypeDef("HFONT", new NativePointer(BuiltinType.NativeVoid))); ns.AddTypeDef(new NativeTypeDef("HDC", new NativePointer(BuiltinType.NativeVoid))); ns.AddTypeDef(new NativeTypeDef("HICON", new NativePointer(BuiltinType.NativeVoid))); return(ns); }
public void FindOrLoad2() { var ns = new BasicSymbolStorage(); ns.AddTypeDef(new NativeTypeDef("td", new NativeBuiltinType(BuiltinType.NativeChar))); NativeSymbolBag bag = new NativeSymbolBag(ns); NativeTypeDef td = null; Assert.False(bag.Storage.TryGetGlobalSymbol("td", out td)); Assert.True(bag.TryGetGlobalSymbol("td", out td)); Assert.True(bag.TryGetGlobalSymbol("td", out td)); }
public void SaveAndLoad4() { NativeTypeDef t1 = new NativeTypeDef("t1"); t1.RealType = new NativeBuiltinType(BuiltinType.NativeByte); var ns = new BasicSymbolStorage(); ns.AddTypeDef(t1); NativeType rett1 = null; Assert.True(ns.TryGetType(t1.Name, out rett1)); Assert.True(NativeTypeEqualityComparer.AreEqualRecursive(rett1, t1)); }
public void ResolveLoad2() { var ns = new BasicSymbolStorage(); ns.AddTypeDef(new NativeTypeDef("TEST_INT", BuiltinType.NativeInt32)); NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeNamedType("TEST_INT"))); NativeSymbolBag bag = new NativeSymbolBag(ns); bag.AddDefinedType(s1); Assert.True(bag.TryResolveSymbolsAndValues()); NativeTypeDef td = null; Assert.True(bag.TryGetGlobalSymbol("TEST_INT", out td)); }
/// <summary> /// Used to create a simple set of types that can be used for testing purposes /// </summary> /// <returns></returns> /// <remarks></remarks> public static BasicSymbolStorage CreateStandard() { var storage = new BasicSymbolStorage(); NativePointer pt1 = default(NativePointer); NativeTypeDef td1 = default(NativeTypeDef); NativeTypeDef td2 = default(NativeTypeDef); NativeStruct s1 = default(NativeStruct); NativeUnion u1 = default(NativeUnion); NativeNamedType n1 = default(NativeNamedType); // Include sal information List <NativeConstant> list = ProcessSal(); foreach (NativeConstant cur in list) { storage.AddConstant(cur); } // Bool types storage.AddTypeDef(new NativeTypeDef("BOOL", BuiltinType.NativeInt32)); storage.AddTypeDef(new NativeTypeDef("DWORD", new NativeBuiltinType(BuiltinType.NativeInt32, true))); // WPARAM td1 = new NativeTypeDef("UINT_PTR", new NativeBuiltinType(BuiltinType.NativeInt32, true)); storage.AddTypeDef(new NativeTypeDef("WPARAM", td1)); storage.AddTypeDef(new NativeTypeDef("LPARAM", td1)); // WCHAR NativeTypeDef wcharTd = new NativeTypeDef("WCHAR", new NativeBuiltinType(BuiltinType.NativeInt16, true)); storage.AddTypeDef(wcharTd); // CHAR td1 = new NativeTypeDef("CHAR", BuiltinType.NativeChar); storage.AddTypeDef(td1); // TCHAR td2 = new NativeTypeDef("TCHAR", td1); storage.AddTypeDef(td2); // LPWSTR pt1 = new NativePointer(wcharTd); td2 = new NativeTypeDef("LPWSTR", pt1); storage.AddTypeDef(td2); // LPCWSTR n1 = new NativeNamedType(wcharTd.Name, wcharTd); n1.IsConst = true; pt1 = new NativePointer(n1); td2 = new NativeTypeDef("LPCWSTR", pt1); storage.AddTypeDef(td2); // LPSTR pt1 = new NativePointer(new NativeBuiltinType(BuiltinType.NativeChar)); td1 = new NativeTypeDef("LPSTR", pt1); storage.AddTypeDef(td1); // LPTSTR storage.AddTypeDef(new NativeTypeDef("LPTSTR", td1)); // LPCSTR n1 = new NativeNamedType("char", true); n1.RealType = new NativeBuiltinType(BuiltinType.NativeChar, false); pt1 = new NativePointer(n1); td1 = new NativeTypeDef("LPCSTR", pt1); storage.AddTypeDef(td1); // LPCTSTR td2 = new NativeTypeDef("LPCTSTR", td1); storage.AddTypeDef(td2); // BSTR storage.AddTypeDef(new NativeTypeDef("OLECHAR", BuiltinType.NativeWChar)); storage.AddTypeDef(new NativeTypeDef("BSTR", new NativePointer(new NativeTypeDef("OLECHAR", BuiltinType.NativeWChar)))); // Struct with a recrsive reference to itself s1 = new NativeStruct("RecursiveStruct"); s1.Members.Add(new NativeMember("m1", new NativePointer(new NativeNamedType(s1.Name)))); storage.AddDefinedType(s1); // Simple struct s1 = new NativeStruct("S1"); s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeBoolean))); storage.AddDefinedType(s1); // Simulate a few well known structures // DECIMAL s1 = new NativeStruct("tagDEC"); storage.AddDefinedType(s1); storage.AddTypeDef(new NativeTypeDef("DECIMAL", s1)); // CURRENCY u1 = new NativeUnion("tagCY"); storage.AddDefinedType(u1); storage.AddTypeDef(new NativeTypeDef("CY", u1)); storage.AddTypeDef(new NativeTypeDef("CURRENCY", new NativeTypeDef("CY", u1))); // BYTE storage.AddTypeDef(new NativeTypeDef("BYTE", new NativeBuiltinType(BuiltinType.NativeChar, true))); return(storage); }