Beispiel #1
0
        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);
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
0
        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,
                };
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 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);
            }
        }
Beispiel #9
0
        void ReadLines(PdbLines lines, InstructionMapper mapper)
        {
            var document = GetDocument(lines.file);

            foreach (var line in lines.lines)
            {
                ReadLine(line, document, mapper);
            }
        }
Beispiel #10
0
		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);
			}
		}
Beispiel #11
0
        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);
        }
Beispiel #12
0
		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);
		}
Beispiel #13
0
        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);
            }
        }
Beispiel #14
0
        void ReadSequencePoints(PdbFunction function, InstructionMapper mapper)
        {
            if (function.lines == null)
            {
                return;
            }

            foreach (PdbLines lines in function.lines)
            {
                ReadLines(lines, mapper);
            }
        }
Beispiel #15
0
 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);
         }
     }
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
 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);
         }
     }
 }
Beispiel #19
0
        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;
        }
Beispiel #20
0
        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;
            }
        }
Beispiel #21
0
		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
					};
				}
			}
		}
Beispiel #22
0
        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
                    };
                }
            }
        }
Beispiel #23
0
        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;
        }
Beispiel #24
0
		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;
		}
Beispiel #25
0
 public void Read(MethodBody body, InstructionMapper mapper)
 {
 }
 public void Read(MethodBody body, InstructionMapper mapper)
 {
 }
Beispiel #27
0
 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);
 }
Beispiel #28
0
        void ReadSequencePoints(PdbFunction function, InstructionMapper mapper)
        {
            if (function.lines == null)
                return;

            foreach (PdbLines lines in function.lines)
                ReadLines (lines, mapper);
        }
Beispiel #29
0
        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);
        }
Beispiel #30
0
        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);
                }
        }
Beispiel #31
0
        static void ReadScopeAndLocals(PdbScope[] scopes, Scope parent, MethodBody body, InstructionMapper mapper)
        {
            foreach (PdbScope scope in scopes)
            {
                ReadScopeAndLocals(scope, parent, body, mapper);
            }

            CreateRootScope(body);
        }
Beispiel #32
0
        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);
        }
Beispiel #33
0
        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);
        }
Beispiel #34
0
        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();
 }
Beispiel #36
0
        void ReadLines(PdbLines lines, InstructionMapper mapper)
        {
            var document = GetDocument (lines.file);

            foreach (var line in lines.lines)
                ReadLine (line, document, mapper);
        }
Beispiel #37
0
		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;
		}
Beispiel #38
0
        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;
        }
Beispiel #39
0
		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,
				};
			}
		}
Beispiel #40
0
        static void ReadScopeAndLocals(PdbScope [] scopes, Scope parent, MethodBody body, InstructionMapper mapper)
        {
            foreach (PdbScope scope in scopes)
                ReadScopeAndLocals (scope, parent, body, mapper);

            CreateRootScope (body);
        }