浏览代码

compiler: disallow regular class methods in records and allow only static class methods. delphi do so and it is logical because records have no inheritance. + tests

git-svn-id: branches/paul/extended_records@16550 -
paul 14 年之前
父节点
当前提交
582ab2dd32
共有 7 个文件被更改,包括 321 次插入292 次删除
  1. 1 0
      .gitattributes
  2. 3 1
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 290 288
      compiler/msgtxt.inc
  5. 6 0
      compiler/ptype.pas
  6. 17 0
      tests/test/terecs5.pp
  7. 1 1
      tests/test/terecs_u1.pp

+ 1 - 0
.gitattributes

@@ -9207,6 +9207,7 @@ tests/test/terecs1.pp svneol=native#text/pascal
 tests/test/terecs2.pp svneol=native#text/pascal
 tests/test/terecs3.pp svneol=native#text/pascal
 tests/test/terecs4.pp svneol=native#text/pascal
+tests/test/terecs5.pp svneol=native#text/pascal
 tests/test/terecs_u1.pp svneol=native#text/pascal
 tests/test/testcmem.pp svneol=native#text/plain
 tests/test/testda1.pp svneol=native#text/plain

+ 3 - 1
compiler/msg/errore.msg

@@ -1310,7 +1310,6 @@ parser_e_no_paras_for_class_constructor=03290_E_Class constructors can't have pa
 parser_e_no_paras_for_class_destructor=03291_E_Class destructors can't have parameters
 % You are declaring a class destructor with a parameter list. Class destructor methods
 % cannot have parameters.
-
 parser_f_modeswitch_objc_required=03292_F_This construct requires the \{\$modeswitch objectivec1\} mode switch to be active
 % Objective-Pascal constructs are not supported when \{\$modeswitch ObjectiveC1\}
 % is not active.
@@ -1346,6 +1345,9 @@ parser_e_no_record_published=03298_E_Record types cannot have published sections
 % Published sections can be used only inside classes.
 parser_e_no_destructor_in_records=03299_E_Destructors aren't allowed in records
 % Destructor declarations aren't allowed in records.
+parser_e_class_methods_only_static_in_records=03300_E_Class methods must be static in records
+% Class methods declarations aren't allowed in records without static modifier.
+% Records have no inheritance and therefore non static class methods have no sence for them.
 #
 # Type Checking
 #

+ 3 - 2
compiler/msgidx.inc

@@ -388,6 +388,7 @@ const
   parser_f_no_generic_inside_generic=03297;
   parser_e_no_record_published=03298;
   parser_e_no_destructor_in_records=03299;
+  parser_e_class_methods_only_static_in_records=03300;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -873,9 +874,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 58003;
+  MsgTxtSize = 58051;
 
   MsgIdxMax : array[1..20] of longint=(
-    24,88,300,97,82,54,111,22,202,63,
+    24,88,301,97,82,54,111,22,202,63,
     49,20,1,1,1,1,1,1,1,1
   );

文件差异内容过多而无法显示
+ 290 - 288
compiler/msgtxt.inc


+ 6 - 0
compiler/ptype.pas

@@ -732,6 +732,12 @@ implementation
                 if assigned(pd) then
                   begin
                     parse_record_proc_directives(pd);
+
+                    { since records have no inheritance don't allow non static
+                      class methods. delphi do so. }
+                    if is_classdef and not (po_staticmethod in pd.procoptions) then
+                      MessagePos(pd.fileinfo, parser_e_class_methods_only_static_in_records);
+
                     handle_calling_convention(pd);
 
                     { add definition to procsym }

+ 17 - 0
tests/test/terecs5.pp

@@ -0,0 +1,17 @@
+{ %fail}
+{ %norun}
+program terecs5;
+
+{$mode delphi}
+
+type
+  TFoo = record
+    class procedure Test; // not allowed without static
+  end;
+
+class procedure TFoo.Test;
+begin
+end;
+
+begin
+end.

+ 1 - 1
tests/test/terecs_u1.pp

@@ -22,7 +22,7 @@ type
     class var
       F5: TBar;
     function Test(n: TBar): TBar;
-    class function Test1(n: TBar): TBar;
+    class function Test1(n: TBar): TBar; static;
 
     procedure Set3(const Value: TBar);
     class procedure Set5(const Value: TBar); static;

部分文件因为文件数量过多而无法显示