Ejemplo n.º 1
0
        private void ApplyType()
        {
            var typeElement = SourceNode.Element("type");

            if (typeElement == null)
            {
                Type = "int1x7";
            }
            else
            {
                Type = typeElement.Value;
            }

            var result = ParseTypeString(Type);

            _primitiveTypeBits = result.bits;

            _primitiveTypeName = result.primitiveType;

            if (result.length == null)
            {
                // Type-specific manual overrides
                switch (Type)
                {
                case "stringNx4":
                    _primitiveTypeLength = 2;
                    break;

                case "stringNx7":
                    _primitiveTypeLength = 2;
                    break;

                default:
                    throw new Exception("Unknown manual override");
                }
            }
            else
            {
                _primitiveTypeLength = (int)result.length;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies the type to this memory section
        /// </summary>
        /// <exception cref="Exception"></exception>
        public virtual void ApplyType()
        {
            var typeElement = SourceNode.Element("type");

            if (typeElement == null)
            {
                throw new Exception(
                          $"Found a struct with no type definition in line {((IXmlLineInfo) typeElement).LineNumber}");
            }

            Type = typeElement.Value;

            var structTypeNode = GetStructType(SourceNode.Document, typeElement.Value);

            foreach (var childElement in structTypeNode.Elements().ToList())
            {
                var elementValue = childElement.Value;
                switch (childElement.Name.ToString())
                {
                case "name":
                    if (elementValue != "$name")
                    {
                        if (!string.IsNullOrWhiteSpace(Name))
                        {
                            Debug.WriteLine(
                                $"ApplyType: Overwriting name '{Name}' with '{elementValue}' from structType {typeElement.Value} at {((IXmlLineInfo) SourceNode).LineNumber}");
                        }
                        else
                        {
                            if (UseArrayIndex)
                            {
                                Name = elementValue + "[" + ArrayIndex + "]";
                            }
                            else
                            {
                                Name = elementValue;
                            }


                            ParentValuePath.AddRange(Parent.ParentValuePath);


                            ParentValuePath.Add(Name);
                            ValuePath = string.Join(".", ParentValuePath);
                        }
                    }


                    break;

                case "address":
                    if (elementValue != "$address")
                    {
                        throw new Exception(
                                  $"ApplyType: Unexpected absolute address from structType {typeElement.Value} at {((IXmlLineInfo) SourceNode).LineNumber}");
                    }

                    break;

                case "size":
                    IsAutoCalculatedSize = false;
                    Size     = ParseSize(elementValue);
                    FileSize = Size;
                    break;

                case "struct":
                    break;

                case "value":
                case "value-rvs":
                    break;

                case "type":
                    break;

                default:
                    Debug.WriteLine(
                        $"ParseStruct: Unknown type {childElement.Name} at {((IXmlLineInfo) childElement).LineNumber}");
                    break;
                }
            }


            DoCallback("RolandStructBeforeApplyChilds");

            foreach (var childElement in structTypeNode.Elements().ToList())
            {
                switch (childElement.Name.ToString())
                {
                case "struct":

                    ApplyFoo(childElement, false);


                    break;

                case "value":
                case "value-rvs":
                    ApplyFoo(childElement, true);
                    break;
                }
            }

            //

            if (IsAutoCalculatedSize)
            {
                FileSize = FileOffset;
                Size     = ChildOffset;
            }
            else
            {
                FileSize = FileOffset;
            }

            CalculatedSize = ChildOffset;
        }