public void CheckCodeArray() { StackFrame defaultTestCaseFrame = GetFrame($"{DefaultModuleName}!TestArray"); VariableCollection locals = defaultTestCaseFrame.Locals; Variable testArrayVariable = locals["testArray"]; CodeArray <int> testArray = new CodeArray <int>(testArrayVariable); Assert.Equal(10000, testArray.Length); foreach (int value in testArray) { Assert.Equal(0x12121212, value); } Variable testStdArrayVariable = locals["testStdArray"]; std.array <int> testStdArray = new std.array <int>(testStdArrayVariable); Assert.Equal(10000, testStdArray.Count); foreach (int value in testStdArray) { Assert.Equal(0x12121212, value); } Assert.Equal(0x12121212, testStdArray[testStdArray.Count - 1]); int[] a = testStdArray.ToArray(); Assert.Equal(10000, a.Length); foreach (int value in a) { Assert.Equal(0x12121212, value); } }
public void BoolContainers() { StackFrame defaultTestCaseFrame = GetFrame($"{DefaultModuleName}!TestBoolContainers"); VariableCollection locals = defaultTestCaseFrame.Locals; bool[] expectedArray = new bool[100]; for (int i = 0, j = 1; i < expectedArray.Length; i += j, j++) { for (int k = 0; k < j && i < expectedArray.Length; k++, i++) { expectedArray[i] = true; } } // C style array CodeArray <bool> carray = new CodeArray <bool>(locals["carray"]); Assert.Equal(expectedArray, carray); // std::array std.array <bool> array = new std.array <bool>(locals["array"]); Assert.Equal(expectedArray, array); // std::vector std.vector <bool> vector = new std.vector <bool>(locals["vector"]); Assert.True(expectedArray.Length < vector.Reserved); Assert.Equal(expectedArray, vector); Assert.Equal(expectedArray, vector.ToArray()); }
private CodeArray GetArray() { this.ReadLeftBracket(); Token token = this.PeekToken(); CodeArray array = new CodeArray(); while (token.Type != Scorpio.Compiler.TokenType.RightBracket) { if (this.PeekToken().Type != Scorpio.Compiler.TokenType.RightBracket) { array._Elements.Add(this.GetObject()); token = this.PeekToken(); if (token.Type == Scorpio.Compiler.TokenType.Comma) { this.ReadComma(); continue; } if (token.Type != Scorpio.Compiler.TokenType.RightBracket) { throw new ParserException("Comma ',' or right parenthesis ']' expected in array object.", token); } } break; } this.ReadRightBracket(); array.Init(); return(array); }
//返回数组 private CodeArray GetArray() { ReadLeftBracket(); Token token = PeekToken(); CodeArray ret = new CodeArray(); while (token.Type != TokenType.RightBracket) { if (PeekToken().Type == TokenType.RightBracket) { break; } ret._Elements.Add(GetObject()); token = PeekToken(); if (token.Type == TokenType.Comma) { ReadComma(); } else if (token.Type == TokenType.RightBracket) { break; } else { throw new ParserException("Comma ',' or right parenthesis ']' expected in array object.", token); } } ReadRightBracket(); ret.Init(); return(ret); }
/// <summary> /// Reads pixels data into single array of pixels with new stride equal to <paramref name="width"/>. /// </summary> /// <typeparam name="T">Type of the pixel.</typeparam> /// <param name="width">Bitmap width.</param> /// <param name="height">Bitmap height.</param> /// <param name="data">Pointer to start of bitmap data.</param> /// <param name="stride">Row stride in bytes.</param> /// <param name="channels">Number of channels in the image.</param> /// <returns>Array of image pixels.</returns> private static T[] ReadPixels <T>(int width, int height, NakedPointer data, int stride, int channels) { int pixelByteSize = System.Runtime.InteropServices.Marshal.SizeOf <T>(); if (stride <= 0 || stride == pixelByteSize * channels * width) { return(new CodeArray <T>(data, width * height * channels).ToArray()); } else { T[] result = new T[width * height * channels]; int rowElements = width * channels; for (int y = 0, j = 0; y < height; y++) { CodeArray <T> array = new CodeArray <T>(data.AdjustPointer(stride * y), rowElements); for (int x = 0; x < rowElements; x++, j++) { result[j] = array[x]; } } return(result); } }
ScriptArray ParseArray(CodeArray array) { ScriptArray ret = m_script.CreateArray(); foreach (CodeObject ele in array.Elements) { ret.Add(ResolveOperand(ele)); } return(ret); }
private ScriptArray ParseArray(CodeArray array) { ScriptArray array2 = this.m_script.CreateArray(); foreach (CodeObject obj2 in array.Elements) { array2.Add(this.ResolveOperand(obj2).Assign()); } return(array2); }
ScriptArray ParseArray(CodeArray array) { ScriptArray ret = m_script.CreateArray(); int num = array.Elements.Count; for (int i = 0; i < num; ++i) { ret.Add(ResolveOperand(array.Elements[i])); } return(ret); }
public void CheckCodeArray() { StackFrame defaultTestCaseFrame = GetFrame($"{DefaultModuleName}!DefaultTestCase"); VariableCollection locals = defaultTestCaseFrame.Locals; Variable testArrayVariable = locals["testArray"]; CodeArray<int> testArray = new CodeArray<int>(testArrayVariable); Assert.AreEqual(10000, testArray.Length); foreach (int value in testArray) Assert.AreEqual(0x12121212, value); }
public void CheckCodeArray() { StackFrame defaultTestCaseFrame = GetFrame($"{DefaultModuleName}!DefaultTestCase"); VariableCollection locals = defaultTestCaseFrame.Locals; Variable testArrayVariable = locals["testArray"]; CodeArray <int> testArray = new CodeArray <int>(testArrayVariable); Assert.AreEqual(10000, testArray.Length); foreach (int value in testArray) { Assert.AreEqual(0x12121212, value); } }
private static void TestReading <T>(Variable var, T expectedValue) { Assert.Equal(expectedValue, var.CastAs <T>()); Assert.Equal(expectedValue, (T)Convert.ChangeType(var, typeof(T))); NakedPointer pointer = new NakedPointer(var.GetPointerAddress()); CodePointer <T> codePointer = new CodePointer <T>(pointer); Assert.Equal(expectedValue, codePointer.Element); codePointer = new CodePointer <T>(pointer.GetPointerAddress()); Assert.Equal(expectedValue, codePointer.Element); codePointer = new CodePointer <T>(var.GetPointer()); Assert.Equal(expectedValue, codePointer.Element); CodeArray <T> codeArray = new CodeArray <T>(pointer, 1); Assert.Equal(expectedValue, codeArray[0]); }
public void ArrayTests() { Module typesModule = Module.All.Single(m => m.Name == "Types"); CodeType fooType = CodeType.Create("Types", typesModule); Variable s_array = fooType.GetStaticField("s_array"); Variable s_one = fooType.GetStaticField("s_one"); Variable s_two = fooType.GetStaticField("s_two"); Variable s_three = fooType.GetStaticField("s_three"); CodeArray <Variable> codeArray = new CodeArray <Variable>(s_array); Variable[] expected = new Variable[] { s_one, s_two, s_three }; Assert.Equal(expected.Length, codeArray.Length); for (int i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], codeArray[i]); } }
/// <summary> /// Initializes a new instance of the <see cref="VectorBoolBase" /> class. /// </summary> /// <param name="variable">The variable.</param> /// <param name="savedData">Data returned from VerifyCodeType function.</param> public VectorBoolBase(Variable variable, object savedData) { data = (ExtractedData)savedData; ulong address = variable.GetPointerAddress(); ulong bufferAddress = data.Process.ReadPointer(address + (uint)data.CompressedBufferOffset); Variable vectorVariable = Variable.CreatePointer(data.CompressedElementCodeType.PointerToType, bufferAddress); int compressedLength = data.ReadCompressedLength(address); if (data.CompressedElementCodeType.Size == 4) { compressedBuffer32 = new CodeArray <uint>(vectorVariable, compressedLength); } else if (data.CompressedElementCodeType.Size == 8) { compressedBuffer64 = new CodeArray <ulong>(vectorVariable, compressedLength); } else { throw new NotImplementedException(); } Count = data.ReadLength(address); }