From dcaf6bc57471eb56c4a267d044eac0219edf2074 Mon Sep 17 00:00:00 2001 From: Aman Goel Date: Thu, 11 Apr 2024 18:45:59 +0000 Subject: [PATCH] [PExplicit] Support continue statement Remove unreachable code after receive case block --- .../Backend/PExplicit/PExplicitCodeGenerator.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs b/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs index e74a9c05c..b4f395687 100644 --- a/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs +++ b/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs @@ -851,6 +851,10 @@ private bool WriteStmt(Function function, CompilationContext context, StringWrit context.WriteLine(output, "break;"); break; + case ContinueStmt _: + context.WriteLine(output, "continue;"); + break; + case CompoundStmt compoundStmt: foreach (var subStmt in compoundStmt.Statements) { @@ -1106,9 +1110,13 @@ private void WriteContinuation(CompilationContext context, StringWriter output, context.WriteLine(output, $"{GetPExplicitType(local.Type)} {CompilationContext.GetVar(local.Name)} = {GetDefaultValue(local.Type)};"); } } - allCasesExited &= WriteStmt(continuation, context, output, caseContext, caseFun.Body); + bool caseExited = WriteStmt(continuation, context, output, caseContext, caseFun.Body); + allCasesExited &= caseExited; context.WriteLine(output, "}"); - context.WriteLine(output, "break;"); + if (!caseExited) + { + context.WriteLine(output, "break;"); + } } context.WriteLine(output, "default:"); context.WriteLine(output, "{");