Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-02

Generics Compile Error, 2.4.2 vs 2.6.0

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

David Copeland

Under FPC 2.4.2 I have been using RBTree unit that uses generics. With 2.6.0 it fails to compile. I know that there have been changes for 2.6.0 but I have checked the syntax in the 2.6.0 Language Reference and cannot see why the error is occurring. I have also looked in Mantis but don't know if anything there relates to my problem. I have excerpted the code below and attached the complete unit.

==================

unit FOS_REDBLACKTREE_GEN;
// (c) Copyright FirmOS Business Solutions GmbH
// Author Helmut Hartl, Franz Schober
}
//{$MODE OBJFPC}
{$MODE DELPHI}
{$H+}
interface
type
  TRB_NodeColor=(R,B);
  { TGFOS_RBTree }
  {$B-}
  generic TGFOS_RBTree<_TKey,_TStore> = class(TInterfacedObject)

*** The error occurs at the line above.

Free Pascal Compiler version 2.6.0 [2012/02/08] for x86_64 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for x86-64
Compiling FOS_REDBLACKTREE_GEN.pas
FOS_REDBLACKTREE_GEN.pas(48,11) Fatal: Syntax error, "=" expected but "identifier TGFOS_RBTREE" found
Fatal: Compilation aborted

    type public
      PFOS_RB_NodeG=^TFOS_RB_NodeG;
      _PStore       =^_TStore;
      TFOS_RB_NodeG = packed record
          k:  _TKey;
          left, right, parent: PFOS_RB_NodeG;
          col: TRB_NodeColor;
          val:_TStore;
       end;
       TCompareKeys     = function  (const Item1, Item2: _TKey):
Integer;
       TGUndefined      = function  :_Tstore;
       TGUndefinedKey   = function  :_TKey;
       TGFOS_RB_OnItem  = procedure (const Item:_TStore) of object;
       TGFOS_RB_OnItemN = procedure (const Item:_TStore);

==================

Thanks for any help.

David Copeland JSI Data Systems Limited 613-727-9353.
J.-c. Chu
to David Copeland

If you are compiling the unit in Delphi mode, you’ll need to use the syntax of Delphi.

* Generics are defined without the GENERIC keyword.
* Generics are specialized without the SPECIALIZE keyword.
* To define class-local types and variables, visibility specifiers need to be placed before the TYPE and VAR keywords.
* Implementations of the methods of a generic class must include the type parameters of the class.

Please check if the attached file works.

David Copeland wrote 66 lines
Under FPC 2.4.2 I have been using RBTree unit that uses generics. With 2.6.0 it fails to compile. I know that there have been changes for 2.6.0 but I have checked the syntax in the 2.6.0 Language Reference and cannot see why the error is occurring. I have also looked in Mantis but don't know if anything there relates to my problem. I have excerpted the code below and attached the complete unit. ================== unit FOS_REDBLACKTREE_GEN; // (c) Copyright FirmOS Business Solutions GmbH // Author Helmut Hartl, Franz Schober } //{$MODE OBJFPC} {$MODE DELPHI} {$H+} interface type TRB_NodeColor=(R,B); { TGFOS_RBTree } {$B-} generic TGFOS_RBTree<_TKey,_TStore> = class(TInterfacedObject) *** The error occurs at the line above. Free Pascal Compiler version 2.6.0 [2012/02/08] for x86_64 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling FOS_REDBLACKTREE_GEN.pas FOS_REDBLACKTREE_GEN.pas(48,11) Fatal: Syntax error, "=" expected but "identifier TGFOS_RBTREE" found Fatal: Compilation aborted type public PFOS_RB_NodeG=^TFOS_RB_NodeG; _PStore =^_TStore; TFOS_RB_NodeG = packed record k: _TKey; left, right, parent: PFOS_RB_NodeG; col: TRB_NodeColor; val:_TStore; end; TCompareKeys = function (const Item1, Item2: _TKey): Integer; TGUndefined = function :_Tstore; TGUndefinedKey = function :_TKey; TGFOS_RB_OnItem = procedure (const Item:_TStore) of object; TGFOS_RB_OnItemN = procedure (const Item:_TStore); ================== Thanks for any help. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Best Regards, J.-c. Chu
David Copeland
to J.-c. Chu

Thanks very much. It now compiles!

Dave.

Earlier message 18 lines
-----Original Message----- From: J.-c. Chu Reply-to: FPC-Pascal users discussions To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] Generics Compile Error, 2.4.2 vs 2.6.0 Date: Tue, 14 Feb 2012 00:59:03 +0800 If you are compiling the unit in Delphi mode, you’ll need to use the syntax of Delphi. * Generics are defined without the GENERIC keyword. * Generics are specialized without the SPECIALIZE keyword. * To define class-local types and variables, visibility specifiers need to be placed before the TYPE and VAR keywords. * Implementations of the methods of a generic class must include the type parameters of the class. Please check if the attached file works.