public override void GenerateCode(Compiler.Emit.MethodBodyGenerator generator) { Body.GenerateCode(generator); if (generator.ReturnTarget != null) { generator.DefineLabelPosition(generator.ReturnTarget); } if (generator.ReturnVariable != null) { generator.LoadVariable(generator.ReturnVariable); } }
/// <inheritdoc/> public override void GenerateCode(Compiler.Emit.MethodBodyGenerator generator) { // Generate code for the start of the statement. var statementLocals = new StatementLocals(); GenerateStartOfStatement(generator, statementLocals); // Emit an unconditional branch. // Note: the break statement might be branching from inside a try { } or finally { } // block to outside. EmitLongJump() handles this. generator.EmitLongJump(generator, generator.GetContinueTarget(Label)); // Generate code for the end of the statement. GenerateEndOfStatement(generator, statementLocals); }
/// <summary> /// Generates CIL for the end of every statement. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="locals"> Variables common to both GenerateStartOfStatement() and GenerateEndOfStatement(). </param> protected void GenerateEndOfStatement(Compiler.Emit.MethodBodyGenerator generator, StatementLocals locals) { if (locals.NonDefaultBreakStatementBehavior == false && this.HasLabels == true) { // Revert the information needed by the break statement. generator.DefineLabelPosition(locals.EndOfStatement); generator.PopBreakOrContinueInfo(); } #if DEBUG && USE_DYNAMIC_IL_INFO // Check that the stack count is zero. if (generator is DynamicILGenerator && ((DynamicILGenerator)generator).StackSize != locals.OriginalStackSize) { throw new InvalidOperationException("Encountered unexpected stack imbalance."); } #endif }
/// <summary> /// Generates CIL for the start of every statement. /// </summary> /// <param name="generator">The generator to output the CIL to. </param> /// <param name="locals"> Variables common to both GenerateStartOfStatement() and GenerateEndOfStatement(). </param> protected void GenerateStartOfStatement(Compiler.Emit.MethodBodyGenerator generator, StatementLocals locals) { #if DEBUG && USE_DYNAMIC_IL_INFO // Statements must not produce or consume any values on the stack. if (generator is DynamicILGenerator) { locals.OriginalStackSize = ((DynamicILGenerator)generator).StackSize; } #endif if (locals.NonDefaultBreakStatementBehavior == false && this.HasLabels == true) { // Set up the information needed by the break statement. locals.EndOfStatement = generator.CreateLabel(); generator.PushBreakOrContinueInfo(this.Labels, locals.EndOfStatement, null, labelledOnly: true); } // Emit debugging information. if (locals.NonDefaultSourceSpanBehavior == false) { //todo span // optimizationInfo.MarkSequencePoint(generator, this.SourceSpan); } }