Hello,

Right now, declaring an Objective-Pascal class/protocol/category as external 
happens in the following way:

type
  { formal external declaration }
  SomeExternalClass = objcclass; external;

  { full external declaration }
  NSObject = objcclass
    <fields and methods>
  end; external name 'NSObject';

This syntax is not really consistent with how existing modifiers for 
Delphi-style classes work: either they're at the start or at the end, but 
always before the final semicolon:
a) sealed/abstract:

type
  tc = class sealed
    <fields and methods>
  end;

b) hints such as "platform" and "deprecated":

type
  tc1 = class
    <fields and methods>
  end platform deprecated 'use tc2 instead';


As far as parsing is concerned, having the information about whether or not a 
class will be external before parsing all method declarations would be the best 
(i.e., similar to "sealed" and "abstract"). Right now, if the objcclass is 
external then after the class has been parsed, we have to go over all methods 
again to also mark them as external.

So I would propose to change the syntax by moving the "external" modifier to 
the same location as where "sealed" and "abstract" can be placed for 
Delphi-style classes. It should be quite easy to modify the Objective-C headers 
parser script to produce that new syntax. I also think that after this change, 
the Objective-Pascal syntax can be finalised and considered as stable.

The main reasons I want to do this, are
1) to reduce the number of places where the compiled parser has to look for 
object-type modifiers from 3 down to 2 places, which simplifies it somewhat 
(and simpler compiler parser code is good for both compiler maintainability and 
for speed)
2) it's more consistent with the syntax for Delphi-style classes, and hence 
should Embarcadero ever decide to support Objective-Pascal as well, I guess 
this is how they would do it (or at least prefer to do it)
3) it removes one place from the parser where ambiguities can occur. The 
following code currently does not compile, because the compiler interprets the 
"external" as a modifier for the objcclass:

type
  tc = objcclass
  end;
{ type }  //-- uncomment to remove ambiguity and fix compilation
  external = longint;

It does replace it with another ambiguity, since this will no longer compile 
after the change, again because the compiler will now interpret the "external" 
as modifier:

type
  tc = objcclass
{   public }  // -- uncomment to remove ambiguity and fix compilation
    external: longint
  end;

However, this second ambiguity already exists for Delphi-style classes in case 
of "abstract" or "sealed" is used 
(http://wiki.freepascal.org/User_Changes_2.4.2#Abstract_and_Sealed_class_modifiers),
 so it sort of consolidates the potential ambiguities in the same location 
regardless of the used object model.


Jonas_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to