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(); }
internal static TreeDump Read(DumpReader reader) { TreeDump typeTree = new TreeDump(); typeTree.ReadTypeTree(reader); return(typeTree); }
private string ReadType(DumpReader reader) { reader.FindValidateLineWord("("); string type = reader.ReadWord(); reader.FindValidateLineWord(")"); reader.FindValidateEOL(); return(type); }
protected string ReadParameter(DumpReader reader, string name) { reader.FindValidateLineWord(name); reader.ValidateWord("{"); string value = reader.ReadWord(); reader.ValidateWord("}"); return(value); }
private string ReadName(DumpReader reader) { string name = reader.FindReadLineWord(); while (reader.FindPeekLineWord() != "//") { name += " " + reader.FindReadLineWord(); } return(name); }
private void ReadTypeTree(DumpReader reader) { ReadHeader(reader); ReadValid(reader); if (IsValid) { if (!ReadAbstract(reader)) { ReadTypeTreeNode(reader, 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); }
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}'"); } }
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}'"); } }
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(); }
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); } }
private string ReadType(DumpReader reader) { string type = reader.FindReadLineWord(); if (type == "unsigned") { string subType = reader.FindReadLineWord(); return($"{type} {subType}"); } else { return(type); } }
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); }
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(); }
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); }
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(); } }
protected bool ReadBoolParameter(DumpReader reader, string name) { return(ReadIntParameter(reader, name) != 0); }