示例#1
0
        private static object[] GetContentIfExists(DatBinaryReader reader, DatSymbol symbol)
        {
            // TODO : Verify and refactor this method.

            object[] result = null;

            if (symbol.Flags.HasFlag(DatSymbolFlag.Classvar) == false)
            {
                if (symbol.Type == DatSymbolType.Func || symbol.Type == DatSymbolType.Class || symbol.Type == DatSymbolType.Prototype)
                {
                    result = new object[1];
                }
                else
                {
                    result = new object[symbol.ArrayLength];
                }

                if ((result.Length == 0) && (symbol.Type == DatSymbolType.Instance))
                {
                    result = new object[1];
                }

                for (int i = 0; i < result.Length; i++)
                {
                    switch (symbol.Type)
                    {
                    case DatSymbolType.String:
                        result[i] = reader.ReadString();
                        break;

                    case DatSymbolType.Float:
                        result[i] = reader.ReadSingle();
                        break;

                    default:
                        result[i] = reader.ReadInt32();
                        break;
                    }
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Creates DatSymbol from binary (DAT formatted) stream
        /// </summary>
        public DatSymbol(DatBinaryReader reader)
        {
            var hasName = Convert.ToBoolean(reader.ReadUInt32());

            if (hasName)  // TODO is it even possible for symbol to not have name?
            {
                Name = reader.ReadString();
            }

            OffClsRet = reader.ReadUInt32();

            uint bitField = reader.ReadUInt32();

            Count       = bitField & 0xFFF;
            BuiltinType = (SymbolType)((bitField & 0xF000) >> 12);
            Flags       = (SymbolFlag)((bitField & 0x3F0000) >> 16);

            FileIndex  = reader.ReadUInt32();
            Line       = reader.ReadUInt32();
            LinesCount = reader.ReadUInt32();
            Column     = reader.ReadUInt32();
            CharsCount = reader.ReadUInt32();

            Content = new object[] {};

            if (!Flags.HasFlag(SymbolFlag.ClassVar))
            {
                switch (BuiltinType)
                {
                case SymbolType.Class:
                case SymbolType.Func:
                case SymbolType.Instance:
                case SymbolType.Prototype:
                    Content = new object[] { reader.ReadInt32() };
                    break;

                default:
                    Content = new object[Count];
                    for (int i = 0; i < Count; ++i)
                    {
                        switch (BuiltinType)
                        {
                        case SymbolType.String:
                            Content[i] = reader.ReadString();
                            break;

                        case SymbolType.Float:
                            Content[i] = reader.ReadSingle();
                            break;

                        default:
                            Content[i] = reader.ReadInt32();
                            break;
                        }
                    }
                    break;
                }
            }

            ParentIndex = reader.ReadInt32();
        }