Embarcadero / octoid

Octoid is a tool for translating Objective-C headers into Delphi code. It is intended as a replacement for SDKTransform which ships with Delphi.
BSD 2-Clause "Simplified" License
31 stars 8 forks source link

Include an option for where line breaks should occur #5

Open DelphiWorlds opened 1 year ago

DelphiWorlds commented 1 year ago

For example when importing the Intents framework, this code is generated:

  INBoatTrip = interface(NSObject)
    ['{AB88A6B6-EFAA-4D6D-A4D2-A55983C4E890}']
    function arrivalBoatTerminalLocation: CLPlacemark; cdecl;
    function boatName: NSString; cdecl;
    function boatNumber: NSString; cdecl;
    function departureBoatTerminalLocation: CLPlacemark; cdecl;
    function initWithProvider(provider: NSString; boatName: NSString; boatNumber: NSString; tripDuration: INDateComponentsRange; departureBoatTerminalLocation: CLPlacemark; arrivalBoatTerminalLocation: CLPlacemark): Pointer; cdecl;
    function provider: NSString; cdecl;
    function tripDuration: INDateComponentsRange; cdecl;
  end;
  TINBoatTrip = class(TOCGenericImport<INBoatTripClass, INBoatTrip>) end;

Line breaks should occur using these rules:

Other rules need to be formulated for other declarations. Using the rules above, with a margin of 150 characters, the class declaration would become this:

  INBoatTrip = interface(NSObject)
    ['{AB88A6B6-EFAA-4D6D-A4D2-A55983C4E890}']
    function arrivalBoatTerminalLocation: CLPlacemark; cdecl;
    function boatName: NSString; cdecl;
    function boatNumber: NSString; cdecl;
    function departureBoatTerminalLocation: CLPlacemark; cdecl;
    function initWithProvider(provider: NSString; boatName: NSString; boatNumber: NSString; tripDuration: INDateComponentsRange;
      departureBoatTerminalLocation: CLPlacemark; arrivalBoatTerminalLocation: CLPlacemark): Pointer; cdecl;
    function provider: NSString; cdecl;
    function tripDuration: INDateComponentsRange; cdecl;
  end;
  TINBoatTrip = class(TOCGenericImport<INBoatTripClass, INBoatTrip>) end;
DelphiWorlds commented 5 months ago

This might be implemented in one of a couple of ways:

  1. Modify TSourceWriter to keep track of the number of characters that have been written to the current line so far, have it be aware of what is about to be written (i.e. whether it's a method parameter etc), and "break" if what is about to be written will exceed the margin. This could prove difficult if a rule is to break before a parameter that has already been written.
  2. Write the entire source, then use a parser (such as DelphiAST) to identify where breaks need to occur.

I'm leaning towards option 2