ソースを参照

* Changed function create_pd into method of ttryfinallynode, so it can be reused for Win32 SEH and, in the future, for DWARF-based exception handling on other targets.
* Additional two minor changes: reset po_delphi_nested_cc on result, so it is independent of current {$modeswitch nestedprocvar} state, and removed call to alloc_proc_symbol (which belongs to pass 2).

git-svn-id: trunk@26222 -

sergei 11 年 前
コミット
1ee9373fa6
2 ファイル変更53 行追加46 行削除
  1. 51 0
      compiler/nflw.pas
  2. 2 46
      compiler/x86_64/nx64flw.pas

+ 51 - 0
compiler/nflw.pas

@@ -192,6 +192,8 @@ interface
           function pass_typecheck:tnode;override;
           function pass_1 : tnode;override;
           function simplify(forinline:boolean): tnode;override;
+       protected
+          function create_finalizer_procdef: tprocdef;
        end;
        ttryfinallynodeclass = class of ttryfinallynode;
 
@@ -238,6 +240,7 @@ implementation
       cutils,verbose,globals,
       symconst,symtable,paramgr,defcmp,defutil,htypechk,pass_1,
       ncal,nadd,ncon,nmem,nld,ncnv,nbas,cgobj,nutils,ninl,nset,
+      pdecsub,
     {$ifdef state_tracking}
       nstate,
     {$endif}
@@ -2144,6 +2147,54 @@ implementation
          end;
      end;
 
+
+    var
+      seq: longint=0;
+
+    function ttryfinallynode.create_finalizer_procdef: tprocdef;
+      var
+        st:TSymTable;
+        checkstack: psymtablestackitem;
+        oldsymtablestack: tsymtablestack;
+        sym:tprocsym;
+      begin
+        { get actual procedure symtable (skip withsymtables, etc.) }
+        st:=nil;
+        checkstack:=symtablestack.stack;
+        while assigned(checkstack) do
+          begin
+            st:=checkstack^.symtable;
+            if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
+              break;
+            checkstack:=checkstack^.next;
+          end;
+        { Create a nested procedure, even from main_program_level.
+          Furthermore, force procdef and procsym into the same symtable
+          (by default, defs are registered with symtablestack.top which may be
+          something temporary like exceptsymtable - in that case, procdef can be
+          destroyed before procsym, leaving invalid pointers). }
+        oldsymtablestack:=symtablestack;
+        symtablestack:=nil;
+        result:=tprocdef.create(max(normal_function_level,st.symtablelevel)+1);
+        symtablestack:=oldsymtablestack;
+        st.insertdef(result);
+        result.struct:=current_procinfo.procdef.struct;
+        { tabstractprocdef constructor sets po_delphi_nested_cc whenever
+          nested procvars modeswitch is active. We must be independent of this switch. }
+        exclude(result.procoptions,po_delphi_nested_cc);
+        result.proctypeoption:=potype_exceptfilter;
+        handle_calling_convention(result);
+        sym:=tprocsym.create('$fin$'+tostr(seq));
+        st.insert(sym);
+        inc(seq);
+
+        result.procsym:=sym;
+        proc_add_definition(result);
+        result.forwarddef:=false;
+        result.aliasnames.insert(result.mangledname);
+      end;
+
+
 {*****************************************************************************
                                 TONNODE
 *****************************************************************************}

+ 2 - 46
compiler/x86_64/nx64flw.pas

@@ -135,50 +135,6 @@ procedure tx64onnode.pass_generate_code;
   end;
 
 { tx64tryfinallynode }
-var
-  seq: longint=0;
-
-
-function create_pd: tprocdef;
-  var
-    st:TSymTable;
-    checkstack: psymtablestackitem;
-    oldsymtablestack: tsymtablestack;
-    sym:tprocsym;
-  begin
-    { get actual procedure symtable (skip withsymtables, etc.) }
-    st:=nil;
-    checkstack:=symtablestack.stack;
-    while assigned(checkstack) do
-      begin
-        st:=checkstack^.symtable;
-          if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
-            break;
-          checkstack:=checkstack^.next;
-      end;
-    { Create a nested procedure, even from main_program_level.
-      Furthermore, force procdef and procsym into the same symtable
-      (by default, defs are registered with symtablestack.top which may be
-      something temporary like exceptsymtable - in that case, procdef can be
-      destroyed before procsym, leaving invalid pointers). }
-    oldsymtablestack:=symtablestack;
-    symtablestack:=nil;
-    result:=tprocdef.create(max(normal_function_level,st.symtablelevel)+1);
-    symtablestack:=oldsymtablestack;
-    st.insertdef(result);
-    result.struct:=current_procinfo.procdef.struct;
-    result.proctypeoption:=potype_exceptfilter;
-    handle_calling_convention(result);
-    sym:=tprocsym.create('$fin$'+tostr(seq));
-    st.insert(sym);
-    inc(seq);
-
-    result.procsym:=sym;
-    proc_add_definition(result);
-    result.forwarddef:=false;
-    result.aliasnames.insert(result.mangledname);
-    alloc_proc_symbol(result);
-  end;
 
 function reset_regvars(var n: tnode; arg: pointer): foreachnoderesult;
   begin
@@ -214,7 +170,7 @@ constructor tx64tryfinallynode.create(l, r: TNode);
       exit;
     finalizepi:=tcgprocinfo(cprocinfo.create(current_procinfo));
     finalizepi.force_nested;
-    finalizepi.procdef:=create_pd;
+    finalizepi.procdef:=create_finalizer_procdef;
     finalizepi.entrypos:=r.fileinfo;
     finalizepi.entryswitches:=r.localswitches;
     finalizepi.exitpos:=current_filepos; // last_endtoken_pos?
@@ -238,7 +194,7 @@ constructor tx64tryfinallynode.create_implicit(l, r, _t1: TNode);
 
     finalizepi:=tcgprocinfo(cprocinfo.create(current_procinfo));
     finalizepi.force_nested;
-    finalizepi.procdef:=create_pd;
+    finalizepi.procdef:=create_finalizer_procdef;
 
     finalizepi.entrypos:=current_filepos;
     finalizepi.exitpos:=current_filepos; // last_endtoken_pos?