Example #1
0
        public void SaveAndLoad6()
        {
            NativeFunctionPointer fptr = new NativeFunctionPointer("f1");

            Assert.Equal(NativeCallingConvention.WinApi, fptr.CallingConvention);
            fptr.CallingConvention    = NativeCallingConvention.Pascal;
            fptr.Signature.ReturnType = new NativeBuiltinType(BuiltinType.NativeChar);

            NativeProcedure proc = new NativeProcedure("p1");

            Assert.Equal(NativeCallingConvention.WinApi, proc.CallingConvention);
            proc.CallingConvention    = NativeCallingConvention.CDeclaration;
            proc.Signature.ReturnType = new NativeBuiltinType(BuiltinType.NativeChar);

            var ns = new BasicSymbolStorage();

            ns.AddProcedure(proc);
            ns.AddDefinedType(fptr);

            NativeDefinedType     temp   = null;
            NativeFunctionPointer retPtr = null;

            Assert.True(ns.TryGetGlobalSymbol(fptr.Name, out temp));
            retPtr = (NativeFunctionPointer)temp;
            Assert.Equal(NativeCallingConvention.Pascal, retPtr.CallingConvention);

            NativeProcedure retProc = null;

            Assert.True(ns.TryGetGlobalSymbol(proc.Name, out retProc));
            Assert.Equal(NativeCallingConvention.CDeclaration, retProc.CallingConvention);
        }
Example #2
0
        public void EnumAdd()
        {
            var enumeration = new NativeEnum("e");

            enumeration.AddValue("v1", "1");
            enumeration.AddValue("v2", "2");

            _storage.AddDefinedType(enumeration);
            Assert.True(_storage.Contains("v1"));
            Assert.True(_storage.Contains("v2"));
        }
Example #3
0
        public void FindOrLoad1()
        {
            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(new NativeStruct("s1"));
            NativeSymbolBag bag = new NativeSymbolBag(ns);

            NativeDefinedType s1 = null;

            Assert.False(bag.Storage.TryGetGlobalSymbol("s1", out s1));
            Assert.True(bag.TryGetGlobalSymbol("s1", out s1));
            Assert.True(bag.TryGetGlobalSymbol("s1", out s1));
        }
Example #4
0
        public void ValueFromStorage3()
        {
            var             ns  = new BasicSymbolStorage();
            NativeSymbolBag bag = new NativeSymbolBag(ns);

            ns.AddDefinedType(new NativeStruct("s1"));

            NativeConstant ntConst1 = new NativeConstant("c1", "(s1)1");

            bag.AddConstant(ntConst1);

            Assert.Equal(1, bag.FindUnresolvedNativeValues().Count);
            Assert.True(bag.TryResolveSymbolsAndValues());
        }
Example #5
0
        public void LoadByName1()
        {
            NativeStruct s1 = new NativeStruct("s");

            s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeInt32)));

            NativeType s2 = null;

            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(s1);

            Assert.True(ns.TryGetGlobalSymbol(s1.Name, out s2));
        }
Example #6
0
        public void ResolveLoad1()
        {
            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(new NativeStruct("s1"));

            NativeSymbolBag bag = new NativeSymbolBag(ns);

            bag.AddTypeDef(new NativeTypeDef("S1", "s1"));
            Assert.True(bag.TryResolveSymbolsAndValues());

            NativeDefinedType td = null;

            Assert.True(bag.TryGetGlobalSymbol("s1", out td));
        }
Example #7
0
        public void SaveAndLoad3()
        {
            NativeStruct s1 = new NativeStruct("s1");

            s1.Members.Add(new NativeMember("m1", new NativeNamedType("foo")));

            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(s1);

            NativeType rets1 = null;

            Assert.True(ns.TryGetType(s1.Name, out rets1));
            Assert.True(NativeTypeEqualityComparer.AreEqualTopLevel(s1, rets1));
        }
Example #8
0
        public void FuncPtr1()
        {
            NativeFunctionPointer fptr = new NativeFunctionPointer("f1");

            fptr.Signature.ReturnType = new NativeBuiltinType(BuiltinType.NativeChar);
            fptr.Signature.Parameters.Add(new NativeParameter("f", new NativeBuiltinType(BuiltinType.NativeFloat)));

            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(fptr);

            NativeDefinedType retFptr = null;

            Assert.True(ns.TryGetGlobalSymbol(fptr.Name, out retFptr));
            Assert.Equal("char (*f1)(float f)", ((NativeFunctionPointer)retFptr).DisplayName);
        }
Example #9
0
        public void LoadByName2()
        {
            NativeStruct s1 = new NativeStruct("s");

            s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeInt32)));
            s1.Members.Add(new NativeMember("m2", new NativeBuiltinType(BuiltinType.NativeByte)));
            s1.Members.Add(new NativeMember("m3", new NativeBitVector(6)));
            s1.Members.Add(new NativeMember("m4", new NativePointer(new NativeBuiltinType(BuiltinType.NativeChar))));
            s1.Members.Add(new NativeMember("m5", new NativeArray(new NativeBuiltinType(BuiltinType.NativeFloat), 4)));
            s1.Members.Add(new NativeMember("m7", new NativeNamedType("bar", new NativeBuiltinType(BuiltinType.NativeDouble))));


            NativeType s2 = null;

            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(s1);

            Assert.True(ns.TryGetType(s1.Name, out s2));
        }
Example #10
0
        public void SaveAndLoad1()
        {
            NativeStruct s1 = new NativeStruct("s1");

            s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeFloat)));

            NativeStruct s2 = new NativeStruct("s2");

            s2.Members.Add(new NativeMember("m1", s1));

            var ns = new BasicSymbolStorage();

            ns.AddDefinedType(s2);

            NativeDefinedType rets2 = null;

            Assert.True(ns.TryGetGlobalSymbol(s2.Name, out rets2));
            Assert.NotNull(rets2);
            Assert.True(NativeTypeEqualityComparer.AreEqualRecursive(s2, rets2));
            Assert.True(NativeTypeEqualityComparer.AreEqualTopLevel(s2, rets2));
        }
Example #11
0
        /// <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);
        }