Ver código fonte

# revisions: 45519,46865,46918

git-svn-id: branches/fixes_3_2@47095 -
marco 4 anos atrás
pai
commit
2b9ddf3bee

+ 4 - 0
.gitattributes

@@ -14617,6 +14617,7 @@ tests/test/tisorec1.pp svneol=native#text/pascal
 tests/test/tisorec2.pp svneol=native#text/pascal
 tests/test/tisorec2.pp svneol=native#text/pascal
 tests/test/tisorec3.pp svneol=native#text/pascal
 tests/test/tisorec3.pp svneol=native#text/pascal
 tests/test/tisorec4.pp svneol=native#text/pascal
 tests/test/tisorec4.pp svneol=native#text/pascal
+tests/test/tisorec5.pp svneol=native#text/pascal
 tests/test/tlea1.pp svneol=native#text/plain
 tests/test/tlea1.pp svneol=native#text/plain
 tests/test/tlea2.pp svneol=native#text/plain
 tests/test/tlea2.pp svneol=native#text/plain
 tests/test/tlib1a.pp svneol=native#text/plain
 tests/test/tlib1a.pp svneol=native#text/plain
@@ -16054,6 +16055,7 @@ tests/webtbf/uw4541.pp svneol=native#text/pascal
 tests/webtbf/uw6922.pp svneol=native#text/plain
 tests/webtbf/uw6922.pp svneol=native#text/plain
 tests/webtbf/uw8738a.pas svneol=native#text/plain
 tests/webtbf/uw8738a.pas svneol=native#text/plain
 tests/webtbf/uw8738b.pas svneol=native#text/plain
 tests/webtbf/uw8738b.pas svneol=native#text/plain
+tests/webtbs/DAT_TW37415 svneol=native#text/plain
 tests/webtbs/Integer.ns.pp svneol=native#text/pascal
 tests/webtbs/Integer.ns.pp svneol=native#text/pascal
 tests/webtbs/Integer.pp svneol=native#text/pascal
 tests/webtbs/Integer.pp svneol=native#text/pascal
 tests/webtbs/tu2002.pp svneol=native#text/plain
 tests/webtbs/tu2002.pp svneol=native#text/plain
@@ -17688,6 +17690,7 @@ tests/webtbs/tw3700.pp svneol=native#text/plain
 tests/webtbs/tw37013.pp svneol=native#text/plain
 tests/webtbs/tw37013.pp svneol=native#text/plain
 tests/webtbs/tw37060.pp svneol=native#text/plain
 tests/webtbs/tw37060.pp svneol=native#text/plain
 tests/webtbs/tw3708.pp svneol=native#text/plain
 tests/webtbs/tw3708.pp svneol=native#text/plain
+tests/webtbs/tw37085.pp svneol=native#text/pascal
 tests/webtbs/tw37095.pp svneol=native#text/plain
 tests/webtbs/tw37095.pp svneol=native#text/plain
 tests/webtbs/tw37095d/uw37095.pp svneol=native#text/plain
 tests/webtbs/tw37095d/uw37095.pp svneol=native#text/plain
 tests/webtbs/tw37154.pp svneol=native#text/pascal
 tests/webtbs/tw37154.pp svneol=native#text/pascal
@@ -17698,6 +17701,7 @@ tests/webtbs/tw37322.pp svneol=native#text/pascal
 tests/webtbs/tw37323.pp svneol=native#text/pascal
 tests/webtbs/tw37323.pp svneol=native#text/pascal
 tests/webtbs/tw37355.pp svneol=native#text/pascal
 tests/webtbs/tw37355.pp svneol=native#text/pascal
 tests/webtbs/tw37397.pp svneol=native#text/plain
 tests/webtbs/tw37397.pp svneol=native#text/plain
+tests/webtbs/tw37415.pp svneol=native#text/plain
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain

+ 70 - 36
compiler/ngenutil.pas

@@ -105,9 +105,9 @@ interface
       class procedure insertbsssym(list: tasmlist; sym: tstaticvarsym; size: asizeint; varalign: shortint); virtual;
       class procedure insertbsssym(list: tasmlist; sym: tstaticvarsym; size: asizeint; varalign: shortint); virtual;
 
 
       { initialization of iso styled program parameters }
       { initialization of iso styled program parameters }
-      class procedure initialize_textrec(p : TObject; statn : pointer);
+      class procedure initialize_filerecs(p : TObject; statn : pointer);
       { finalization of iso styled program parameters }
       { finalization of iso styled program parameters }
-      class procedure finalize_textrec(p : TObject; statn : pointer);
+      class procedure finalize_filerecs(p : TObject; statn : pointer);
      public
      public
       class procedure insertbssdata(sym : tstaticvarsym); virtual;
       class procedure insertbssdata(sym : tstaticvarsym); virtual;
 
 
@@ -533,49 +533,83 @@ implementation
     end;
     end;
 
 
 
 
-  class procedure tnodeutils.initialize_textrec(p:TObject;statn:pointer);
+  class procedure tnodeutils.initialize_filerecs(p:TObject;statn:pointer);
     var
     var
       stat: ^tstatementnode absolute statn;
       stat: ^tstatementnode absolute statn;
     begin
     begin
       if (tsym(p).typ=staticvarsym) and
       if (tsym(p).typ=staticvarsym) and
-       (tstaticvarsym(p).vardef.typ=filedef) and
-       (tfiledef(tstaticvarsym(p).vardef).filetyp=ft_text) and
-       (tstaticvarsym(p).isoindex<>0) then
-       begin
-         if cs_transparent_file_names in current_settings.globalswitches then
-           addstatement(stat^,ccallnode.createintern('fpc_textinit_filename_iso',
-             ccallparanode.create(
-               cstringconstnode.createstr(tstaticvarsym(p).Name),
-             ccallparanode.create(
-               cordconstnode.create(tstaticvarsym(p).isoindex,uinttype,false),
-             ccallparanode.create(
-               cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
-             nil)))))
-         else
-           addstatement(stat^,ccallnode.createintern('fpc_textinit_iso',
-             ccallparanode.create(
-               cordconstnode.create(tstaticvarsym(p).isoindex,uinttype,false),
-             ccallparanode.create(
-               cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
-             nil))));
-       end;
+        (tstaticvarsym(p).vardef.typ=filedef) and
+        (tstaticvarsym(p).isoindex<>0) then
+        case tfiledef(tstaticvarsym(p).vardef).filetyp of
+          ft_text:
+            begin
+              if cs_transparent_file_names in current_settings.globalswitches then
+                addstatement(stat^,ccallnode.createintern('fpc_textinit_filename_iso',
+                  ccallparanode.create(
+                    cstringconstnode.createstr(tstaticvarsym(p).Name),
+                  ccallparanode.create(
+                    cordconstnode.create(tstaticvarsym(p).isoindex,uinttype,false),
+                  ccallparanode.create(
+                    cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
+                  nil)))))
+              else
+                addstatement(stat^,ccallnode.createintern('fpc_textinit_iso',
+                  ccallparanode.create(
+                    cordconstnode.create(tstaticvarsym(p).isoindex,uinttype,false),
+                  ccallparanode.create(
+                    cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
+                  nil))));
+            end;
+          ft_typed:
+            begin
+              if cs_transparent_file_names in current_settings.globalswitches then
+                addstatement(stat^,ccallnode.createintern('fpc_typedfile_init_filename_iso',
+                  ccallparanode.create(
+                    cstringconstnode.createstr(tstaticvarsym(p).Name),
+                  ccallparanode.create(
+                    cordconstnode.create(tstaticvarsym(p).isoindex,uinttype,false),
+                  ccallparanode.create(
+                    cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
+                  nil)))))
+              else
+                addstatement(stat^,ccallnode.createintern('fpc_typedfile_init_iso',
+                  ccallparanode.create(
+                    cordconstnode.create(tstaticvarsym(p).isoindex,uinttype,false),
+                  ccallparanode.create(
+                    cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
+                  nil))));
+            end;
+          else
+            ;
+        end;
     end;
     end;
 
 
 
 
-  class procedure tnodeutils.finalize_textrec(p:TObject;statn:pointer);
+  class procedure tnodeutils.finalize_filerecs(p:TObject;statn:pointer);
     var
     var
       stat: ^tstatementnode absolute statn;
       stat: ^tstatementnode absolute statn;
     begin
     begin
       if (tsym(p).typ=staticvarsym) and
       if (tsym(p).typ=staticvarsym) and
-       (tstaticvarsym(p).vardef.typ=filedef) and
-       (tfiledef(tstaticvarsym(p).vardef).filetyp=ft_text) and
-       (tstaticvarsym(p).isoindex<>0) then
-       begin
-         addstatement(stat^,ccallnode.createintern('fpc_textclose_iso',
-           ccallparanode.create(
-             cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
-           nil)));
-       end;
+        (tstaticvarsym(p).vardef.typ=filedef) and
+        (tstaticvarsym(p).isoindex<>0) then
+        case tfiledef(tstaticvarsym(p).vardef).filetyp of
+          ft_text:
+            begin
+              addstatement(stat^,ccallnode.createintern('fpc_textclose_iso',
+                ccallparanode.create(
+                  cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
+                nil)));
+            end;
+          ft_typed:
+            begin
+              addstatement(stat^,ccallnode.createintern('fpc_typedfile_close_iso',
+                ccallparanode.create(
+                  cloadnode.create(tstaticvarsym(p),tstaticvarsym(p).Owner),
+                nil)));
+            end;
+          else
+            ;
+        end;
     end;
     end;
 
 
 
 
@@ -607,9 +641,9 @@ implementation
         (pd.proctypeoption=potype_proginit) then
         (pd.proctypeoption=potype_proginit) then
         begin
         begin
           block:=internalstatements(stat);
           block:=internalstatements(stat);
-          pd.localst.SymList.ForEachCall(@initialize_textrec,@stat);
+          pd.localst.SymList.ForEachCall(@initialize_filerecs,@stat);
           addstatement(stat,result);
           addstatement(stat,result);
-          pd.localst.SymList.ForEachCall(@finalize_textrec,@stat);
+          pd.localst.SymList.ForEachCall(@finalize_filerecs,@stat);
           result:=block;
           result:=block;
         end;
         end;
 
 

+ 57 - 44
compiler/pinline.pas

@@ -74,8 +74,60 @@ implementation
         storepos : tfileposinfo;
         storepos : tfileposinfo;
         variantdesc : pvariantrecdesc;
         variantdesc : pvariantrecdesc;
         found : boolean;
         found : boolean;
-        j,i : longint;
         variantselectsymbol : tfieldvarsym;
         variantselectsymbol : tfieldvarsym;
+
+      procedure ReadVariantRecordConstants;
+        var
+          i,j : longint;
+        begin
+          if (([m_iso,m_extpas]*current_settings.modeswitches)<>[]) and (is_record(tpointerdef(p.resultdef).pointeddef)) then
+            begin
+              variantdesc:=trecorddef(tpointerdef(p.resultdef).pointeddef).variantrecdesc;
+              while (token=_COMMA) and assigned(variantdesc) do
+                begin
+                  consume(_COMMA);
+                  p2:=factor(false,[]);
+                  do_typecheckpass(p2);
+                  if p2.nodetype=ordconstn then
+                    begin
+                      found:=false;
+                      { we do not have dynamic dfa, so avoid warning on variantselectsymbol below }
+                      variantselectsymbol:=nil;
+                      for i:=0 to high(variantdesc^.branches) do
+                        begin
+                          for j:=0 to high(variantdesc^.branches[i].values) do
+                            if variantdesc^.branches[i].values[j]=tordconstnode(p2).value then
+                              begin
+                                found:=true;
+                                variantselectsymbol:=tfieldvarsym(variantdesc^.variantselector);
+                                variantdesc:=variantdesc^.branches[i].nestedvariant;
+                                break;
+                              end;
+                          if found then
+                            break;
+                        end;
+                      if found then
+                        begin
+                          if is_new then
+                            begin
+                              { if no tag-field is given, do not create an assignment statement for it }
+                              if assigned(variantselectsymbol) then
+                                { setup variant selector }
+                                addstatement(newstatement,cassignmentnode.create(
+                                    csubscriptnode.create(variantselectsymbol,
+                                      cderefnode.create(ctemprefnode.create(temp))),
+                                    p2));
+                            end;
+                        end
+                      else
+                        Message(parser_e_illegal_expression);
+                    end
+                  else
+                    Message(parser_e_illegal_expression);
+                end;
+              end;
+        end;
+
       begin
       begin
         if target_info.system in systems_managed_vm then
         if target_info.system in systems_managed_vm then
           message(parser_e_feature_unsupported_for_vm);
           message(parser_e_feature_unsupported_for_vm);
@@ -345,49 +397,8 @@ implementation
                          p,
                          p,
                          ctemprefnode.create(temp)));
                          ctemprefnode.create(temp)));
 
 
-                     if (([m_iso,m_extpas]*current_settings.modeswitches)<>[]) and (is_record(tpointerdef(p.resultdef).pointeddef)) then
-                       begin
-                         variantdesc:=trecorddef(tpointerdef(p.resultdef).pointeddef).variantrecdesc;
-                         while (token=_COMMA) and assigned(variantdesc) do
-                           begin
-                             consume(_COMMA);
-                             p2:=factor(false,[]);
-                             do_typecheckpass(p2);
-                             if p2.nodetype=ordconstn then
-                               begin
-                                 found:=false;
-                                 { we do not have dynamic dfa, so avoid warning on variantselectsymbol below }
-                                 variantselectsymbol:=nil;
-                                 for i:=0 to high(variantdesc^.branches) do
-                                   begin
-                                     for j:=0 to high(variantdesc^.branches[i].values) do
-                                       if variantdesc^.branches[i].values[j]=tordconstnode(p2).value then
-                                         begin
-                                           found:=true;
-                                           variantselectsymbol:=tfieldvarsym(variantdesc^.variantselector);
-                                           variantdesc:=variantdesc^.branches[i].nestedvariant;
-                                           break;
-                                         end;
-                                     if found then
-                                       break;
-                                   end;
-                                 if found then
-                                   begin
-                                     { if no tag-field is given, do not create an assignment statement for it }
-                                     if assigned(variantselectsymbol) then
-                                       { setup variant selector }
-                                       addstatement(newstatement,cassignmentnode.create(
-                                           csubscriptnode.create(variantselectsymbol,
-                                             cderefnode.create(ctemprefnode.create(temp))),
-                                           p2));
-                                   end
-                                 else
-                                   Message(parser_e_illegal_expression);
-                               end
-                             else
-                               Message(parser_e_illegal_expression);
-                           end;
-                       end;
+                     ReadVariantRecordConstants;
+
                      { release temp }
                      { release temp }
                      addstatement(newstatement,ctempdeletenode.create(temp));
                      addstatement(newstatement,ctempdeletenode.create(temp));
                    end
                    end
@@ -406,6 +417,8 @@ implementation
                        else
                        else
                          addstatement(newstatement,cnodeutils.finalize_data_node(cderefnode.create(p.getcopy)));
                          addstatement(newstatement,cnodeutils.finalize_data_node(cderefnode.create(p.getcopy)));
 
 
+                     ReadVariantRecordConstants;
+
                      { create call to fpc_freemem }
                      { create call to fpc_freemem }
                      if not assigned(temp) then
                      if not assigned(temp) then
                        para := ccallparanode.create(p,nil)
                        para := ccallparanode.create(p,nil)

+ 5 - 0
rtl/inc/compproc.inc

@@ -810,6 +810,11 @@ Procedure fpc_rewrite_typed_name_iso(var f : TypedFile;const FileName : String;S
 Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf); compilerproc;
 Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf); compilerproc;
 Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
 Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
 Procedure fpc_typed_read_iso(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
 Procedure fpc_typed_read_iso(TypeSize : Longint;var f : TypedFile;out Buf); compilerproc;
+
+Procedure fpc_typedfile_init_iso(var t : TypedFile;nr : DWord);compilerproc;
+Procedure fpc_typedfile_init_filename_iso(var t : TypedFile;nr : DWord;const filename : string); compilerproc;
+Procedure fpc_typedfile_close_iso(var t : TypedFile); compilerproc;
+
 {$endif FPC_HAS_FEATURE_FILEIO}
 {$endif FPC_HAS_FEATURE_FILEIO}
 
 
 {$ifdef FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
 {$ifdef FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}

+ 4 - 2
rtl/inc/iso7185.pp

@@ -206,8 +206,10 @@ unit iso7185;
 
 
     procedure Get(var f:TypedFile);[IOCheck];
     procedure Get(var f:TypedFile);[IOCheck];
       Begin
       Begin
-        if not(eof(f)) then
-          BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1);
+        if not(system.eof(f)) then
+          BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
+        else
+          FileRec(f)._private[1]:=1;
       End;
       End;
 
 
 
 

+ 41 - 0
rtl/inc/typefile.inc

@@ -199,3 +199,44 @@ Begin
   Result:=pbyte(@f)+sizeof(TypedFile);
   Result:=pbyte(@f)+sizeof(TypedFile);
 end;
 end;
 
 
+
+Procedure fpc_typedfile_init_iso(var t : TypedFile;nr : DWord);compilerproc;
+begin
+{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
+  assign(t,paramstr(nr));
+{$else FPC_HAS_FEATURE_COMMANDARGS}
+  { primitive workaround for targets supporting no command line arguments,
+    invent some file name, try to avoid complex procedures like concating strings which might
+    pull-in bigger parts of the rtl }
+  assign(t,chr((nr mod 16)+65));
+{$endif FPC_HAS_FEATURE_COMMANDARGS}
+end;
+
+
+Procedure fpc_typedfile_init_filename_iso(var t : TypedFile;nr : DWord;const filename : string);compilerproc;
+begin
+{$ifdef FPC_HAS_FEATURE_COMMANDARGS}
+  if paramstr(nr)='' then
+    assign(t,filename)
+  else
+    assign(t,paramstr(nr));
+{$else FPC_HAS_FEATURE_COMMANDARGS}
+  { primitive workaround for targets supporting no command line arguments,
+    invent some file name, try to avoid complex procedures like concating strings which might
+    pull-in bigger parts of the rtl }
+  assign(t,chr((nr mod 16)+65));
+{$endif FPC_HAS_FEATURE_COMMANDARGS}
+end;
+
+
+
+Procedure fpc_typedfile_close_iso(var t : TypedFile);compilerproc;
+begin
+  { reset inout result as this procedure is only called by the compiler and no I/O checking is carried out,
+    so further I/O does not fail }
+  inoutres:=0;
+  close(t);
+  inoutres:=0;
+end;
+
+

+ 25 - 0
tests/test/tisorec5.pp

@@ -0,0 +1,25 @@
+{$mode iso}
+type
+  tr = record
+    l : longint;
+    case i : integer of
+      1 : (s : array[0..255] of char);
+      2 : (n : integer);
+      3 : (w : word; case j : integer of
+        1 : (t : array[0..255] of char);
+        2 : (a : integer);
+        );
+  end;
+  pr = ^tr;
+
+var
+  r : pr;
+begin
+  new(r,3,2);
+  if r^.i<>3 then
+    halt(1);
+  if r^.j<>2 then
+    halt(1);
+  dispose(r,3,2);
+  writeln('ok');
+end.

+ 1 - 0
tests/webtbs/DAT_TW37415

@@ -0,0 +1 @@
+1234

+ 18 - 0
tests/webtbs/tw37085.pp

@@ -0,0 +1,18 @@
+{$mode iso}
+
+type
+  v = ^x;
+  x = record
+    n: Integer;
+    case b: Boolean OF
+      True:  (x0: Real);
+      False: (x1, x2: Integer)
+  end;
+
+var
+  a: v;
+
+begin
+  New(a, True);
+  Dispose(a, True);
+end.

+ 9 - 0
tests/webtbs/tw37415.pp

@@ -0,0 +1,9 @@
+{ %OPT=-Miso -Sr }
+{ %FILES=DAT_TW37415 }
+program fileTest(dat_tw37415);
+
+var
+  dat_tw37415: file of integer;
+begin
+  reset(dat_tw37415);
+end.