浏览代码

compiler: rename parser_e_constructors_always_objects message to parser_e_only_methods_allowed and extended the meaning it has, don't allow class constructors to be declared outside the class/record + test

git-svn-id: trunk@16626 -
paul 14 年之前
父节点
当前提交
3c6fde4acc

+ 1 - 0
.gitattributes

@@ -9596,6 +9596,7 @@ tests/test/tobject5.pp svneol=native#text/pascal
 tests/test/tobject6.pp svneol=native#text/plain
 tests/test/tobject7.pp svneol=native#text/plain
 tests/test/toperator1.pp svneol=native#text/plain
+tests/test/toperator10.pp svneol=native#text/pascal
 tests/test/toperator2.pp svneol=native#text/plain
 tests/test/toperator3.pp svneol=native#text/plain
 tests/test/toperator4.pp svneol=native#text/plain

+ 2 - 2
compiler/msg/errorct.msg

@@ -570,8 +570,8 @@ parser_e_void_function=03080_E_Els procediments no poden retornar cap valor
 % In \fpc, you can specify a return value for a function when using 
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Els constructors i destructors han de ser mètodes
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Els constructors, destructors i class operators han de ser mètodes
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_L'operador no està sobrecarregat
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errord.msg

@@ -636,8 +636,8 @@ parser_e_void_function=03080_E_Prozeduren k
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Konstruktoren und Destruktoren m�ssen Methoden sein
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Konstruktoren, Destructoren und class operators m�ssen Methoden sein
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator besitzt kein Overload
 % You're trying to use an overloaded operator when it isn't overloaded for

+ 2 - 2
compiler/msg/errorda.msg

@@ -598,8 +598,8 @@ parser_e_void_function=03080_E_Procedurer kan ikke returnere værdier
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures  cannot return a value.
-parser_e_constructors_always_objects=03081_E_constructors og destructors skal være metoder
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_constructors destructors og class operators skal være metoder
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operatoren er ikke overloaded
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errordu.msg

@@ -636,8 +636,8 @@ parser_e_void_function=03080_E_Prozeduren können keinen Wert zurückliefern
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Konstruktoren und Destruktoren müssen Methoden sein
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Konstruktoren, Destructoren und Class operators müssen Methoden sein
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator besitzt kein Overload
 % You're trying to use an overloaded operator when it isn't overloaded for

+ 2 - 2
compiler/msg/errore.msg

@@ -626,8 +626,8 @@ parser_e_void_function=03080_E_Procedures can't return a value
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_constructors and destructors must be methods
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_constructors, destructors and class operators must be methods
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator is not overloaded
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errores.msg

@@ -575,8 +575,8 @@ parser_e_void_function=03080_E_Los procedimientos no pueden devolver ning
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_constructores y destructores deben ser métodos
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_constructores, destructors y class operators deben ser métodos
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_El operador no esta sobrecargado
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errorf.msg

@@ -583,8 +583,8 @@ parser_e_void_function=03080_E_Les proc
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Les constructeurs et destructeurs doivent ˆtre des m‚thodes
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Les constructeurs, destructeurs et class operators doivent ˆtre des m‚thodes
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator n'est pas surcharg‚
 % You're trying to use an overloaded operator when it isn't overloaded for

+ 2 - 2
compiler/msg/errorfi.msg

@@ -603,8 +603,8 @@ parser_e_void_function=03080_E_Les proc
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Les constructeurs et les destructeurs doivent être des méthodes
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Les constructeurs, les destructeurs et les class operators doivent être des méthodes
+% You're declaring a procedure as destructor, constructor or class operators, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_L'opérateur n'est pas surchargé
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errorhe.msg

@@ -616,8 +616,8 @@ parser_e_void_function=03080_E_
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_äéåöøéí åääåøñéí çééáéí ìäéåú îúåãééí
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_äéåöøéí åääåøñéí çééáéí ìäéåú îúåãééí
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_äàåôøéèåø ìà îøåáä ùéîåù
 % You're trying to use an overloaded operator when it is not overloaded for

+ 1 - 1
compiler/msg/errorheu.msg

@@ -616,7 +616,7 @@ parser_e_void_function=03080_E_פרוצדורה לא יכולה להחזיר ע
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_היוצרים וההורסים חייבים להיות מתודיים
+parser_e_only_methods_allowed=03081_E_היוצרים וההורסים חייבים להיות מתודיים
 % You're declaring a procedure as destructor or constructor, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_האופריטור לא מרובה שימוש

+ 2 - 2
compiler/msg/errorid.msg

@@ -615,8 +615,8 @@ parser_e_void_function=03080_E_Prosedur tidak mengembalikan nilai
 % Dalam \fpc, anda dapat menetapkan nilai balik untuk sebuah fungsi saat
 % memakai pernyataan \var{exit}. Kesalahan ini terjadi ketika anda mencoba untuk
 % melakukan ini dengan prosedur. Prosedure tidak bisa mengembalikan nilai.
-parser_e_constructors_always_objects=03081_E_konstruktor dan destruktor harus sebuah metode
-% Anda mendeklarasikan sebuah procedure sebagai destruktor atau konstruktor, ketika
+parser_e_only_methods_allowed=03081_E_konstruktor, destruktor dan class operator harus sebuah metode
+% Anda mendeklarasikan sebuah procedure sebagai destruktor, konstructor atau class operator, ketika
 % prosedure bukan metode kelas.
 parser_e_operator_not_overloaded=03082_E_Operator tidak di-overload
 % Anda mencoba untuk menggunakan operator yang di-overload saat ia bukan tipe

+ 2 - 2
compiler/msg/errorn.msg

@@ -602,8 +602,8 @@ parser_e_void_function=03080_E_Procedures kunnen geen resultaat teruggeven
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Constructors en destructors moeten methoden zijn
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Constructors, destructors en class operators moeten methoden zijn
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator is niet hergedefineerd
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errorpl.msg

@@ -578,8 +578,8 @@ parser_e_void_function=03080_E_Procedury nie mog
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Konstruktory i destruktory musz¥ by† metodami
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Konstruktory, destruktory i class operators musz¥ by† metodami
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator nie jest przeci¥¾ony
 % You're trying to use an overloaded operator when it isn't overloaded for

+ 2 - 2
compiler/msg/errorpli.msg

@@ -578,8 +578,8 @@ parser_e_void_function=03080_E_Procedury nie mog
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Konstruktory i destruktory musz± byæ metodami
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Konstruktory, destructory i class operators musz± byæ metodami
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operator nie jest przeci±¿ony
 % You're trying to use an overloaded operator when it isn't overloaded for

+ 2 - 2
compiler/msg/errorpt.msg

@@ -628,8 +628,8 @@ parser_e_void_function=03080_E_Procedimentos n
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Construtores e destruidores devem ser m‚todos
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Construtores destruidores e class operators devem ser m‚todos
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operador nÆo ‚ sobrecarregado
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errorptu.msg

@@ -628,8 +628,8 @@ parser_e_void_function=03080_E_Procedimentos não podem retornar um valor
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_Construtores e destruidores devem ser métodos
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_Construtores destruidores e class operators devem ser métodos
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_Operador não é sobrecarregado
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msg/errorr.msg

@@ -588,8 +588,8 @@ parser_e_void_function=03080_E_
 % \fpc ¯®§¢®«ï¥â 㪠§ âì ¢®§¢à é ¥¬®¥ §­ ç¥­¨¥ ¤«ï ä㭪樨 ¯à¨ ¨á¯®«ì§®¢ ­¨¨
 % ¢ëà ¦¥­¨ï \var{exit}. Žè¨¡ª  ¢®§­¨ª ¥â ¯à¨ ¯®¯ë⪥ ᤥ« âì íâ® ¢ ¯à®æ¥¤ãà¥.
 % �à®æ¥¤ãà  ­¥ ¬®¦¥â ¢®§¢à é âì §­ ç¥­¨¥.
-parser_e_constructors_always_objects=03081_E_Š®­áâpyªâ®pë ¨ ¤¥áâpyªâ®pë ¤®«¦­ë ¡ëâì ¬¥â®¤ ¬¨
-% �®¯ë⪠ ®¯à¥¤¥«¨âì ¯à®æ¥¤ãàã, ­¥ ïîéãîáï ¬¥â®¤®¬ ª« áá , ª ª ª®­áâàãªâ®à ¨«¨ ¤¥áâàãªâ®à.
+parser_e_only_methods_allowed=03081_E_Š®­áâpyªâ®pë, ¤¥áâpyªâ®pë ¨ ®¯¥à â®àë ª« áá  ¤®«¦­ë ¡ëâì ¬¥â®¤ ¬¨
+% �®¯ë⪠ ®¯à¥¤¥«¨âì ¯à®æ¥¤ãàã, ­¥ ïîéãîáï ¬¥â®¤®¬ ª« áá , ª ª ª®­áâàãªâ®à, ¤¥áâàãªâ®à ¨«¨ ®¯¥à â®à ª« áá .
 parser_e_operator_not_overloaded=03082_E_ޝ¥p â®p ­¥ ¯¥p¥£py¦¥­
 % �®¯ë⪠ ¨á¯®«ì§®¢ âì ¯¥à¥£à㦥­­ë© ®¯¥à â®à, ª®£¤  ®­ ­¥ ¯¥à¥£à㦥­ ¤«ï ¤ ­­®£® ⨯ .
 parser_e_no_such_assignment=03083_E_�¥¢®§¬®¦­® ¯¥à¥£à㧨âì ¯à¨á¢®¥­¨¥ ¤«ï ®¤¨­ ª®¢ëå ⨯®¢

+ 2 - 2
compiler/msg/errorru.msg

@@ -588,8 +588,8 @@ parser_e_void_function=03080_E_Пpоцедypа не может возвpащат
 % \fpc позволяет указать возвращаемое значение для функции при использовании
 % выражения \var{exit}. Ошибка возникает при попытке сделать это в процедуре.
 % Процедура не может возвращать значение.
-parser_e_constructors_always_objects=03081_E_Констpyктоpы и дестpyктоpы должны быть методами
-% Попытка определить процедуру, не являющуюся методом класса, как конструктор или деструктор.
+parser_e_only_methods_allowed=03081_E_Констpyктоpы, дестpyктоpы и операторы класса должны быть методами
+% Попытка определить процедуру, не являющуюся методом класса, как конструктор, деструктор или оператор класса.
 parser_e_operator_not_overloaded=03082_E_Опеpатоp не пеpегpyжен
 % Попытка использовать перегруженный оператор, когда он не перегружен для данного типа.
 parser_e_no_such_assignment=03083_E_Невозможно перегрузить присвоение для одинаковых типов

+ 2 - 2
compiler/msg/errorues.msg

@@ -569,8 +569,8 @@ parser_e_void_function=03080_E_Los procedimientos no pueden devolver ningún val
 % In \fpc, you can specify a return value for a function when using
 % the \var{exit} statement. This error occurs when you try to do this with a
 % procedure. Procedures cannot return a value.
-parser_e_constructors_always_objects=03081_E_constructores y destructores deben ser métodos
-% You're declaring a procedure as destructor or constructor, when the
+parser_e_only_methods_allowed=03081_E_constructores, destructores y class operators deben ser métodos
+% You're declaring a procedure as destructor, constructor or class operator, when the
 % procedure isn't a class method.
 parser_e_operator_not_overloaded=03082_E_El operador no esta sobrecargado
 % You're trying to use an overloaded operator when it is not overloaded for

+ 2 - 2
compiler/msgidx.inc

@@ -178,7 +178,7 @@ const
   parser_e_invalid_record_const=03078;
   parser_e_false_with_expr=03079;
   parser_e_void_function=03080;
-  parser_e_constructors_always_objects=03081;
+  parser_e_only_methods_allowed=03081;
   parser_e_operator_not_overloaded=03082;
   parser_e_no_such_assignment=03083;
   parser_e_overload_impossible=03084;
@@ -876,7 +876,7 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 58202;
+  MsgTxtSize = 58219;
 
   MsgIdxMax : array[1..20] of longint=(
     24,88,303,97,82,54,111,22,202,63,

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


+ 5 - 4
compiler/pdecsub.pas

@@ -1004,11 +1004,12 @@ implementation
          end
         else
          begin
-           { check for constructor/destructor which is not allowed here }
+           { check for constructor/destructor/class operators which are not allowed here }
            if (not parse_only) and
-              (potype in [potype_constructor,potype_destructor,
-                          potype_class_constructor,potype_class_destructor]) then
-             Message(parser_e_constructors_always_objects);
+              ((potype in [potype_constructor,potype_destructor,
+                           potype_class_constructor,potype_class_destructor]) or
+               ((potype=potype_operator) and (m_delphi in current_settings.modeswitches))) then
+             Message(parser_e_only_methods_allowed);
 
            repeat
              searchagain:=false;

+ 18 - 0
tests/test/toperator10.pp

@@ -0,0 +1,18 @@
+program toperator10;
+
+{$mode delphi}
+
+type
+  TFoo = record
+    F: Integer;
+  end;
+
+// don't allow class operator declaration outside the class
+class operator Add(A, B: TFoo): TFoo;
+begin
+  Result.F := A.F + B.F;
+end;
+
+begin
+end.
+

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