Browse Source

* Allow rtti-attributes only when the modeswitch prefixedattributes is set
* Set the prefixedattributes by default in mode delphi

git-svn-id: branches/joost/classattributes@25838 -

joost 12 years ago
parent
commit
aa3135f740

+ 1 - 1
compiler/globals.pas

@@ -52,7 +52,7 @@ interface
          [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
          [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
           m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
           m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
           m_out,m_default_para,m_duplicate_names,m_hintdirective,
           m_out,m_default_para,m_duplicate_names,m_hintdirective,
-          m_property,m_default_inline,m_except,m_advanced_records];
+          m_property,m_default_inline,m_except,m_advanced_records,m_prefixed_attributes];
        delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage,m_default_unicodestring];
        delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage,m_default_unicodestring];
        fpcmodeswitches =
        fpcmodeswitches =
          [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
          [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,

+ 4 - 2
compiler/globtype.pas

@@ -336,8 +336,9 @@ interface
          m_final_fields,        { allows declaring fields as "final", which means they must be initialised
          m_final_fields,        { allows declaring fields as "final", which means they must be initialised
                                   in the (class) constructor and are constant from then on (same as final
                                   in the (class) constructor and are constant from then on (same as final
                                   fields in Java) }
                                   fields in Java) }
-         m_default_unicodestring { makes the default string type in $h+ mode unicodestring rather than
+         m_default_unicodestring, { makes the default string type in $h+ mode unicodestring rather than
                                    ansistring; similarly, char becomes unicodechar rather than ansichar }
                                    ansistring; similarly, char becomes unicodechar rather than ansichar }
+         m_prefixed_attributes  { enable attributes that are defined before the type they belong to }
        );
        );
        tmodeswitches = set of tmodeswitch;
        tmodeswitches = set of tmodeswitch;
 
 
@@ -492,7 +493,8 @@ interface
          'ISOUNARYMINUS',
          'ISOUNARYMINUS',
          'SYSTEMCODEPAGE',
          'SYSTEMCODEPAGE',
          'FINALFIELDS',
          'FINALFIELDS',
-         'UNICODESTRINGS');
+         'UNICODESTRINGS',
+         'PREFIXEDATTRIBUTES');
 
 
 
 
      type
      type

+ 5 - 4
compiler/pdecl.pas

@@ -498,10 +498,11 @@ implementation
            generictokenbuf:=nil;
            generictokenbuf:=nil;
 
 
            { class attribute definitions? }
            { class attribute definitions? }
-           while token=_LECKKLAMMER do
-             begin
-               parse_rttiattributes(current_rtticlassattributesdef);
-             end;
+           if m_prefixed_attributes in current_settings.modeswitches then
+             while token=_LECKKLAMMER do
+               begin
+                 parse_rttiattributes(current_rtticlassattributesdef);
+               end;
 
 
            { fpc generic declaration? }
            { fpc generic declaration? }
            isgeneric:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_GENERIC);
            isgeneric:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_GENERIC);

+ 4 - 1
compiler/pdecobj.pas

@@ -1227,7 +1227,10 @@ implementation
               end;
               end;
             _LECKKLAMMER:
             _LECKKLAMMER:
               begin
               begin
-                parse_rttiattributes(current_rttiattributesdef);
+                if m_prefixed_attributes in current_settings.modeswitches then
+                  parse_rttiattributes(current_rttiattributesdef)
+                else
+                  consume(_ID);
               end;
               end;
             _END :
             _END :
               begin
               begin

+ 1 - 0
tests/test/tclassattribute1.pp

@@ -1,6 +1,7 @@
 program tclassattribute1;
 program tclassattribute1;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 uses
 uses
   typinfo;
   typinfo;

+ 1 - 0
tests/test/tclassattribute2.pp

@@ -2,6 +2,7 @@
 program tclassattribute2;
 program tclassattribute2;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 type
 type
   // Delphi XE does compile attributes that are not defined, but ignores them.
   // Delphi XE does compile attributes that are not defined, but ignores them.

+ 1 - 0
tests/test/tclassattribute3.pp

@@ -2,6 +2,7 @@
 program tclassattribute3;
 program tclassattribute3;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 type
 type
 
 

+ 1 - 1
tests/test/tclassattribute4.pp

@@ -1,6 +1,6 @@
 program tclassattribute4;
 program tclassattribute4;
 
 
-{$mode objfpc}{$H+}
+{$mode delphi}
 
 
 uses
 uses
   typinfo;
   typinfo;

+ 1 - 0
tests/test/tclassattribute5.pp

@@ -2,6 +2,7 @@
 program tclassattribute5;
 program tclassattribute5;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 uses
 uses
   typinfo;
   typinfo;

+ 1 - 0
tests/test/tclassattribute6.pp

@@ -1,6 +1,7 @@
 program tclassattribute6;
 program tclassattribute6;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 uses
 uses
   typinfo;
   typinfo;

+ 1 - 0
tests/test/tclassattribute7.pp

@@ -2,6 +2,7 @@
 program tclassattribute7;
 program tclassattribute7;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 uses
 uses
   typinfo;
   typinfo;

+ 1 - 0
tests/test/tclassattribute8.pp

@@ -2,6 +2,7 @@
 program tclassattribute8;
 program tclassattribute8;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 uses
 uses
   typinfo;
   typinfo;

+ 1 - 0
tests/test/tclassattribute9.pp

@@ -1,6 +1,7 @@
 program tclassattribute9;
 program tclassattribute9;
 
 
 {$mode objfpc}{$H+}
 {$mode objfpc}{$H+}
+{$modeswitch prefixedattributes}
 
 
 uses
 uses
   typinfo;
   typinfo;