mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 16:59:12 +02:00
* make generic basics working again
git-svn-id: trunk@2458 -
This commit is contained in:
parent
05bac3dceb
commit
a59690b147
@ -393,6 +393,7 @@ implementation
|
|||||||
defpos,storetokenpos : tfileposinfo;
|
defpos,storetokenpos : tfileposinfo;
|
||||||
old_block_type : tblock_type;
|
old_block_type : tblock_type;
|
||||||
ch : tclassheader;
|
ch : tclassheader;
|
||||||
|
isgeneric,
|
||||||
isunique,
|
isunique,
|
||||||
istyperenaming : boolean;
|
istyperenaming : boolean;
|
||||||
generictypelist : tsinglelist;
|
generictypelist : tsinglelist;
|
||||||
@ -408,32 +409,26 @@ implementation
|
|||||||
generictypelist:=nil;
|
generictypelist:=nil;
|
||||||
generictokenbuf:=nil;
|
generictokenbuf:=nil;
|
||||||
|
|
||||||
|
{ generic declaration? }
|
||||||
|
isgeneric:=try_to_consume(_GENERIC);
|
||||||
|
|
||||||
typename:=pattern;
|
typename:=pattern;
|
||||||
orgtypename:=orgpattern;
|
orgtypename:=orgpattern;
|
||||||
consume(_ID);
|
consume(_ID);
|
||||||
|
|
||||||
{$ifdef GENERICSHARPBRACKET}
|
|
||||||
{ Generic type declaration? }
|
{ Generic type declaration? }
|
||||||
if try_to_consume(_LSHARPBRACKET) then
|
if isgeneric then
|
||||||
begin
|
begin
|
||||||
|
consume(_LSHARPBRACKET);
|
||||||
generictypelist:=parse_generic_parameters;
|
generictypelist:=parse_generic_parameters;
|
||||||
consume(_RSHARPBRACKET);
|
consume(_RSHARPBRACKET);
|
||||||
end;
|
end;
|
||||||
{$endif GENERICSHARPBRACKET}
|
|
||||||
|
|
||||||
consume(_EQUAL);
|
consume(_EQUAL);
|
||||||
|
|
||||||
{ support 'ttype=type word' syntax }
|
{ support 'ttype=type word' syntax }
|
||||||
isunique:=try_to_consume(_TYPE);
|
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 }
|
{ MacPas object model is more like Delphi's than like TP's, but }
|
||||||
{ uses the object keyword instead of class }
|
{ uses the object keyword instead of class }
|
||||||
if (m_mac in aktmodeswitches) and
|
if (m_mac in aktmodeswitches) and
|
||||||
|
@ -90,24 +90,16 @@ implementation
|
|||||||
Comment(V_Error,'Specialization is only supported for generic types');
|
Comment(V_Error,'Specialization is only supported for generic types');
|
||||||
pt1.resulttype:=generrortype;
|
pt1.resulttype:=generrortype;
|
||||||
{ recover }
|
{ recover }
|
||||||
{$ifdef GENERICSHARPBRACKET}
|
|
||||||
consume(_LSHARPBRACKET);
|
consume(_LSHARPBRACKET);
|
||||||
{$endif GENERICSHARPBRACKET}
|
|
||||||
consume(_LKLAMMER);
|
|
||||||
repeat
|
repeat
|
||||||
pt2:=factor(false);
|
pt2:=factor(false);
|
||||||
pt2.free;
|
pt2.free;
|
||||||
until not try_to_consume(_COMMA);
|
until not try_to_consume(_COMMA);
|
||||||
{$ifdef GENERICSHARPBRACKET}
|
|
||||||
consume(_RSHARPBRACKET);
|
consume(_RSHARPBRACKET);
|
||||||
{$endif GENERICSHARPBRACKET}
|
|
||||||
consume(_RKLAMMER);
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{$ifdef GENERICSHARPBRACKET}
|
|
||||||
consume(_LSHARPBRACKET);
|
consume(_LSHARPBRACKET);
|
||||||
{$endif GENERICSHARPBRACKET}
|
block_type:=bt_specialize;
|
||||||
consume(_LKLAMMER);
|
|
||||||
{ Parse generic parameters, for each undefineddef in the symtable of
|
{ Parse generic parameters, for each undefineddef in the symtable of
|
||||||
the genericdef we need to have a new def }
|
the genericdef we need to have a new def }
|
||||||
err:=false;
|
err:=false;
|
||||||
@ -159,10 +151,7 @@ implementation
|
|||||||
try_to_consume(_SEMICOLON);
|
try_to_consume(_SEMICOLON);
|
||||||
end;
|
end;
|
||||||
generictypelist.free;
|
generictypelist.free;
|
||||||
{$ifdef GENERICSHARPBRACKET}
|
|
||||||
consume(_RSHARPBRACKET);
|
consume(_RSHARPBRACKET);
|
||||||
{$endif GENERICSHARPBRACKET}
|
|
||||||
consume(_RKLAMMER);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -3583,7 +3583,7 @@ In case not, the value returned can be arbitrary.
|
|||||||
'>' :
|
'>' :
|
||||||
begin
|
begin
|
||||||
readchar;
|
readchar;
|
||||||
if (block_type=bt_type) then
|
if (block_type in [bt_type,bt_specialize]) then
|
||||||
token:=_RSHARPBRACKET
|
token:=_RSHARPBRACKET
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -3615,7 +3615,7 @@ In case not, the value returned can be arbitrary.
|
|||||||
'<' :
|
'<' :
|
||||||
begin
|
begin
|
||||||
readchar;
|
readchar;
|
||||||
if (block_type=bt_type) then
|
if (block_type in [bt_type,bt_specialize]) then
|
||||||
token:=_LSHARPBRACKET
|
token:=_LSHARPBRACKET
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
|
||||||
type
|
type
|
||||||
TList=generic(_T) class(TObject)
|
generic TList<_T>=class(TObject)
|
||||||
data : _T;
|
data : _T;
|
||||||
procedure Add(item: _T);
|
procedure Add(item: _T);
|
||||||
end;
|
end;
|
||||||
@ -12,8 +12,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyIntList = specialize TList(integer);
|
TMyIntList = specialize TList<integer>;
|
||||||
TMyStringList = specialize TList(string);
|
TMyStringList = specialize TList<string>;
|
||||||
|
|
||||||
var
|
var
|
||||||
ilist : TMyIntList;
|
ilist : TMyIntList;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
|
||||||
type
|
type
|
||||||
TList=generic(_T) class(TObject)
|
generic TList<_T>=class(TObject)
|
||||||
data : _T;
|
data : _T;
|
||||||
procedure Add(item: _T);
|
procedure Add(item: _T);
|
||||||
end;
|
end;
|
||||||
@ -18,7 +18,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyStringList = specialize TList(string);
|
TMyStringList = specialize TList<string>;
|
||||||
|
|
||||||
var
|
var
|
||||||
slist : TMyStringList;
|
slist : TMyStringList;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
uses ugeneric3;
|
uses ugeneric3;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyStringList = specialize TList(string);
|
TMyStringList = specialize TList<string>;
|
||||||
|
|
||||||
var
|
var
|
||||||
slist : TMyStringList;
|
slist : TMyStringList;
|
||||||
|
@ -6,7 +6,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyStringList = specialize TList(string);
|
TMyStringList = specialize TList<string>;
|
||||||
|
|
||||||
var
|
var
|
||||||
slist : TMyStringList;
|
slist : TMyStringList;
|
||||||
|
@ -4,7 +4,7 @@ uses
|
|||||||
typinfo;
|
typinfo;
|
||||||
|
|
||||||
type
|
type
|
||||||
TList=generic(_T) class(TObject)
|
generic TList<_T>=class(TObject)
|
||||||
data : _T;
|
data : _T;
|
||||||
procedure Add(item: _T);
|
procedure Add(item: _T);
|
||||||
end;
|
end;
|
||||||
@ -33,7 +33,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyIntList = specialize TList(integer);
|
TMyIntList = specialize TList<integer>;
|
||||||
|
|
||||||
var
|
var
|
||||||
ilist : TMyIntList;
|
ilist : TMyIntList;
|
||||||
|
@ -5,7 +5,7 @@ interface
|
|||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
|
||||||
type
|
type
|
||||||
TList=generic(_T) class(TObject)
|
generic TList<_T>=class(TObject)
|
||||||
data : _T;
|
data : _T;
|
||||||
procedure Add(item: _T);
|
procedure Add(item: _T);
|
||||||
end;
|
end;
|
||||||
|
@ -5,7 +5,7 @@ interface
|
|||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
|
||||||
type
|
type
|
||||||
TList=generic(_T) class(TObject)
|
generic TList<_T>=class(TObject)
|
||||||
data : _T;
|
data : _T;
|
||||||
procedure Fill;
|
procedure Fill;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user