Bladeren bron

Don't allow "static" for class operators or normal methods (except in objects).

pdecsub.pas, pd_static:
  * check whether the given pd is an operator or a class method not inside an Object and generate an error if either of these is true
msg/errore.msg, msgidx.inc, msgtxt.inc:
  * add a message to inform that a certain procedure directive is not allowed

+ added tests

git-svn-id: trunk@23944 -
svenbarth 12 jaren geleden
bovenliggende
commit
376bd046aa
8 gewijzigde bestanden met toevoegingen van 449 en 371 verwijderingen
  1. 3 0
      .gitattributes
  2. 4 1
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 367 366
      compiler/msgtxt.inc
  5. 13 2
      compiler/pdecsub.pas
  6. 19 0
      tests/tbf/tb0231.pp
  7. 20 0
      tests/tbf/tb0232.pp
  8. 20 0
      tests/tbf/tb0233.pp

+ 3 - 0
.gitattributes

@@ -9244,6 +9244,9 @@ tests/tbf/tb0227.pp svneol=native#text/pascal
 tests/tbf/tb0228.pp svneol=native#text/pascal
 tests/tbf/tb0228.pp svneol=native#text/pascal
 tests/tbf/tb0229.pp svneol=native#text/pascal
 tests/tbf/tb0229.pp svneol=native#text/pascal
 tests/tbf/tb0230.pp svneol=native#text/pascal
 tests/tbf/tb0230.pp svneol=native#text/pascal
+tests/tbf/tb0231.pp svneol=native#text/pascal
+tests/tbf/tb0232.pp svneol=native#text/pascal
+tests/tbf/tb0233.pp svneol=native#text/pascal
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain

+ 4 - 1
compiler/msg/errore.msg

@@ -392,7 +392,7 @@ scan_w_setpeoptflags_not_support=02092_W_SETPEOPTFLAGS is not supported by the t
 #
 #
 # Parser
 # Parser
 #
 #
-# 03332 is the last used one
+# 03333 is the last used one
 #
 #
 % \section{Parser messages}
 % \section{Parser messages}
 % This section lists all parser messages. The parser takes care of the
 % This section lists all parser messages. The parser takes care of the
@@ -1487,6 +1487,9 @@ parser_e_not_allowed_in_record=03332_E_Visibility section "$1" not allowed in re
 % The visibility sections \var(protected) and \var(strict protected) are only
 % The visibility sections \var(protected) and \var(strict protected) are only
 % useful together with inheritance. Since records do not support that they are
 % useful together with inheritance. Since records do not support that they are
 % forbidden.
 % forbidden.
+parser_e_proc_dir_not_allowed=03333_E_Procedure directive "$1" not allowed here
+% This procedure directive is not allowed in the given context. E.g. "static"
+% is not allowed for instance methods or class operators.
 %
 %
 %
 %
 % \end{description}
 % \end{description}

+ 3 - 2
compiler/msgidx.inc

@@ -428,6 +428,7 @@ const
   parser_e_no_properties_in_local_anonymous_records=03330;
   parser_e_no_properties_in_local_anonymous_records=03330;
   parser_e_no_class_in_local_anonymous_records=03331;
   parser_e_no_class_in_local_anonymous_records=03331;
   parser_e_not_allowed_in_record=03332;
   parser_e_not_allowed_in_record=03332;
+  parser_e_proc_dir_not_allowed=03333;
   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;
@@ -972,9 +973,9 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 68811;
+  MsgTxtSize = 68861;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
-    26,93,333,121,88,56,126,27,202,63,
+    26,93,334,121,88,56,126,27,202,63,
     54,20,1,1,1,1,1,1,1,1
     54,20,1,1,1,1,1,1,1,1
   );
   );

File diff suppressed because it is too large
+ 367 - 366
compiler/msgtxt.inc


+ 13 - 2
compiler/pdecsub.pas

@@ -1611,8 +1611,19 @@ end;
 
 
 procedure pd_static(pd:tabstractprocdef);
 procedure pd_static(pd:tabstractprocdef);
 begin
 begin
-  if pd.typ=procdef then
-    include(tprocdef(pd).procsym.symoptions,sp_static);
+  if pd.typ<>procdef then
+    internalerror(2013032001);
+  if not assigned(tprocdef(pd).struct) then
+    internalerror(2013032002);
+  include(tprocdef(pd).procsym.symoptions,sp_static);
+  { "static" is not allowed for operators or normal methods (except in objects) }
+  if (pd.proctypeoption=potype_operator) or
+      (
+        not (po_classmethod in pd.procoptions) and
+        not is_object(tprocdef(pd).struct)
+      )
+      then
+    Message1(parser_e_proc_dir_not_allowed,arraytokeninfo[_STATIC].str);
   include(pd.procoptions,po_staticmethod);
   include(pd.procoptions,po_staticmethod);
 end;
 end;
 
 

+ 19 - 0
tests/tbf/tb0231.pp

@@ -0,0 +1,19 @@
+{ %FAIL }
+
+program tb0231;
+
+{$mode objfpc}
+
+type
+  TTest = class
+    procedure Test; static;
+  end;
+
+procedure TTest.Test;
+begin
+
+end;
+
+begin
+
+end.

+ 20 - 0
tests/tbf/tb0232.pp

@@ -0,0 +1,20 @@
+{ %FAIL }
+
+program tb0232;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+    procedure Test; static;
+  end;
+
+procedure TTest.Test;
+begin
+
+end;
+
+begin
+
+end.

+ 20 - 0
tests/tbf/tb0233.pp

@@ -0,0 +1,20 @@
+{ %FAIL }
+
+program tb0233;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+    class operator + (aLeft, aRight: TTest): TTest; static;
+  end;
+
+class operator TTest.+(aLeft, aRight: TTest): TTest;
+begin
+
+end;
+
+begin
+
+end.

Some files were not shown because too many files changed in this diff