Пример #1
0
        private ElementArray ProcessTagBlockDefinition(ElementArray parent, MoonfishTagDefinition tagBlock,
                                                       ref int offset, bool inline = false)
        {
            var size = tagBlock.CalculateSizeOfFieldSet();

            var blockElementArray = new ElementArray
            {
                name            = tagBlock.Name,
                elementSize     = size,
                address         = offset,
                parent          = parent,
                maxElementCount = tagBlock.MaximumElementCount,
                alignment       = tagBlock.Alignment
            };

            var i           = 0;
            var blockOffset = inline ? offset : 0;

            ProcessFields(tagBlock.Fields, blockElementArray, ref i, ref blockOffset);
            if (inline)
            {
                offset = blockOffset;
            }
            return(blockElementArray);
        }
Пример #2
0
 public MoonfishTagGroup(GuerillaTagGroup guerillaTag)
 {
     Name        = guerillaTag.Name;
     Class       = guerillaTag.Class;
     ParentClass = guerillaTag.ParentClass;
     Definition  = new MoonfishTagDefinition(guerillaTag.Definition);
 }
Пример #3
0
        private void ProcessFields(IList <MoonfishTagField> fields, ElementArray elementArray, ref int i, ref int offset)
        {
            for (; i < fields.Count; ++i)
            {
                var field = fields[i];
                // Check the field type.
                switch (field.Type)
                {
                case MoonfishFieldType.FieldBlock:
                {
                    var childElementArray = ProcessTagBlockDefinition(elementArray, field.Definition, ref offset);
                    elementArray.children.Add(childElementArray);
                    break;
                }

                case MoonfishFieldType.FieldStruct:
                {
                    var struct_definition = (MoonfishTagStruct)field.Definition;
                    var structOffset      = offset;
                    var childElementArray = ProcessTagStructDefinition(elementArray, struct_definition.Definition,
                                                                       ref structOffset);
                    elementArray.children.AddRange(childElementArray);

                    break;
                }

                case MoonfishFieldType.FieldData:
                {
                    var data_definition   = (MoonfishTagDataDefinition)field.Definition;
                    var childElementArray = new ElementArray
                    {
                        elementSize = ((MoonfishTagDataDefinition)field.Definition).DataElementSize,
                        name        = data_definition.Name,
                        address     = offset,
                        parent      = elementArray,
                        alignment   = data_definition.Alignment
                    };
                    elementArray.children.Add(childElementArray);
                    break;
                }

                case MoonfishFieldType.FieldArrayStart:
                {
                    ProcessArrayFields(fields, elementArray, field, ref i, ref offset);
                    break;
                }

                case MoonfishFieldType.FieldArrayEnd:
                {
                    return;
                }
                }
                offset += MoonfishTagDefinition.CalculateSizeOfField(field);
            }
        }
Пример #4
0
        private ClassInfo BeginProcessTagBlockDefinition(MoonfishTagDefinition block,
                                                         string className = "")
        {
            var size      = block.CalculateSizeOfFieldSet();
            var alignment = block.Alignment;

#if DEBUG
            System.Diagnostics.Debug.Assert(alignment > 0 && alignment % 2 == 0);
#endif

            var @class = new ClassInfo
            {
                AccessModifiers = AccessModifiers.Public,
                Name            = className == string.Empty ? ToTypeName(block.Name) : ToTypeName(className),
                Attributes      =
                {
                    new AttributeInfo(typeof(LayoutAttribute),
                                      StaticReflection.GetMemberName((LayoutAttribute layout) => layout.Size),     size,
                                      StaticReflection.GetMemberName((LayoutAttribute layout) => layout.Alignment),alignment
                                      )
                },
                Properties =
                {
                    new PropertyInfo
                    {
                        AccessModifiers = AccessModifiers.Public | AccessModifiers.Override,
                        GetBody         = string.Format("return {0};", size),
                        Returns         = "int",
                        Name            = "SerializedSize"
                    },
                    new PropertyInfo
                    {
                        AccessModifiers = AccessModifiers.Public | AccessModifiers.Override,
                        GetBody         = string.Format("return {0};", alignment),
                        Returns         = "int",
                        Name            = "Alignment"
                    }
                },
                BaseClass = new ClassInfo("GuerillaBlock")
            };



            ProcessFields(block.Fields, @class);
            @class.Format();
            return(@class);
        }
Пример #5
0
        private IEnumerable <ElementArray> ProcessTagStructDefinition(ElementArray parent,
                                                                      MoonfishTagDefinition definition, ref int offset)
        {
            var size = definition.CalculateSizeOfFieldSet();

            var blockElementArray = new ElementArray
            {
                name            = definition.Name,
                elementSize     = size,
                address         = offset,
                parent          = parent,
                maxElementCount = definition.MaximumElementCount,
                alignment       = definition.Alignment
            };

            var i = 0;

            ProcessFields(definition.Fields, blockElementArray, ref i, ref offset);
            return(blockElementArray.children);
        }
Пример #6
0
        private ClassInfo ProcessArrayFields(List <MoonfishTagField> fields)
        {
            var size       = MoonfishTagDefinition.CalculateSizeOfFieldSet(fields.GetRange(1, fields.Count - 2));
            var arrayClass = new ClassInfo
            {
                Attributes =
                {
                    new AttributeInfo(typeof(LayoutAttribute),
                                      StaticReflection.GetMemberName((LayoutAttribute layout) => layout.Size),     size,
                                      StaticReflection.GetMemberName((LayoutAttribute layout) => layout.Alignment), 1)
                },
                Name            = ToTypeName(fields[0].Strings),
                AccessModifiers = AccessModifiers.Public,
                BaseClass       = new ClassInfo("GuerillaBlock"),
                Properties      =
                {
                    new PropertyInfo
                    {
                        AccessModifiers = AccessModifiers.Public | AccessModifiers.Override,
                        GetBody         = string.Format("return {0};", size),
                        Returns         = "int",
                        Name            = "SerializedSize"
                    },
                    new PropertyInfo
                    {
                        AccessModifiers = AccessModifiers.Public | AccessModifiers.Override,
                        GetBody         = string.Format("return {0};", 1),
                        Returns         = "int",
                        Name            = "Alignment"
                    }
                }
            };

            fields.RemoveAt(0);
            ProcessFields(fields, arrayClass);

            return(arrayClass);
        }
Пример #7
0
 public void AssignDefinition(MoonfishTagDefinition definition)
 {
     Definition = definition;
 }
Пример #8
0
 public MoonfishTagStruct(tag_struct_definition definition)
 {
     Name       = definition.Name;
     Class      = definition.Class;
     Definition = new MoonfishTagDefinition((TagBlockDefinition)definition.Definition);
 }
Пример #9
0
 public MoonfishTagStruct(MoonfishTagDefinition definition)
 {
     Name       = definition.Name;
     Class      = TagClass.Empty;
     Definition = definition;
 }
Пример #10
0
 private ElementArray ProcessTagBlockDefinition(MoonfishTagDefinition tagBlock, ref int offset,
                                                bool inline = false)
 {
     return(ProcessTagBlockDefinition(null, tagBlock, ref offset, inline));
 }