mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 00:59:08 +02:00
* enabled type and var keywords in objects for generics
git-svn-id: trunk@5062 -
This commit is contained in:
parent
d4d4309e44
commit
ca6f992504
@ -38,6 +38,7 @@ interface
|
|||||||
procedure const_dec;
|
procedure const_dec;
|
||||||
procedure label_dec;
|
procedure label_dec;
|
||||||
procedure type_dec;
|
procedure type_dec;
|
||||||
|
procedure types_dec;
|
||||||
procedure var_dec;
|
procedure var_dec;
|
||||||
procedure threadvar_dec;
|
procedure threadvar_dec;
|
||||||
procedure property_dec;
|
procedure property_dec;
|
||||||
@ -369,8 +370,7 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ reads a type declaration to the symbol table }
|
procedure types_dec;
|
||||||
procedure type_dec;
|
|
||||||
|
|
||||||
function parse_generic_parameters:TFPObjectList;
|
function parse_generic_parameters:TFPObjectList;
|
||||||
var
|
var
|
||||||
@ -405,7 +405,6 @@ implementation
|
|||||||
begin
|
begin
|
||||||
old_block_type:=block_type;
|
old_block_type:=block_type;
|
||||||
block_type:=bt_type;
|
block_type:=bt_type;
|
||||||
consume(_TYPE);
|
|
||||||
typecanbeforward:=true;
|
typecanbeforward:=true;
|
||||||
repeat
|
repeat
|
||||||
defpos:=akttokenpos;
|
defpos:=akttokenpos;
|
||||||
@ -605,6 +604,14 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ reads a type declaration to the symbol table }
|
||||||
|
procedure type_dec;
|
||||||
|
begin
|
||||||
|
consume(_TYPE);
|
||||||
|
types_dec;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure var_dec;
|
procedure var_dec;
|
||||||
{ parses variable declarations and inserts them in }
|
{ parses variable declarations and inserts them in }
|
||||||
{ the top symbol table of symtablestack }
|
{ the top symbol table of symtablestack }
|
||||||
|
@ -40,7 +40,7 @@ implementation
|
|||||||
symconst,symbase,symsym,symtable,
|
symconst,symbase,symsym,symtable,
|
||||||
node,nld,nmem,ncon,ncnv,ncal,
|
node,nld,nmem,ncon,ncnv,ncal,
|
||||||
scanner,
|
scanner,
|
||||||
pbase,pexpr,pdecsub,pdecvar,ptype
|
pbase,pexpr,pdecsub,pdecvar,ptype,pdecl
|
||||||
;
|
;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -505,6 +505,7 @@ implementation
|
|||||||
dummysymoptions : tsymoptions;
|
dummysymoptions : tsymoptions;
|
||||||
i : longint;
|
i : longint;
|
||||||
generictype : ttypesym;
|
generictype : ttypesym;
|
||||||
|
current_blocktype : tblock_type;
|
||||||
begin
|
begin
|
||||||
old_object_option:=current_object_option;
|
old_object_option:=current_object_option;
|
||||||
|
|
||||||
@ -564,9 +565,20 @@ implementation
|
|||||||
{ short class declaration ? }
|
{ short class declaration ? }
|
||||||
if (classtype<>odt_class) or (token<>_SEMICOLON) then
|
if (classtype<>odt_class) or (token<>_SEMICOLON) then
|
||||||
begin
|
begin
|
||||||
{ Parse componenten }
|
{ Parse componenten }
|
||||||
|
current_blocktype:=bt_general;
|
||||||
repeat
|
repeat
|
||||||
case token of
|
case token of
|
||||||
|
_TYPE :
|
||||||
|
begin
|
||||||
|
consume(_TYPE);
|
||||||
|
current_blocktype:=bt_type;
|
||||||
|
end;
|
||||||
|
_VAR :
|
||||||
|
begin
|
||||||
|
consume(_VAR);
|
||||||
|
current_blocktype:=bt_general;
|
||||||
|
end;
|
||||||
_ID :
|
_ID :
|
||||||
begin
|
begin
|
||||||
case idtoken of
|
case idtoken of
|
||||||
@ -639,7 +651,10 @@ implementation
|
|||||||
not(oo_can_have_published in aktobjectdef.objectoptions) then
|
not(oo_can_have_published in aktobjectdef.objectoptions) then
|
||||||
Message(parser_e_cant_have_published);
|
Message(parser_e_cant_have_published);
|
||||||
|
|
||||||
read_record_fields([vd_object]);
|
if current_blocktype=bt_general then
|
||||||
|
read_record_fields([vd_object])
|
||||||
|
else
|
||||||
|
types_dec;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -21,15 +21,19 @@ unit fgl;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
const
|
||||||
|
MaxListSize = Maxint div 16;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TFPList class }
|
{ TFPList class }
|
||||||
generic TGList<TG> = class(TObject)
|
generic TGList<TG> = class(TObject)
|
||||||
type
|
type
|
||||||
PTGList = ^TPointerList;
|
PTGList = ^TTGList;
|
||||||
TTGList = array[0..MaxListSize - 1] of TG;
|
TTGList = array[0..MaxListSize - 1] of TG;
|
||||||
TListSortCompare = function (Item1, Item2: TG): Integer;
|
TListSortCompare = function (Item1, Item2: TG): Integer;
|
||||||
TListCallback = procedure(data,arg: TG) of object;
|
TListCallback = procedure(data,arg: TG) of object;
|
||||||
TListStaticCallback = procedure(data,arg: TG);
|
TListStaticCallback = procedure(data,arg: TG);
|
||||||
|
var
|
||||||
private
|
private
|
||||||
FList: PTGList;
|
FList: PTGList;
|
||||||
FCount: Integer;
|
FCount: Integer;
|
||||||
@ -68,6 +72,9 @@ unit fgl;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
rtlconsts,sysutils,classes;
|
||||||
|
|
||||||
{****************************************************************************}
|
{****************************************************************************}
|
||||||
{* TGList *}
|
{* TGList *}
|
||||||
{****************************************************************************}
|
{****************************************************************************}
|
||||||
@ -94,7 +101,7 @@ unit fgl;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TGList.Extract(item: Pointer): Pointer;
|
function TGList.Extract(const item: TG): TG;
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
begin
|
begin
|
||||||
@ -146,7 +153,7 @@ unit fgl;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TGList.Add(Item: Pointer): Integer; inline;
|
function TGList.Add(const Item: TG): Integer; inline;
|
||||||
begin
|
begin
|
||||||
if FCount = FCapacity then
|
if FCount = FCapacity then
|
||||||
Self.Expand;
|
Self.Expand;
|
||||||
@ -225,7 +232,7 @@ unit fgl;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TGList.IndexOf(Item: Pointer): Integer;
|
function TGList.IndexOf(const Item: TG): Integer;
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
while(Result < FCount) and (Flist^[Result] <> Item) do Result := Result + 1;
|
while(Result < FCount) and (Flist^[Result] <> Item) do Result := Result + 1;
|
||||||
@ -271,7 +278,7 @@ unit fgl;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TGList.Remove(Item: Pointer): Integer;
|
function TGList.Remove(const Item: TG): Integer;
|
||||||
begin
|
begin
|
||||||
Result := IndexOf(Item);
|
Result := IndexOf(Item);
|
||||||
If Result <> -1 then
|
If Result <> -1 then
|
||||||
@ -285,9 +292,11 @@ unit fgl;
|
|||||||
Runner : Longint;
|
Runner : Longint;
|
||||||
begin
|
begin
|
||||||
// Not the fastest; but surely correct
|
// Not the fastest; but surely correct
|
||||||
|
{
|
||||||
for Runner := Fcount - 1 downto 0 do
|
for Runner := Fcount - 1 downto 0 do
|
||||||
if Items[Runner] = Nil then
|
if Items[Runner] = Nil then
|
||||||
Self.Delete(Runner);
|
Self.Delete(Runner);
|
||||||
|
}
|
||||||
{ The following may be faster in case of large and defragmented lists
|
{ The following may be faster in case of large and defragmented lists
|
||||||
If count=0 then exit;
|
If count=0 then exit;
|
||||||
Runner:=0;I:=0;
|
Runner:=0;I:=0;
|
||||||
|
Loading…
Reference in New Issue
Block a user