Re: [Dwarf-discuss] Question on "pascal property"

2024-05-03 Thread Martin via Dwarf-discuss
I had a look at the Apple properties extension. There is also a Borland 
one, but for that I could not find anything beyond just the names.


The apple one bears some similarities. There documentation is here
https://github.com/llvm/llvm-project/blob/main/llvm/docs/SourceLevelDebugging.rst#debugging-information-format-1

I don't have any Objective-C experience myself, but briefly consulted 
with someone who has.


1) ObjC apparently always has an "ivar" (field) - Pascal may not have one
2) In ObjC the "ivar" refers to the property - For Pascal the opposite 
direction would be desirable (though of course a debugger could perform 
a backward search)
3) InObjC getter and setter attributes are strings => Apparently the 
given names are used for some dispatch call. In Pascal getter/setter 
should have to be either -field, -procedure/function (no oop), 
-method(oop), -method on different object


There are a few other things to be added for Pascal.

.

Then next is the question, how to start an attempt to get it standardized?

What to submit and where?

How specific/generic should the specs be?

E.g. the above Apple extension appears to rely on the debugger knowing 
it is ObjC, and the debugger knowing how to invoke the dispatch (well, 
that is from what I understood on my brief consultation).

Adding a description for a getter/setter method:
- should this assume the debugger knows how to call it (where the 
parameter goes, etc)? Even if there could be different languages with 
different ways to call it?
- should it have some defaults? (e.g. where the _this param goes, 
default for the value param)
- should it give detailed instructions (describe how to compute each 
param).



I don't know the full needs properties in other languages would have. 
But some provisions could be included (and maybe someone with additional 
knowledge will join).
Like C#, properties can have their own getter/setter instead of a 
reference to an existing, so that could be accommodated.






On 01/05/2024 23:46, Adrian Prantl wrote:
Just a quick very general remark: For Objective-C, Clang (and presumably 
also GCC) are producing a couple of property-related attributes in the 
DW_AT_APPLE extension space


https://github.com/llvm/llvm-project/blob/505f6da1961ab55c601d7239648c53ce863b5d70/llvm/include/llvm/BinaryFormat/Dwarf.def#L630
 


maybe these are useful for you. I also wouldn't be opposed to 
standardizing a more generally useful mechanism for properties; we could 
potentially also find use for them in the Swift compiler.



--
Dwarf-discuss mailing list
Dwarf-discuss@lists.dwarfstd.org
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss


Re: [Dwarf-discuss] Question on "pascal property"

2024-05-03 Thread Martin via Dwarf-discuss

On 03/05/2024 10:08, Martin via Dwarf-discuss wrote:

Then next is the question, how to start an attempt to get it standardized?



I started on a DRAFT. (still discussing on the Pascal community, to 
ensure it comprises everything required.


I post it here for comments on the general direction and format.


# 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



--
Dwarf-discuss mailing list
Dwarf-discuss@lists.dwarfstd.org
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss