Esempio n. 1
0
        public static void CreateIterator(IMethodData method, TypeContainer 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(),
                                             TypeManager.CSharpName(ret));
                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.ISBYREF) != 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)
            {
                parent.Compiler.Report.Error(1629, method.Location, "Unsafe code may not appear in iterators");
            }

            method.Block.WrapIntoIterator(method, parent, iterator_type, is_enumerable);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void SymbolRelatedToPreviousError(MemberInfo mi)
        {
            if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
            {
                return;
            }

            Type dt = TypeManager.DropGenericTypeArguments(mi.DeclaringType);

            if (TypeManager.IsDelegateType(dt))
            {
                SymbolRelatedToPreviousError(dt);
                return;
            }

            DeclSpace temp_ds = TypeManager.LookupDeclSpace(dt);

            if (temp_ds == null)
            {
                SymbolRelatedToPreviousError(dt.Assembly.Location, TypeManager.GetFullNameSignature(mi));
            }
            else
            {
                MethodBase mb = mi as MethodBase;
                if (mb != null)
                {
                    mb = TypeManager.DropGenericMethodArguments(mb);
                    IMethodData md = TypeManager.GetMethod(mb);
                    if (md != null)
                    {
                        SymbolRelatedToPreviousError(md.Location, md.GetSignatureForError());
                    }

                    return;
                }

                // FIXME: Completely wrong, it has to use FindMembers
                MemberCore mc = temp_ds.GetDefinition(mi.Name);
                if (mc != null)
                {
                    SymbolRelatedToPreviousError(mc);
                }
            }
        }
Esempio n. 4
0
        public static void CreateIterator(IMethodData method, TypeContainer parent, Modifiers modifiers, CompilerContext ctx)
        {
            bool is_enumerable;
            TypeSpec iterator_type;

            TypeSpec ret = method.ReturnType;
            if (ret == null)
                return;

            if (!CheckType (ret, out iterator_type, out is_enumerable)) {
                ctx.Report.Error (1624, method.Location,
                          "The body of `{0}' cannot be an iterator block " +
                          "because `{1}' is not an iterator interface type",
                          method.GetSignatureForError (),
                          TypeManager.CSharpName (ret));
                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.ISBYREF) != 0) {
                    ctx.Report.Error (1623, p.Location,
                        "Iterators cannot have ref or out parameters");
                    return;
                }

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

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

            if ((modifiers & Modifiers.UNSAFE) != 0) {
                ctx.Report.Error (1629, method.Location, "Unsafe code may not appear in iterators");
                return;
            }

            // TODO: Ugly leftover
            new Iterator (ctx, method, parent, iterator_type, is_enumerable);
        }
Esempio n. 5
0
		public bool Resolve (FlowBranching parent, BlockContext rc, IMethodData md)
		{
			if (resolved)
				return true;

			resolved = true;

			if (rc.HasSet (ResolveContext.Options.ExpressionTreeConversion))
				flags |= Flags.IsExpressionTree;

			try {
				ResolveMeta (rc);

				using (rc.With (ResolveContext.Options.DoFlowAnalysis, true)) {
					FlowBranchingToplevel top_level = rc.StartFlowBranching (this, parent);

					if (!Resolve (rc))
						return false;

					unreachable = top_level.End ();
				}
			} catch (Exception e) {
				if (e is CompletionResult || rc.Report.IsDisabled)
					throw;

				if (rc.CurrentBlock != null) {
					rc.Report.Error (584, rc.CurrentBlock.StartLocation, "Internal compiler error: {0}", e.Message);
				} else {
					rc.Report.Error (587, "Internal compiler error: {0}", e.Message);
				}

				if (Report.DebugFlags > 0)
					throw;
			}

			if (rc.ReturnType != TypeManager.void_type && !unreachable) {
				if (rc.CurrentAnonymousMethod == null) {
					// FIXME: Missing FlowAnalysis for generated iterator MoveNext method
					if (md is IteratorMethod) {
						unreachable = true;
					} else {
						rc.Report.Error (161, md.Location, "`{0}': not all code paths return a value", md.GetSignatureForError ());
						return false;
					}
				} else {
					rc.Report.Error (1643, rc.CurrentAnonymousMethod.Location, "Not all code paths return a value in anonymous method of type `{0}'",
							  rc.CurrentAnonymousMethod.GetSignatureForError ());
					return false;
				}
			}

			return true;
		}
Esempio n. 6
0
 public override string GetSignatureForError()
 {
     return(OriginalMethod.GetSignatureForError());
 }
		public bool Resolve (FlowBranching parent, BlockContext rc, ParametersCompiled ip, IMethodData md)
		{
			if (resolved)
				return true;

			resolved = true;

			try {
				if (!ResolveMeta (rc, ip))
					return false;

				using (rc.With (ResolveContext.Options.DoFlowAnalysis, true)) {
					FlowBranchingToplevel top_level = rc.StartFlowBranching (this, parent);

					if (!Resolve (rc))
						return false;

					unreachable = top_level.End ();
				}
			} catch (Exception) {
#if PRODUCTION
				if (rc.CurrentBlock != null) {
					ec.Report.Error (584, rc.CurrentBlock.StartLocation, "Internal compiler error: Phase Resolve");
				} else {
					ec.Report.Error (587, "Internal compiler error: Phase Resolve");
				}
#endif
				throw;
			}

			if (rc.ReturnType != TypeManager.void_type && !unreachable) {
				if (rc.CurrentAnonymousMethod == null) {
					rc.Report.Error (161, md.Location, "`{0}': not all code paths return a value", md.GetSignatureForError ());
					return false;
				} else if (!rc.CurrentAnonymousMethod.IsIterator) {
					rc.Report.Error (1643, rc.CurrentAnonymousMethod.Location, "Not all code paths return a value in anonymous method of type `{0}'",
							  rc.CurrentAnonymousMethod.GetSignatureForError ());
					return false;
				}
			}

			return true;
		}
Esempio n. 8
0
		public bool ResolveTopBlock (EmitContext anonymous_method_host, ToplevelBlock block,
					     Parameters ip, IMethodData md, out bool unreachable)
		{
			if (resolved) {
				unreachable = this.unreachable;
				return true;
			}

			current_phase = Phase.Resolving;
			unreachable = false;

			if (!loc.IsNull)
				CurrentFile = loc.File;

#if PRODUCTION
			try {
#endif
				if (!block.ResolveMeta (this, ip))
					return false;

				using (this.With (EmitContext.Flags.DoFlowAnalysis, true)) {
					FlowBranchingToplevel top_level;
					if (anonymous_method_host != null)
						top_level = new FlowBranchingToplevel (anonymous_method_host.CurrentBranching, block);
					else 
						top_level = block.TopLevelBranching;

					current_flow_branching = top_level;
					bool ok = block.Resolve (this);
					current_flow_branching = null;

					if (!ok)
						return false;

					bool flow_unreachable = top_level.End ();
					if (flow_unreachable)
						this.unreachable = unreachable = true;
				}
#if PRODUCTION
			} catch (Exception e) {
				Console.WriteLine ("Exception caught by the compiler while compiling:");
				Console.WriteLine ("   Block that caused the problem begin at: " + loc);

				if (CurrentBlock != null){
					Console.WriteLine ("                     Block being compiled: [{0},{1}]",
							   CurrentBlock.StartLocation, CurrentBlock.EndLocation);
				}
				Console.WriteLine (e.GetType ().FullName + ": " + e.Message);
				throw;
			}
#endif

			if (return_type != TypeManager.void_type && !unreachable) {
				if (CurrentAnonymousMethod == null) {
					Report.Error (161, md.Location, "`{0}': not all code paths return a value", md.GetSignatureForError ());
					return false;
				} else if (!CurrentAnonymousMethod.IsIterator) {
					Report.Error (1643, CurrentAnonymousMethod.Location, "Not all code paths return a value in anonymous method of type `{0}'",
						      CurrentAnonymousMethod.GetSignatureForError ());
					return false;
				}
			}

			resolved = true;
			return true;
		}