Browse Source

compiler: add current_structdef: tabstractrecorddef and point current_objectdef to it

git-svn-id: branches/paul/extended_records@16515 -
paul 14 years ago
parent
commit
902a78eec1
3 changed files with 31 additions and 26 deletions
  1. 14 10
      compiler/ptype.pas
  2. 2 1
      compiler/symdef.pas
  3. 15 15
      compiler/symtable.pas

+ 14 - 10
compiler/ptype.pas

@@ -551,7 +551,7 @@ implementation
           end;
           end;
       end;
       end;
 
 
-    procedure parse_record_members(recorddef: trecorddef);
+    procedure parse_record_members;
 
 
         procedure maybe_parse_hint_directives(pd:tprocdef);
         procedure maybe_parse_hint_directives(pd:tprocdef);
         var
         var
@@ -583,7 +583,7 @@ implementation
         if (token=_SEMICOLON) then
         if (token=_SEMICOLON) then
           Exit;
           Exit;
 
 
-        recorddef.symtable.currentvisibility:=vis_public;
+        current_structdef.symtable.currentvisibility:=vis_public;
         has_destructor:=false;
         has_destructor:=false;
         fields_allowed:=true;
         fields_allowed:=true;
         is_classdef:=false;
         is_classdef:=false;
@@ -615,7 +615,7 @@ implementation
                   _PRIVATE :
                   _PRIVATE :
                     begin
                     begin
                        consume(_PRIVATE);
                        consume(_PRIVATE);
-                       recorddef.symtable.currentvisibility:=vis_private;
+                       current_structdef.symtable.currentvisibility:=vis_private;
                        fields_allowed:=true;
                        fields_allowed:=true;
                        is_classdef:=false;
                        is_classdef:=false;
                        classfields:=false;
                        classfields:=false;
@@ -624,7 +624,7 @@ implementation
                    _PROTECTED :
                    _PROTECTED :
                      begin
                      begin
                        consume(_PROTECTED);
                        consume(_PROTECTED);
-                       recorddef.symtable.currentvisibility:=vis_protected;
+                       current_structdef.symtable.currentvisibility:=vis_protected;
                        fields_allowed:=true;
                        fields_allowed:=true;
                        is_classdef:=false;
                        is_classdef:=false;
                        classfields:=false;
                        classfields:=false;
@@ -633,7 +633,7 @@ implementation
                    _PUBLIC :
                    _PUBLIC :
                      begin
                      begin
                        consume(_PUBLIC);
                        consume(_PUBLIC);
-                       recorddef.symtable.currentvisibility:=vis_public;
+                       current_structdef.symtable.currentvisibility:=vis_public;
                        fields_allowed:=true;
                        fields_allowed:=true;
                        is_classdef:=false;
                        is_classdef:=false;
                        classfields:=false;
                        classfields:=false;
@@ -643,7 +643,7 @@ implementation
                      begin
                      begin
                        Message(parser_e_no_record_published);
                        Message(parser_e_no_record_published);
                        consume(_PUBLISHED);
                        consume(_PUBLISHED);
-                       recorddef.symtable.currentvisibility:=vis_published;
+                       current_structdef.symtable.currentvisibility:=vis_published;
                        fields_allowed:=true;
                        fields_allowed:=true;
                        is_classdef:=false;
                        is_classdef:=false;
                        classfields:=false;
                        classfields:=false;
@@ -658,12 +658,12 @@ implementation
                               _PRIVATE:
                               _PRIVATE:
                                 begin
                                 begin
                                   consume(_PRIVATE);
                                   consume(_PRIVATE);
-                                  recorddef.symtable.currentvisibility:=vis_strictprivate;
+                                  current_structdef.symtable.currentvisibility:=vis_strictprivate;
                                 end;
                                 end;
                               _PROTECTED:
                               _PROTECTED:
                                 begin
                                 begin
                                   consume(_PROTECTED);
                                   consume(_PROTECTED);
-                                  recorddef.symtable.currentvisibility:=vis_strictprotected;
+                                  current_structdef.symtable.currentvisibility:=vis_strictprotected;
                                 end;
                                 end;
                               else
                               else
                                 message(parser_e_protected_or_private_expected);
                                 message(parser_e_protected_or_private_expected);
@@ -873,16 +873,19 @@ implementation
     { reads a record declaration }
     { reads a record declaration }
     function record_dec : tdef;
     function record_dec : tdef;
       var
       var
+         old_current_structdef : tabstractrecorddef;
          recst : trecordsymtable;
          recst : trecordsymtable;
       begin
       begin
+         old_current_structdef:=current_structdef;
          { create recdef }
          { create recdef }
          recst:=trecordsymtable.create(current_settings.packrecords);
          recst:=trecordsymtable.create(current_settings.packrecords);
-         result:=trecorddef.create(recst);
+         current_structdef:=trecorddef.create(recst);
+         result:=current_structdef;
          { insert in symtablestack }
          { insert in symtablestack }
          symtablestack.push(recst);
          symtablestack.push(recst);
          { parse record }
          { parse record }
          consume(_RECORD);
          consume(_RECORD);
-         parse_record_members(trecorddef(result));
+         parse_record_members;
          { make the record size aligned }
          { make the record size aligned }
          recst.addalignmentpadding;
          recst.addalignmentpadding;
          { restore symtable stack }
          { restore symtable stack }
@@ -890,6 +893,7 @@ implementation
          if trecorddef(record_dec).is_packed and
          if trecorddef(record_dec).is_packed and
             is_managed_type(record_dec) then
             is_managed_type(record_dec) then
            Message(type_e_no_packed_inittable);
            Message(type_e_no_packed_inittable);
+         current_structdef:=old_current_structdef;
       end;
       end;
 
 
 
 

+ 2 - 1
compiler/symdef.pas

@@ -633,7 +633,8 @@ interface
        end;
        end;
 
 
     var
     var
-       current_objectdef : tobjectdef;  { used for private functions check !! }
+       current_structdef: tabstractrecorddef;
+       current_objectdef : tobjectdef absolute current_structdef;  { used for private functions check !! }
        current_genericdef : tobjectdef; { used to reject declaration of generic class inside generic class }
        current_genericdef : tobjectdef; { used to reject declaration of generic class inside generic class }
        current_specializedef : tobjectdef; { used to implement usage of generic class in itself }
        current_specializedef : tobjectdef; { used to implement usage of generic class in itself }
 
 

+ 15 - 15
compiler/symtable.pas

@@ -1724,28 +1724,28 @@ implementation
                       ( // the case of specialize inside the generic declaration
                       ( // the case of specialize inside the generic declaration
                        (symownerdef.owner.symtabletype = objectsymtable) and
                        (symownerdef.owner.symtabletype = objectsymtable) and
                        (
                        (
-                         assigned(current_objectdef) and
+                         assigned(current_structdef) and
                          (
                          (
-                           (current_objectdef=symownerdef) or
-                           (current_objectdef.owner.iscurrentunit)
+                           (current_structdef=symownerdef) or
+                           (current_structdef.owner.iscurrentunit)
                          )
                          )
                        ) or
                        ) or
                        (
                        (
-                         not assigned(current_objectdef) and
+                         not assigned(current_structdef) and
                          (symownerdef.owner.iscurrentunit)
                          (symownerdef.owner.iscurrentunit)
                        )
                        )
                       );
                       );
             end;
             end;
           vis_strictprivate :
           vis_strictprivate :
             begin
             begin
-              result:=assigned(current_objectdef) and
-                      is_holded_by(current_objectdef,symownerdef);
+              result:=assigned(current_structdef) and
+                      is_holded_by(current_structdef,symownerdef);
             end;
             end;
           vis_strictprotected :
           vis_strictprotected :
             begin
             begin
-               result:=assigned(current_objectdef) and
-                       (current_objectdef.is_related(symownerdef) or
-                        is_holded_by(current_objectdef,symownerdef));
+               result:=assigned(current_structdef) and
+                       (current_structdef.is_related(symownerdef) or
+                        is_holded_by(current_structdef,symownerdef));
             end;
             end;
           vis_protected :
           vis_protected :
             begin
             begin
@@ -1766,14 +1766,14 @@ implementation
                        ( // the case of specialize inside the generic declaration
                        ( // the case of specialize inside the generic declaration
                         (symownerdef.owner.symtabletype = objectsymtable) and
                         (symownerdef.owner.symtabletype = objectsymtable) and
                         (
                         (
-                          assigned(current_objectdef) and
+                          assigned(current_structdef) and
                           (
                           (
-                            (current_objectdef=symownerdef) or
-                            (current_objectdef.owner.iscurrentunit)
+                            (current_structdef=symownerdef) or
+                            (current_structdef.owner.iscurrentunit)
                           )
                           )
                         ) or
                         ) or
                         (
                         (
-                          not assigned(current_objectdef) and
+                          not assigned(current_structdef) and
                           (symownerdef.owner.iscurrentunit)
                           (symownerdef.owner.iscurrentunit)
                          )
                          )
                        )
                        )
@@ -1851,7 +1851,7 @@ implementation
                        (srsymtable.defowner.owner.iscurrentunit) then
                        (srsymtable.defowner.owner.iscurrentunit) then
                       contextstructdef:=tobjectdef(srsymtable.defowner)
                       contextstructdef:=tobjectdef(srsymtable.defowner)
                     else
                     else
-                      contextstructdef:=current_objectdef;
+                      contextstructdef:=current_structdef;
                     if not (srsym.owner.symtabletype in [objectsymtable,recordsymtable]) or
                     if not (srsym.owner.symtabletype in [objectsymtable,recordsymtable]) or
                        is_visible_for_object(srsym,contextstructdef) then
                        is_visible_for_object(srsym,contextstructdef) then
                       begin
                       begin
@@ -1905,7 +1905,7 @@ implementation
                    not(srsym.typ in [fieldvarsym,paravarsym]) and
                    not(srsym.typ in [fieldvarsym,paravarsym]) and
                    (
                    (
                     not (srsym.owner.symtabletype in [objectsymtable,recordsymtable]) or
                     not (srsym.owner.symtabletype in [objectsymtable,recordsymtable]) or
-                    (is_visible_for_object(srsym,current_objectdef) and
+                    (is_visible_for_object(srsym,current_structdef) and
                      (srsym.typ=typesym))
                      (srsym.typ=typesym))
                    ) then
                    ) then
                   begin
                   begin