Browse Source

Add support for parsing "weak" directive for variables, fields and parameters.

symdef.pas, tabstractprocdef:
  + add a field retisweak to denote that the result variable is to be considered as weak
  * ppuload: load retisweak from PPU
  * ppuwrite: write retisweak to PPU
pdecvar.pas: 
  + read_var_decls: new function read_weak which ensures that "weak" is only applied to a single variable (like "absolute" or default values) and sets the flag
  * read_var_decls: parse "weak" after "absolute" has been parsed
  * read_record_fields: parse "weak" and set the flag (without error only if it's only one field that gets the flag set)
pdecsub.pas:
  * parse_parameter_dec: parse "weak" and set the flag (without error only if it's only one parameter that gets the flag set)
  * parse_proc_dec: parse "weak" for function and operator results and set the flag
ppu.pas:
  * increase PPU version

git-svn-id: branches/svenbarth/arc@28804 -
svenbarth 10 năm trước cách đây
mục cha
commit
1671645bc0
4 tập tin đã thay đổi với 48 bổ sung1 xóa
  1. 16 0
      compiler/pdecsub.pas
  2. 28 0
      compiler/pdecvar.pas
  3. 1 1
      compiler/ppu.pas
  4. 3 0
      compiler/symdef.pas

+ 16 - 0
compiler/pdecsub.pas

@@ -459,6 +459,14 @@ implementation
                        end;
                     end;
                   end;
+                if is_class(hdef) and
+                    (oo_is_reference_counted in tobjectdef(hdef).objectoptions) and
+                    try_to_consume(_WEAK) then
+                  begin
+                    if sc.count>1 then
+                      Message1(parser_e_directive_only_one_var,arraytokeninfo[_WEAK].str);
+                    include(tabstractvarsym(sc[0]).varoptions,vo_is_weakref);
+                  end;
                 if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
                   begin
                     if (idtoken=_LOCATION) then
@@ -1162,6 +1170,10 @@ implementation
                       if try_to_consume(_COLON) then
                        begin
                          read_returndef(pd);
+                         if is_class(pd.returndef) and
+                             (oo_is_reference_counted in tobjectdef(pd.returndef).objectoptions) and
+                             try_to_consume(_WEAK) then
+                           pd.retisweak:=true;
                          if (target_info.system in [system_m68k_amiga]) then
                           begin
                            if (idtoken=_LOCATION) then
@@ -1307,6 +1319,10 @@ implementation
                   else
                    begin
                      read_returndef(pd);
+                     if is_class(pd.returndef) and
+                         (oo_is_reference_counted in tobjectdef(pd.returndef).objectoptions) and
+                         try_to_consume(_WEAK) then
+                       pd.retisweak:=true;
                      { check that class operators have either return type of structure or }
                      { at least one argument of that type                                 }
                      if (po_classmethod in pd.procoptions) and

+ 28 - 0
compiler/pdecvar.pas

@@ -1103,6 +1103,17 @@ implementation
         end;
 {$endif}
 
+
+        procedure read_weak(sc:tfpobjectlist);
+          var
+            vs : tabstractvarsym;
+          begin
+            if sc.count>1 then
+              Message1(parser_e_directive_only_one_var,arraytokeninfo[_WEAK].str);
+            vs:=tabstractvarsym(sc[0]);
+            include(vs.varoptions,vo_is_weakref);
+          end;
+
         procedure read_absolute(sc : TFPObjectList);
         var
           vs     : tabstractvarsym;
@@ -1340,6 +1351,13 @@ implementation
                  allowdefaultvalue:=false;
                end;
 
+             if is_class(hdef) and
+                 (oo_is_reference_counted in tobjectdef(hdef).objectoptions) and
+                 try_to_consume(_WEAK) then
+               begin
+                 read_weak(sc);
+               end;
+
              { Check for EXTERNAL etc directives before a semicolon }
              if (idtoken in [_EXPORT,_EXTERNAL,_WEAKEXTERNAL,_PUBLIC,_CVAR]) then
                begin
@@ -1602,6 +1620,16 @@ implementation
                end;
 {$endif powerpc or powerpc64}
 
+             if is_class(hdef)
+                 and (oo_is_reference_counted in tobjectdef(hdef).objectoptions)
+                 and try_to_consume(_WEAK) then
+               begin
+                 if sc.count>1 then
+                   Message1(parser_e_directive_only_one_var,arraytokeninfo[_WEAK].str);
+                 vs:=tabstractvarsym(sc[0]);
+                 include(vs.varoptions,vo_is_weakref);
+               end;
+
              { types that use init/final are not allowed in variant parts, but
                classes are allowed }
              if (variantrecordlevel>0) then

+ 1 - 1
compiler/ppu.pas

@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion = 172;
+  CurrentPPUVersion = 173;
 
 { buffer sizes }
   maxentrysize = 1024;

+ 3 - 0
compiler/symdef.pas

@@ -563,6 +563,7 @@ interface
           exp_funcretloc : tregister;   { explicit funcretloc for AmigaOS }
 {$endif}
           funcretloc : array[tcallercallee] of TCGPara;
+          retisweak : boolean;
           has_paraloc_info : tcallercallee; { paraloc info is available }
           { number of user visible parameters }
           maxparacount,
@@ -4286,6 +4287,7 @@ implementation
          proctypeoption:=tproctypeoption(ppufile.getbyte);
          proccalloption:=tproccalloption(ppufile.getbyte);
          ppufile.getnormalset(procoptions);
+         retisweak:=boolean(ppufile.getbyte);
 
          funcretloc[callerside].init;
          if po_explicitparaloc in procoptions then
@@ -4311,6 +4313,7 @@ implementation
          ppufile.putbyte(ord(proctypeoption));
          ppufile.putbyte(ord(proccalloption));
          ppufile.putnormalset(procoptions);
+         ppufile.putbyte(ord(retisweak));
          ppufile.do_interface_crc:=oldintfcrc;
 
          if (po_explicitparaloc in procoptions) then