JCF: Implement basic generics support. Issue #16128, patch from Julian Puhl.

git-svn-id: trunk@46971 -
This commit is contained in:
juha 2014-11-23 16:24:49 +00:00
parent 579e8170bd
commit 8f66caf323
5 changed files with 25 additions and 4 deletions

View File

@ -143,6 +143,7 @@ type
procedure RecogniseRecordBody;
procedure RecogniseRecVariant;
procedure RecogniseRestrictedType;
procedure RecogniseSpecializeType;
procedure RecogniseSetType;
procedure RecogniseSimpleType;
procedure RecogniseStringType;
@ -1160,6 +1161,13 @@ begin
PushNode(nTypeDecl);
//Recognise generic keyword (for fpc)
if (fcTokenList.FirstSolidTokenType = ttGeneric) then
begin
Recognise(ttGeneric);
end;
// Delph.Net Attribute?
if (fcTokenList.FirstSolidTokenType = ttOpenSquareBracket) then
RecogniseAttributes;
@ -1582,6 +1590,8 @@ begin
ttArray, ttSet, ttFile, ttRecord:
RecogniseStrucType;
ttSpecialize:
RecogniseSpecializeType;
ttHat:
RecognisePointerType;
ttString, ttAnsiString, ttWideString:
@ -1840,6 +1850,13 @@ begin
Recognise([ttAnsiString, ttWideString]);
end;
//Recognise specialize keyword in type definition (for fpc)
procedure TBuildParseTree.RecogniseSpecializeType;
begin
Recognise(ttSpecialize);
RecogniseType;
end;
procedure TBuildParseTree.RecogniseStrucType;
var
lc: TSourceToken;

View File

@ -131,6 +131,7 @@ type
ttRequires,
ttResourcestring,
ttSet,
ttSpecialize,
ttThen,
ttThreadvar,
ttTo,
@ -184,6 +185,7 @@ type
ttLocal,
ttImplements,
ttReintroduce,
ttGeneric,
// used in asm
ttOffset,
@ -604,6 +606,7 @@ begin
AddKeyword('repeat', wtReservedWord, ttRepeat);
AddKeyword('resourcestring', wtReservedWord, ttResourceString);
AddKeyword('set', wtReservedWord, ttSet);
AddKeyword('specialize', wtReservedWord, ttSpecialize);
AddKeyword('then', wtReservedWord, ttThen);
AddKeyword('threadvar', wtReservedWord, ttThreadvar);
AddKeyword('to', wtReservedWord, ttTo);
@ -660,6 +663,7 @@ begin
AddKeyword('overload', wtReservedWordDirective, ttOverload);
AddKeyword('resident', wtReservedWordDirective, ttResident);
AddKeyword('local', wtReservedWordDirective, ttLocal);
AddKeyword('generic', wtReservedWordDirective, ttGeneric);
AddKeyword('implements', wtReservedWordDirective, ttImplements);
AddKeyword('reintroduce', wtReservedWordDirective, ttReintroduce);

View File

@ -77,7 +77,7 @@ end;
function TNoReturnAfter.NeedsNoReturn(const pt: TSourceToken): boolean;
const
NoReturnWords: TTokenTypeSet = [ttProcedure, ttFunction,
ttConstructor, ttDestructor, ttProperty, ttGoto];
ttConstructor, ttDestructor, ttProperty, ttGoto, ttGeneric];
var
lcSetReturns: TSetReturns;
lcNext, lcNext2: TSourceToken;

View File

@ -99,8 +99,8 @@ begin
lcPrev := pt.PriorSolidToken;
// not if there's an attibute before the identifier
if (lcPrev.TokenType = ttCloseSquareBracket) and (lcPrev.HasParentNode(nAttribute)) then
// not if there's an attibute or generic keyword before the identifier
if (lcPrev.TokenType = ttCloseSquareBracket) and (lcPrev.HasParentNode(nAttribute)) or (lcPrev.TokenType = ttGeneric) then
exit;
if (lcPrev <> nil) and (lcPrev.TokenType <> ttType) then

View File

@ -61,7 +61,7 @@ const
SingleSpaceAfterWords: TTokenTypeSet = [
ttProcedure, ttFunction,
ttConstructor, ttDestructor, ttProperty,
ttOf, ttDo, ttWhile, ttUntil, ttCase, ttIf, ttTo, ttDownTo];
ttOf, ttDo, ttWhile, ttUntil, ttCase, ttIf, ttTo, ttDownTo, ttGeneric];
PossiblyUnaryOperators: TTokenTypeSet = [ttPlus, ttMinus];