/// <summary>
        /// Extracts the class and field from the given name
        /// </summary>
        /// <param name="name">The name</param>
        private (ClassMetadata, Field) ExtractClassAndField(string name)
        {
            TypeSystem.ExtractClassAndFieldName(name, out var className, out var fieldName);
            var classMetadata = this.virtualMachine.ClassMetadataProvider.GetMetadata(className);

            return(classMetadata, classMetadata.GetField(fieldName));
        }
Exemple #2
0
        protected override void HandleLoadField(VerifierData verifierData, Instruction instruction, int index)
        {
            this.AssertOperandCount(verifierData, instruction, index, 1);

            var classRefType = verifierData.OperandStack.Pop();
            var isNull       = TypeSystem.IsNullType(classRefType);

            if (!classRefType.IsClass && !isNull)
            {
                ThrowError(
                    verifierData,
                    instruction,
                    index,
                    $"Expected first operand to be a class reference, but got type: '{classRefType}'.");
            }

            if (TypeSystem.ExtractClassAndFieldName(instruction.StringValue, out var className, out var fieldName))
            {
                if (!this.virtualMachine.ClassMetadataProvider.IsDefined(className))
                {
                    ThrowError(
                        verifierData,
                        instruction,
                        index,
                        $"'{className}' is not a class type.");
                }

                var classMetadata = this.virtualMachine.ClassMetadataProvider.GetMetadata(className);
                var classType     = this.virtualMachine.TypeProvider.FindClassType(className);

                if (!isNull)
                {
                    AssertSameType(verifierData, instruction, index, classType, classRefType);
                }

                if (!classMetadata.FieldExists(fieldName))
                {
                    ThrowError(
                        verifierData,
                        instruction,
                        index,
                        $"There exists no field '{fieldName}' in the class '{className}'.");
                }

                verifierData.OperandStack.Push(classMetadata.GetField(fieldName).Type);
            }