Browse Source

* make generic basics working again

git-svn-id: trunk@2458 -
peter 19 years ago
parent
commit
a59690b147

+ 6 - 11
compiler/pdecl.pas

@@ -393,6 +393,7 @@ implementation
          defpos,storetokenpos : tfileposinfo;
          old_block_type : tblock_type;
          ch       : tclassheader;
+         isgeneric,
          isunique,
          istyperenaming : boolean;
          generictypelist : tsinglelist;
@@ -408,32 +409,26 @@ implementation
            generictypelist:=nil;
            generictokenbuf:=nil;
 
+           { generic declaration? }
+           isgeneric:=try_to_consume(_GENERIC);
+
            typename:=pattern;
            orgtypename:=orgpattern;
            consume(_ID);
 
-{$ifdef GENERICSHARPBRACKET}
            { Generic type declaration? }
-           if try_to_consume(_LSHARPBRACKET) then
+           if isgeneric then
              begin
+               consume(_LSHARPBRACKET);
                generictypelist:=parse_generic_parameters;
                consume(_RSHARPBRACKET);
              end;
-{$endif GENERICSHARPBRACKET}
 
            consume(_EQUAL);
 
            { support 'ttype=type word' syntax }
            isunique:=try_to_consume(_TYPE);
 
-           { Generic type declaration? }
-           if try_to_consume(_GENERIC) then
-             begin
-               consume(_LKLAMMER);
-               generictypelist:=parse_generic_parameters;
-               consume(_RKLAMMER);
-             end;
-
            { MacPas object model is more like Delphi's than like TP's, but }
            { uses the object keyword instead of class                      }
            if (m_mac in aktmodeswitches) and

+ 1 - 12
compiler/ptype.pas

@@ -90,24 +90,16 @@ implementation
             Comment(V_Error,'Specialization is only supported for generic types');
             pt1.resulttype:=generrortype;
             { recover }
-{$ifdef GENERICSHARPBRACKET}
             consume(_LSHARPBRACKET);
-{$endif GENERICSHARPBRACKET}
-            consume(_LKLAMMER);
             repeat
               pt2:=factor(false);
               pt2.free;
             until not try_to_consume(_COMMA);
-{$ifdef GENERICSHARPBRACKET}
             consume(_RSHARPBRACKET);
-{$endif GENERICSHARPBRACKET}
-            consume(_RKLAMMER);
             exit;
           end;
-{$ifdef GENERICSHARPBRACKET}
         consume(_LSHARPBRACKET);
-{$endif GENERICSHARPBRACKET}
-        consume(_LKLAMMER);
+        block_type:=bt_specialize;
         { Parse generic parameters, for each undefineddef in the symtable of
           the genericdef we need to have a new def }
         err:=false;
@@ -159,10 +151,7 @@ implementation
             try_to_consume(_SEMICOLON);
           end;
         generictypelist.free;
-{$ifdef GENERICSHARPBRACKET}
         consume(_RSHARPBRACKET);
-{$endif GENERICSHARPBRACKET}
-        consume(_RKLAMMER);
       end;
 
 

+ 2 - 2
compiler/scanner.pas

@@ -3583,7 +3583,7 @@ In case not, the value returned can be arbitrary.
              '>' :
                begin
                  readchar;
-                 if (block_type=bt_type) then
+                 if (block_type in [bt_type,bt_specialize]) then
                    token:=_RSHARPBRACKET
                  else
                    begin
@@ -3615,7 +3615,7 @@ In case not, the value returned can be arbitrary.
              '<' :
                begin
                  readchar;
-                 if (block_type=bt_type) then
+                 if (block_type in [bt_type,bt_specialize]) then
                    token:=_LSHARPBRACKET
                  else
                    begin

+ 3 - 3
tests/test/tgeneric1.pp

@@ -1,7 +1,7 @@
 {$mode objfpc}
 
 type
-   TList=generic(_T) class(TObject)
+   generic TList<_T>=class(TObject)
      data : _T;
      procedure Add(item: _T);
    end;
@@ -12,8 +12,8 @@ begin
 end;
 
 type
-  TMyIntList = specialize TList(integer);
-  TMyStringList = specialize TList(string);
+  TMyIntList = specialize TList<integer>;
+  TMyStringList = specialize TList<string>;
 
 var
   ilist : TMyIntList;

+ 2 - 2
tests/test/tgeneric2.pp

@@ -3,7 +3,7 @@
 {$mode objfpc}
 
 type
-   TList=generic(_T) class(TObject)
+   generic TList<_T>=class(TObject)
      data : _T;
      procedure Add(item: _T);
    end;
@@ -18,7 +18,7 @@ begin
 end;
 
 type
-  TMyStringList = specialize TList(string);
+  TMyStringList = specialize TList<string>;
 
 var
   slist : TMyStringList;

+ 1 - 1
tests/test/tgeneric3.pp

@@ -1,7 +1,7 @@
 uses ugeneric3;
 
 type
-  TMyStringList = specialize TList(string);
+  TMyStringList = specialize TList<string>;
 
 var
   slist : TMyStringList;

+ 1 - 1
tests/test/tgeneric4.pp

@@ -6,7 +6,7 @@ begin
 end;
 
 type
-  TMyStringList = specialize TList(string);
+  TMyStringList = specialize TList<string>;
 
 var
   slist : TMyStringList;

+ 2 - 2
tests/test/tgeneric5.pp

@@ -4,7 +4,7 @@ uses
   typinfo;
 
 type
-   TList=generic(_T) class(TObject)
+   generic TList<_T>=class(TObject)
      data : _T;
      procedure Add(item: _T);
    end;
@@ -33,7 +33,7 @@ begin
 end;
 
 type
-  TMyIntList = specialize TList(integer);
+  TMyIntList = specialize TList<integer>;
 
 var
   ilist : TMyIntList;

+ 1 - 1
tests/test/ugeneric3.pp

@@ -5,7 +5,7 @@ interface
 {$mode objfpc}
 
 type
-   TList=generic(_T) class(TObject)
+   generic TList<_T>=class(TObject)
      data : _T;
      procedure Add(item: _T);
    end;

+ 1 - 1
tests/test/ugeneric4.pp

@@ -5,7 +5,7 @@ interface
 {$mode objfpc}
 
 type
-   TList=generic(_T) class(TObject)
+   generic TList<_T>=class(TObject)
      data : _T;
      procedure Fill;
    end;