Ver código fonte

compiler: don't allow local or anonymous records to have types (the second part of issue #0019099)

git-svn-id: trunk@17336 -
paul 14 anos atrás
pai
commit
f904f41664

+ 2 - 0
.gitattributes

@@ -9696,6 +9696,8 @@ tests/test/tenumerators1.pp svneol=native#text/pascal
 tests/test/terecs1.pp svneol=native#text/pascal
 tests/test/terecs1.pp svneol=native#text/pascal
 tests/test/terecs10.pp svneol=native#text/pascal
 tests/test/terecs10.pp svneol=native#text/pascal
 tests/test/terecs11.pp svneol=native#text/pascal
 tests/test/terecs11.pp svneol=native#text/pascal
+tests/test/terecs12.pp svneol=native#text/pascal
+tests/test/terecs13.pp svneol=native#text/pascal
 tests/test/terecs2.pp svneol=native#text/pascal
 tests/test/terecs2.pp svneol=native#text/pascal
 tests/test/terecs3.pp svneol=native#text/pascal
 tests/test/terecs3.pp svneol=native#text/pascal
 tests/test/terecs4.pp svneol=native#text/pascal
 tests/test/terecs4.pp svneol=native#text/pascal

+ 3 - 0
compiler/msg/errore.msg

@@ -1382,6 +1382,9 @@ parser_e_no_class_constructor_in_helpers=03308_E_Class constructors aren't allow
 parser_e_inherited_not_in_record=03309_E_The use of "inherited" is not allowed in a record
 parser_e_inherited_not_in_record=03309_E_The use of "inherited" is not allowed in a record
 % As records don't suppport inheritance the use of "inherited" is prohibited for
 % As records don't suppport inheritance the use of "inherited" is prohibited for
 % these as well as for record helpers (in mode "Delphi" only).
 % these as well as for record helpers (in mode "Delphi" only).
+parser_e_no_types_in_local_anonymous_records=03310_E_Type declarations are not allowed in local or anonymous records
+% Records with types must be defined globally. Types cannot be defined inside records which are defined in a
+% procedure or function or in anonymous records.
 % \end{description}
 % \end{description}
 # Type Checking
 # Type Checking
 #
 #

+ 3 - 2
compiler/msgidx.inc

@@ -398,6 +398,7 @@ const
   parser_e_not_allowed_in_helper=03307;
   parser_e_not_allowed_in_helper=03307;
   parser_e_no_class_constructor_in_helpers=03308;
   parser_e_no_class_constructor_in_helpers=03308;
   parser_e_inherited_not_in_record=03309;
   parser_e_inherited_not_in_record=03309;
+  parser_e_no_types_in_local_anonymous_records=03310;
   type_e_mismatch=04000;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
   type_e_not_equal_types=04002;
@@ -891,9 +892,9 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 59257;
+  MsgTxtSize = 59329;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
-    24,88,310,103,84,54,111,22,202,63,
+    24,88,311,103,84,54,111,22,202,63,
     49,20,1,1,1,1,1,1,1,1
     49,20,1,1,1,1,1,1,1,1
   );
   );

Diferenças do arquivo suprimidas por serem muito extensas
+ 334 - 332
compiler/msgtxt.inc


+ 5 - 1
compiler/ptype.pas

@@ -491,7 +491,6 @@ implementation
         srsymtable : TSymtable;
         srsymtable : TSymtable;
         s,sorg : TIDString;
         s,sorg : TIDString;
         t : ttoken;
         t : ttoken;
-        structdef : tabstractrecorddef;
       begin
       begin
          s:=pattern;
          s:=pattern;
          sorg:=orgpattern;
          sorg:=orgpattern;
@@ -684,6 +683,11 @@ implementation
               begin
               begin
                 consume(_TYPE);
                 consume(_TYPE);
                 member_blocktype:=bt_type;
                 member_blocktype:=bt_type;
+
+                { local and anonymous records can not have inner types. skip top record symtable }
+                if (current_structdef.objname^='') or 
+                   not(symtablestack.stack^.next^.symtable.symtabletype in [globalsymtable,staticsymtable,objectsymtable,recordsymtable]) then
+                  Message(parser_e_no_types_in_local_anonymous_records);
               end;
               end;
             _VAR :
             _VAR :
               begin
               begin

+ 1 - 1
tests/test/terecs11.pp

@@ -1,4 +1,4 @@
-program texrec1;
+program terecs11;
 
 
 {$ifdef fpc}
 {$ifdef fpc}
   {$mode delphi}
   {$mode delphi}

+ 19 - 0
tests/test/terecs12.pp

@@ -0,0 +1,19 @@
+{ %FAIL }
+{ %NORUN }
+program terecs12;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+procedure Test;
+type
+  TRecord = record
+  private type
+    TTestRange = 0..42;
+  end;
+begin
+end;
+
+begin
+end.

+ 16 - 0
tests/test/terecs13.pp

@@ -0,0 +1,16 @@
+{ %FAIL }
+{ %NORUN }
+program terecs13;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+var
+  R: record
+    private type
+      TTestRange = 0..42;
+  end;
+
+begin
+end.

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff