From 03013cf2e15dcb9f9688f137783c2c726ea2236c Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 29 Nov 2018 21:31:34 +0000 Subject: [PATCH] * make ttryfinallynode inherit from ttertiary node so it has a "third" node member. This one will be used by the LLVM descendent to keep a copy of the finally code, as it must use a separate version for the code that gets executed when an exception is caught and when no exception happens git-svn-id: branches/debug_eh@40416 - --- compiler/nflw.pas | 19 ++++++++++++++++--- compiler/nutils.pas | 8 ++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/compiler/nflw.pas b/compiler/nflw.pas index 84cb5dc167..3042b557f8 100644 --- a/compiler/nflw.pas +++ b/compiler/nflw.pas @@ -189,7 +189,10 @@ interface end; ttryexceptnodeclass = class of ttryexceptnode; - ttryfinallynode = class(tbinarynode) + { the third node is to store a copy of the finally code for llvm: + it needs one copy to execute in case an exception occurs, and + one in case no exception occurs } + ttryfinallynode = class(ttertiarynode) implicitframe : boolean; constructor create(l,r:tnode);virtual;reintroduce; constructor create_implicit(l,r:tnode);virtual; @@ -2299,14 +2302,16 @@ implementation constructor ttryfinallynode.create(l,r:tnode); begin - inherited create(tryfinallyn,l,r); + inherited create(tryfinallyn,l,r,nil); + third:=nil; implicitframe:=false; end; constructor ttryfinallynode.create_implicit(l,r:tnode); begin - inherited create(tryfinallyn,l,r); + inherited create(tryfinallyn,l,r,nil); + third:=nil; implicitframe:=true; end; @@ -2323,6 +2328,12 @@ implementation typecheckpass(right); // "except block" is "used"? (JM) set_varstate(right,vs_readwritten,[vsf_must_be_valid]); + + if assigned(third) then + begin + typecheckpass(third); + set_varstate(third,vs_readwritten,[vsf_must_be_valid]); + end; end; @@ -2333,6 +2344,8 @@ implementation firstpass(left); firstpass(right); + if assigned(third) then + firstpass(third); include(current_procinfo.flags,pi_do_call); diff --git a/compiler/nutils.pas b/compiler/nutils.pas index fff2bdf17c..06c5a784a6 100644 --- a/compiler/nutils.pas +++ b/compiler/nutils.pas @@ -202,8 +202,8 @@ implementation result := foreachnode(procmethod,tloopnode(n).t1,f,arg) or result; result := foreachnode(procmethod,tloopnode(n).t2,f,arg) or result; end; - raisen: - { frame tree } + raisen, tryfinallyn: + { frame tree/copy of finally code } result := foreachnode(ttertiarynode(n).third,f,arg) or result; tempcreaten: { temp. initialization code } @@ -299,8 +299,8 @@ implementation result := foreachnodestatic(procmethod,tloopnode(n).t1,f,arg) or result; result := foreachnodestatic(procmethod,tloopnode(n).t2,f,arg) or result; end; - raisen: - { frame tree } + raisen, tryfinallyn: + { frame tree/copy of finally code } result := foreachnodestatic(ttertiarynode(n).third,f,arg) or result; tempcreaten: { temp. initialization code }