fcl-passrc: scanner: added modeswitch prefixedattributes, parser: skip attributes

git-svn-id: trunk@37597 -
This commit is contained in:
Mattias Gaertner 2017-11-17 09:49:23 +00:00
parent 19bf7df3fb
commit bfb89bfd0f
5 changed files with 49 additions and 37 deletions

View File

@ -165,6 +165,9 @@ Works:
- array var - array var
ToDo: ToDo:
- Warning: An inherited method is hidden by "constructor Create(TComponent);
- mode delphi: Error: Not all declarations of "Create" are declared with OVERLOAD
-
- for..in..do - for..in..do
- function: enumerator - function: enumerator
- class - class

View File

@ -3256,7 +3256,7 @@ begin
ParseLabels(Declarations); ParseLabels(Declarations);
end; end;
tkSquaredBraceOpen: tkSquaredBraceOpen:
if msIgnoreAttributes in CurrentModeSwitches then if [msPrefixedAttributes,msIgnoreAttributes]*CurrentModeSwitches<>[] then
ParseAttribute(Declarations) ParseAttribute(Declarations)
else else
ParseExcSyntaxError; ParseExcSyntaxError;
@ -4460,10 +4460,11 @@ begin
// Writeln(modcount, curtokentext); // Writeln(modcount, curtokentext);
LastToken:=CurToken; LastToken:=CurToken;
NextToken; NextToken;
if (ModCount in [1,2,3]) and (CurToken = tkEqual) then if (ModCount<=3) and (CurToken = tkEqual) and not (Parent is TPasProcedure) then
begin begin
// for example: const p: procedure = nil; // for example: const p: procedure = nil;
UngetToken; UngetToken;
Engine.FinishScope(stProcedureHeader,Element);
exit; exit;
end; end;
If CurToken=tkSemicolon then If CurToken=tkSemicolon then
@ -4489,8 +4490,8 @@ begin
end; end;
end; end;
ExpectTokens([tkSemicolon,tkEqual]); ExpectTokens([tkSemicolon,tkEqual]);
if curtoken=tkEqual then if CurToken=tkEqual then
ungettoken; UngetToken;
end end
else if IsProc and TokenIsProcedureModifier(Parent,CurTokenString,PM) then else if IsProc and TokenIsProcedureModifier(Parent,CurTokenString,PM) then
HandleProcedureModifier(Parent,PM) HandleProcedureModifier(Parent,PM)
@ -4520,20 +4521,19 @@ begin
end end
else if (CurToken = tkSquaredBraceOpen) then else if (CurToken = tkSquaredBraceOpen) then
begin begin
// [] can be an attribute or FPC's [] modifier if ([msPrefixedAttributes,msIgnoreAttributes]*CurrentModeswitches<>[]) then
if IsProc and ([msFpc, msObjfpc]*CurrentModeswitches<>[]) then
begin begin
// FPC's [] modifier // [attribute]
UngetToken;
break;
end
else
begin
// ToDo: read FPC's [] modifiers, e.g. [public,alias:'']
repeat repeat
NextToken NextToken
until CurToken = tkSquaredBraceClose; until CurToken = tkSquaredBraceClose;
ExpectToken(tkSemicolon); ExpectToken(tkSemicolon);
end
else
begin
// attribute
UngetToken;
Exit;
end; end;
end end
else else
@ -5994,7 +5994,7 @@ begin
HaveClass:=False; HaveClass:=False;
end; end;
tkSquaredBraceOpen: tkSquaredBraceOpen:
if msIgnoreAttributes in CurrentModeswitches then if [msPrefixedAttributes,msIgnoreAttributes]*CurrentModeswitches<>[] then
ParseAttribute(AType) ParseAttribute(AType)
else else
CheckToken(tkIdentifier); CheckToken(tkIdentifier);

View File

@ -263,6 +263,7 @@ type
msISOLikeProgramsPara, { program parameters as it required by an ISO compatible compiler } msISOLikeProgramsPara, { program parameters as it required by an ISO compatible compiler }
msISOLikeMod, { mod operation as it is required by an iso compatible compiler } msISOLikeMod, { mod operation as it is required by an iso compatible compiler }
msExternalClass, { Allow external class definitions } msExternalClass, { Allow external class definitions }
msPrefixedAttributes, { Allow attributes, disable proc modifier [] }
msIgnoreInterfaces, { workaround til resolver/converter supports interfaces } msIgnoreInterfaces, { workaround til resolver/converter supports interfaces }
msIgnoreAttributes { workaround til resolver/converter supports attributes } msIgnoreAttributes { workaround til resolver/converter supports attributes }
); );
@ -822,6 +823,7 @@ const
'ISOPROGRAMPARAS', 'ISOPROGRAMPARAS',
'ISOMOD', 'ISOMOD',
'EXTERNALCLASS', 'EXTERNALCLASS',
'PREFIXEDATTRIBUTES',
'IGNOREINTERFACES', 'IGNOREINTERFACES',
'IGNOREATTRIBUTES' 'IGNOREATTRIBUTES'
); );
@ -857,7 +859,7 @@ const
const const
AllLanguageModes = [msFPC,msObjFPC,msDelphi,msTP7,msMac,msISO,msExtPas]; AllLanguageModes = [msFPC,msObjFPC,msDelphi,msTP7,msMac,msISO,msExtPas];
Const const
MessageTypeNames : Array[TMessageType] of string = ( MessageTypeNames : Array[TMessageType] of string = (
'Fatal','Error','Warning','Note','Hint','Info','Debug' 'Fatal','Error','Warning','Note','Hint','Info','Debug'
); );
@ -866,33 +868,37 @@ const
// all mode switches supported by FPC // all mode switches supported by FPC
msAllFPCModeSwitches = [low(TModeSwitch)..High(TModeSwitch)]; msAllFPCModeSwitches = [low(TModeSwitch)..High(TModeSwitch)];
DelphiModeSwitches = [msDelphi,msClass,msObjpas,msresult,msstringpchar, DelphiModeSwitches = [msDelphi,msClass,msObjpas,msResult,msStringPchar,
mspointer2procedure,msautoderef,msTPprocvar,msinitfinal,msdefaultansistring, msPointer2Procedure,msAutoDeref,msTPProcVar,msInitFinal,msDefaultAnsistring,
msout,msdefaultpara,msduplicatenames,mshintdirective, msOut,msDefaultPara,msDuplicateNames,msHintDirective,
msproperty,msdefaultinline,msexcept,msadvancedrecords,mstypehelpers]; msProperty,msDefaultInline,msExcept,msAdvancedRecords,msTypeHelpers,
msPrefixedAttributes
];
DelphiUnicodeModeSwitches = delphimodeswitches + [mssystemcodepage,msdefaultunicodestring]; DelphiUnicodeModeSwitches = delphimodeswitches + [msSystemCodePage,msDefaultUnicodestring];
// mode switches of $mode FPC, don't confuse with msAllFPCModeSwitches // mode switches of $mode FPC, don't confuse with msAllFPCModeSwitches
FPCModeSwitches = [msfpc,msstringpchar,msnestedcomment,msrepeatforward, FPCModeSwitches = [msFpc,msStringPchar,msNestedComment,msRepeatForward,
mscvarsupport,msinitfinal,mshintdirective, msproperty,msdefaultinline]; msCVarSupport,msInitFinal,msHintDirective,msProperty,msDefaultInline];
OBJFPCModeSwitches = [msobjfpc,msclass,msobjpas,msresult,msstringpchar,msnestedcomment, OBJFPCModeSwitches = [msObjfpc,msClass,msObjpas,msResult,msStringPchar,msNestedComment,
msrepeatforward,mscvarsupport,msinitfinal,msout,msdefaultpara,mshintdirective, msRepeatForward,msCVarSupport,msInitFinal,msOut,msDefaultPara,msHintDirective,
msproperty,msdefaultinline,msexcept]; msProperty,msDefaultInline,msExcept];
TPModeSwitches = [mstp7,mstpprocvar,msduplicatenames]; TPModeSwitches = [msTP7,msTPProcVar,msDuplicateNames];
GPCModeSwitches = [msgpc,mstpprocvar]; GPCModeSwitches = [msGPC,msTPProcVar];
MacModeSwitches = [msmac,mscvarsupport,msmacprocvar,msnestedprocvars,msnonlocalgoto, MacModeSwitches = [msMac,msCVarSupport,msMacProcVar,msNestedProcVars,
msisolikeunaryminus,msdefaultinline]; msNonLocalGoto,msISOLikeUnaryMinus,msDefaultInline];
ISOModeSwitches = [msiso,mstpprocvar,msduplicatenames,msnestedprocvars,msnonlocalgoto,msisolikeunaryminus,msisolikeio, ISOModeSwitches = [msIso,msTPProcVar,msDuplicateNames,msNestedProcVars,
msisolikeprogramspara, msisolikemod]; msNonLocalGoto,msISOLikeUnaryMinus,msISOLikeIO,msISOLikeProgramsPara,
msISOLikeMod];
ExtPasModeSwitches = [msextpas,mstpprocvar,msduplicatenames,msnestedprocvars,msnonlocalgoto,msisolikeunaryminus,msisolikeio, ExtPasModeSwitches = [msExtpas,msTPProcVar,msDuplicateNames,msNestedProcVars,
msisolikeprogramspara, msisolikemod]; msNonLocalGoto,msISOLikeUnaryMinus,msISOLikeIO,msISOLikeProgramsPara,
msISOLikeMod];
function StrToModeSwitch(aName: String): TModeSwitch; function StrToModeSwitch(aName: String): TModeSwitch;
function FilenameIsAbsolute(const TheFilename: string):boolean; function FilenameIsAbsolute(const TheFilename: string):boolean;

View File

@ -11065,7 +11065,7 @@ procedure TTestResolver.TestAttributes_Ignore;
begin begin
StartProgram(false); StartProgram(false);
Add([ Add([
'{$modeswitch ignoreattributes}', '{$modeswitch IgnoreAttributes}',
'type', 'type',
' [custom1, custom2(1+3,''foo'')] [mod1.custom3]', ' [custom1, custom2(1+3,''foo'')] [mod1.custom3]',
' TObject = class', ' TObject = class',
@ -11077,6 +11077,10 @@ begin
' [Attr]', ' [Attr]',
' TBird = class(TObject)', ' TBird = class(TObject)',
' end;', ' end;',
'[Attr]',
'procedure DoA; forward;',
'[Attr]',
'procedure DoA; begin end;',
'var', 'var',
' [custom6]', ' [custom6]',
' o: TObject;', ' o: TObject;',

View File

@ -446,8 +446,7 @@ begin
if (tk=tkLineEnding) and not (t in [tkEOF,tkLineEnding]) then if (tk=tkLineEnding) and not (t in [tkEOF,tkLineEnding]) then
tk:=FScanner.FetchToken; tk:=FScanner.FetchToken;
AssertEquals('EOF reached.',tkEOF,FScanner.FetchToken); AssertEquals('EOF reached.',tkEOF,FScanner.FetchToken);
end end;
end; end;
procedure TTestScanner.TestToken(t: TToken; const ASource: String; procedure TTestScanner.TestToken(t: TToken; const ASource: String;
@ -463,7 +462,7 @@ begin
DoTestToken(t,S); DoTestToken(t,S);
end; end;
DoTestToken(t,UpperCase(ASource)); DoTestToken(t,UpperCase(ASource));
DoTestToken(t,LowerCase(ASource)); DoTestToken(t,LowerCase(ASource),CheckEOF);
end; end;
procedure TTestScanner.TestTokens(t: array of TToken; const ASource: String; procedure TTestScanner.TestTokens(t: array of TToken; const ASource: String;