Browse Source

* allow $MinEnumSize, $PackSet and $PackRecords to be used with $Push and $Pop
+ added tests

git-svn-id: trunk@39215 -

svenbarth 7 years ago
parent
commit
be0d51d64c
7 changed files with 127 additions and 1 deletions
  1. 3 0
      .gitattributes
  2. 7 1
      compiler/globals.pas
  3. 9 0
      compiler/scandir.pas
  4. 39 0
      compiler/switches.pas
  5. 20 0
      tests/test/tpushpop1.pp
  6. 27 0
      tests/test/tpushpop2.pp
  7. 22 0
      tests/test/tpushpop3.pp

+ 3 - 0
.gitattributes

@@ -13556,6 +13556,9 @@ tests/test/tprop.pp svneol=native#text/plain
 tests/test/tprop1.pp svneol=native#text/plain
 tests/test/tprop2.pp svneol=native#text/plain
 tests/test/tpropdef.pp svneol=native#text/plain
+tests/test/tpushpop1.pp svneol=native#text/pascal
+tests/test/tpushpop2.pp svneol=native#text/pascal
+tests/test/tpushpop3.pp svneol=native#text/pascal
 tests/test/trange1.pp svneol=native#text/plain
 tests/test/trange2.pp svneol=native#text/plain
 tests/test/trange3.pp svneol=native#text/plain

+ 7 - 1
compiler/globals.pas

@@ -216,7 +216,10 @@ interface
       tpendingstateflag = (
         psf_alignment_changed,
         psf_verbosity_full_switched,
-        psf_local_switches_changed
+        psf_local_switches_changed,
+        psf_packenum_changed,
+        psf_packrecords_changed,
+        psf_setalloc_changed
       );
       tpendingstateflags = set of tpendingstateflag;
 
@@ -227,6 +230,9 @@ interface
         nextcallingstr : shortstring;
         nextmessagerecord : pmessagestaterecord;
         nextalignment : talignmentinfo;
+        nextpackenum : shortint;
+        nextpackrecords : shortint;
+        nextsetalloc : shortint;
         flags : tpendingstateflags;
       end;
 

+ 9 - 0
compiler/scandir.pas

@@ -38,6 +38,9 @@ unit scandir;
         verbosity: longint;
         pmessage : pmessagestaterecord;
         alignment : talignmentinfo;
+        setalloc,
+        packenum,
+        packrecords : shortint;
       end;
 
     type
@@ -1178,6 +1181,9 @@ unit scandir;
       recordpendinglocalfullswitch(switchesstatestack[switchesstatestackpos].localsw);
       recordpendingverbosityfullswitch(switchesstatestack[switchesstatestackpos].verbosity);
       recordpendingalignmentfullswitch(switchesstatestack[switchesstatestackpos].alignment);
+      recordpendingpackenum(switchesstatestack[switchesstatestackpos].packenum);
+      recordpendingpackrecords(switchesstatestack[switchesstatestackpos].packrecords);
+      recordpendingsetalloc(switchesstatestack[switchesstatestackpos].setalloc);
       pendingstate.nextmessagerecord:=switchesstatestack[switchesstatestackpos].pmessage;
       { Reset verbosity and forget previous pmeesage }
       RestoreLocalVerbosity(nil);
@@ -1216,6 +1222,9 @@ unit scandir;
       switchesstatestack[switchesstatestackpos].pmessage:= current_settings.pmessage;
       switchesstatestack[switchesstatestackpos].verbosity:=status.verbosity;
       switchesstatestack[switchesstatestackpos].alignment:=current_settings.alignment;
+      switchesstatestack[switchesstatestackpos].setalloc:=current_settings.setalloc;
+      switchesstatestack[switchesstatestackpos].packenum:=current_settings.packenum;
+      switchesstatestack[switchesstatestackpos].packrecords:=current_settings.packrecords;
       Inc(switchesstatestackpos);
     end;
 

+ 39 - 0
compiler/switches.pas

@@ -38,6 +38,9 @@ procedure recordpendinglocalfullswitch(const switches: tlocalswitches);
 procedure recordpendingverbosityfullswitch(verbosity: longint);
 procedure recordpendingcallingswitch(const str: shortstring);
 procedure recordpendingalignmentfullswitch(const alignment : talignmentinfo);
+procedure recordpendingsetalloc(alloc:shortint);
+procedure recordpendingpackenum(size:shortint);
+procedure recordpendingpackrecords(size:shortint);
 procedure flushpendingswitchesstate;
 
 implementation
@@ -354,6 +357,27 @@ procedure recordpendingcallingswitch(const str: shortstring);
   end;
 
 
+procedure recordpendingsetalloc(alloc:shortint);
+  begin
+    pendingstate.nextsetalloc:=alloc;
+    include(pendingstate.flags,psf_setalloc_changed);
+  end;
+
+
+procedure recordpendingpackenum(size:shortint);
+  begin
+    pendingstate.nextpackenum:=size;
+    include(pendingstate.flags,psf_packenum_changed);
+  end;
+
+
+procedure recordpendingpackrecords(size:shortint);
+  begin
+    pendingstate.nextpackrecords:=size;
+    include(pendingstate.flags,psf_packrecords_changed);
+  end;
+
+
 procedure flushpendingswitchesstate;
   var
     tmpproccal: tproccalloption;
@@ -376,6 +400,21 @@ procedure flushpendingswitchesstate;
         current_settings.alignment:=pendingstate.nextalignment;
         exclude(pendingstate.flags,psf_alignment_changed);
       end;
+    if psf_packenum_changed in pendingstate.flags then
+      begin
+        current_settings.packenum:=pendingstate.nextpackenum;
+        exclude(pendingstate.flags,psf_packenum_changed);
+      end;
+    if psf_packrecords_changed in pendingstate.flags then
+      begin
+        current_settings.packrecords:=pendingstate.nextpackrecords;
+        exclude(pendingstate.flags,psf_packrecords_changed);
+      end;
+    if psf_setalloc_changed in pendingstate.flags then
+      begin
+        current_settings.setalloc:=pendingstate.nextsetalloc;
+        exclude(pendingstate.flags,psf_setalloc_changed);
+      end;
     { process pending verbosity changes (warnings on, etc) }
     if pendingstate.nextverbositystr<>'' then
       begin

+ 20 - 0
tests/test/tpushpop1.pp

@@ -0,0 +1,20 @@
+program tpushpop1;
+
+type
+{$MinEnumSize 1}
+  TTest1 = (t1One, t1Two, t1Three);
+{$push}
+{$MinEnumSize 2}
+  TTest2 = (t2One, t2Two, t2Three);
+{$pop}
+  TTest3 = (t3One, t3Two, t3Three);
+
+begin
+  if SizeOf(TTest1) <> 1 then
+    Halt(1);
+  if SizeOf(TTest2) <> 2 then
+    Halt(2);
+  if SizeOf(TTest3) <> 1 then
+    Halt(3);
+  Writeln('ok');
+end.

+ 27 - 0
tests/test/tpushpop2.pp

@@ -0,0 +1,27 @@
+program tpushpop2;
+
+type
+{$PackRecords 1}
+  TTest1 = record
+    b: Byte;
+    l: LongInt;
+  end;
+{$Push}
+{$PackRecords 4}
+  TTest2 = record
+    b: Byte;
+    l: LongInt;
+  end;
+{$Pop}
+  TTest3 = record
+    b: Byte;
+    l: LongInt;
+  end;
+
+begin
+  if SizeOf(TTest1) <> SizeOf(TTest3) then
+    Halt(1);
+  if SizeOf(TTest1) = SizeOf(TTest2) then
+    Halt(2);
+  Writeln('ok');
+end.

+ 22 - 0
tests/test/tpushpop3.pp

@@ -0,0 +1,22 @@
+program tpushpop3;
+
+type
+  TTest = (tOne, tTwo, tThree);
+
+{$PackSet 1}
+  TTestSet1 = set of TTest;
+{$Push}
+{$PackSet 2}
+  TTestSet2 = set of TTest;
+{$Pop}
+  TTestSet3 = set of TTest;
+
+begin
+  if SizeOf(TTestSet1) <> 1 then
+    Halt(1);
+  if SizeOf(TTestSet2) <> 2 then
+    Halt(2);
+  if SizeOf(TTestSet3) <> 1 then
+    Halt(3);
+  Writeln('ok');
+end.