Ejemplo n.º 1
0
 private PointerTypeSignature ImportPointerTypeSignature(PointerTypeSignature signature)
 {
     return(new PointerTypeSignature(ImportTypeSignature(signature.BaseType))
     {
         IsValueType = signature.IsValueType
     });
 }
        /// <inheritdoc />
        public bool Equals(TypeSignature x, TypeSignature y)
        {
            if (ReferenceEquals(x, y))
            {
                return(true);
            }
            if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
            {
                return(false);
            }

            return(x switch
            {
                CorLibTypeSignature corLibType => Equals(corLibType, y as CorLibTypeSignature),
                TypeDefOrRefSignature typeDefOrRef => Equals(typeDefOrRef, y as TypeDefOrRefSignature),
                SzArrayTypeSignature szArrayType => Equals(szArrayType, y as SzArrayTypeSignature),
                ArrayTypeSignature arrayType => Equals(arrayType, y as ArrayTypeSignature),
                ByReferenceTypeSignature byRefType => Equals(byRefType, y as ByReferenceTypeSignature),
                BoxedTypeSignature boxedType => Equals(boxedType, y as BoxedTypeSignature),
                GenericInstanceTypeSignature genericInstanceType => Equals(genericInstanceType, y as GenericInstanceTypeSignature),
                GenericParameterSignature genericParameter => Equals(genericParameter, y as GenericParameterSignature),
                PointerTypeSignature pointerType => Equals(pointerType, y as PointerTypeSignature),
                PinnedTypeSignature pinnedType => Equals(pinnedType, y as PinnedTypeSignature),
                CustomModifierTypeSignature modifierType => Equals(modifierType, y as CustomModifierTypeSignature),
                _ => throw new NotSupportedException()
            });
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether two types are considered equal according to their signature.
        /// </summary>
        /// <param name="signature1">The first type to compare.</param>
        /// <param name="signature2">The second type to compare.</param>
        /// <returns><c>True</c> if the types are considered equal, <c>False</c> otherwise.</returns>
        public bool Equals(PointerTypeSignature signature1, PointerTypeSignature signature2)
        {
            if (signature1 == null && signature2 == null)
            {
                return(true);
            }
            if (signature1 == null || signature2 == null)
            {
                return(false);
            }

            return(Equals(signature1.BaseType, signature2.BaseType));
        }
Ejemplo n.º 4
0
        public void CopyFromUnknownAddressShouldSetToUnknownBits()
        {
            var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>();

            var int32Type      = environment.Module.CorLibTypeFactory.Int32;
            var intPointerType = new PointerTypeSignature(int32Type);

            var destinationPointer = environment.MemoryAllocator.AllocateMemory(sizeof(int), true);

            var stack = ExecutionContext.ProgramState.Stack;

            stack.Push(environment.CliMarshaller.ToCliValue(destinationPointer, intPointerType));
            stack.Push(new PointerValue(false));

            var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Cpobj, int32Type.Type));

            Assert.True(result.IsSuccess);
            Assert.False(destinationPointer.ReadInteger32(0).IsKnown);
        }
Ejemplo n.º 5
0
        private TypeSignature ParseType()
        {
            TypeSignature type = ParseTypeName();

            while (true)
            {
                switch (CurrentToken.Kind)
                {
                case TokenKind.OpenBracket:
                    EatToken();
                    int rank = 1;
                    while (CurrentToken.Kind == TokenKind.Comma)
                    {
                        EatToken();
                        rank++;
                    }
                    if (CurrentToken.Kind != TokenKind.CloseBracket)
                    {
                        throw InvalidSignature();
                    }
                    EatToken();
                    type = new ArrayTypeSignature(type, rank);
                    break;

                case TokenKind.Asterisk:
                    EatToken();
                    type = new PointerTypeSignature(type);
                    break;

                case TokenKind.QuestionMark:
                    EatToken();
                    type = new GenericTypeSignature(
                        SpecialType.System_Nullable_T.GetTypeSignature(),
                        ImmutableArray.Create(type)
                        );
                    break;

                default:
                    return(type);
                }
            }
        }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public int GetHashCode(PointerTypeSignature obj) =>
 GetHashCode(obj as TypeSpecificationSignature);
Ejemplo n.º 7
0
 /// <inheritdoc />
 public bool Equals(PointerTypeSignature x, PointerTypeSignature y) =>
 Equals(x as TypeSpecificationSignature, y);
Ejemplo n.º 8
0
 /// <inheritdoc />
 public object VisitPointerType(PointerTypeSignature signature)
 {
     signature.BaseType.AcceptVisitor(this);
     _writer.Write('*');
     return(null);
 }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public TypeMemoryLayout VisitPointerType(PointerTypeSignature signature) =>
 new TypeMemoryLayout(signature, PointerSize);