public StartFlowBranching ( |
||
block | ||
리턴 | Mono.CSharp.FlowBranching |
public override bool Resolve(BlockContext ec) { ec.StartFlowBranching(iterator); bool ok = original_block.Resolve(ec); ec.EndFlowBranching(); return(ok); }
/// <summary> /// We already know that the statement is unreachable, but we still /// need to resolve it to catch errors. /// </summary> public virtual bool ResolveUnreachable (BlockContext ec, bool warn) { // // This conflicts with csc's way of doing this, but IMHO it's // the right thing to do. // // If something is unreachable, we still check whether it's // correct. This means that you cannot use unassigned variables // in unreachable code, for instance. // if (warn) ec.Report.Warning (162, 2, loc, "Unreachable code detected"); ec.StartFlowBranching (FlowBranching.BranchingType.Block, loc); bool ok = Resolve (ec); ec.KillFlowBranching (); return ok; }
protected override Expression DoResolve(ResolveContext ec) { IteratorHost = (IteratorStorey)block.TopBlock.AnonymousMethodStorey; BlockContext ctx = new BlockContext(ec, block, ReturnType); ctx.CurrentAnonymousMethod = this; ctx.StartFlowBranching(this, ec.CurrentBranching); Block.Resolve(ctx); ctx.EndFlowBranching(); var move_next = new IteratorMethod(IteratorHost, new TypeExpression(ec.BuiltinTypes.Bool, loc), Modifiers.PUBLIC, new MemberName("MoveNext", Location)); move_next.Block.AddStatement(new MoveNextMethodStatement(this)); IteratorHost.AddMethod(move_next); eclass = ExprClass.Value; return(this); }
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; }
public override bool Resolve (BlockContext ec) { bool ok = true; ec.StartFlowBranching (FlowBranching.BranchingType.Loop, loc); bool was_unreachable = ec.CurrentBranching.CurrentUsageVector.IsUnreachable; ec.StartFlowBranching (FlowBranching.BranchingType.Embedded, loc); if (!EmbeddedStatement.Resolve (ec)) ok = false; ec.EndFlowBranching (); if (ec.CurrentBranching.CurrentUsageVector.IsUnreachable && !was_unreachable) ec.Report.Warning (162, 2, expr.Location, "Unreachable code detected"); expr = expr.Resolve (ec); if (expr == null) ok = false; else if (expr is Constant){ bool infinite = !((Constant) expr).IsDefaultValue; if (infinite) ec.CurrentBranching.CurrentUsageVector.Goto (); } ec.EndFlowBranching (); return ok; }
public override bool Resolve (BlockContext ec) { // this flow-branching will be terminated when the surrounding block ends ec.StartFlowBranching (this); return true; }
public override bool Resolve (BlockContext ec) { bool ok = true; Report.Debug (1, "START IF BLOCK", loc); expr = Expression.ResolveBoolean (ec, expr, loc); if (expr == null){ ok = false; goto skip; } Assign ass = expr as Assign; if (ass != null && ass.Source is Constant) { ec.Report.Warning (665, 3, loc, "Assignment in conditional expression is always constant; did you mean to use == instead of = ?"); } // // Dead code elimination // if (expr is Constant){ bool take = !((Constant) expr).IsDefaultValue; if (take){ if (!TrueStatement.Resolve (ec)) return false; if ((FalseStatement != null) && !FalseStatement.ResolveUnreachable (ec, true)) return false; FalseStatement = null; } else { if (!TrueStatement.ResolveUnreachable (ec, true)) return false; TrueStatement = null; if ((FalseStatement != null) && !FalseStatement.Resolve (ec)) return false; } return true; } skip: ec.StartFlowBranching (FlowBranching.BranchingType.Conditional, loc); ok &= TrueStatement.Resolve (ec); is_true_ret = ec.CurrentBranching.CurrentUsageVector.IsUnreachable; ec.CurrentBranching.CreateSibling (); if (FalseStatement != null) ok &= FalseStatement.Resolve (ec); ec.EndFlowBranching (); Report.Debug (1, "END IF BLOCK", loc); return ok; }
public override bool Resolve (BlockContext ec) { using (ec.Set (ResolveContext.Options.FixedInitializerScope)) { if (!decl.Resolve (ec)) return false; } ec.StartFlowBranching (FlowBranching.BranchingType.Conditional, loc); bool ok = statement.Resolve (ec); bool flow_unreachable = ec.EndFlowBranching (); has_ret = flow_unreachable; return ok; }
public override bool Resolve (BlockContext ec) { expr = expr.Resolve (ec); if (expr == null) return false; expr_type = expr.Type; if (!TypeManager.ImplementsInterface (expr_type, TypeManager.idisposable_type)) { if (Convert.ImplicitConversion (ec, expr, TypeManager.idisposable_type, loc) == null) { Using.Error_IsNotConvertibleToIDisposable (ec, expr); return false; } } local_copy = new TemporaryVariable (expr_type, loc); local_copy.Resolve (ec); ec.StartFlowBranching (this); bool ok = Statement.Resolve (ec); ec.EndFlowBranching (); ok &= base.Resolve (ec); if (TypeManager.void_dispose_void == null) { TypeManager.void_dispose_void = TypeManager.GetPredefinedMethod ( TypeManager.idisposable_type, "Dispose", loc, Type.EmptyTypes); } return ok; }
public override bool Resolve (BlockContext ec) { bool ok = DoResolve (ec); ec.StartFlowBranching (this); ok &= statement.Resolve (ec); ec.EndFlowBranching (); ok &= base.Resolve (ec); return ok; }
public override bool Resolve (BlockContext ec) { Block prev_block = ec.CurrentBlock; bool ok = true; int errors = ec.Report.Errors; ec.CurrentBlock = this; ec.StartFlowBranching (this); Report.Debug (4, "RESOLVE BLOCK", StartLocation, ec.CurrentBranching); // // Compiler generated scope statements // if (scope_initializers != null) { foreach (Statement s in scope_initializers) s.Resolve (ec); } // // This flag is used to notate nested statements as unreachable from the beginning of this block. // For the purposes of this resolution, it doesn't matter that the whole block is unreachable // from the beginning of the function. The outer Resolve() that detected the unreachability is // responsible for handling the situation. // int statement_count = statements.Count; for (int ix = 0; ix < statement_count; ix++){ Statement s = (Statement) statements [ix]; if (s == null) continue; // Check possible empty statement (CS0642) if (ix + 1 < statement_count && ec.Report.WarningLevel >= 3 && statements [ix + 1] is ExplicitBlock) CheckPossibleMistakenEmptyStatement (ec, s); // // Warn if we detect unreachable code. // if (unreachable) { if (s is EmptyStatement) continue; if (!unreachable_shown && !(s is LabeledStatement)) { ec.Report.Warning (162, 2, s.loc, "Unreachable code detected"); unreachable_shown = true; } Block c_block = s as Block; if (c_block != null) c_block.unreachable = c_block.unreachable_shown = true; } // // Note that we're not using ResolveUnreachable() for unreachable // statements here. ResolveUnreachable() creates a temporary // flow branching and kills it afterwards. This leads to problems // if you have two unreachable statements where the first one // assigns a variable and the second one tries to access it. // if (!s.Resolve (ec)) { ok = false; if (ec.IsInProbingMode) break; statements [ix] = EmptyStatement.Value; continue; } if (unreachable && !(s is LabeledStatement) && !(s is Block)) statements [ix] = EmptyStatement.Value; unreachable = ec.CurrentBranching.CurrentUsageVector.IsUnreachable; if (unreachable && s is LabeledStatement) throw new InternalErrorException ("should not happen"); } Report.Debug (4, "RESOLVE BLOCK DONE", StartLocation, ec.CurrentBranching, statement_count); while (ec.CurrentBranching is FlowBranchingLabeled) ec.EndFlowBranching (); bool flow_unreachable = ec.EndFlowBranching (); ec.CurrentBlock = prev_block; if (flow_unreachable) flags |= Flags.HasRet; // If we're a non-static `struct' constructor which doesn't have an // initializer, then we must initialize all of the struct's fields. if (this == Toplevel && !Toplevel.IsThisAssigned (ec) && !flow_unreachable) ok = false; if ((labels != null) && (ec.Report.WarningLevel >= 2)) { foreach (LabeledStatement label in labels.Values) if (!label.HasBeenReferenced) ec.Report.Warning (164, 2, label.loc, "This label has not been referenced"); } if (ok && errors == ec.Report.Errors) UsageWarning (ec); return ok; }
public override bool Resolve (BlockContext ec) { VariableReference vr; bool vr_locked = false; using (ec.Set (ResolveContext.Options.UsingInitializerScope)) { if (decl.Variable == null) { vr = decl.ResolveExpression (ec) as VariableReference; if (vr != null) { vr_locked = vr.IsLockedByStatement; vr.IsLockedByStatement = true; } } else { if (!decl.Resolve (ec)) return false; if (decl.Declarators != null) { stmt = decl.RewriteForDeclarators (ec, stmt); } vr = null; } } ec.StartFlowBranching (this); stmt.Resolve (ec); ec.EndFlowBranching (); if (vr != null) vr.IsLockedByStatement = vr_locked; base.Resolve (ec); return true; }
public override bool Resolve (BlockContext ec) { if (!ec.IsUnsafe){ Expression.UnsafeError (ec, loc); return false; } TypeExpr texpr = type.ResolveAsContextualType (ec, false); if (texpr == null) { if (type is VarExpr) ec.Report.Error (821, type.Location, "A fixed statement cannot use an implicitly typed local variable"); return false; } expr_type = texpr.Type; data = new Emitter [declarators.Count]; if (!expr_type.IsPointer){ ec.Report.Error (209, loc, "The type of locals declared in a fixed statement must be a pointer type"); return false; } int i = 0; foreach (var p in declarators){ LocalInfo vi = p.Key; Expression e = p.Value; vi.VariableInfo.SetAssigned (ec); vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed); // // The rules for the possible declarators are pretty wise, // but the production on the grammar is more concise. // // So we have to enforce these rules here. // // We do not resolve before doing the case 1 test, // because the grammar is explicit in that the token & // is present, so we need to test for this particular case. // if (e is Cast){ ec.Report.Error (254, loc, "The right hand side of a fixed statement assignment may not be a cast expression"); return false; } using (ec.Set (ResolveContext.Options.FixedInitializerScope)) { e = e.Resolve (ec); } if (e == null) return false; // // Case 2: Array // if (e.Type.IsArray){ TypeSpec array_type = TypeManager.GetElementType (e.Type); // // Provided that array_type is unmanaged, // if (!TypeManager.VerifyUnmanaged (ec.Compiler, array_type, loc)) return false; // // and T* is implicitly convertible to the // pointer type given in the fixed statement. // ArrayPtr array_ptr = new ArrayPtr (e, array_type, loc); Expression converted = Convert.ImplicitConversionRequired ( ec, array_ptr, vi.VariableType, loc); if (converted == null) return false; // // fixed (T* e_ptr = (e == null || e.Length == 0) ? null : converted [0]) // converted = new Conditional (new BooleanExpression (new Binary (Binary.Operator.LogicalOr, new Binary (Binary.Operator.Equality, e, new NullLiteral (loc), loc), new Binary (Binary.Operator.Equality, new MemberAccess (e, "Length"), new IntConstant (0, loc), loc), loc)), new NullPointer (loc), converted, loc); converted = converted.Resolve (ec); data [i] = new ExpressionEmitter (converted, vi); i++; continue; } // // Case 3: string // if (e.Type == TypeManager.string_type){ data [i] = new StringEmitter (e, vi, loc).Resolve (ec); i++; continue; } // Case 4: fixed buffer if (e is FixedBufferPtr) { data [i++] = new ExpressionEmitter (e, vi); continue; } // // Case 1: & object. // Unary u = e as Unary; if (u != null && u.Oper == Unary.Operator.AddressOf) { IVariableReference vr = u.Expr as IVariableReference; if (vr == null || !vr.IsFixed) { data [i] = new ExpressionEmitter (e, vi); } } if (data [i++] == null) ec.Report.Error (213, vi.Location, "You cannot use the fixed statement to take the address of an already fixed expression"); e = Convert.ImplicitConversionRequired (ec, e, expr_type, loc); } ec.StartFlowBranching (FlowBranching.BranchingType.Conditional, loc); bool ok = statement.Resolve (ec); bool flow_unreachable = ec.EndFlowBranching (); has_ret = flow_unreachable; return ok; }
public override bool Resolve (BlockContext ec) { expr = expr.Resolve (ec); if (expr == null) return false; if (!TypeManager.IsReferenceType (expr.Type)){ ec.Report.Error (185, loc, "`{0}' is not a reference type as required by the lock statement", expr.Type.GetSignatureForError ()); } if (expr.Type.IsGenericParameter) { expr = Convert.ImplicitTypeParameterConversion (expr, TypeManager.object_type); } VariableReference lv = expr as VariableReference; bool locked; if (lv != null) { locked = lv.IsLockedByStatement; lv.IsLockedByStatement = true; } else { lv = null; locked = false; } ec.StartFlowBranching (this); Statement.Resolve (ec); ec.EndFlowBranching (); if (lv != null) { lv.IsLockedByStatement = locked; } base.Resolve (ec); // // Have to keep original lock value around to unlock same location // in the case the original has changed or is null // expr_copy = TemporaryVariableReference.Create (TypeManager.object_type, ec.CurrentBlock.Parent, loc); expr_copy.Resolve (ec); // // Ensure Monitor methods are available // if (ResolvePredefinedMethods (ec) > 1) { lock_taken = TemporaryVariableReference.Create (TypeManager.bool_type, ec.CurrentBlock.Parent, loc); lock_taken.Resolve (ec); } return true; }
protected override Expression DoResolve (ResolveContext ec) { IteratorHost = (IteratorStorey) block.TopBlock.AnonymousMethodStorey; BlockContext ctx = new BlockContext (ec, block, ReturnType); ctx.CurrentAnonymousMethod = this; ctx.StartFlowBranching (this, ec.CurrentBranching); Block.Resolve (ctx); ctx.EndFlowBranching (); var move_next = new IteratorMethod (IteratorHost, new TypeExpression (TypeManager.bool_type, loc), Modifiers.PUBLIC, new MemberName ("MoveNext", Location)); move_next.Block.AddStatement (new MoveNextMethodStatement (this)); IteratorHost.AddMethod (move_next); eclass = ExprClass.Value; return this; }
public override bool Resolve (BlockContext ec) { bool ok = true; ec.StartFlowBranching (this); if (!parent.ResolveLoop (ec)) ok = false; ec.EndFlowBranching (); ok &= base.Resolve (ec); if (TypeManager.void_dispose_void == null) { TypeManager.void_dispose_void = TypeManager.GetPredefinedMethod ( TypeManager.idisposable_type, "Dispose", loc, Type.EmptyTypes); } return ok; }
public override bool Resolve (BlockContext ec) { bool ok = true; expr = expr.Resolve (ec); if (expr == null) ok = false; // // Inform whether we are infinite or not // if (expr is Constant){ bool value = !((Constant) expr).IsDefaultValue; if (value == false){ if (!Statement.ResolveUnreachable (ec, true)) return false; empty = true; return true; } else infinite = true; } ec.StartFlowBranching (FlowBranching.BranchingType.Loop, loc); if (!infinite) ec.CurrentBranching.CreateSibling (); ec.StartFlowBranching (FlowBranching.BranchingType.Embedded, loc); if (!Statement.Resolve (ec)) ok = false; ec.EndFlowBranching (); // There's no direct control flow from the end of the embedded statement to the end of the loop ec.CurrentBranching.CurrentUsageVector.Goto (); ec.EndFlowBranching (); return ok; }
public override bool Resolve (BlockContext ec) { if (!ResolveVariable (ec)) return false; ec.StartFlowBranching (this); bool ok = stmt.Resolve (ec); ec.EndFlowBranching (); ok &= base.Resolve (ec); if (TypeManager.void_dispose_void == null) { TypeManager.void_dispose_void = TypeManager.GetPredefinedMethod ( TypeManager.idisposable_type, "Dispose", loc, TypeSpec.EmptyTypes); } return ok; }
public override bool Resolve (BlockContext ec) { Expr = Expr.Resolve (ec); if (Expr == null) return false; new_expr = SwitchGoverningType (ec, Expr); if ((new_expr == null) && TypeManager.IsNullableType (Expr.Type)) { unwrap = Nullable.Unwrap.Create (Expr, false); if (unwrap == null) return false; new_expr = SwitchGoverningType (ec, unwrap); } if (new_expr == null){ ec.Report.Error (151, loc, "A switch expression of type `{0}' cannot be converted to an integral type, bool, char, string, enum or nullable type", TypeManager.CSharpName (Expr.Type)); return false; } // Validate switch. SwitchType = new_expr.Type; if (RootContext.Version == LanguageVersion.ISO_1 && SwitchType == TypeManager.bool_type) { ec.Report.FeatureIsNotAvailable (loc, "switch expression of boolean type"); return false; } if (!CheckSwitch (ec)) return false; if (HaveUnwrap) Elements.Remove (SwitchLabel.NullStringCase); Switch old_switch = ec.Switch; ec.Switch = this; ec.Switch.SwitchType = SwitchType; Report.Debug (1, "START OF SWITCH BLOCK", loc, ec.CurrentBranching); ec.StartFlowBranching (FlowBranching.BranchingType.Switch, loc); var constant = new_expr as Constant; if (constant != null) { is_constant = true; object key = constant.GetValue (); SwitchLabel label; if (Elements.TryGetValue (key, out label)) constant_section = FindSection (label); if (constant_section == null) constant_section = default_section; } bool first = true; bool ok = true; foreach (SwitchSection ss in Sections){ if (!first) ec.CurrentBranching.CreateSibling ( null, FlowBranching.SiblingType.SwitchSection); else first = false; if (is_constant && (ss != constant_section)) { // If we're a constant switch, we're only emitting // one single section - mark all the others as // unreachable. ec.CurrentBranching.CurrentUsageVector.Goto (); if (!ss.Block.ResolveUnreachable (ec, true)) { ok = false; } } else { if (!ss.Block.Resolve (ec)) ok = false; } } if (default_section == null) ec.CurrentBranching.CreateSibling ( null, FlowBranching.SiblingType.SwitchSection); ec.EndFlowBranching (); ec.Switch = old_switch; Report.Debug (1, "END OF SWITCH BLOCK", loc, ec.CurrentBranching); if (!ok) return false; if (SwitchType == TypeManager.string_type && !is_constant) { // TODO: Optimize single case, and single+default case ResolveStringSwitchMap (ec); } return true; }
public override bool Resolve (BlockContext ec) { bool ok = true; ec.StartFlowBranching (this); if (!Block.Resolve (ec)) ok = false; TypeSpec[] prev_catches = new TypeSpec [Specific.Count]; int last_index = 0; foreach (Catch c in Specific){ ec.CurrentBranching.CreateSibling (c.Block, FlowBranching.SiblingType.Catch); if (!c.Resolve (ec)) { ok = false; continue; } TypeSpec resolved_type = c.CatchType; for (int ii = 0; ii < last_index; ++ii) { if (resolved_type == prev_catches[ii] || TypeSpec.IsBaseClass (resolved_type, prev_catches[ii], true)) { ec.Report.Error (160, c.loc, "A previous catch clause already catches all exceptions of this or a super type `{0}'", TypeManager.CSharpName (prev_catches [ii])); ok = false; } } prev_catches [last_index++] = resolved_type; } if (General != null) { if (CodeGen.Assembly.WrapNonExceptionThrows) { foreach (Catch c in Specific){ if (c.CatchType == TypeManager.exception_type && ec.Compiler.PredefinedAttributes.RuntimeCompatibility.IsDefined) { ec.Report.Warning (1058, 1, c.loc, "A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a `System.Runtime.CompilerServices.RuntimeWrappedException'"); } } } ec.CurrentBranching.CreateSibling (General.Block, FlowBranching.SiblingType.Catch); if (!General.Resolve (ec)) ok = false; } ec.EndFlowBranching (); // System.Reflection.Emit automatically emits a 'leave' at the end of a try/catch clause // So, ensure there's some IL code after this statement if (!inside_try_finally && !code_follows && ec.CurrentBranching.CurrentUsageVector.IsUnreachable) ec.NeedReturnLabel (); return ok; }
public override bool Resolve (BlockContext ec) { expr = expr.Resolve (ec); if (expr == null) return false; if (!TypeManager.IsReferenceType (expr.Type)){ ec.Report.Error (185, loc, "`{0}' is not a reference type as required by the lock statement", TypeManager.CSharpName (expr.Type)); return false; } ec.StartFlowBranching (this); bool ok = Statement.Resolve (ec); ec.EndFlowBranching (); ok &= base.Resolve (ec); temp = TemporaryVariableReference.Create (expr.Type, ec.CurrentBlock.Parent, loc); temp.Resolve (ec); if (TypeManager.void_monitor_enter_object == null || TypeManager.void_monitor_exit_object == null) { TypeSpec monitor_type = TypeManager.CoreLookupType (ec.Compiler, "System.Threading", "Monitor", MemberKind.Class, true); TypeManager.void_monitor_enter_object = TypeManager.GetPredefinedMethod ( monitor_type, "Enter", loc, TypeManager.object_type); TypeManager.void_monitor_exit_object = TypeManager.GetPredefinedMethod ( monitor_type, "Exit", loc, TypeManager.object_type); } return ok; }
public override bool Resolve (BlockContext ec) { using (ec.Set (ResolveContext.Options.UsingInitializerScope)) { if (decl.Variable == null) { decl.ResolveExpression (ec); } else { if (!decl.Resolve (ec)) return false; if (decl.Declarators != null) { stmt = decl.RewriteForDeclarators (ec, stmt); } } } ec.StartFlowBranching (this); bool ok = stmt.Resolve (ec); ec.EndFlowBranching (); ok &= base.Resolve (ec); return ok; }
public override bool Resolve (BlockContext ec) { bool ok = true; ec.StartFlowBranching (this); if (!stmt.Resolve (ec)) ok = false; if (ok) ec.CurrentBranching.CreateSibling (fini, FlowBranching.SiblingType.Finally); using (ec.With (ResolveContext.Options.FinallyScope, true)) { if (!fini.Resolve (ec)) ok = false; } ec.EndFlowBranching (); ok &= base.Resolve (ec); return ok; }
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; }
public override bool Resolve (BlockContext ec) { bool ok = true; if (InitStatement != null){ if (!InitStatement.Resolve (ec)) ok = false; } if (Test != null){ Test = Test.Resolve (ec); if (Test == null) ok = false; else if (Test is Constant){ bool value = !((Constant) Test).IsDefaultValue; if (value == false){ if (!Statement.ResolveUnreachable (ec, true)) return false; if ((Increment != null) && !Increment.ResolveUnreachable (ec, false)) return false; empty = true; return true; } else infinite = true; } } else infinite = true; ec.StartFlowBranching (FlowBranching.BranchingType.Loop, loc); if (!infinite) ec.CurrentBranching.CreateSibling (); bool was_unreachable = ec.CurrentBranching.CurrentUsageVector.IsUnreachable; ec.StartFlowBranching (FlowBranching.BranchingType.Embedded, loc); if (!Statement.Resolve (ec)) ok = false; ec.EndFlowBranching (); if (Increment != null){ if (ec.CurrentBranching.CurrentUsageVector.IsUnreachable) { if (!Increment.ResolveUnreachable (ec, !was_unreachable)) ok = false; } else { if (!Increment.Resolve (ec)) ok = false; } } // There's no direct control flow from the end of the embedded statement to the end of the loop ec.CurrentBranching.CurrentUsageVector.Goto (); ec.EndFlowBranching (); return ok; }
public override bool Resolve (BlockContext ec) { bool ok = true; Report.Debug (1, "START IF BLOCK", loc); expr = expr.Resolve (ec); if (expr == null) { ok = false; } else { // // Dead code elimination // if (expr is Constant) { bool take = !((Constant) expr).IsDefaultValue; if (take) { if (!TrueStatement.Resolve (ec)) return false; if ((FalseStatement != null) && !FalseStatement.ResolveUnreachable (ec, true)) return false; FalseStatement = null; } else { if (!TrueStatement.ResolveUnreachable (ec, true)) return false; TrueStatement = null; if ((FalseStatement != null) && !FalseStatement.Resolve (ec)) return false; } return true; } } ec.StartFlowBranching (FlowBranching.BranchingType.Conditional, loc); ok &= TrueStatement.Resolve (ec); is_true_ret = ec.CurrentBranching.CurrentUsageVector.IsUnreachable; ec.CurrentBranching.CreateSibling (); if (FalseStatement != null) ok &= FalseStatement.Resolve (ec); ec.EndFlowBranching (); Report.Debug (1, "END IF BLOCK", loc); return ok; }
public override bool Resolve (BlockContext ec) { Block variables_block = variable.local_info.Block; copy = TemporaryVariableReference.Create (for_each.expr.Type, variables_block, loc); copy.Resolve (ec); int rank = length_exprs.Length; Arguments list = new Arguments (rank); for (int i = 0; i < rank; i++) { var v = TemporaryVariableReference.Create (TypeManager.int32_type, variables_block, loc); variables[i] = v; counter[i] = new StatementExpression (new UnaryMutator (UnaryMutator.Mode.PostIncrement, v, loc)); counter[i].Resolve (ec); if (rank == 1) { length_exprs [i] = new MemberAccess (copy, "Length").Resolve (ec); } else { lengths[i] = TemporaryVariableReference.Create (TypeManager.int32_type, variables_block, loc); lengths[i].Resolve (ec); Arguments args = new Arguments (1); args.Add (new Argument (new IntConstant (i, loc))); length_exprs [i] = new Invocation (new MemberAccess (copy, "GetLength"), args).Resolve (ec); } list.Add (new Argument (v)); } access = new ElementAccess (copy, list, loc).Resolve (ec); if (access == null) return false; Expression var_type = for_each.type; VarExpr ve = var_type as VarExpr; if (ve != null) { // Infer implicitly typed local variable from foreach array type var_type = new TypeExpression (access.Type, ve.Location); } var_type = var_type.ResolveAsTypeTerminal (ec, false); if (var_type == null) return false; conv = Convert.ExplicitConversion (ec, access, var_type.Type, loc); if (conv == null) return false; bool ok = true; ec.StartFlowBranching (FlowBranching.BranchingType.Loop, loc); ec.CurrentBranching.CreateSibling (); variable.local_info.Type = conv.Type; variable.Resolve (ec); ec.StartFlowBranching (FlowBranching.BranchingType.Embedded, loc); if (!statement.Resolve (ec)) ok = false; ec.EndFlowBranching (); // There's no direct control flow from the end of the embedded statement to the end of the loop ec.CurrentBranching.CurrentUsageVector.Goto (); ec.EndFlowBranching (); return ok; }
public override bool Resolve (BlockContext ec) { Block prev_block = ec.CurrentBlock; bool ok = true; ec.CurrentBlock = this; ec.StartFlowBranching (this); Report.Debug (4, "RESOLVE BLOCK", StartLocation, ec.CurrentBranching); // // Compiler generated scope statements // if (scope_initializers != null) { for (resolving_init_idx = 0; resolving_init_idx < scope_initializers.Count; ++resolving_init_idx) { scope_initializers[resolving_init_idx.Value].Resolve (ec); } resolving_init_idx = null; } // // This flag is used to notate nested statements as unreachable from the beginning of this block. // For the purposes of this resolution, it doesn't matter that the whole block is unreachable // from the beginning of the function. The outer Resolve() that detected the unreachability is // responsible for handling the situation. // int statement_count = statements.Count; for (int ix = 0; ix < statement_count; ix++){ Statement s = statements [ix]; // // Warn if we detect unreachable code. // if (unreachable) { if (s is EmptyStatement) continue; if (!unreachable_shown && !(s is LabeledStatement)) { ec.Report.Warning (162, 2, s.loc, "Unreachable code detected"); unreachable_shown = true; } Block c_block = s as Block; if (c_block != null) c_block.unreachable = c_block.unreachable_shown = true; } // // Note that we're not using ResolveUnreachable() for unreachable // statements here. ResolveUnreachable() creates a temporary // flow branching and kills it afterwards. This leads to problems // if you have two unreachable statements where the first one // assigns a variable and the second one tries to access it. // if (!s.Resolve (ec)) { ok = false; if (ec.IsInProbingMode) break; statements [ix] = new EmptyStatement (s.loc); continue; } if (unreachable && !(s is LabeledStatement) && !(s is Block)) statements [ix] = new EmptyStatement (s.loc); unreachable = ec.CurrentBranching.CurrentUsageVector.IsUnreachable; if (unreachable && s is LabeledStatement) throw new InternalErrorException ("should not happen"); } Report.Debug (4, "RESOLVE BLOCK DONE", StartLocation, ec.CurrentBranching, statement_count); while (ec.CurrentBranching is FlowBranchingLabeled) ec.EndFlowBranching (); bool flow_unreachable = ec.EndFlowBranching (); ec.CurrentBlock = prev_block; if (flow_unreachable) flags |= Flags.HasRet; // If we're a non-static `struct' constructor which doesn't have an // initializer, then we must initialize all of the struct's fields. if (this == ParametersBlock.TopBlock && !ParametersBlock.TopBlock.IsThisAssigned (ec) && !flow_unreachable) ok = false; return ok; }
public override bool Resolve(BlockContext ec) { ec.StartFlowBranching (iterator); bool ok = original_block.Resolve (ec); ec.EndFlowBranching (); return ok; }
public override bool ResolveUnreachable (BlockContext ec, bool warn) { unreachable_shown = true; unreachable = true; if (warn) ec.Report.Warning (162, 2, loc, "Unreachable code detected"); ec.StartFlowBranching (FlowBranching.BranchingType.Block, loc); bool ok = Resolve (ec); ec.KillFlowBranching (); return ok; }