public void Iterate1() { NativeStruct nt1 = new NativeStruct(); nt1.Name = "s1"; VerifyReachable(nt1, "s1"); }
public void Empty() { var ns = new NativeStruct("test"); var code = _factory.GenerateStruct(ns); Assert.Equal("", code.ToFullString()); }
public void Iterate2() { NativeStruct nt1 = new NativeStruct(); nt1.Name = "s1"; nt1.Members.Add(new NativeMember("f", new NativeBuiltinType(BuiltinType.NativeInt32))); VerifyReachable(nt1, "s1", "int"); }
public void Child2() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeByte))); s1.ReplaceChild(s1.Members[0], new NativeMember("m2", new NativeBuiltinType(BuiltinType.NativeDouble))); VerifyTree(s1, "s1(m2(double))"); }
internal StructDeclarationSyntax GenerateStruct(NativeStruct nativeStruct) { var structSyntax = SyntaxFactory.StructDeclaration(nativeStruct.Name); structSyntax = structSyntax.WithAttributeLists(GenerateSimpleAttribute(GenerateStructLayout())); return(structSyntax); }
public void TestStruct4() { ParseResult result = ParseFile("SampleFiles\\Struct4.txt"); NativeStruct nt1 = (NativeStruct)result.ParsedTypes[0]; NativeStruct nt2 = (NativeStruct)result.ParsedTypes[1]; VerifyMembers(nt1, "s1", "int", "i", "double*", "j"); VerifyMembers(nt2, "s2", "s1", "parent"); }
public void AddDefinedTypeTest3() { NativeSymbolBag bag = new NativeSymbolBag(); NativeStruct definedNt1 = new NativeStruct("s1"); NativeStruct definedNt2 = new NativeStruct("s1"); bag.AddDefinedType(definedNt1); Assert.Throws <ArgumentException>(() => bag.AddDefinedType(definedNt2)); }
public void Iterate5() { NativeStruct nt1 = new NativeStruct("s1"); NativeTypeDef nt2 = new NativeTypeDef("td1"); NativeNamedType nt3 = new NativeNamedType("n1"); nt2.RealType = nt3; nt1.Members.Add(new NativeMember("foo", nt2)); VerifyReachable(nt1, "s1", "td1", "n1"); }
public void Child1() { NativeStruct s1 = new NativeStruct("s1"); VerifyTree(s1, "s1"); s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeChar))); VerifyTree(s1, "s1(m1(char))"); s1.Members.Add(new NativeMember("m2", new NativeBuiltinType(BuiltinType.NativeByte))); VerifyTree(s1, "s1(m1(char))(m2(byte))"); }
public void TypeRename4() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeNamedType("s1", new NativeBuiltinType(BuiltinType.NativeByte)))); NativeSymbolTransform transform = new NativeSymbolTransform(); transform.RenameTypeSymbol(s1, "s1", "s2"); VerifyTree(s1, "s2(m1(s2(byte)))"); }
public void TypeRename3() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("s1", new NativeBuiltinType(BuiltinType.NativeChar))); NativeSymbolTransform transform = new NativeSymbolTransform(); transform.RenameTypeSymbol(s1, "s1", "s2"); VerifyTree(s1, "s2(s1(char))"); }
public void TopLevel13() { NativeStruct left = new NativeStruct("s"); left.Members.Add(new NativeMember("m1", new NativeNamedType("foo"))); NativeStruct right = new NativeStruct("s"); right.Members.Add(new NativeMember("m1", new NativeStruct("foo"))); Assert.True(NativeTypeEqualityComparer.AreEqualTopLevel(left, right)); }
public void AnonymousType1() { NativeStruct nt = new NativeStruct(); nt.IsAnonymous = true; Assert.False(string.IsNullOrEmpty(nt.Name)); NativeSymbolBag bag = new NativeSymbolBag(); bag.AddDefinedType(nt); Assert.True(NativeSymbolBag.IsAnonymousName(nt.Name)); }
public void AddDefinedTypeTest() { NativeSymbolBag bag = new NativeSymbolBag(); NativeStruct definedNt1 = new NativeStruct("s1"); bag.AddDefinedType(definedNt1); NativeType ret1 = null; Assert.True(bag.TryGetType(definedNt1.DisplayName, out ret1)); Assert.Same(ret1, definedNt1); }
public void CollapseTypedef1() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeTypeDef("PCHAR", new NativePointer(new NativeBuiltinType(BuiltinType.NativeChar))))); VerifyTree(s1, "s1(m1(PCHAR(*(char))))"); NativeSymbolTransform transform = new NativeSymbolTransform(); transform.CollapseTypedefs(s1); VerifyTree(s1, "s1(m1(*(char)))"); }
public void CollapseTypedef2() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeTypeDef("foo"))); VerifyTree(s1, "s1(m1(foo))"); NativeSymbolTransform transform = new NativeSymbolTransform(); transform.CollapseNamedTypes(s1); VerifyTree(s1, "s1(m1(foo))"); }
public void TypeRename2() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeChar))); NativeTypeDef td = new NativeTypeDef("foo", s1); NativeSymbolTransform transform = new NativeSymbolTransform(); transform.RenameTypeSymbol(td, "s1", "s2"); VerifyTree(td, "foo(s2(m1(char)))"); }
public void CallapseNamed2() { NativeStruct s1 = new NativeStruct("s1"); s1.Members.Add(new NativeMember("m1", new NativeNamedType("char"))); VerifyTree(s1, "s1(m1(char))"); NativeSymbolTransform transform = new NativeSymbolTransform(); transform.CollapseNamedTypes(s1); VerifyTree(s1, "s1(m1(char))"); }
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)); }
public void Value3() { NativeSymbolBag bag = new NativeSymbolBag(); NativeStruct ntStruct1 = new NativeStruct("s1"); bag.AddDefinedType(ntStruct1); NativeConstant ntConst1 = new NativeConstant("c1", "(s1)1"); bag.AddConstant(ntConst1); Assert.Equal(1, bag.FindUnresolvedNativeValues().Count); Assert.True(bag.TryResolveSymbolsAndValues()); }
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)); }
public void TopLevel8() { NativeStruct nd1 = new NativeStruct("s"); NativeStruct nd2 = new NativeStruct("s"); nd1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeBoolean))); nd2.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeBoolean))); NativeTypeEqualityComparer eq = NativeTypeEqualityComparer.TopLevel; Assert.True(eq.Equals1(nd1, nd2)); nd1.Members.Clear(); Assert.False(eq.Equals1(nd1, nd2)); }
public void Proc2() { NativeStruct s1 = new NativeStruct("s1"); NativeProcedure p1 = new NativeProcedure("p1"); p1.Signature.ReturnType = s1; var ns = new BasicSymbolStorage(); ns.AddProcedure(p1); NativeProcedure retp1 = null; Assert.True(ns.TryGetGlobalSymbol(p1.Name, out retp1)); Assert.Equal(p1.DisplayName, retp1.DisplayName); }
public void Resolve1() { NativeSymbolBag bag = new NativeSymbolBag(); NativeStruct s1 = new NativeStruct("s1"); bag.AddDefinedType(s1); NativeTypeDef td1 = new NativeTypeDef("td1"); NativeNamedType n1 = new NativeNamedType("s1"); td1.RealType = n1; bag.AddTypeDef(td1); Assert.True(bag.TryResolveSymbolsAndValues()); Assert.Same(s1, n1.RealType); }
public void Iterate3() { NativeStruct nt1 = new NativeStruct(); nt1.Name = "s1"; NativeStruct nt2 = new NativeStruct(); nt2.Name = "s2"; NativeSymbolBag bag = new NativeSymbolBag(); bag.AddDefinedType(nt1); bag.AddDefinedType(nt2); VerifyReachable(bag, "s1", "s2"); }
public void AddMixed2() { NativeSymbolBag bag = new NativeSymbolBag(); NativeStruct definedNt1 = new NativeStruct("s1"); bag.AddDefinedType(definedNt1); NativeTypeDef td1 = new NativeTypeDef("s1"); bag.AddTypeDef(td1); NativeType ret = null; Assert.True(bag.TryGetType(definedNt1.DisplayName, out ret)); Assert.Same(definedNt1, ret); Assert.True(bag.TryGetType(td1.DisplayName, out ret)); Assert.Same(definedNt1, ret); }
public void Anonymous1() { NativeStruct nd1 = new NativeStruct("ndaaoeu"); NativeStruct nd2 = new NativeStruct("a"); nd1.IsAnonymous = true; nd2.IsAnonymous = true; nd1.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeBoolean))); nd2.Members.Add(new NativeMember("m1", new NativeBuiltinType(BuiltinType.NativeBoolean))); nd1.Members.Add(new NativeMember("m2", new NativeBuiltinType(BuiltinType.NativeBoolean))); nd2.Members.Add(new NativeMember("m2", new NativeBuiltinType(BuiltinType.NativeBoolean))); NativeTypeEqualityComparer eq = NativeTypeEqualityComparer.TopLevel; Assert.True(eq.Equals1(nd1, nd2)); }
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> /// Generate the struct definition /// </summary> /// <param name="ntStruct"></param> /// <returns></returns> /// <remarks></remarks> public CodeTypeDeclaration GenerateStruct(NativeStruct ntStruct) { if (ntStruct == null) { throw new ArgumentNullException("ntStruct"); } // Generate the core type CodeTypeDeclaration ctd = new CodeTypeDeclaration(ntStruct.Name); ctd.IsStruct = true; ctd.UserData[TransformConstants.DefinedType] = ntStruct; // Add the struct layout attribute ctd.CustomAttributes.Add(MarshalAttributeFactory.CreateStructLayoutAttribute(LayoutKind.Sequential)); GenerateContainerMembers(ntStruct, ctd); return(ctd); }
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)); }
public SteamParamStringArray(IList<string> values) { // Need one buffer per string nativeStrings = new IntPtr[values.Count]; for (int i = 0; i < values.Count; i++) { // Create native strings for all values nativeStrings[i] = Marshal.StringToHGlobalAnsi(values[i]); } // Create one array of string pointers nativeDoubleStringArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * nativeStrings.Length); Marshal.Copy(nativeStrings, 0, nativeDoubleStringArray, nativeStrings.Length); NativeStruct nativeStruct = new NativeStruct() { Strings = nativeDoubleStringArray, StringCount = nativeStrings.Length, }; nativeStructMemory = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NativeStruct))); Marshal.StructureToPtr(nativeStruct, nativeStructMemory, false); }