codetools: added compiler mode pas2js

git-svn-id: trunk@54284 -
This commit is contained in:
mattias 2017-02-26 22:18:28 +00:00
parent 9a860927f8
commit 9a663cc51d
4 changed files with 44 additions and 19 deletions

View File

@ -157,6 +157,7 @@ var
WordIsPredefinedDelphiIdentifier,
UnexpectedKeyWordInBeginBlock,
UnexpectedKeyWordInAsmBlock,
UnexpectedKeyWordInAsmPas2JSBlock,
UnexpectedKeyWordInBrackets
: TKeyWordFunctionList;
UpChars: array[char] of char;
@ -1419,6 +1420,16 @@ begin
Add('VAR',{$ifdef FPC}@{$endif}AllwaysTrue);
end;
UnexpectedKeyWordInAsmPas2JSBlock:=TKeyWordFunctionList.Create('UnexpectedKeyWordInAsmPas2JSBlock');
KeyWordLists.Add(UnexpectedKeyWordInAsmPas2JSBlock);
with UnexpectedKeyWordInAsmBlock do begin
Add('ASSEMBLER',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('BEGIN',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('FINALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('INITIALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('PROCEDURE',{$ifdef FPC}@{$endif}AllwaysTrue);
end;
UnexpectedKeyWordInBrackets:=TKeyWordFunctionList.Create('UnexpectedKeyWordInBrackets');
KeyWordLists.Add(UnexpectedKeyWordInBrackets);
with UnexpectedKeyWordInBrackets do begin

View File

@ -157,7 +157,9 @@ type
cmTP,
cmOBJFPC,
cmMacPas,
cmISO);
cmISO,
cmPas2Js
);
{ TCompilerModeSwitch - see fpc/compiler/globtype.pas tmodeswitch }
TCompilerModeSwitch = (
cmsAdd_pointer, { ? }
@ -228,7 +230,11 @@ const
cmsISOLike_unary_minus,cmsDefault_inline],
// cmISO
[cmsTp_procvar,cmsDuplicate_names,cmsNestedProcVars,cmsNonLocalGoto,
cmsISOLike_unary_minus]
cmsISOLike_unary_minus],
// cmPas2Js
[cmsNested_comment,cmsRepeat_forward,
cmsInitfinal,cmsHintdirective,cmsProperty,cmsDefault_inline,
cmsResult]
);
type
@ -753,8 +759,16 @@ type
const
// upper case
CompilerModeNames: array[TCompilerMode] of shortstring=(
'FPC', 'DELPHI', 'DELPHIUNICODE', 'GPC', 'TP', 'OBJFPC', 'MACPAS', 'ISO'
);
'FPC',
'DELPHI',
'DELPHIUNICODE',
'GPC',
'TP',
'OBJFPC',
'MACPAS',
'ISO',
'PAS2JS'
);
// upper case (see fpc/compiler/globtype.pas modeswitchstr )
CompilerModeSwitchNames: array[TCompilerModeSwitch] of shortstring=(
@ -3405,7 +3419,7 @@ begin
FDirectives[FDirectivesCount-1].Kind:=lsdkMode;
ReadSpace;
ValStart:=SrcPos;
while (SrcPos<=SrcLen) and (IsWordChar[Src[SrcPos]]) do
while (SrcPos<=SrcLen) and (IsIdentChar[Src[SrcPos]]) do
inc(SrcPos);
// undefine all mode macros
for AMode:=Low(TCompilerMode) to High(TCompilerMode) do

View File

@ -2835,7 +2835,6 @@ begin
BlockStartPos:=CurPos.StartPos;
repeat
ReadNextAtom;
//debugln(['TPascalParserTool.ReadTilBlockEnd next=',GetAtom]);
if (CurPos.StartPos>SrcLen) then
SaveRaiseExceptionWithBlockStartHint(ctsUnexpectedEndOfSource);
@ -2855,6 +2854,16 @@ begin
UndoReadNextAtom;
break;
end;
end else if BlockType=ebtAsm then begin
if (Src[CurPos.StartPos-1]='@') then begin
// allow anything behind @
end else if (CurPos.Flag=cafWord) then begin
if Scanner.CompilerMode=cmPas2Js then begin
if UnexpectedKeyWordInAsmPas2JSBlock.DoIdentifier(@Src[CurPos.StartPos]) then
SaveRaiseUnexpectedKeyWordInBeginEndBlock;
end else if UnexpectedKeyWordInAsmBlock.DoIdentifier(@Src[CurPos.StartPos]) then
SaveRaiseUnexpectedKeyWordInBeginEndBlock;
end;
end else if CurPos.Flag=cafSemicolon then begin
// ;
if BlockType=ebtIf then begin
@ -2863,13 +2872,9 @@ begin
end;
end else if CurPos.Flag<>cafWord then begin
continue;
end else if (BlockType=ebtAsm) and (Src[CurPos.StartPos-1]='@') then begin
// allow anything behind @
end else if BlockStatementStartKeyWordFuncList.DoIdentifier(@Src[CurPos.StartPos])
then begin
if BlockType=ebtAsm then begin
SaveRaiseUnexpectedKeyWordInAsmBlock;
end else if (BlockType<>ebtRecord) then begin
if (BlockType<>ebtRecord) then begin
ReadTilBlockEnd(false,CreateNodes);
if (BlockType=ebtIf) and (CurPos.Flag in [cafSemicolon]) then
break;
@ -2918,15 +2923,9 @@ begin
end else begin
// check for unexpected keywords
case BlockType of
ebtBegin,ebtTry,ebtIf,ebtCase,ebtRepeat:
if UnexpectedKeyWordInBeginBlock.DoIdentifier(@Src[CurPos.StartPos]) then
SaveRaiseUnexpectedKeyWordInBeginEndBlock;
ebtAsm:
if UnexpectedKeyWordInAsmBlock.DoIdentifier(@Src[CurPos.StartPos]) then
SaveRaiseUnexpectedKeyWordInBeginEndBlock;
end;
end;
until false;

View File

@ -34,12 +34,13 @@ implementation
const
// CompilerMode names to be shown after -M...
CompilerModesPretty: array[TCompilerMode] of shortstring = (
'fpc', 'Delphi', 'DelphiUnicode', 'gpc', 'tp', 'ObjFPC', 'MacPas', 'iso'
'fpc', 'Delphi', 'DelphiUnicode', 'gpc', 'tp', 'ObjFPC', 'MacPas', 'iso', 'pas2js'
);
// CompilerMode descriptions.
CompilerModesDescr: array[TCompilerMode] of shortstring = (
'Free Pascal', 'Delphi', 'Delphi Unicode', 'GNU Pascal', 'Turbo Pascal',
'Object Pascal', 'Mac Pascal', 'ISO/IEC 7185 Pascal'
'Object Pascal', 'Mac Pascal', 'ISO/IEC 7185 Pascal',
'Pas2JS - Pascal to JavaScript transpiler'
);
function SyntaxModeToCaption(const ModeStr: string): string;