Beispiel #1
0
        protected void ReadTypeTreeNode(DumpReader reader, int indent)
        {
            Type = ReadType(reader);
            Name = ReadName(reader);

            reader.FindValidateWord("//");

            ByteSize = ReadHexIntParameter(reader, "ByteSize");
            reader.FindValidateLineWord(",");
            Index = ReadHexIntParameter(reader, "Index");
            reader.FindValidateLineWord(",");
            Version = ReadHexIntParameter(reader, "Version");
            reader.FindValidateLineWord(",");
            IsArray = ReadBoolParameter(reader, "IsArray");
            reader.FindValidateLineWord(",");
            MetaFlag = unchecked ((uint)ReadHexIntParameter(reader, "MetaFlag"));
            reader.FindValidateEOL();
            reader.FindNextLine();

            int childIndent = indent + 1;
            List <TreeNodeDump> children = new List <TreeNodeDump>();

            while (reader.PeekIndend() == childIndent)
            {
                TreeNodeDump child = new TreeNodeDump();
                child.ReadTypeTreeNode(reader, childIndent);
                children.Add(child);
            }
            Children = children.ToArray();
        }
Beispiel #2
0
        internal static TreeDump Read(DumpReader reader)
        {
            TreeDump typeTree = new TreeDump();

            typeTree.ReadTypeTree(reader);
            return(typeTree);
        }
Beispiel #3
0
        private string ReadType(DumpReader reader)
        {
            reader.FindValidateLineWord("(");
            string type = reader.ReadWord();

            reader.FindValidateLineWord(")");
            reader.FindValidateEOL();
            return(type);
        }
Beispiel #4
0
        protected string ReadParameter(DumpReader reader, string name)
        {
            reader.FindValidateLineWord(name);
            reader.ValidateWord("{");
            string value = reader.ReadWord();

            reader.ValidateWord("}");
            return(value);
        }
Beispiel #5
0
        private string ReadName(DumpReader reader)
        {
            string name = reader.FindReadLineWord();

            while (reader.FindPeekLineWord() != "//")
            {
                name += " " + reader.FindReadLineWord();
            }
            return(name);
        }
Beispiel #6
0
 private void ReadTypeTree(DumpReader reader)
 {
     ReadHeader(reader);
     ReadValid(reader);
     if (IsValid)
     {
         if (!ReadAbstract(reader))
         {
             ReadTypeTreeNode(reader, 0);
         }
     }
 }
Beispiel #7
0
        public static DBDump Read(Stream stream)
        {
            DBDump dump = new DBDump();

            using (DumpReader reader = new DumpReader(stream))
            {
                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                watch.Start();
                dump.ReadInner(reader);
                watch.Stop();
            }
            return(dump);
        }
Beispiel #8
0
        protected int ReadHexIntParameter(DumpReader reader, string name)
        {
            string value = ReadParameter(reader, name);

            if (int.TryParse(value, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out int intValue))
            {
                return(intValue);
            }
            else
            {
                throw new Exception($"Can't parse int value '{value}'");
            }
        }
Beispiel #9
0
        protected int ReadIntParameter(DumpReader reader, string name)
        {
            string value = ReadParameter(reader, name);

            if (int.TryParse(value, out int intValue))
            {
                return(intValue);
            }
            else
            {
                throw new Exception($"Can't parse int value '{value}'");
            }
        }
Beispiel #10
0
        private void ReadInner(DumpReader reader)
        {
            Version = ReadVersion(reader);
            Type    = ReadType(reader);

            List <TreeDump> trees = new List <TreeDump>();

            while (!ReadValidation(reader, trees))
            {
                TreeDump tree = TreeDump.Read(reader);
                trees.Add(tree);
            }
            TypeTrees = trees.ToArray();
        }
Beispiel #11
0
        private bool ReadValidation(DumpReader reader, IReadOnlyList <TreeDump> trees)
        {
            reader.FindContent();

            bool validation = false;

            reader.StartPeeking();
            if (reader.ReadWord() == "//")
            {
                if (reader.FindReadLineWord().StartsWith("==", StringComparison.InvariantCulture))
                {
                    validation = true;
                }
            }
            reader.FinishPeeking();

            if (validation)
            {
                reader.ValidateWord("//");
                reader.FindReadLineWord();
                reader.FindValidateEOL();
                reader.FindNextLine();

                reader.ValidateWord("//");
                reader.FindValidateLineWord("Successfully");
                reader.FindValidateLineWord("finished");
                reader.FindValidateLineWord(".");
                reader.FindValidateLineWord("Written");
                int written = reader.FindReadLineInt();
                reader.FindValidateLineWord("of");
                int count = reader.FindReadLineInt();
                reader.FindValidateEOL();

                if (trees.Count != count)
                {
                    throw new Exception($"Class count mismatch. Read {trees.Count} expected {count}");
                }
                int validCount = trees.Count(t => t.IsValid);
                if (validCount != written)
                {
                    throw new Exception($"Valid class count mismatch. Read {validCount} expected {written}");
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #12
0
        private string ReadType(DumpReader reader)
        {
            string type = reader.FindReadLineWord();

            if (type == "unsigned")
            {
                string subType = reader.FindReadLineWord();
                return($"{type} {subType}");
            }
            else
            {
                return(type);
            }
        }
Beispiel #13
0
        private bool ReadAbstract(DumpReader reader)
        {
            int level = 0;

            while (reader.PeekWord() == "//")
            {
                string name = level == 0 ? ClassName : Inheritance[level - 1];
                reader.ValidateWord("//");
                reader.FindValidateWord(name);
                reader.FindValidateWord("is");
                reader.FindValidateWord("abstract");
                reader.FindValidateEOL();
                reader.FindNextLine();
                level++;
            }
            IsAbstract = level > 0;
            return(level == Inheritance.Count + 1);
        }
Beispiel #14
0
        private void ReadHeader(DumpReader reader)
        {
            reader.ValidateWord("//");
            ClassID = ReadIntParameter(reader, "classID");
            reader.ValidateWord(":");
            ClassName = reader.FindReadLineWord();

            List <string> inheritance = new List <string>();

            while (reader.FindLineContent())
            {
                reader.ValidateWord("<-");
                string baseName = reader.FindReadLineWord();
                inheritance.Add(baseName);
            }
            Inheritance = inheritance.ToArray();
            reader.FindNextLine();
        }
Beispiel #15
0
        private Version ReadVersion(DumpReader reader)
        {
            reader.FindValidateWord("version");
            reader.ValidateWord(":");

            string major = reader.FindReadLineWord();

            reader.ValidateWord(".");
            string minor = reader.ReadWord();

            reader.ValidateWord(".");
            string buildType     = reader.ReadWord();
            string versionString = $"{major}.{minor}.{buildType}";

            Version version = new Version();

            version.Parse(versionString);
            return(version);
        }
Beispiel #16
0
        private void ReadValid(DumpReader reader)
        {
            IsValid = true;
            reader.StartPeeking();
            if (reader.ReadWord() == "//")
            {
                if (reader.FindReadLineWord() == "Can't")
                {
                    IsValid = false;
                }
            }
            reader.FinishPeeking();

            if (!IsValid)
            {
                reader.ValidateWord("//");
                reader.FindValidateLineWord("Can't");
                reader.FindValidateLineWord("produce");
                reader.FindValidateLineWord(ClassName);
                reader.FindValidateEOL();
                reader.FindNextLine();
            }
        }
Beispiel #17
0
 protected bool ReadBoolParameter(DumpReader reader, string name)
 {
     return(ReadIntParameter(reader, name) != 0);
 }