Browse Source

compiler: don't generate code for empty initialization and finalization sections (with help of Florian) (issue #0013482)

git-svn-id: trunk@14543 -
paul 15 years ago
parent
commit
8b27daae2c
2 changed files with 22 additions and 14 deletions
  1. 2 2
      compiler/pmodules.pas
  2. 20 12
      compiler/psub.pas

+ 2 - 2
compiler/pmodules.pas

@@ -1209,7 +1209,7 @@ implementation
          if not current_module.interface_only and (token=_FINALIZATION) then
            begin
               { set module options }
-              current_module.flags:=current_module.flags or uf_finalize;
+              // current_module.flags:=current_module.flags or uf_finalize;
 
               { Compile the finalize }
               finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable);
@@ -2138,7 +2138,7 @@ implementation
          if token=_FINALIZATION then
            begin
               { set module options }
-              current_module.flags:=current_module.flags or uf_finalize;
+              //current_module.flags:=current_module.flags or uf_finalize;
               { Parse the finalize }
               finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable);
               finalize_procinfo.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));

+ 20 - 12
compiler/psub.pas

@@ -207,21 +207,29 @@ implementation
                      begin
                         { The library init code is already called and does not
                           need to be in the initfinal table (PFV) }
-                        if not islibrary then
-                          current_module.flags:=current_module.flags or uf_init;
                         block:=statement_block(_INITIALIZATION);
+                        { optimize empty initialization block away }
+                        if (tstatementnode(block).left=nil) then
+                            FreeAndNil(block)
+                        else
+                          if not islibrary then
+                            current_module.flags:=current_module.flags or uf_init;
                      end
-                   else if (token=_FINALIZATION) then
+                   else if token=_FINALIZATION then
                      begin
-                        if (current_module.flags and uf_finalize)<>0 then
-                          block:=statement_block(_FINALIZATION)
-                        else
-                          begin
-                          { can we allow no INITIALIZATION for DLL ??
-                            I think it should work PM }
-                             block:=nil;
-                             exit;
-                          end;
+                       { when a unit has only a finalization section, we can come to this
+                         point when we try to read the nonh existing initalization section
+                         so we've to check if we are really try to parse the finalization }
+                       if current_procinfo.procdef.proctypeoption=potype_unitfinalize then
+                         begin
+                           block:=statement_block(_FINALIZATION);
+                           { optimize empty finalization block away }
+                           if (tstatementnode(block).left=nil) then
+                               FreeAndNil(block)
+                           else
+                             if not islibrary then
+                               current_module.flags:=current_module.flags or uf_finalize;
+                         end;
                      end
                    else
                      begin