Browse Source

* more current_scanner fixes

peter 23 years ago
parent
commit
197899d70a
2 changed files with 61 additions and 46 deletions
  1. 43 35
      compiler/fppu.pas
  2. 18 11
      compiler/parser.pas

+ 43 - 35
compiler/fppu.pas

@@ -182,7 +182,7 @@ uses
            exit;
          end;
        { check if floating point emulation is on?}
-        if ((ppufile.header.flags and uf_fpu_emulation)<>0) and 
+        if ((ppufile.header.flags and uf_fpu_emulation)<>0) and
             (cs_fp_emulation in aktmoduleswitches) then
          begin
            ppufile.free;
@@ -190,7 +190,7 @@ uses
            Message(unit_u_ppu_invalid_fpumode);
            exit;
          end;
-       
+
       { Load values to be access easier }
         flags:=ppufile.header.flags;
         crc:=ppufile.header.checksum;
@@ -476,9 +476,9 @@ uses
         { write the number of symbols }
         ppufile.putlongint(librarydata.asmsymbolppuidx);
         { write the symbols from the indexed list to the ppu }
-        for i:=0 to librarydata.asmsymbolppuidx-1 do
+        for i:=1 to librarydata.asmsymbolppuidx do
          begin
-           s:=librarydata.asmsymbolidx^[i];
+           s:=librarydata.asmsymbolidx^[i-1];
            if not assigned(s) then
             internalerror(200208071);
            ppufile.putstring(s.name);
@@ -679,12 +679,12 @@ uses
         if librarydata.asmsymbolppuidx>0 then
          begin
            getmem(librarydata.asmsymbolidx,librarydata.asmsymbolppuidx*sizeof(pointer));
-           for i:=0 to librarydata.asmsymbolppuidx-1 do
+           for i:=1 to librarydata.asmsymbolppuidx do
             begin
               name:=ppufile.getstring;
               bind:=tasmsymbind(ppufile.getbyte);
               typ:=tasmsymtype(ppufile.getbyte);
-              librarydata.asmsymbolidx^[i]:=librarydata.newasmsymboltype(name,bind,typ);
+              librarydata.asmsymbolidx^[i-1]:=librarydata.newasmsymboltype(name,bind,typ);
             end;
          end;
       end;
@@ -741,7 +741,7 @@ uses
       var
         b : byte;
       begin
-       { read interface part }
+         { read implementation part }
          repeat
            b:=ppufile.readentry;
            case b of
@@ -754,10 +754,10 @@ uses
            end;
          until false;
 
-         { we can now derefence all pointers to the objectdata }
-         tstoredsymtable(globalsymtable).derefobjectdata;
+         { we can now derefence all pointers to the implementation parts }
+         tstoredsymtable(globalsymtable).derefimpl;
          if assigned(localsymtable) then
-           tstoredsymtable(localsymtable).derefobjectdata;
+           tstoredsymtable(localsymtable).derefimpl;
       end;
 
 
@@ -770,7 +770,7 @@ uses
         if ((flags and uf_local_browser)<>0) then
           begin
              localsymtable:=tstaticsymtable.create(modulename^);
-             tstaticsymtable(localsymtable).load(ppufile);
+             tstaticsymtable(localsymtable).ppuload(ppufile);
           end;
 
         { load browser }
@@ -846,7 +846,7 @@ uses
          ppufile.writeentry(ibendinterface);
 
          { write the symtable entries }
-         tstoredsymtable(globalsymtable).write(ppufile);
+         tstoredsymtable(globalsymtable).ppuwrite(ppufile);
 
          { everything after this doesn't affect the crc }
          ppufile.do_crc:=false;
@@ -861,7 +861,7 @@ uses
            needed for local debugging of unit functions }
          if ((flags and uf_local_browser)<>0) and
             assigned(localsymtable) then
-           tstoredsymtable(localsymtable).write(ppufile);
+           tstoredsymtable(localsymtable).ppuwrite(ppufile);
 
          { write all browser section }
          if (flags and uf_has_browser)<>0 then
@@ -930,7 +930,7 @@ uses
          ppufile.writeentry(ibendinterface);
 
          { write the symtable entries }
-         tstoredsymtable(globalsymtable).write(ppufile);
+         tstoredsymtable(globalsymtable).ppuwrite(ppufile);
 
          { save crc  }
          crc:=ppufile.crc;
@@ -1008,10 +1008,12 @@ uses
            pu:=tused_unit(pu.next);
          end;
         { ok, now load the interface of this unit }
-        current_module:=self;
-        SetCompileModule(current_module);
+        if current_module<>self then
+         internalerror(200208187);
+//        current_module:=self;
+//        SetCompileModule(current_module);
         globalsymtable:=tglobalsymtable.create(modulename^);
-        tstoredsymtable(globalsymtable).load(ppufile);
+        tstoredsymtable(globalsymtable).ppuload(ppufile);
         { now only read the implementation uses }
         in_implementation:=true;
         pu:=tused_unit(used_units.first);
@@ -1049,13 +1051,15 @@ uses
            pu:=tused_unit(pu.next);
          end;
 
-        { read the implementation/object part }
+        { read the implementation/objectdata part }
         load_implementation;
 
         { load browser info if stored }
         if ((flags and uf_has_browser)<>0) and load_refs then
          begin
-           current_module:=self;
+           if current_module<>self then
+            internalerror(200208188);
+//           current_module:=self;
            load_symtable_refs;
          end;
         { remove the map, it's not needed anymore }
@@ -1103,16 +1107,10 @@ uses
                     in_second_compile:=true;
                     Message1(parser_d_compiling_second_time,modulename^);
                   end;
-                if assigned(current_scanner) then
-                  current_scanner.tempcloseinputfile;
                 name:=mainsource^;
                 { compile this module }
-                current_module:=self;
                 compile(name);
                 in_second_compile:=false;
-                { the scanner can be reset }
-                if assigned(current_scanner) then
-                  current_scanner.tempopeninputfile;
               end;
            end;
          if assigned(ppufile) then
@@ -1141,8 +1139,14 @@ uses
         ups   : stringid;
       begin
          old_current_module:=current_module;
+         { we are loading a new module, save the state of the scanner
+           and reset scanner+module }
+         if assigned(current_scanner) then
+           current_scanner.tempcloseinputfile;
+         current_scanner:=nil;
+         current_module:=nil;
          { Info }
-         Message3(unit_u_load_unit,current_module.modulename^,ImplIntf[current_module.in_implementation],s);
+         Message3(unit_u_load_unit,old_current_module.modulename^,ImplIntf[old_current_module.in_implementation],s);
          ups:=upper(s);
          { unit not found }
          st:=nil;
@@ -1173,11 +1177,11 @@ uses
                       else
                        begin
                          { both units in interface ? }
-                         if (not current_module.in_implementation) and
+                         if (not old_current_module.in_implementation) and
                             (not hp.in_implementation) then
                           begin
                             { check for a cycle }
-                            hp2:=current_module.loaded_from;
+                            hp2:=old_current_module.loaded_from;
                             while assigned(hp2) and (hp2<>hp) do
                              begin
                                if hp2.in_implementation then
@@ -1186,7 +1190,7 @@ uses
                                  hp2:=hp2.loaded_from;
                              end;
                             if assigned(hp2) then
-                              Message2(unit_f_circular_unit_reference,current_module.modulename^,hp.modulename^);
+                              Message2(unit_f_circular_unit_reference,old_current_module.modulename^,hp.modulename^);
                           end;
                        end;
                       break;
@@ -1204,13 +1208,13 @@ uses
           begin
             if assigned(hp) then
              begin
-               { remove the old unit, but save the scanner }
+               current_module:=hp;
+               { remove the old unit }
                loaded_units.remove(hp);
                hp.reset;
                { try to reopen ppu }
                hp.search_unit(s,fn,false);
                { try to load the unit a second time first }
-               current_module:=hp;
                current_module.in_second_load:=true;
                Message1(unit_u_second_load_unit,current_module.modulename^);
                second_time:=true;
@@ -1259,18 +1263,22 @@ uses
             assigned(tppumodule(old_current_module).ppufile) then
            tppumodule(old_current_module).ppufile.tempopen;
 {$endif SHORT_ON_FILE_HANDLES}
-         { we are back }
+         { we are back, restore current_module and current_scanner }
          current_module:=old_current_module;
+         current_scanner:=tscannerfile(current_module.scanner);
+         if assigned(current_scanner) then
+           current_scanner.tempopeninputfile;
          SetCompileModule(current_module);
          loadunit:=hp;
       end;
 
-
-
 end.
 {
   $Log$
-  Revision 1.21  2002-08-15 15:09:41  carl
+  Revision 1.22  2002-08-18 19:58:28  peter
+    * more current_scanner fixes
+
+  Revision 1.21  2002/08/15 15:09:41  carl
     + fpu emulation helpers (ppu checking also)
 
   Revision 1.20  2002/08/12 16:46:04  peter

+ 18 - 11
compiler/parser.pas

@@ -95,8 +95,9 @@ implementation
          orgpattern:='';
          current_scanner:=nil;
 
-         { register all nodes }
+         { register all nodes and tais }
          registernodes;
+         registertais;
 
          { memory sizes }
          if heapsize=0 then
@@ -460,19 +461,21 @@ implementation
          it's the default to release the trees }
          codegen_donemodule;
 
-       { free ppu }
+         { free ppu }
          if assigned(tppumodule(current_module).ppufile) then
           begin
             tppumodule(current_module).ppufile.free;
             tppumodule(current_module).ppufile:=nil;
           end;
-       { free scanner }
-         if assigned(current_scanner) then
+
+         { free scanner }
+         if assigned(current_module.scanner) then
           begin
-            current_scanner.free;
-            current_scanner:=nil;
+            if current_scanner=tscannerfile(current_module.scanner) then
+              current_scanner:=nil;
+            tscannerfile(current_module.scanner).free;
+            current_module.scanner:=nil;
           end;
-         current_module.scanner:=nil;
 
          if (compile_level>1) then
            begin
@@ -487,9 +490,6 @@ implementation
               idtoken:=oldidtoken;
               akttokenpos:=oldtokenpos;
               block_type:=old_block_type;
-              current_scanner:=tscannerfile(old_compiled_module.scanner);
-              if assigned(current_scanner) then
-                parser_current_file:=current_scanner.inputfile.name^;
               { restore cg }
               parse_only:=oldparse_only;
               { restore asmlists }
@@ -508,6 +508,10 @@ implementation
               { object data }
               ResourceStrings:=OldResourceStrings;
               objectlibrary:=oldobjectlibrary;
+              { restore previous scanner }
+              current_scanner:=tscannerfile(old_compiled_module.scanner);
+              if assigned(current_scanner) then
+                parser_current_file:=current_scanner.inputfile.name^;
               { restore symtable state }
               refsymtable:=oldrefsymtable;
               symtablestack:=oldsymtablestack;
@@ -595,7 +599,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.42  2002-08-16 15:31:08  peter
+  Revision 1.43  2002-08-18 19:58:28  peter
+    * more current_scanner fixes
+
+  Revision 1.42  2002/08/16 15:31:08  peter
     * fixed possible crashes with current_scanner
 
   Revision 1.41  2002/08/15 19:10:35  peter