Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads DatSymbol from binary DAT formatted stream
        /// </summary>
        public static DatSymbol Load(DatBinaryReader reader)
        {
            var symbol = new DatSymbol();

            // Read Name
            var hasName = Convert.ToBoolean(reader.ReadUInt32());

            if (hasName)
            {
                symbol.Name = reader.ReadString();
            }

            // Read ReturnType / ClassSize / ClassVarOffset / ArrayLength / Type / Flags
            var valueField = reader.ReadInt32();
            var bitField   = reader.ReadUInt32();

            symbol.ArrayLength = bitField & 0xFFF;
            symbol.Type        = (DatSymbolType)((bitField & 0xF000) >> 12);
            symbol.Flags       = (DatSymbolFlag)((bitField & 0x3F0000) >> 16);

            if (symbol.Type == DatSymbolType.Func && symbol.Flags.HasFlag(DatSymbolFlag.Return))
            {
                symbol.ReturnType = (DatSymbolType)valueField;
            }

            if (symbol.Type == DatSymbolType.Class)
            {
                symbol.ClassSize = valueField;
            }

            if (symbol.Flags.HasFlag(DatSymbolFlag.Classvar))
            {
                symbol.ClassVarOffset = valueField;
            }

            symbol.Location = new DatSymbolLocation
            {
                FileNumber     = reader.ReadInt32(),
                Line           = reader.ReadInt32(),
                LinesCount     = reader.ReadInt32(),
                Position       = reader.ReadInt32(),
                PositionsCount = reader.ReadInt32(),
            };

            switch (symbol.Type)
            {
            case DatSymbolType.Class:
                symbol.ClassOffset = reader.ReadInt32();
                break;

            case DatSymbolType.Func:
            case DatSymbolType.Instance:
            case DatSymbolType.Prototype:
                symbol.FirstTokenAddress = reader.ReadInt32();
                break;

            default:
                symbol.Content = GetContentIfExists(reader, symbol);
                break;
            }

            symbol.ParentIndex = reader.ReadInt32();

            return(symbol);
        }