private void PrependTypeField() { string kind = (Domain == "Redirection" ? "REDIRECTIONCMD" : (Domain == "DWM" ? "DWMCMD" : "MILCMD")); McgField field = new McgField( Domain == "DWM" ? "type" : "Type", // special case for DWM commands null, m_resourceModel.FindType(kind), "Implicit command type field", false, // is not animated null, // has no property alias true, // isReadOnly false, // isManagedOnly false, // isUnmanagedOnly false, // isValidate false, // isNew null, // defaultValue false, // isInternal false, // isProtected false, // no PropertyChanged hook false, // is not commonly set null, // CoerceValueCallback is null by default true, // Visible to Serialization null, // no TypeConverter false // locally cached dp ); PrependField(field); }
private void AppendCollectionSizeField() { McgField field = new McgField( "Size", null, m_resourceModel.FindType("UInt32"), "Implicit resource collection size field", false, // is not animated null, // has no property alias true, // isReadOnly false, // isManagedOnly false, // isUnmanagedOnly false, // isValidate false, // isNew null, // defaultValue false, // isInternal false, // isProtected false, // no PropertyChanged hook false, // is not commonly set null, // CoerceValueCallback is null by default true, // Visible to Serialization null, // no TypeConverter false // locally cached dp ); AppendField(field); }
// ----------------------------------------------------------------- // // Private Methods // // ----------------------------------------------------------------- #region Private Methods /// <summary> /// Prepends a field to this padded command. Alignment is not updated. /// </summary> /// <remarks> /// /// </remarks> private void PrependField(McgField field) { Helpers.CodeGenHelpers.AlignmentEntry entry = new Helpers.CodeGenHelpers.AlignmentEntry(field, false, false); List <Helpers.CodeGenHelpers.AlignmentEntry> entries = new List <Helpers.CodeGenHelpers.AlignmentEntry>(m_paddedStructData.AlignmentEntries); // // Update the existing field offsets // foreach (Helpers.CodeGenHelpers.AlignmentEntry existingEntry in entries) { existingEntry.Offset += field.Type.UnpaddedSize; } // // Prepend the new entry and write back the result // entries.Insert(0, entry); m_paddedStructData.AlignmentEntries = entries.ToArray(); m_paddedStructData.PaddedSize += field.Type.UnpaddedSize; }
public AlignmentEntry( McgField field, bool isAnimation, bool isPad) { Field = field; IsAnimation = isAnimation; IsPad = isPad; }
internal static void AppendParameter( DelimitedList parameterList, McgField field, ParameterType parameterType) { AppendParameter(parameterList, field.Type, field.Name, field.Name, field.PropertyName, field.PropertyName, field.IsAnimated, parameterType); }
/// <summary> /// Appends a field to this padded command. Alignment is not updated. /// </summary> /// <remarks> /// /// </remarks> private void AppendField(McgField field) { Helpers.CodeGenHelpers.AlignmentEntry entry = new Helpers.CodeGenHelpers.AlignmentEntry(field, false, false); List <Helpers.CodeGenHelpers.AlignmentEntry> entries = new List <Helpers.CodeGenHelpers.AlignmentEntry>(m_paddedStructData.AlignmentEntries); entries.Add(entry); m_paddedStructData.AlignmentEntries = entries.ToArray(); m_paddedStructData.PaddedSize += field.Type.UnpaddedSize; }
/// <summary> /// Builds the real field names and decides their type. /// </summary> internal void BuildMarshaledFieldNames() { int padSuffix = 0; foreach (AlignmentEntry entry in AlignmentEntries) { McgField field = entry.Field; // // This primary if else else block switches between the tree types of entries in the // paddedFields alignment list: padding, animation and normal field entries. // if (field == null) { entry.Name = "padQuadAlignment" + padSuffix++; entry.IsPad = true; } else if (entry.IsAnimation) { entry.Name = "h" + field.PropertyName + "Animations"; entry.IsHandle = true; } else { // This case is a boring, non animate field. McgType type = field.Type; McgResource resourceType = type as McgResource; // If it's an McgResource, we have to handle reference types and collections if (resourceType != null && !resourceType.IsValueType) { entry.Name = "h" + field.Name; entry.IsHandle = true; } else { entry.Name = field.Name; if (type.Name == "ResourceHandle") { entry.IsHandle = true; } } } } }
internal static string WriteFieldStatement(McgField field, string statement) { string fieldName = field.PropertyName; string animationContainerName = field.PropertyName + "Animations"; string animationContainerType = field.Type.ManagedName + "AnimationCollection"; StringBuilder output = new StringBuilder(statement); output.Replace("{type}", field.Type.Name); output.Replace("{managedType}", field.Type.ManagedName); output.Replace("{localName}", field.Name); output.Replace("{propertyName}", field.PropertyName); output.Replace("{propertyFlag}", field.PropertyFlag); output.Replace("{dpPropertyName}", field.DPPropertyName); output.Replace("{fieldName}", fieldName); output.Replace("{parseMethod}", field.Type.ParseMethod); output.Replace("{animationContainerName}", animationContainerName); output.Replace("{animationContainerType}", animationContainerType); output.Replace("{marshalValue}", field.IsUnmanagedOnly ? field.Default : field.PropertyName); return(output.ToString()); }
internal static int AppendStructParameters( DelimitedList parameterList, PaddedStructData paddedFields, int initialPosition, bool unmanagedStruct, bool kernelAccessibleStruct ) { int padSuffix = 0; Helpers.CodeGenHelpers.AlignedFieldOffsetHelper alignedFieldHelper = new Helpers.CodeGenHelpers.AlignedFieldOffsetHelper(4, 4); foreach (AlignmentEntry alignmentEntry in paddedFields.AlignmentEntries) { McgField field = alignmentEntry.Field; int position = initialPosition + alignmentEntry.Offset; alignedFieldHelper.MoveToNextEntry(position, alignmentEntry.Size); int alignedFieldOffset = alignedFieldHelper.AlignedFieldOffset; if (unmanagedStruct) { // Insert enough padding to ensure the field is properly aligned foreach (string alignmentField in alignedFieldHelper.AlignmentFields) { parameterList.Append(alignmentField); } } // This primary if else else block switches between the tree types of entries in the // paddedFields alignment list: padding, animation and normal field entries. // The offset of each field is stored in "position", which is the padding offset of the // entry + the initial position. if (field == null) { Debug.Assert(alignmentEntry.IsPad); string padIdentifier = "padQuadAlignment" + padSuffix; if (unmanagedStruct) { parameterList.Append("UINT32 " + padIdentifier + ";"); } else { parameterList.Append("[FieldOffset(" + alignedFieldOffset + ")] private UInt32 " + padIdentifier); } ++padSuffix; } else if (alignmentEntry.IsAnimation) { if (unmanagedStruct) { parameterList.Append("HMIL_RESOURCE " + "h" + field.PropertyName + "Animations;"); } else { parameterList.Append("[FieldOffset(" + alignedFieldOffset + ")] internal DUCE.ResourceHandle h" + field.PropertyName + "Animations"); } } else { // This case is a boring, non animate field. bool constructedParam = false; McgType type = field.Type; McgResource resourceType = type as McgResource; // If it's an McgResource, we have to handle reference types and collections if (resourceType != null) { // Currently, collections are accounted for by storing just their size inline if (resourceType.IsCollection) { if (unmanagedStruct) { parameterList.Append("UINT32 " + field.Name + "Size;"); } else { parameterList.Append("[FieldOffset(" + alignedFieldOffset + ")] internal UInt32 " + field.Name + "Size"); } constructedParam = true; } // If it's not a collection, is it a reference type? If so, it's passed by handle. else if (!resourceType.IsValueType) { if (unmanagedStruct) { parameterList.Append("HMIL_RESOURCE " + "h" + field.Name + ";"); } else { parameterList.Append("[FieldOffset(" + alignedFieldOffset + ")] internal DUCE.ResourceHandle h" + field.Name); } constructedParam = true; } } // If we haven't yet handled this parameter, we're left with a primitive type, // like a struct or an enum. At this point, the value will be stored inline. // The only real question left is whether the unmanaged struct matches the managed struct. // If so, the struct is simply stored. If not, then .NeedsConvert is true, and // the record is of the unmanaged type, even on the managed side of things. if (!constructedParam) { if (type.NeedsConvert) { if (unmanagedStruct) { parameterList.Append(type.BaseUnmanagedType + " " + field.Name + ";"); } else { parameterList.Append("[FieldOffset(" + alignedFieldOffset + ")] internal " + type.MarshalUnmanagedType + " " + field.Name); } } else { if (unmanagedStruct) { if (kernelAccessibleStruct) { McgEnum enumType = type as McgEnum; if (enumType != null) { parameterList.Append(enumType.KernelAccessibleType + " " + field.Name + ";"); constructedParam = true; } } if (!constructedParam) { parameterList.Append(type.BaseUnmanagedType + " " + field.Name + ";"); } } else { parameterList.Append("[FieldOffset(" + alignedFieldOffset + ")] internal " + type.ManagedName + " " + field.Name); } } } } } if (unmanagedStruct) { // Insert enough padding to ensure the struct's size falls on a packing boundary foreach (string packingField in alignedFieldHelper.NativePackingFields) { parameterList.Append(packingField); } } else { // Insert enough padding to ensure the struct's size falls on a packing boundary foreach (string packingField in alignedFieldHelper.ManagedPackingFields) { parameterList.Append(packingField); } } return(initialPosition + paddedFields.PaddedSize); }