[fpc-devel] apple properties // Re: Help/Guidance please: Dwarf support for properties

Martin Frb lazarus at mfriebe.de
Fri May 3 12:13:19 CEST 2024


In case it goes ahead, I am trying to thing of what would be needed....
Can anyone think of any feature for Pascal properties that is not 
covered by the below?



# Proposal to implement "properties" for Pascal

## Background

Pascal has a property construct, that allows a "variable like" 
identifier, which can either point to a field (member variable) or a 
getter/setter function.
They can be read/write, read only, write only.
   TFoo = class
     FField: integer;
     function GetProp: integer;
     procedure SetProp(AVal: Integer);
     property MyProp: integer read GetProp write SetProp;
     property MyOtherProp: integer read FField;
   end;

Properties can exist in a structure, interface, or on a global level.

Properties can have one or more array like indexes.
   TFoo = class
     function GetProp(AIdx:word; AIdx2: boolean): integer;
     procedure SetProp(AIdx:word; AIdx2: boolean; AVal: Integer);
     property MyProp[AIdx:word; AIdx2: boolean]: integer read GetProp 
write SetProp;
   end;

Properties can share a method, and provide an index (constant) to 
identify which property called the method.
   TFoo = class
     function GetProp(AIndex: Integer): integer;
     procedure SetProp(AIndex: Integer; AValue: integer);
     property MyProp1: integer index 1 read GetProp write SetProp;
     property MyProp2: integer index 2 read GetProp write SetProp;
   end;

Properties can be streamed and therefore can have a default value 
(constant or via function). They can also have a "stored" value 
(function) indicating if they need to be stored in the stream.

Properties can be elevated to a higher visibility (private/public) in 
inherited classes.

There may be partial overlaps with properties in Objective-C and C#

## Proposed Changes

Introducing a new tag

DW_TAG_PROPERTY or DW_TAG_PROPERTY_PASCAL
This tag can occur anywhere where DW_TAG_MEMBER can occur. It can also 
occur on a global scope.

It can have
   DW_AT_NAME
   DW_AT_TYPE
   DW_AT_ACCESSIBILITY
   DW_AT_decl_column, DW_AT_decl_file and DW_AT_decl_line.

It can then contain any of
   DW_TAG_PROPERTY_SETTER
   DW_TAG_PROPERTY_READER
   DW_TAG_PROPERTY_DEFAULT
   DW_TAG_PROPERTY_STORED

Each of them can have

   DW_AT_PROPERTY_FORWARD  reference/constant
     refernce to the field or function
   DW_AT_PROPERTY_OBJECT  reference/expression/constant
     the object on which the value is stored (value for 
DW_OP_push_object_address)
     can be omitted for inherited classes, if it computes to the same as 
the current class

A getter (also "default" and "stored" should be a function returning the 
same type as the property. It should either take no arguments or only 
DW_AT_object_pointer
A setter should be a procedure, it should take optional 
DW_AT_object_pointer and one argument of the same type as the property.

Instead of having attributes grouped in DW_TAG_PROPERTY_SETTER/... all 
attribute could exist top level, in 4 versions. That would be shorter if 
no object needs to be specified. But it is less flexible for later 
additions.


For indexed properties the DW_TAG_PROPERTY also has
   DW_TAG_PROPERTY_INDEX_LIST
containing one or more
   DW_TAG_PROPERTY_INDEX

   DW_AT_NAME
   DW_AT_TYPE
   DW_AT_VALUE  reference or constant or expression (returning value)
   DW_AT_IS_PROPERTY_VALUE  flag

DW_AT_NAME and  DW_AT_TYPE can be optional. They can be gotten from the 
linked procedure
DW_AT_VALUE is optional. It is used when properties share a getter.

DW_AT_IS_PROPERTY_VALUE is optional. It can be used to specify the 
position of the "assigned value" in a setter. If not specified the 
assigned value will be passed as the last parametr.


To change visibility of an inherited property,
DW_TAG_PROPERTY
   DW_AT_NAME
   DW_AT_ACCESSIBILITY


OFF TOPIC:
   For C# it may be of interest to allow DW_TAG_PROPERTY_SETTER/... to 
have their own   DW_AT_ACCESSIBILITY
   For C# it may be of interest to allow an inlined function declaration 
instead of DW_AT_PROPERTY_VALUE


## References

FreePascal property doc 
https://www.freepascal.org/docs-html/ref/refse27.html
APPLE extension for Objective-C 
https://github.com/llvm/llvm-project/blob/main/llvm/docs/SourceLevelDebugging.rst#debugging-information-format-1




More information about the fpc-devel mailing list