[fpc-devel] Some compiler changes...
Joost van der Sluis
joost at cnoc.nl
Tue Jan 23 09:18:21 CET 2007
I'm very against this (especially in mode objfpc), and I don't get the
point at all.
In my opinion we have to keep the language as clean as possible.
What could be a rood reason to escape a keyword? Why do you as
programmer insist on the use of a keyword? Why do you insist that your
property is called 'unit'? It's just obfuscating the code. With this you
can mangle your code completely...
(If you want to make a code-obfuscator, as they do sometimes with .php
pages, yes, then I understand why you should want this.)
And about the 'method' thing... We could also replace the 'property'
keyword by 'something'. Hey, we can also replace method by 'something'!
Woudn't that be nice. So you get:
type
TMyObject = class
Fs : String;
something Foo;
something Bar: Integer;
class something ClassFoo;
class something ClassBar: Integer;
something s : read Fs write Fs;
end;
Hmm... maye it's better to get rid off 'something' completely, then...
In short: why do ou want to get rid of the difference between
'procedure' and 'function'?
Or do I miss something completely?
Joost.
On Tue, 2007-01-23 at 12:00 +1000, Thorsten Engler wrote:
> While playing around with the compiler source to familiarize myself I've
> produced the attached patch. While I didn't set out to produce anything for
> inclusion into the official codebase at least some of the changes might be
> generally useful.
>
> a) now modeswitch: m_ident_escape
>
> Allows escaping of identifiers which might otherwise be recognized as
> keywords. This mirrors Delphi's (and Chrome's) implementation.
>
> type
> TMyRecord = record
> &unit: Integer;
> end;
>
> No space is allowed betweehn & and identifier. As identifiers are not
> allowed to start with digits there is no collision with the &123 support for
> base 8 integer constants.
>
> b) new modeswitch: m_always_ident_after_dot
>
> There are no valid cases in the pascal grammer where a keyword follows a
> single dot. As a) makes it now possible to declare identifiers which are
> identical to keywords qualified access to these fields can now be simplified
> by always recognizing an identifier/keyword following a dot as a simple
> identifier, no matter if it matches a keyword or not.
>
> I'm not sure if Delphi implements this. Chrome does.
>
> var
> myRecord: TMyRecord;
> begin
> myRecord.unit := 123;
> end;
>
>
> These 2 switches should not affect compatibility to existing code. I can run
> a complete make all / make install with both of these generally active. It
> could be considered to add them to {$mode objfpc}
>
> c) new $mode: m_chrome
>
> Currently baseed on objfpc with the addition of all 3 new mode switches. In
> addition to a) and b) m_chrome allows the use of "method" as an alternative
> to both procedure and function (if the method is a procedure or function can
> simply be determined by the presence of a defined result type).
>
> A slightly extreme example follows:
>
> >>>>
> {$mode chrome}
>
> program ChromeTest;
>
> type
> TMyObject = class
> method Foo;
> method Bar: Integer;
> class method ClassFoo;
> class method ClassBar: Integer;
>
> method &class;
> method &method(&string: string):string;
> end;
>
> type
> &method = method(&string: string):string of object;
>
> { TMyObject }
>
> method TMyObject.Bar: Integer;
> begin
> WriteLn('TMyObject.Bar');
> Result := 0;
> end;
>
> method TMyObject.Foo;
> begin
> WriteLn('TMyObject.Foo');
> end;
>
> class method TMyObject.ClassBar: Integer;
> begin
> WriteLn('TMyObject.ClassBar');
> Result := 0;
> end;
>
> class method TMyObject.ClassFoo;
> begin
> WriteLn('TMyObject.ClassFoo');
> end;
>
> method TMyObject.class;
> begin
> WriteLn('Class');
> end;
>
> method TMyObject.method(&string: string):string;
> begin
> Result := '*** ' + &string + ' ***';
> end;
>
> method Foo;
> begin
> WriteLn('Foo');
> end;
>
> method Bar: Integer;
> begin
> WriteLn('Bar');
> Result := 0;
> end;
>
> var
> &object: TMyObject;
> amethod: &method;
>
> begin
> Foo;
> Bar;
> TMyObject.ClassFoo;
> TMyObject.ClassBar;
>
> &object := TMyObject.Create;
>
> &object.Class;
>
> amethod := @&object.method;
> WriteLn(amethod('method'));
>
> with &object do try
> Foo;
> Bar;
> &class;
> finally
> Free;
> end;
> end.
> <<<<
>
>
> Cheers,
> Thorsten
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
--
Met vriendelijke groeten,
Joost van der Sluis
CNOC Informatiesystemen en Netwerken
http://www.cnoc.nl
More information about the fpc-devel
mailing list