Ejemplo n.º 1
0
        public void ToMemberId_returns_expected_value_for_array_types_03()
        {
            // ARRANGE
            var cs = @"
                using System;
                using System.Collections.Generic;

                namespace Namespace1.Namespace2
                {
                    public class Class1
                    {
                        public void Method1(string[,] parameter) { }
                    }
                }
            ";

            using var assembly = Compile(cs);

            var typeReference = assembly.MainModule.Types
                                .Single(x => x.Name == "Class1")
                                .Methods
                                .Single(x => x.Name == "Method1")
                                .Parameters
                                .Single()
                                .ParameterType;

            var expectedMemberId = new ArrayTypeId(new SimpleTypeId("System", "String"), 2);

            // ACT
            var actualMemberId = typeReference.ToMemberId();

            // ASSERT
            Assert.NotNull(actualMemberId);
            Assert.Equal(expectedMemberId, actualMemberId);
        }
Ejemplo n.º 2
0
        internal ArrayType GetMirrorOf(ArrayTypeId arrayTypeId)
        {
            if (arrayTypeId == default(ArrayTypeId))
            {
                return(null);
            }

            return(new ArrayType(this, arrayTypeId));
        }
Ejemplo n.º 3
0
        private TypeId ParseArraySuffix(TypeId elementType)
        {
            if (Current.Kind != MemberIdTokenKind.OpenSquareBracket)
            {
                return(elementType);
            }

            var type = elementType;

            while (Current.Kind == MemberIdTokenKind.OpenSquareBracket)
            {
                MatchToken(MemberIdTokenKind.OpenSquareBracket);

                var dimensions = ParseArrayDimensions();

                MatchToken(MemberIdTokenKind.CloseSquareBracket);

                // wrap type into an array
                type = new ArrayTypeId(type, dimensions);
            }

            return(type);
        }
 internal ArrayType(VirtualMachine virtualMachine, ArrayTypeId typeId)
     : base(virtualMachine, new TaggedReferenceTypeId(TypeTag.Array, typeId))
 {
     Contract.Requires(virtualMachine != null);
 }
Ejemplo n.º 5
0
 public Error CreateArrayInstance(out TaggedObjectId newArray, ArrayTypeId arrayType, int length)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
        public Error CreateArrayInstance(ArrayTypeId arrayType, int length, out TaggedObjectId newArray)
        {
            newArray = default(TaggedObjectId);

            JniEnvironment nativeEnvironment;
            JvmtiEnvironment environment;
            jvmtiError error = GetEnvironment(out environment, out nativeEnvironment);
            if (error != jvmtiError.None)
                return GetStandardError(error);

            using (var arrayTypeHandle = VirtualMachine.GetLocalReferenceForClass(nativeEnvironment, arrayType))
            {
                if (!arrayTypeHandle.IsAlive)
                    return Error.InvalidClass;

                string signature;
                string genericSignature;
                error = environment.GetClassSignature(arrayTypeHandle.Value, out signature, out genericSignature);
                if (error != jvmtiError.None)
                    return GetStandardError(error);

                jobject array;
                switch (signature[1])
                {
                case 'Z':
                    array = nativeEnvironment.NewBooleanArray(length);
                    break;

                case 'B':
                    array = nativeEnvironment.NewByteArray(length);
                    break;

                case 'C':
                    array = nativeEnvironment.NewCharArray(length);
                    break;

                case 'D':
                    array = nativeEnvironment.NewDoubleArray(length);
                    break;

                case 'F':
                    array = nativeEnvironment.NewFloatArray(length);
                    break;

                case 'I':
                    array = nativeEnvironment.NewIntegerArray(length);
                    break;

                case 'J':
                    array = nativeEnvironment.NewLongArray(length);
                    break;

                case 'S':
                    array = nativeEnvironment.NewShortArray(length);
                    break;

                case '[':
                case 'L':
                    throw new NotImplementedException();
                    //array = nativeEnvironment.NewObjectArray(length, elementType, jobject.Null);
                    //break;

                case 'V':
                default:
                    throw new FormatException();
                }

                if (array == jobject.Null)
                    throw new NotImplementedException();

                newArray = VirtualMachine.TrackLocalObjectReference(array, environment, nativeEnvironment, false);
                VirtualMachine.AddGlobalReference(environment, nativeEnvironment, array);
                nativeEnvironment.DeleteLocalReference(array);
                return Error.None;
            }
        }
Ejemplo n.º 7
0
 internal ArrayType(VirtualMachine virtualMachine, ArrayTypeId typeId)
     : base(virtualMachine, new TaggedReferenceTypeId(TypeTag.Array, typeId))
 {
     Contract.Requires(virtualMachine != null);
 }
Ejemplo n.º 8
0
        internal ArrayType GetMirrorOf(ArrayTypeId arrayTypeId)
        {
            if (arrayTypeId == default(ArrayTypeId))
                return null;

            return new ArrayType(this, arrayTypeId);
        }