Author Topic: Delphi/Freepascal Generics and Anonymous methods breaks importing into EA  (Read 777 times)

AndiFriess

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Importing Pascal files with generics break the import for this unit.

a simple line
Code: [Select]
  TWBSrcList = specialize TFPGObjectList<TWorkPageSource>;breaks the complete import.
Quote
There was an error parsing C:\data\xxx\yyyyy.pas  on line 68.  Unexpected symbol: TFPGObjectList   

And i find no soloution to  say, dont stop on errors and process the rest of the file. And i am also not able to write an rule in nBNF for the grammar parser because Delphi/Pascal is an internal sealed  system.

And in the Book 'Kompendium zu Enterprise Architekt von SparxSystems' is introduced (around page 206) only the way to build an complete MDG (and no way for a partial Extension).  In other posts about generics there i a small hint about the support have information 2016 !. ?!?

Im using EA 13 now, and generics are well known since years.

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6197
  • Karma: +47/-5
    • View Profile
The short answer it's never been fixed because there's never been a not a language definition or complete samples available. Contact support and we can give a technology that provides our "best guess" implementation of the grammar rules. Unfortunately, that level of certainty doesn't meet our quality standards to claim that we support it.
Simon

support@sparxsystems.com

AndiFriess

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
The short answer it's never been fixed because there's never been a not a language definition or complete samples available.
What is the requirement for a 'complete' sample ?


Quote
Generic class types

--generic type generic -identifier- <  template list- > =  -generic type -;---
     

--          ---         ----------------------------------------
  template list -identifi;er-list--|
     

--identifier list--identifier-------------------------------------------
                  ,       :  |-type identifier| |
                             -----cl,ass ------|
                             ----interface-----|
                             -----object------|
                             -----record------|
     

--generic type---- class type----------------------------------------
             ---object type---|
             --interface type--|
             -procedural type-|
             |--record type---|
             ---array type-----
     
....
For classes, objects, procedural types and extended records, the generic type declaration should be followed by a type implementation. It is the same as a normal class implementation with a single exception, namely that any identifier with the same name as one of the template identifiers must be a type identifier.
So, the generic type declaration is much like a normal type declaration, except that there is an as yet unknown type present. The unknown types are listed in the placeholder list, and they are unknown until the class is specialized.
The following is a valid generic class definition:

Type 
  generic TList<_T>=class(TObject) 
  Public 
    type 
       TCompareFunc = function(const Item1, Item2: _T): Integer; 
    var 
      data : _T; 
    procedure Add(item: _T); 
    procedure Sort(compare: TCompareFunc); 
  end;
This class could be followed by an implementation as follows:

procedure TList.Add(item: _T); 
begin 
  data:=item; 
end; 
 
procedure TList.Sort(compare: TCompareFunc); 
begin 
  if compare(data, 20) <= 0 then 
    halt(1); 
end;
See https://www.freepascal.org/docs-html/ref/refse50.html#x104-1260008.2
Sample:
Quote
How to use generics
Aus Free Pascal wiki
An example of how to use generics to write a function gmax() that takes the maximum of two not-yet-typed variables. Note that the functions are namespaced by the classname. A disadvantage may be that generics can't be overloaded.
program UseGenerics;
 
{$mode objfpc}{$H+}
 
type
  generic TFakeClass<_GT> = class
    class function gmax(a,b: _GT):_GT;
  end;
 
  TFakeClassInt = specialize TFakeClass<integer>;
  TFakeClassDouble = specialize TFakeClass<double>;
 
  class function TFakeClass.gmax(a,b: _GT):_GT;
  begin
    if a > b then
      result := a
    else
      result := b;
  end;
 
begin
    // show max of two integers
  writeln( 'Integer GMax:', TFakeClassInt.gmax( 23, 56 ) );
    // show max of two doubles
  writeln( 'Double GMax:', TFakeClassDouble.gmax( 23.89, 56.5) );
  readln();
end.
see http://wiki.freepascal.org/How_to_use_generics


The generic itself is not the major problem, the problem is, the converter makes an error and STOP conversion without an valid output. If the converter makes only a message and continue, it is often ok, the rest can be done by hand.

My question is
Quote
And i find no soloution to  say, dont stop on errors and process the rest of the file.

Is there an option to say, finish conversion on error.

Regards
  Andreas

Graham_Moir

  • EA User
  • **
  • Posts: 677
  • Karma: +4/-4
    • View Profile

Have you contacted support as suggested by Simon M. ?

AndiFriess

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Have you contacted support as suggested by Simon M. ?
Yes.

But have you an answer for my question, asked 2 times in my posts before (This is the 3rd attemp) ? 

Quote
And i find no soloution to  say, dont stop on errors and process the rest of the file. Is there an option to say, finish conversion on error.

Andreas

qwerty

  • EA Guru
  • *****
  • Posts: 8964
  • Karma: +136/-123
  • I'm no guru at all
    • View Profile
AFAIK there is no such option.

q.

AndiFriess

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
IMHO can this be a good additional option.

Because the user can decide if he want the result or not.

Andreas