Пример #1
0
            public override object visitStructDef(StructDef structDef, WritableScope s)
            {
                WritableScope membersScope = WritableScope.create(structDef.symbol);

                structDef.symbol.membersScope = membersScope;
                return(scan(structDef.members, new CompoundScope(membersScope, s)));
            }
Пример #2
0
        public void StructToClass(StreamWriter sw, string structNamespace, StructDef str, AbiDef abi)
        {
            sw.WriteLine("using Newtonsoft.Json;");
            sw.WriteLine("using Ditch.EOS;");
            sw.WriteLine("using Ditch.Core.Models;");
            sw.WriteLine("using Ditch.EOS.Models;");
            sw.WriteLine();
            sw.WriteLine($"namespace {structNamespace}");
            sw.WriteLine("{");

            var inden = new string(' ', 4);

            sw.WriteLine($"{inden}[JsonObject(MemberSerialization.OptIn)]");
            sw.WriteLine($"{inden}public class {str.Name.ToTitleCase()}{(string.IsNullOrEmpty(str.Base) ? string.Empty : $" : {str.Base.ToTitleCase()}")}");
            sw.WriteLine($"{inden}{{");

            foreach (var field in str.Fields)
            {
                sw.WriteLine($"{inden}{inden}[JsonProperty(\"{field.Name}\")]");
                sw.WriteLine($"{inden}{inden}public {GetType(field.Type, abi)} {field.Name.ToTitleCase()} {{get; set;}}");
                sw.WriteLine();
            }

            sw.WriteLine($"{inden}}}");
            sw.WriteLine("}");
        }
Пример #3
0
        public Construct VisitStructDef(StructDef node)
        {
            // Create the body buffer list.
            List <LlvmType> body = new List <LlvmType>();

            // Create a buffer dictionary for the symbol.
            Dictionary <string, LlvmType> symbolProperties = new Dictionary <string, LlvmType>();

            // Map the body's properties onto the body.
            foreach (StructDefProperty property in node.Body)
            {
                // Visit the kind.
                this.VisitKind(property.Kind);

                // Pop the type off the stack.
                LlvmType type = this.typeStack.Pop();

                // Append it to the body.
                body.Add(type);

                // Append it to the symbol's properties dictionary.
                symbolProperties.Add(property.Identifier, type);
            }

            // Create the struct.
            LlvmType @struct = this.module.CreateStruct(node.Identifier, body.ToArray());

            // Append the resulting struct onto the stack.
            this.typeStack.Push(@struct);

            // Return the node.
            return(node);
        }
Пример #4
0
        public void LoadData(string fileName, StructDef def)
        {
            var dataFile = new DataFile(fileName, def);

            _dataFiles.Add(dataFile);
            LoadDataFile(dataFile);
        }
Пример #5
0
        public override void Visit(StructDef n)
        {
            n.type = AST.STRUCT;
            List <Tuple <string, int> > tuples = new List <Tuple <string, int> >();

            PlusScope();
            foreach (AST ast in n.declarings)
            {
                ast.accept(this);
                if (ast is SymDeclaring)
                {
                    SymDeclaring symDeclaring = ast as SymDeclaring;
                    tuples.Add(new Tuple <string, int>(symDeclaring.id, GetType(ast)));
                }
                else if (ast is FuncDecl)
                {
                    FuncDecl     funcDecl     = ast as FuncDecl;
                    SymDeclaring symDeclaring = funcDecl.declaring as SymDeclaring;
                    tuples.Add(new Tuple <string, int>(symDeclaring.id, GetType(funcDecl.declaring)));
                }
            }
            MinusScope();
            SymReferencing current = n.structType as SymReferencing;

            StructDic.Add(current.id, tuples);
        }
Пример #6
0
        [Test] public void FieldGroup()
        {
            StructFile structFile = new StructParser().LoadStructs("struct a { repeat(8) { u8; } }");
            StructDef  structDef  = structFile.Structs[0];

            Assert.AreEqual(1, structDef.Fields[0].ChildFields.Count);
        }
Пример #7
0
        [Test] public void StructWithAttributes()
        {
            StructFile structFile = new StructParser().LoadStructs("[filemask=\"*.bmp\"] struct BITMAPFILEHEADER { }");
            StructDef  structDef  = structFile.Structs[0];

            Assert.AreEqual("*.bmp", structDef.FileMask);
        }
Пример #8
0
        private void ParseStrcut(string namespace_, StructDeclarationSyntax structSyntax, SemanticModel semanticModel)
        {
            var structDef = new StructDef();

            structDef.Internal = structSyntax;

            structDef.Namespace = namespace_;
            structDef.Name      = structSyntax.Identifier.ValueText;

            var fullName = namespace_ + "." + structDef.Name;

            {
                var partial = definitions.Structs.FirstOrDefault(x => x.Namespace + "." + x.Name == fullName);
                if (partial != null)
                {
                    structDef = partial;
                }
            }

            if (TypesNotParsed.Contains(fullName))
            {
                return;
            }

            // Summary
            var declaredSymbol = semanticModel.GetDeclaredSymbol(structSyntax);
            var xml            = declaredSymbol?.GetDocumentationCommentXml();

            structDef.Summary = SummaryComment.Parse(xml);

            ParseTypeDeclaration(structDef, structSyntax, semanticModel);

            definitions.Structs.Add(structDef);
        }
Пример #9
0
            ushort GetStructDef(Type type, Metadata metadata, Metadata[] fields)
            {
                var index = Schema.structs.Count;
                var structDef = new StructDef();
                Schema.structs.Add(structDef);
                structDef.metadata = metadata;

                var baseType = type.GetBaseSchemaType();
                if (baseType != null)
                    structDef.base_def = GetTypeDef(baseType);

                var i = 0;
                foreach (var field in type.GetSchemaFields())
                {
                    var fieldDef = new FieldDef
                    {
                        id = field.Id,
                        metadata = fields[i++],
                        type = GetTypeDef(field.GetSchemaType())
                    };

                    structDef.fields.Add(fieldDef);
                }

                return (ushort) index;
            }
Пример #10
0
        public override void LoadData(BinaryReader reader, StructInstance instance)
        {
            StructDef structDef = GetIncludedStruct();

            if (structDef.FieldLike)
            {
                instance.PushAddedCellHandler(cell => cell.Tag = Tag);
            }
            bool oldHidden = instance.HideAddedCells(_hidden);

            try
            {
                structDef.LoadInstanceData(instance, reader.BaseStream);
            }
            finally
            {
                if (structDef.FieldLike)
                {
                    instance.PopAddedCellHandler();
                }
                instance.HideAddedCells(oldHidden);
            }

            if (GetBoolAttribute("replace"))
            {
                instance.SetNodeName(structDef.Name);
            }
        }
Пример #11
0
        [Test] public void ParseSingleFieldStruct()
        {
            StructParser parser     = new StructParser();
            StructFile   structFile = parser.LoadStructs("struct BITMAPINFOHEADER { u32 biSize; }");
            StructDef    structDef  = structFile.Structs[0];

            Assert.AreEqual(1, structDef.Fields.Count);
            Assert.AreEqual("biSize", structDef.Fields[0].Tag);
        }
Пример #12
0
 protected void define_struct(string name, Action act)
 {
     _curStructDef = new StructDef {
         Name = name
     };
     act();
     _curProcessDef.DataTypes.AddType(_curStructDef);
     _curStructDef = null;
 }
Пример #13
0
 public override void Visit(StructDef n)
 {
     plusScope();
     foreach (AST ast in n.declarings)
     {
         ast.accept(this);
     }
     minusScope();
 }
Пример #14
0
            private StructSymbol makeStructSymbol(StructDef structDef, Symbol owner)
            {
                StructSymbol ssym = new StructSymbol(structDef.name, owner, null);

                ssym.type = new StructType(ssym);

                structDef.symbol = ssym;

                return(ssym);
            }
Пример #15
0
            public override object visitStructDef(StructDef structDef, WritableScope enclScope)
            {
                StructSymbol ssym = makeStructSymbol(structDef, enclScope.owner);

                if (check.checkUnique(structDef.Pos, ssym, enclScope))
                {
                    enclScope.enter(ssym);
                }
                return(null);
            }
Пример #16
0
        [Test] public void ParseSingleEmptyStruct()
        {
            StructParser parser     = new StructParser();
            StructFile   structFile = parser.LoadStructs("struct BITMAPINFOHEADER { }");

            Assert.AreEqual(1, structFile.Structs.Count);
            StructDef structDef = structFile.Structs[0];

            Assert.AreEqual("BITMAPINFOHEADER", structDef.Name);
        }
Пример #17
0
        public StructWindow(int pid, IntPtr address, StructDef struc)
        {
            InitializeComponent();
            this.AddEscapeToClose();
            this.SetTopMost();

            _pid     = pid;
            _address = address;
            _struct  = struc;
        }
Пример #18
0
        static void WriteVariableRecursive(SymFile symFile, string name, uint address, TypeInfo typeInfo)
        {
            if (typeInfo.isFake)
            {
                return;
            }

            BaseType baseType = typeInfo.typeDef.baseType;

            uint arrayLength = 1;
            //bool isArray = IsArray(typeInfo.typeDef);
            bool isArray   = Array.IndexOf(typeInfo.typeDef.derivedTypes, DerivedType.Array) >= 0;
            bool isPointer = Array.IndexOf(typeInfo.typeDef.derivedTypes, DerivedType.Pointer) >= 0;

            if (isArray)
            {
                int dims = typeInfo.dims.Length;
                foreach (uint d in typeInfo.dims)
                {
                    arrayLength *= d;
                }
            }

            arrayLength = Math.Max(1, arrayLength);
            uint arrayEntrySize = Math.Max(1, typeInfo.size / arrayLength);

            // Only cap the array length after getting the arrayEntrySize.
            arrayLength = Math.Min(arrayLength, maxArrayLength);

            for (int i = 0; i < arrayLength; i++)
            {
                uint   arrayAddress = address + (arrayEntrySize * (uint)i);
                string arrayName    = name;
                if (isArray)
                {
                    arrayName += "[" + i.ToString() + "]";
                }

                if (baseType == BaseType.StructDef && !isPointer)
                {
                    StructDef structDef = symFile.m_structs[typeInfo.tag];
                    foreach (StructMember member in structDef.members)
                    {
                        uint   memberAddress = arrayAddress + unchecked ((uint)member.typedValue.value);
                        string memberName    = arrayName + "." + member.name;
                        WriteVariableRecursive(symFile, memberName, memberAddress, member.typeInfo);
                    }
                }
                else
                {
                    WriteVariable(symFile, arrayName, arrayAddress, typeInfo, isPointer);
                }
            }
        }
Пример #19
0
        private void BuildDefs()
        {
            var defs = definitions.Value <JObject>("defs");

            recordHeaderDef = (StructDef)BuildDef((JObject)defs["MainRecordHeader"]);
            groupHeaderDef  = (StructDef)BuildDef((JObject)defs["GroupRecordHeader"]);
            foreach (var(key, src) in defs)
            {
                defMap[key] = BuildDef((JObject)src);
            }
            definitions.Remove("defs");
            GC.Collect();
        }
Пример #20
0
        [Test] public void ParseFieldWithAttributes()
        {
            StructParser parser     = new StructParser();
            StructFile   structFile = parser.LoadStructs("struct BITMAPFILEHEADER { str [len=2] bfType; }");
            StructDef    structDef  = structFile.Structs[0];

            Assert.AreEqual(1, structDef.Fields.Count);
            Assert.IsInstanceOfType(typeof(StrField), structDef.Fields [0]);
            StrField field = (StrField)structDef.Fields[0];

            Assert.AreEqual("bfType", field.Tag);
            Assert.AreEqual("2", field.GetExpressionAttribute("len").ToString());
        }
Пример #21
0
        private void DoLoadChildren(StructInstance instance, InstanceTreeNode parent, Stream stream,
                                    long?offset, int count)
        {
            StructInstance lastChild = instance.LastChild;
            string         groupName = GetStringAttribute("group");

            if (groupName != null)
            {
                GroupContainer container = new GroupContainer(parent, groupName);
                parent.AddChild(container);
                parent = container;
            }

            if (count == 0)
            {
                return;
            }

            StructDef childDef = GetStructAttribute("struct");

            if (childDef == null)
            {
                childDef = _structDef;
            }

            StructInstance childInstance;
            bool           followChildren = GetBoolAttribute("followchildren");

            if (offset.HasValue)
            {
                childInstance = new StructInstance(childDef, parent, stream, offset.Value);
            }
            else
            {
                bool firstFollowChildren = followChildren && lastChild != parent;
                childInstance = new StructInstance(childDef, parent, stream, lastChild, firstFollowChildren);
            }
            parent.AddChild(childInstance);
            if (count > 1)
            {
                childInstance.SequenceIndex = 0;
            }

            for (int i = 1; i < count; i++)
            {
                var nextInstance = new StructInstance(childDef, parent, stream, childInstance, followChildren);
                parent.AddChild(nextInstance);
                nextInstance.SequenceIndex = i;
                childInstance = nextInstance;
            }
        }
Пример #22
0
        /// <summary>
        /// Get the definition of internal task data structure (all variables)
        /// Warning: there are no required fields in the internal data schema. So any variable, even the required ones, can be skipped
        /// in an xml document.
        /// </summary>
        /// <returns></returns>
        public virtual StructDef GetInternalDataSchema()
        {
            if (ParentProcess == null)
            {
                throw new Exception();
            }
            StructDef sd = new StructDef();

            sd.ParentTypeSet = ParentProcess.DataTypes;
            foreach (VariableDef vd in Variables)
            {
                VariableDef vd2 = new VariableDef(vd); vd2.IsRequired = false;
                sd.Members.Add(vd2);
            }
            return(sd);
        }
Пример #23
0
        public static void ValidationTest()
        {
            TypeSet ts = new TypeSet();
            StructDef sd = new StructDef();
            sd.ParentTypeSet = ts;
            sd.Name = "T1";
            sd.Members.Add(new MemberDef("F1", "string", false, false));
            sd.Members.Add(new MemberDef("F2", "int", true, true));

            DataObject dob = new DataObject();
            dob["F1"] = 399;
            List<int> lst = new List<int>();
            lst.AddRange(new int[] {1, 2, 3, 4});
            dob["F2"] = lst;
            dob["F3"] = null;
            dob.Validate(sd);
        }
Пример #24
0
        public void StructToClass(string outDirPath, string structNamespace, StructDef str, AbiDef abi)
        {
            FileStream   fs = null;
            StreamWriter sw = null;

            try
            {
                fs = new FileStream($"{outDirPath}{str.Name.ToTitleCase()}.cs", FileMode.OpenOrCreate);
                sw = new StreamWriter(fs);
                StructToClass(sw, structNamespace, str, abi);
            }
            finally
            {
                sw?.Dispose();
                fs?.Dispose();
            }
        }
Пример #25
0
        /// <summary>
        /// Get task output data definition
        /// </summary>
        /// <returns></returns>
        public virtual StructDef GetOutputDataSchema()
        {
            if (ParentProcess == null)
            {
                throw new Exception();
            }
            StructDef sd = new StructDef();

            sd.ParentTypeSet = ParentProcess.DataTypes;
            foreach (VariableDef vd in Variables)
            {
                if (vd.VariableDir == VariableDef.Dir.Out || vd.VariableDir == VariableDef.Dir.InOut)
                {
                    sd.Members.Add(vd);
                }
            }
            return(sd);
        }
Пример #26
0
        public override void Visit(StructDef n)
        {
            plusScope();
            foreach (AST ast in n.declarings)
            {
                if (ast is SymDeclaring)
                {
                    SymDeclaring sym = ast as SymDeclaring;
                    InitiationTable[GetKey(sym.id)] = 1;
                }
                else
                {
                    ast.accept(this);
                }
            }
            SymReferencing current = n.structType as SymReferencing;

            StructDic.Remove(current.id);
            minusScope();
        }
Пример #27
0
        public override Type visitStructDef(StructDef structDef, Environment env)
        {
            Environment newEnv = new Environment {
                scope      = new CompoundScope(structDef.symbol.membersScope, env.scope),
                parent     = env,
                enclStruct = structDef.symbol
            };

            for (var i = 0; i < structDef.members.Count; i++)
            {
                Tree member = structDef.members[i];
                if (member.Tag == Tag.FUNC_DEF)
                {
                    FuncDef funcDef = (FuncDef)member;
                    visitFuncDef(funcDef, newEnv);
                }
            }

            return(null);
        }
Пример #28
0
        /// <summary>
        /// Generates a struct definition with the specified name and fields.
        /// If the struct is to contain no fields pass null for the fields parameter.
        /// </summary>
        /// <param name="name">The name of the struct to be created.</param>
        /// <param name="fields">Optional list of fields.  Pass null if the struct has no fields.</param>
        /// <returns>Root node for this struct definition's AST.</returns>
        public static Node Generate(string name, IReadOnlyList <StructFieldDef> fields)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(nameof(name));
            }

            if (fields != null && fields.Count == 0)
            {
                throw new ArgumentException("pass null for no struct fields");
            }

            var typeDef = new TypeDef();

            typeDef.AddChild(new Identifier(name));

            var structDef = new StructDef();
            var defStart  = new OpenDelimiter(BinaryDelimiterType.Brace);

            if (fields != null)
            {
                foreach (var field in fields)
                {
                    var id = new Identifier(field.Name);
                    id.AddChild(new TypeName(field.TypeName));

                    if (field.Tag != null)
                    {
                        id.AddChild(new Tag(field.Tag));
                    }

                    defStart.AddChild(id);
                }
            }

            defStart.AddClosingDelimiter();
            structDef.AddChild(defStart);

            typeDef.AddChild(structDef);
            return(typeDef);
        }
Пример #29
0
 public override void Visit(StructDef n)
 {
     emit("{\n");
     if (n.declarings.Count > 0)
     {
         AST first = n.declarings[0];
         foreach (AST ast in n.declarings)
         {
             if (first != ast)
             {
                 emit("\n");
             }
             ast.accept(this);
             if (ast is SymDeclaring)
             {
                 emit(";");
             }
         }
     }
     emit("}");
 }
Пример #30
0
        public StructViewer(int pid, IntPtr address, StructDef struc)
        {
            InitializeComponent();

            _struct                = struc;
            treeStruct.Model       = _model;
            treeStruct.ContextMenu = menuStruct;

            GenericViewMenu.AddMenuItems(copyMenuItem.MenuItems, treeStruct);

            try
            {
                FieldValue[] values;

                _struct.Offset     = address;
                _struct.IOProvider = new ProcessMemoryIO(pid);
                _struct.Structs    = Program.Structs;
                values             = _struct.Read();

                _model.Nodes.Add(new StructNode(new FieldValue
                {
                    Name      = "Struct",
                    FieldType = FieldType.StringUTF16,
                    Value     = string.Empty
                }));

                foreach (FieldValue val in values)
                {
                    this.AddNode(_model.Nodes[0], val);
                }

                treeStruct.Root.Children[0].IsExpanded = true;
            }
            catch (Exception ex)
            {
                PhUtils.ShowException("Unable to view the struct", ex);
                this.Error = true;
            }
        }
Пример #31
0
        public override void LoadData(BinaryReader reader, StructInstance instance)
        {
            int offset = (int)reader.BaseStream.Position;
            int len;

            try
            {
                len = GetExpressionAttribute("len").EvaluateInt(instance);
            }
            catch (OverflowException)
            {
                throw new LoadDataException("Blob size is larger than Int32");
            }
            if (offset + len > reader.BaseStream.Length)
            {
                throw new LoadDataException("Blob size " + len + " exceeds stream length");
            }
            if (len < 0)
            {
                throw new LoadDataException("Blob size " + len + " is negative");
            }
            var decodedSizeExpr = GetExpressionAttribute("decodedsize");
            int decodedSize     = decodedSizeExpr != null?decodedSizeExpr.EvaluateInt(instance) : -1;

            string      encoding    = GetStringAttribute("encoding");
            BlobDecoder blobDecoder = FindBlobEncoding(instance, encoding);
            BlobCell    cell        = new BlobCell(this, reader.BaseStream, offset, len, blobDecoder, decodedSize);

            instance.AddCell(cell, _hidden);
            instance.RegisterCellSize(cell, len);
            reader.BaseStream.Position += len;

            StructDef structDef = GetStructAttribute("struct");

            if (structDef != null)
            {
                instance.AddChildSeed(new BlobChildSeed(structDef, cell));
            }
        }
Пример #32
0
        public void StructDefUnitTest()
        {
            try {
                StructDef structDef =
                    new StructDef(
                        new List <AST>()
                {
                    new IntDcl("pinPower"),
                    new FuncDecl(new VoidDcl("Power"),
                                 new List <SymDeclaring>()
                    {
                        new IntDcl("value")
                    },
                                 new List <AST>()
                    {
                        new Assigning(new SymReferencing("pinPower"), new SymReferencing("value"))
                    },
                                 null)
                });
                structDef.structType = new SymReferencing("pin");
                SymbolTableFilling symbolTableFilling = new SymbolTableFilling();
                structDef.accept(symbolTableFilling);

                Dictionary <Tuple <string, string>, int> actual = AST.SymbolTable;

                Dictionary <Tuple <string, string>, int> expected =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("11", "pinPower"), 2 },
                    { new Tuple <string, string>("11", "Power"), 0 },
                    { new Tuple <string, string>("111", "value"), 2 }
                };

                Assert.IsTrue(ObjectCompare(actual, expected), "Struct Def faild");
            } finally {
                AST.SymbolTable.Clear();
            }
        }
Пример #33
0
 public ImageField(StructDef structDef)
     : base(structDef)
 {
 }
Пример #34
0
 public StructDef define(String name)
 {
     StructDef sdef = new StructDef(name);
     this.definedTypes.Add(name, sdef);
     return sdef;
 }
Пример #35
0
 public GlobalField(StructDef structDef)
     : base(structDef)
 {
 }
Пример #36
0
 public BlobField(StructDef structDef)
     : base(structDef, "len", false)
 {
 }
Пример #37
0
 public DosDateTimeField(StructDef structDef)
     : base(structDef)
 {
 }
Пример #38
0
 public NodenameField(StructDef structDef)
     : base(structDef, "name", false)
 {
 }
Пример #39
0
 public WhileField(StructDef structDef)
     : base(structDef, "expr", true)
 {
 }
Пример #40
0
 public MessageField(StructDef structDef, bool error)
     : base(structDef, "text", false)
 {
     _error = error;
 }
Пример #41
0
 public UnixTimeField(StructDef structDef)
     : base(structDef)
 {
 }
Пример #42
0
 public IncludeField(StructDef structDef)
     : base(structDef, "struct", false)
 {
 }
Пример #43
0
 public BitsField(StructDef structDef, int size)
     : base(structDef, size, true)
 {
 }
Пример #44
0
 public RepeatField(StructDef structDef)
     : base(structDef, "count", true)
 {
 }
Пример #45
0
 public ElseField(StructDef structDef)
     : base(structDef, null, true)
 {
 }
Пример #46
0
 public SeekField(StructDef structDef, bool relative)
     : base(structDef, "offset", false)
 {
     _relative = relative;
 }
Пример #47
0
 public SwitchField(StructDef structDef)
     : base(structDef, "expr", true)
 {
 }
Пример #48
0
 public BreakField(StructDef structDef)
     : base(structDef)
 {
 }
Пример #49
0
 public AlignField(StructDef structDef)
     : base(structDef, "bytes", false)
 {
 }
Пример #50
0
 public AssertField(StructDef structDef)
     : base(structDef, "expr", false)
 {
 }
Пример #51
0
 public BlobChildSeed(StructDef def, BlobCell cell)
 {
     _def = def;
     _cell = cell;
 }
Пример #52
0
 public ElseIfField(StructDef structDef)
     : base(structDef, "expr", true)
 {
 }
Пример #53
0
 public StrField(StructDef structDef, bool wide, bool requireNullTerminated)
     : base(structDef)
 {
     _wide = wide;
     _requireNullTerminated = requireNullTerminated;
 }
Пример #54
0
 public ChildField(StructDef structDef, bool isSibling)
     : base(structDef)
 {
     _isSibling = isSibling;
 }
Пример #55
0
 public IntField(StructDef structDef, int size, bool unsigned, bool hex)
     : base(structDef, size, unsigned)
 {
     _hex = hex;
 }
Пример #56
0
        public StructField CreateField(StructDef structDef, string name, AttributeRegistry registry)
        {
            FieldAlias alias;
            if (_aliasRegistry.TryGetValue(name, out alias))
            {
                StructField baseField = CreateField(structDef, alias.BaseName, registry);
                foreach(StructParser.Attribute attr in alias.Attrs)
                    registry.SetFieldAttribute(baseField, attr.Key, attr.Value, attr.Position);
                return baseField;
            }

            switch(name)
            {
                case "str": return new StrField(structDef, false, false);
                case "cstr": return new StrField(structDef, false, true);
                case "wstr": return new StrField(structDef, true, false);
                case "child": return new ChildField(structDef, false);
                case "sibling": return new ChildField(structDef, true);
                case "seek": return new SeekField(structDef, false);
                case "skip": return new SeekField(structDef, true);
                case "rewind": return new RewindField(structDef);
                case "repeat": return new RepeatField(structDef);
                case "if": return new IfField(structDef);
                case "elif": return new ElseIfField(structDef);
                case "else": return new ElseField(structDef);
                case "while": return new WhileField(structDef);
                case "include": return new IncludeField(structDef);
                case "assert": return new AssertField(structDef);
                case "bitfield": return new BitfieldField(structDef);
                case "nodename": return new NodenameField(structDef);
                case "switch": return new SwitchField(structDef);
                case "case": return new CaseField(structDef, false);
                case "default": return new CaseField(structDef, true);
                case "unixtime": return new UnixTimeField(structDef);
                case "dosdatetime": return new DosDateTimeField(structDef);
                case "global": return new GlobalField(structDef);
                case "local": return new CalcField(structDef, true);
                case "calc": return new CalcField(structDef, false);
                case "align": return new AlignField(structDef);
                case "blob": return new BlobField(structDef);
                case "image": return new ImageField(structDef);
                case "float": return new FloatField(structDef);
                case "break": return new BreakField(structDef);
                case "i": return new IntField(structDef, 0, false, false);
                case "u": return new IntField(structDef, 0, true, false);
                case "x": return new IntField(structDef, 0, true, true);
                case "enum": return new EnumField(structDef, 0);
                case "message": return new MessageField(structDef, false);
                case "error": return new MessageField(structDef, true);
            }

            int size;
            if (name.EndsWith("8"))
            {
                size = 1;
                name = name.Substring(0, name.Length - 1);
            }
            else if (name.EndsWith("16") || name.EndsWith("32") || name.EndsWith("64"))
            {
                size = name.EndsWith("16") ? 2 : name.EndsWith("32") ? 4 : 8;
                name = name.Substring(0, name.Length - 2);
            }
            else
                throw new Exception("Unknown field type " + name);

            switch(name)
            {
                case "i":    return new IntField(structDef, size, false, false);
                case "u":    return new IntField(structDef, size, true, false);
                case "x":    return new IntField(structDef, size, true, true);
                case "enum": return new EnumField(structDef, size);
                case "set":  return new SetField(structDef, size);
                case "bits": return new BitsField(structDef, size);
            }
            throw new Exception("Unknown field type " + name);
        }
Пример #57
0
 protected StructDef GetTaskInternalDataSchema()
 {
     StructDef sd = new StructDef();
     sd.ParentTypeSet = ProcessTask.ParentProcess.DataTypes;
     foreach (VariableDef vd in ProcessTask.TaskVariables)
     {
         if (vd.VariableDir == VariableDef.Dir.In || vd.VariableDir == VariableDef.Dir.InOut)
         {
             sd.Members.Add(vd);
         }
         else
         {
             VariableDef vd2 = new VariableDef(vd); vd2.IsRequired = false;
             sd.Members.Add(vd2);
         }
     }
     return sd;
 }
Пример #58
0
 public RewindField(StructDef structDef)
     : base(structDef)
 {
 }
Пример #59
0
 public BitfieldField(StructDef structDef)
     : base(structDef, "size", true)
 {
 }
Пример #60
0
 /// <summary>
 /// Get the definition of task output data
 /// </summary>
 /// <returns></returns>
 public StructDef GetTaskOutputDataSchema()
 {
     if (ParentProcess == null) throw new Exception();
     StructDef sd = new StructDef();
     sd.ParentTypeSet = ParentProcess.DataTypes;
     foreach (VariableDef vd in TaskVariables)
     {
         if (vd.VariableDir == VariableDef.Dir.Out || vd.VariableDir == VariableDef.Dir.InOut)
         {
             sd.Members.Add(vd);
         }
     }
     return sd;
 }