public void TestMoveToInstruction() { var drone = CreateDrone(); var date = new DateTime(2018, 1, 1); var dest = new CoordinateInt2D() { X = 45, Y = 45 }; var source = new CoordinateInt2D() { X = 1, Y = 1 }; var globalInstruction = new GlobalInstruction() { TYPE = "MoveTo", Destination = dest, DroneName = "Drone_1" }; var playerCtx = new PlayerContext() { Level = 1 }; var mapper = new InstructionMapper(playerCtx); var expectedInstruction = new MoveTo(playerCtx, drone, date, source, dest); var actualInstruction = mapper.ToSpecificInstruction(globalInstruction, drone, date); actualInstruction.Should().BeEquivalentTo(expectedInstruction); }
public void TestUnknownInstruction() { var drone = CreateDrone(); var globalInstruction = new GlobalInstruction() { TYPE = "Poulet", Destination = null, DroneName = "Drone_1" }; var playerCtx = new PlayerContext() { Level = 1 }; var mapper = new InstructionMapper(playerCtx); var date = new DateTime(2018, 1, 1); Action toSpecificInstructionAction = () => { mapper.ToSpecificInstruction(globalInstruction, drone, date); }; toSpecificInstructionAction.Should().Throw <ArgumentException>() .WithMessage("Unknown instruction type Poulet"); }
public void TestUnloadInstruction() { var drone = new Drone(new CoordinateInt2D() { X = 4, Y = 4 }) { Name = "Drone_1", Speed = 1, StorageSize = 10 }; var globalInstruction = new GlobalInstruction() { TYPE = "Unload", Destination = null, DroneName = "Drone_1" }; var playerCtx = new PlayerContext() { Level = 1 }; var mapper = new InstructionMapper(playerCtx); var date = new DateTime(2018, 1, 1); var expectedInstruction = new Unload(playerCtx, drone, date); var actualInstruction = mapper.ToSpecificInstruction(globalInstruction, drone, date); actualInstruction.Should().BeEquivalentTo(expectedInstruction); }
public void Read(MethodBody body, InstructionMapper mapper) { var method_token = body.Method.MetadataToken; PdbFunction function; if (!functions.TryGetValue(method_token.ToUInt32(), out function)) { return; } ReadSequencePoints(function, mapper); ReadScopeAndLocals(function.scopes, null, body, mapper); if (!string.IsNullOrEmpty(function.iteratorClass)) { body.IteratorType = body.Method.DeclaringType.GetNestedType(function.iteratorClass); } if (function.iteratorScopes != null) { foreach (Microsoft.Cci.ILocalScope scope in function.iteratorScopes) { InstructionRange range = new InstructionRange(); SetInstructionRange(body, mapper, range, scope.Offset, scope.Length); body.IteratorScopes.Add(range); } } }
void ReadLineNumbers(MethodEntry entry, InstructionMapper mapper) { Document document = null; var table = entry.GetLineNumberTable(); foreach (var line in table.LineNumbers) { var instruction = mapper(line.Offset); if (instruction == null) { continue; } if (document == null) { document = GetDocument(entry.CompileUnit.SourceFile); } instruction.SequencePoint = new SequencePoint(document) { StartLine = line.Row, EndLine = line.Row, }; } }
static Scope [] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper) { var blocks = entry.GetCodeBlocks(); var scopes = new Scope [blocks.Length]; foreach (var block in blocks) { if (block.BlockType != CodeBlockEntry.Type.Lexical) { continue; } var scope = new Scope(); scope.Start = mapper(block.StartOffset); scope.End = mapper(block.EndOffset); scopes [block.Index] = scope; if (body.Scope == null) { body.Scope = scope; } if (!AddScope(body.Scope, scope)) { body.Scope = scope; } } return(scopes); }
private static Scope[] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper) { CodeBlockEntry[] blocks = entry.GetCodeBlocks(); Scope[] scopes = new Scope[blocks.Length]; CodeBlockEntry[] array = blocks; for (int i = 0; i < array.Length; i++) { CodeBlockEntry block = array[i]; if (block.BlockType == CodeBlockEntry.Type.Lexical) { Scope scope = new Scope(); scope.Start = mapper(block.StartOffset); scope.End = mapper(block.EndOffset); scopes[block.Index] = scope; if (body.Scope == null) { body.Scope = scope; } if (!MdbReader.AddScope(body.Scope, scope)) { body.Scope = scope; } } } return(scopes); }
private string ProcessInstruction(GlobalInstruction globInstruction) { try { var drone = PlayerContext.Drones.First( dr => dr.Name == globInstruction.DroneName ); if (drone.State == DroneState.ExecutionInstruction) { return("drone is already doing an action " + drone.GetLastValidInstruction().GetType().Name); } var mapper = new InstructionMapper(PlayerContext); drone.AddInstruction(mapper.ToSpecificInstruction(globInstruction, drone, DateTime.Now)); return("OK, drone will do " + drone.GetLastValidInstruction().GetType().Name); } catch (InvalidInstructionException e) { Console.WriteLine(e.Message); return("Invalid Instruction: " + e.Message + " for instruction: " + globInstruction); } catch (InvalidOperationException e) { Console.WriteLine(e.Message); return("no such drone named: " + globInstruction.DroneName); } }
void ReadLines(PdbLines lines, InstructionMapper mapper) { var document = GetDocument(lines.file); foreach (var line in lines.lines) { ReadLine(line, document, mapper); } }
public void Read(MethodBody body, InstructionMapper mapper) { MetadataToken method_token = body.Method.MetadataToken; MethodEntry entry = this.symbol_file.GetMethodByToken(method_token.ToInt32()); if (entry != null) { Scope[] scopes = MdbReader.ReadScopes(entry, body, mapper); this.ReadLineNumbers(entry, mapper); MdbReader.ReadLocalVariables(entry, body, scopes); } }
public void Read(MethodBody body, InstructionMapper mapper) { var method_token = body.Method.MetadataToken; PdbFunction function; if (!functions.TryGetValue (method_token.ToUInt32 (), out function)) return; ReadSequencePoints (function, mapper); ReadScopeAndLocals (function.scopes, null, body, mapper); }
public void Read (MethodBody body, InstructionMapper mapper) { var method_token = body.Method.MetadataToken; var entry = symbol_file.GetMethodByToken (method_token.ToInt32 ()); if (entry == null) return; var scopes = ReadScopes (entry, body, mapper); ReadLineNumbers (entry, mapper); ReadLocalVariables (entry, body, scopes); }
public void Read(MethodBody body, InstructionMapper mapper) { MetadataToken method_token = body.Method.MetadataToken; MethodEntry entry = this.symbol_file.GetMethodByToken(method_token.ToInt32()); if (entry != null) { Scope[] scopes = MdbReader.ReadScopes(entry, body, mapper); this.ReadLineNumbers(entry, mapper); MdbReader.ReadLocalVariables(entry, body, scopes); } }
void ReadSequencePoints(PdbFunction function, InstructionMapper mapper) { if (function.lines == null) { return; } foreach (PdbLines lines in function.lines) { ReadLines(lines, mapper); } }
void ReadLines(PdbLines lines, InstructionMapper mapper) { var document = GetDocument(lines.file); { var __array = (lines.lines); var __arrayLength = __array.Length; for (int __i = 0; __i < __arrayLength; ++__i) { var line = __array[__i]; ReadLine(line, document, mapper); } } }
public void Read(MethodBody body, InstructionMapper mapper) { var method_token = body.Method.MetadataToken; PdbFunction function; if (!functions.TryGetValue(method_token.ToUInt32(), out function)) { return; } ReadSequencePoints(function, mapper); ReadScopeAndLocals(function.scopes, null, body, mapper); }
public void Read(MethodBody body, InstructionMapper mapper) { var method_token = body.Method.MetadataToken; var entry = symbol_file.GetMethodByToken(method_token.ToInt32()); if (entry == null) { return; } var scopes = ReadScopes(entry, body, mapper); ReadLineNumbers(entry, mapper); ReadLocalVariables(entry, body, scopes); }
void ReadSequencePoints(PdbFunction function, InstructionMapper mapper) { if (function.lines == null) { return; } { // foreach(var lines in function.lines) var __enumerator4 = (function.lines).GetEnumerator(); while (__enumerator4.MoveNext()) { var lines = (PdbLines)__enumerator4.Current; ReadLines(lines, mapper); } } }
static void ReadLine(PdbLine line, Document document, InstructionMapper mapper) { var instruction = mapper((int)line.offset); if (instruction == null) { return; } var sequence_point = new SequencePoint(document); sequence_point.StartLine = (int)line.lineBegin; sequence_point.StartColumn = (int)line.colBegin; sequence_point.EndLine = (int)line.lineEnd; sequence_point.EndColumn = (int)line.colEnd; instruction.SequencePoint = sequence_point; }
static void SetInstructionRange(MethodBody body, InstructionMapper mapper, InstructionRange range, uint offset, uint length) { range.Start = mapper((int)offset); range.End = mapper((int)(offset + length)); if (range.End == null) { range.End = body.Instructions[body.Instructions.Count - 1]; } else { range.End = range.End.Previous; } if (range.Start == null) { range.Start = range.End; } }
private void ReadLineNumbers(MethodEntry entry, InstructionMapper mapper) { Document document = null; LineNumberTable table = entry.GetLineNumberTable(); LineNumberEntry[] lineNumbers = table.LineNumbers; for (int i = 0; i < lineNumbers.Length; i++) { LineNumberEntry line = lineNumbers[i]; Instruction instruction = mapper(line.Offset); if (instruction != null) { if (document == null) { document = this.GetDocument(entry.CompileUnit.SourceFile); } instruction.SequencePoint = new SequencePoint(document) { StartLine = line.Row, EndLine = line.Row }; } } }
private void ReadLineNumbers(MethodEntry entry, InstructionMapper mapper) { Document document = null; LineNumberTable table = entry.GetLineNumberTable(); LineNumberEntry[] lineNumbers = table.LineNumbers; for (int i = 0; i < lineNumbers.Length; i++) { LineNumberEntry line = lineNumbers[i]; Instruction instruction = mapper(line.Offset); if (instruction != null) { if (document == null) { document = this.GetDocument(entry.CompileUnit.SourceFile); } instruction.SequencePoint = new SequencePoint(document) { StartLine = line.Row, EndLine = line.Row }; } } }
static void SetInstructionRange(MethodBody body, InstructionMapper mapper, InstructionRange range, uint offset, uint length) { range.Start = mapper ((int) offset); range.End = mapper ((int)(offset + length)); if (range.End == null) range.End = body.Instructions[body.Instructions.Count - 1]; else range.End = range.End.Previous; }
private static Scope[] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper) { CodeBlockEntry[] blocks = entry.GetCodeBlocks(); Scope[] scopes = new Scope[blocks.Length]; CodeBlockEntry[] array = blocks; for (int i = 0; i < array.Length; i++) { CodeBlockEntry block = array[i]; if (block.BlockType == CodeBlockEntry.Type.Lexical) { Scope scope = new Scope(); scope.Start = mapper(block.StartOffset); scope.End = mapper(block.EndOffset); scopes[block.Index] = scope; if (body.Scope == null) { body.Scope = scope; } if (!MdbReader.AddScope(body.Scope, scope)) { body.Scope = scope; } } } return scopes; }
public void Read(MethodBody body, InstructionMapper mapper) { }
public void Read(MethodBody body, InstructionMapper mapper) { }
static void ReadScopeAndLocals(PdbScope[] scopes, Scope parent, MethodBody body, InstructionMapper mapper) { { var __array2 = scopes; var __arrayLength2 = __array2.Length; for (int __i2 = 0; __i2 < __arrayLength2; ++__i2) { var scope = (PdbScope)__array2[__i2]; ReadScopeAndLocals(scope, parent, body, mapper); } } CreateRootScope(body); }
void ReadSequencePoints(PdbFunction function, InstructionMapper mapper) { if (function.lines == null) return; foreach (PdbLines lines in function.lines) ReadLines (lines, mapper); }
static void ReadScopeAndLocals(PdbScope scope, Scope parent, MethodBody body, InstructionMapper mapper) { if (scope == null) return; Scope s = new Scope (); SetInstructionRange (body, mapper, s, scope.offset, scope.length); if (parent != null) parent.Scopes.Add (s); else if (body.Scope == null) body.Scope = s; else throw new InvalidDataException () ; foreach (PdbSlot slot in scope.slots) { int index = (int) slot.slot; if (index < 0 || index >= body.Variables.Count) continue; VariableDefinition variable = body.Variables [index]; variable.Name = slot.name; s.Variables.Add (variable); } ReadScopeAndLocals (scope.scopes, s, body, mapper); }
public void Read(MethodBody body, InstructionMapper mapper) { var method_token = body.Method.MetadataToken; PdbFunction function; if (!functions.TryGetValue (method_token.ToUInt32 (), out function)) return; ReadSequencePoints (function, mapper); ReadScopeAndLocals (function.scopes, null, body, mapper); if (!string.IsNullOrEmpty (function.iteratorClass)) body.IteratorType = body.Method.DeclaringType.GetNestedType (function.iteratorClass); if (function.iteratorScopes != null) foreach (Microsoft.Cci.ILocalScope scope in function.iteratorScopes) { InstructionRange range = new InstructionRange (); SetInstructionRange (body, mapper, range, scope.Offset, scope.Length); body.IteratorScopes.Add (range); } }
static void ReadScopeAndLocals(PdbScope[] scopes, Scope parent, MethodBody body, InstructionMapper mapper) { foreach (PdbScope scope in scopes) { ReadScopeAndLocals(scope, parent, body, mapper); } CreateRootScope(body); }
static void ReadScopeAndLocals(PdbScope scope, Scope parent, MethodBody body, InstructionMapper mapper) { if (scope == null) { return; } Scope s = new Scope(); SetInstructionRange(body, mapper, s, scope.offset, scope.length); if (parent != null) { parent.Scopes.Add(s); } else if (body.Scope == null) { body.Scope = s; } else { throw new InvalidDataException(); } foreach (PdbSlot slot in scope.slots) { int index = (int)slot.slot; if (index < 0 || index >= body.Variables.Count) { continue; } VariableDefinition variable = body.Variables [index]; variable.Name = slot.name; s.Variables.Add(variable); } ReadScopeAndLocals(scope.scopes, s, body, mapper); }
static void ReadScopeAndLocals(PdbScope scope, Scope parent, MethodBody body, InstructionMapper mapper) { //Scope s = new Scope (); //s.Start = GetInstruction (body, instructions, (int) scope.address); //s.End = GetInstruction (body, instructions, (int) scope.length - 1); //if (parent != null) // parent.Scopes.Add (s); //else // body.Scopes.Add (s); if (scope == null) { return; } foreach (PdbSlot slot in scope.slots) { int index = (int)slot.slot; if (index < 0 || index >= body.Variables.Count) { continue; } VariableDefinition variable = body.Variables[index]; variable.Name = slot.name; //s.Variables.Add (variable); } ReadScopeAndLocals(scope.scopes, null /* s */, body, mapper); }
static void ReadScopeAndLocals(PdbScope scope, Scope parent, MethodBody body, InstructionMapper mapper) { //Scope s = new Scope (); //s.Start = GetInstruction (body, instructions, (int) scope.address); //s.End = GetInstruction (body, instructions, (int) scope.length - 1); //if (parent != null) // parent.Scopes.Add (s); //else // body.Scopes.Add (s); if (scope == null) return; foreach (PdbSlot slot in scope.slots) { int index = (int) slot.slot; if (index < 0 || index >= body.Variables.Count) continue; VariableDefinition variable = body.Variables [index]; variable.Name = slot.name; //s.Variables.Add (variable); } ReadScopeAndLocals (scope.scopes, null /* s */, body, mapper); }
public InstructionMapperTests() { mapper = new InstructionMapper(); }
void ReadLines(PdbLines lines, InstructionMapper mapper) { var document = GetDocument (lines.file); foreach (var line in lines.lines) ReadLine (line, document, mapper); }
static Scope [] ReadScopes (MethodEntry entry, MethodBody body, InstructionMapper mapper) { var blocks = entry.GetCodeBlocks (); var scopes = new Scope [blocks.Length]; foreach (var block in blocks) { if (block.BlockType != CodeBlockEntry.Type.Lexical) continue; var scope = new Scope (); scope.Start = mapper (block.StartOffset); scope.End = mapper (block.EndOffset); scopes [block.Index] = scope; if (body.Scope == null) body.Scope = scope; if (!AddScope (body.Scope, scope)) body.Scope = scope; } return scopes; }
static void ReadLine(PdbLine line, Document document, InstructionMapper mapper) { var instruction = mapper ((int) line.offset); if (instruction == null) return; var sequence_point = new SequencePoint (document); sequence_point.StartLine = (int) line.lineBegin; sequence_point.StartColumn = (int) line.colBegin; sequence_point.EndLine = (int) line.lineEnd; sequence_point.EndColumn = (int) line.colEnd; instruction.SequencePoint = sequence_point; }
void ReadLineNumbers (MethodEntry entry, InstructionMapper mapper) { Document document = null; var table = entry.GetLineNumberTable (); foreach (var line in table.LineNumbers) { var instruction = mapper (line.Offset); if (instruction == null) continue; if (document == null) document = GetDocument (entry.CompileUnit.SourceFile); instruction.SequencePoint = new SequencePoint (document) { StartLine = line.Row, EndLine = line.Row, }; } }
static void ReadScopeAndLocals(PdbScope [] scopes, Scope parent, MethodBody body, InstructionMapper mapper) { foreach (PdbScope scope in scopes) ReadScopeAndLocals (scope, parent, body, mapper); CreateRootScope (body); }