public void ValueFromStorage1() { var ns = new BasicSymbolStorage(); ns.AddConstant(new NativeConstant("c1", "1")); var bag = new NativeSymbolBag(ns); bag.AddConstant(new NativeConstant("c2", "5+c1")); Assert.Equal(1, bag.FindUnresolvedNativeValues().Count); Assert.True(bag.TryResolveSymbolsAndValues()); }
public void SaveAndLoad5() { NativeConstant c1 = new NativeConstant("c1", "v1"); NativeConstant c2 = new NativeConstant("c2", "v2", ConstantKind.MacroMethod); var ns = new BasicSymbolStorage(); ns.AddConstant(c1); ns.AddConstant(c2); NativeConstant ret = null; Assert.True(ns.TryGetGlobalSymbol("c1", out ret)); Assert.Equal("c1", ret.Name); Assert.Equal("v1", ret.Value.Expression); Assert.Equal(ConstantKind.Macro, ret.ConstantKind); Assert.True(ns.TryGetGlobalSymbol("c2", out ret)); Assert.Equal("c2", ret.Name); Assert.Equal("\"v2\"", ret.Value.Expression); Assert.Equal(ConstantKind.MacroMethod, ret.ConstantKind); }
public void FindOrLoad3() { var ns = new BasicSymbolStorage(); ns.AddConstant(new NativeConstant("c1", "value")); NativeSymbolBag bag = new NativeSymbolBag(ns); NativeConstant c = null; Assert.False(bag.Storage.TryGetGlobalSymbol("c1", out c)); Assert.True(bag.TryGetGlobalSymbol("c1", out c)); Assert.True(bag.TryGetGlobalSymbol("c1", out c)); }
/// <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); }