/// <summary> /// Generate the specified union /// </summary> /// <param name="ntUnion"></param> /// <returns></returns> /// <remarks></remarks> public CodeTypeDeclaration GenerateUnion(NativeUnion ntUnion) { if (ntUnion == null) { throw new ArgumentNullException("ntUnion"); } // Generate the core type CodeTypeDeclaration ctd = new CodeTypeDeclaration(ntUnion.Name); ctd.IsStruct = true; ctd.UserData[TransformConstants.DefinedType] = ntUnion; // Add the struct layout attribute ctd.CustomAttributes.Add(MarshalAttributeFactory.CreateStructLayoutAttribute(LayoutKind.Explicit)); // Generate the container members GenerateContainerMembers(ntUnion, ctd); // Go through and put each struct back at the start of the struct to simulate the // union foreach (CodeTypeMember member in ctd.Members) { CodeMemberField fieldMember = member as CodeMemberField; if (fieldMember != null) { fieldMember.CustomAttributes.Add(MarshalAttributeFactory.CreateFieldOffsetAttribute(0)); } } return(ctd); }
/// <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); }
private void VerifyUnion(NativeType nt, string name, params string[] args) { NativeUnion ntUnion = nt as NativeUnion; Assert.NotNull(ntUnion); VerifyMembers(ntUnion, name, args); }
internal StructDeclarationSyntax GenerateUnion(NativeUnion nativeUnion) { throw new NotSupportedException(); }
public void UnionSimple() { var u = new NativeUnion("u1"); TestRoundTrip(u); }