[Dwarf-discuss] Proposal: Add support for "property" with getter/setter (based on Pascal properties)

Martin lists@mfriebe.de
Wed May 8 10:35:25 GMT 2024


Here are 2 examples of what it would look like

## Property with different visibility

```
   type
     TFoo = class
     private
       MyMember: integer;
       function MyFunc: integer;
     protected
       // "read public" is currently from oxygene, but may be added to 
FreePascal
       property MyProp: integer read public MyFunc write MyMember;
     end;

     TBar = clall(TFoo)
     public
       property MyProp; // elevate to public
     end;
```

```
   DW_TAG_Structure_type
     DW_AT_Name :  "TFoo"
L1:
     DW_TAG_Member
         DW_AT_Name            :  "MyMember"
         DW_AT_Type            :  <...>
         DW_AT_Member_location :  <...>
L2:
     DW_TAG_subprogram
         DW_AT_Name            :  "MyFunc"
         DW_AT_Type            :  <...>

     DW_TAG_Property
         DW_AT_Name             :  "MyProp"
         DW_AT_Type             :  <...>
         DW_AT_Accessibility    :  DW_ACCESS_protected
         DW_AT_Default_Property :  TRUE
       DW_TAG_Property_Getter
           DW_AT_Property_Forward :  reference to L2
           DW_AT_Accessibility    :  DW_ACCESS_public
       DW_TAG_Property_Setter
           DW_AT_Property_Forward :  reference to L1

   DW_TAG_Structure_type
     DW_AT_Name :  "TBar"
     DW_TAG_Inheritance
         <...>
     DW_TAG_Property
         DW_AT_Name             :  "MyProp"
         DW_AT_Accessibility    :  DW_ACCESS_public
```

## Property with access to nested field


```
   type
     TFoo = class
       OtherData: DWORD;
       FNested: record
         MyMember: integer;
       end;
       property MyProp: integer read FNested.MyMember;
     end;
```

```
L1:
   DW_TAG_Structure_type
L2:
     DW_TAG_Member
         DW_AT_Name            :  "MyMember"
         DW_AT_Type            :  <...>
         DW_AT_Member_location :  <...>    ! inside FNested

   DW_TAG_Structure_type
     DW_AT_Name :  "TFoo"
     DW_TAG_Member
         DW_AT_Name :  "OtherData"
     DW_TAG_Member
         DW_AT_Name :  "FNested"
         DW_AT_Type            :  reference to L1
         DW_AT_Member_location :
               DW_OP_plus_uconst 4             ! where 4 == offset of 
MyMember in the instance data

     DW_TAG_Property
         DW_AT_Name             :  "MyProp"
         DW_AT_Type             :  <...>
       DW_TAG_Property_Getter
           DW_AT_Property_Forward :  reference to L2
           DW_AT_Property_Object  :
               DW_OP_push_object_address  ! maybe should be on stack by 
default
               DW_OP_plus_uconst 4        ! where 4 == offset of 
MyMember in the instance data
                                          ! There could be several 
levels of nesting, so that expression could be more complex
```

In the example the property does not have a reference to FNested itself. 
All it needs is the object_address of FNested, so it can calculate the 
location of the referenced field MyMember (using the member_location).




More information about the Dwarf-discuss mailing list