Diff of /cmajor++/Cm/Cm.Core/Statement.cpp [r570] .. [r571]  Maximize  Restore

Switch to side-by-side view

--- a/cmajor++/Cm/Cm.Core/Statement.cpp
+++ b/cmajor++/Cm/Cm.Core/Statement.cpp
@@ -92,7 +92,7 @@
 }
 
 Statement::Statement(const std::string& name_, const Position& pos_, ScopePtr enclosingScope_, ScopePtr fileScope_, const std::string& label_):
-    Object(name_, pos_, enclosingScope_, fileScope_), label(label_), parent(nullptr), cfgNode(nullptr), generatedStatement(false), firstHandlerStatement(false)
+    Object(name_, pos_, enclosingScope_, fileScope_), label(label_), parent(nullptr), cfgNode(nullptr), generatedStatement(false), genNoDebugInfo(false)
 {
 }
 
@@ -952,7 +952,7 @@
 CompoundStatement::CompoundStatement(const std::string& name_, const Position& pos_, ScopePtr enclosingScope_, ScopePtr fileScope_, const std::string& label_, bool member_):
     Statement(name_, pos_, enclosingScope_, fileScope_, label_), member(member_), scope(new Cm::Core::EnclosingScope(name_, pos_, enclosingScope_, fileScope_, 
         enclosingScope_->Ns(), ScopeKind(ScopeKind::block | (member_ || enclosingScope_->IsMemberScope() ? ScopeKind::member : ScopeKind::none)))),
-        statements(), firstNonReceiveStatementIndex(0), hasBreakChild(false), hasContinueChild(false), tryBlock(false), closeBracePos(Pos()), lexicalBlockNode(nullptr),
+        statements(), firstNonReceiveStatementIndex(0), hasBreakChild(false), hasContinueChild(false), tryBlock(false), catchBlock(false), closeBracePos(Pos()), lexicalBlockNode(nullptr),
         synthesized(false)
 {
 }
@@ -1290,10 +1290,22 @@
 
     SharedControlFlowGraphPtr cfg = GetFunction()->GetCfg();
     GenFlags diFlags = flags & GenFlags::genNoRegularDebugInfo;
+    if (IsCatchBlock())
+    {
+        diFlags = GenFlags::none;
+    }
     if (cfg && diFlags == GenFlags::none && (Parent() == nullptr || !synthesized)) // function entry or block entry
     {
         CfgNodePtr enterNode = cfg->CreateNode(Pos(), Pos());
-        cfg->PatchPrevNodes(enterNode);
+        if (IsCatchBlock())
+        {
+            cfg->GetPrevNodes();    // clear prev nodes
+            enterNode->SetKind(CfgNodeKind::catchNode);
+        }
+        else
+        {
+            cfg->PatchPrevNodes(enterNode);
+        }
         SetCfgNode(enterNode);
         emitter.UseCDebugNode(enterNode);
         GetFunction()->EmitDummyStatement(emitter);
@@ -1311,16 +1323,12 @@
     {
         if (statement->IsReceive()) continue;
         emitter.SetNextInstructionComment(statement->ToString());
-        if (statement->IsFirstHandlerStatement())
-        {
-            diFlags = GenFlags::none;
-        }
         GenFlags statementFlags = GenFlags::label | diFlags;
+        if (statement->GenNoDebugInfo())
+        {
+            statementFlags = statementFlags | GenFlags::genNoRegularDebugInfo;
+        }
         GenResult statementResult = statement->Gen(emitter, statementFlags);
-        if (statement->IsFirstHandlerStatement() && statement->GetCfgNode())
-        {
-            statement->GetCfgNode()->SetKind(CfgNodeKind::catchNode);
-        }
         if (!GetCfgNode() && statement->GetCfgNode())
         {
             SetCfgNode(statement->GetCfgNode());