Exemplo n.º 1
0
        public static void CreateIterator(IMethodData method, TypeDefinition parent, Modifiers modifiers)
        {
            bool     is_enumerable;
            TypeSpec iterator_type;

            TypeSpec ret = method.ReturnType;

            if (ret == null)
            {
                return;
            }

            if (!CheckType(ret, parent, out iterator_type, out is_enumerable))
            {
                parent.Compiler.Report.Error(1624, method.Location,
                                             "The body of `{0}' cannot be an iterator block " +
                                             "because `{1}' is not an iterator interface type",
                                             method.GetSignatureForError(),
                                             ret.GetSignatureForError());
                return;
            }

            ParametersCompiled parameters = method.ParameterInfo;

            for (int i = 0; i < parameters.Count; i++)
            {
                Parameter          p   = parameters [i];
                Parameter.Modifier mod = p.ModFlags;
                if ((mod & Parameter.Modifier.RefOutMask) != 0)
                {
                    parent.Compiler.Report.Error(1623, p.Location,
                                                 "Iterators cannot have ref or out parameters");
                    return;
                }

                if (p is ArglistParameter)
                {
                    parent.Compiler.Report.Error(1636, method.Location,
                                                 "__arglist is not allowed in parameter list of iterators");
                    return;
                }

                if (parameters.Types [i].IsPointer)
                {
                    parent.Compiler.Report.Error(1637, p.Location,
                                                 "Iterators cannot have unsafe parameters or yield types");
                    return;
                }
            }

            if ((modifiers & Modifiers.UNSAFE) != 0)
            {
                Expression.UnsafeInsideIteratorError(parent.Compiler.Report, method.Location);
            }

            method.Block = method.Block.ConvertToIterator(method, parent, iterator_type, is_enumerable);
        }