codetools: fixed use of keywordlists

git-svn-id: trunk@30954 -
This commit is contained in:
mattias 2011-05-29 08:34:20 +00:00
parent 8c9b6e6548
commit 8c39496157
7 changed files with 80 additions and 54 deletions

View File

@ -424,14 +424,14 @@ begin
if KeyWordLists<>nil then exit; if KeyWordLists<>nil then exit;
KeyWordLists:=TFPList.Create; KeyWordLists:=TFPList.Create;
IsCCodeFunctionModifier:=TKeyWordFunctionList.Create; IsCCodeFunctionModifier:=TKeyWordFunctionList.Create('IsCCodeFunctionModifier');
KeyWordLists.Add(IsCCodeFunctionModifier); KeyWordLists.Add(IsCCodeFunctionModifier);
with IsCCodeFunctionModifier do begin with IsCCodeFunctionModifier do begin
Add('static' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('static' ,{$ifdef FPC}@{$endif}AllwaysTrue);
Add('inline' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('inline' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsCCodeCustomOperator:=TKeyWordFunctionList.Create; IsCCodeCustomOperator:=TKeyWordFunctionList.Create('IsCCodeCustomOperator');
KeyWordLists.Add(IsCCodeCustomOperator); KeyWordLists.Add(IsCCodeCustomOperator);
with IsCCodeCustomOperator do begin with IsCCodeCustomOperator do begin
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1183,7 +1183,7 @@ end;
procedure TCCodeParserTool.InitKeyWordList; procedure TCCodeParserTool.InitKeyWordList;
begin begin
if FDefaultTokenList=nil then begin if FDefaultTokenList=nil then begin
FDefaultTokenList:=TKeyWordFunctionList.Create; FDefaultTokenList:=TKeyWordFunctionList.Create('TCCodeParserTool.DefaultTokenList');
with FDefaultTokenList do begin with FDefaultTokenList do begin
Add('#',{$ifdef FPC}@{$endif}DirectiveToken); Add('#',{$ifdef FPC}@{$endif}DirectiveToken);
Add('extern',{$ifdef FPC}@{$endif}ExternToken); Add('extern',{$ifdef FPC}@{$endif}ExternToken);

View File

@ -391,7 +391,7 @@ constructor TCustomCodeTool.Create;
begin begin
inherited Create; inherited Create;
Tree:=TCodeTree.Create; Tree:=TCodeTree.Create;
KeyWordFuncList:=TKeyWordFunctionList.Create; KeyWordFuncList:=TKeyWordFunctionList.Create('TCustomCodeTool.KeyWordFuncList');
BuildDefaultKeyWordFunctions; BuildDefaultKeyWordFunctions;
WordIsKeyWordFuncList:=WordIsKeyWord; WordIsKeyWordFuncList:=WordIsKeyWord;
LastAtoms:=TAtomRing.Create; LastAtoms:=TAtomRing.Create;

View File

@ -3719,13 +3719,13 @@ begin
FCache:=TAVLTree.Create(@CompareDirectoryDefines); FCache:=TAVLTree.Create(@CompareDirectoryDefines);
FDefineStrings:=TStringTree.Create; FDefineStrings:=TStringTree.Create;
FMacroFunctions:=TKeyWordFunctionList.Create; FMacroFunctions:=TKeyWordFunctionList.Create('TDefineTree.Create.MacroFunctions');
FMacroFunctions.AddExtended('Ext',nil,@MacroFuncExtractFileExt); FMacroFunctions.AddExtended('Ext',nil,@MacroFuncExtractFileExt);
FMacroFunctions.AddExtended('PATH',nil,@MacroFuncExtractFilePath); FMacroFunctions.AddExtended('PATH',nil,@MacroFuncExtractFilePath);
FMacroFunctions.AddExtended('NAME',nil,@MacroFuncExtractFileName); FMacroFunctions.AddExtended('NAME',nil,@MacroFuncExtractFileName);
FMacroFunctions.AddExtended('NAMEONLY',nil,@MacroFuncExtractFileNameOnly); FMacroFunctions.AddExtended('NAMEONLY',nil,@MacroFuncExtractFileNameOnly);
FMacroVariables:=TKeyWordFunctionList.Create; FMacroVariables:=TKeyWordFunctionList.Create('TDefineTree.Create.MacroVariables');
end; end;
destructor TDefineTree.Destroy; destructor TDefineTree.Destroy;

View File

@ -596,7 +596,7 @@ var
c: Char; c: Char;
begin begin
if FDefaultDirectiveFuncList=nil then begin if FDefaultDirectiveFuncList=nil then begin
FDefaultDirectiveFuncList:=TKeyWordFunctionList.Create; FDefaultDirectiveFuncList:=TKeyWordFunctionList.Create('TCompilerDirectivesTree.DefaultDirectiveFuncList');
with FDefaultDirectiveFuncList do begin with FDefaultDirectiveFuncList do begin
for c:='A' to 'Z' do begin for c:='A' to 'Z' do begin
if CompilerSwitchesNames[c]<>'' then begin if CompilerSwitchesNames[c]<>'' then begin

View File

@ -56,9 +56,11 @@ type
TBaseKeyWordFunctionList = class TBaseKeyWordFunctionList = class
private private
FHasOnlyIdentifiers: boolean;
FItems: PKeyWordFunctionListItem; FItems: PKeyWordFunctionListItem;
FCount: integer; FCount: integer;
FCapacity: integer; FCapacity: integer;
FName: string;
FSorted: boolean; FSorted: boolean;
FBucketStart: {$ifdef FPC}^{$else}array of {$endif}integer; FBucketStart: {$ifdef FPC}^{$else}array of {$endif}integer;
FMaxHashIndex: integer; FMaxHashIndex: integer;
@ -69,6 +71,8 @@ type
function KeyWordToHashIndex(Start: PChar; Len: integer): integer; function KeyWordToHashIndex(Start: PChar; Len: integer): integer;
public public
DefaultKeyWordFunction: TKeyWordFunction; DefaultKeyWordFunction: TKeyWordFunction;
constructor Create(const aName: string = '');
destructor Destroy; override;
procedure Clear; procedure Clear;
procedure Add(const AKeyWord: shortstring; procedure Add(const AKeyWord: shortstring;
const AFunction: TKeyWordFunction); const AFunction: TKeyWordFunction);
@ -84,9 +88,9 @@ type
function Count: integer; function Count: integer;
function GetItem(Index: integer): TBaseKeyWordFunctionListItem; function GetItem(Index: integer): TBaseKeyWordFunctionListItem;
function IndexOf(const AKeyWord: shortstring): integer; function IndexOf(const AKeyWord: shortstring): integer;
constructor Create;
destructor Destroy; override;
function CalcMemSize: PtrUInt; function CalcMemSize: PtrUInt;
property HasOnlyIdentifiers: boolean read FHasOnlyIdentifiers;
property Name: string read FName write FName;
end; end;
{ TKeyWordFunctionList } { TKeyWordFunctionList }
@ -264,12 +268,14 @@ end;
{ TBaseKeyWordFunctionList } { TBaseKeyWordFunctionList }
constructor TBaseKeyWordFunctionList.Create; constructor TBaseKeyWordFunctionList.Create(const aName: string);
begin begin
inherited Create; inherited Create;
FName:=aName;
FSorted:=true; FSorted:=true;
FMaxHashIndex:=-1; FMaxHashIndex:=-1;
DefaultKeyWordFunction:={$ifdef FPC}@{$endif}AllwaysFalse; DefaultKeyWordFunction:={$ifdef FPC}@{$endif}AllwaysFalse;
FHasOnlyIdentifiers:=true;
end; end;
destructor TBaseKeyWordFunctionList.Destroy; destructor TBaseKeyWordFunctionList.Destroy;
@ -301,6 +307,7 @@ begin
end; end;
FMaxHashIndex:=-1; FMaxHashIndex:=-1;
FSorted:=true; FSorted:=true;
FHasOnlyIdentifiers:=true;
end; end;
function TBaseKeyWordFunctionList.KeyWordToHashIndex( function TBaseKeyWordFunctionList.KeyWordToHashIndex(
@ -378,6 +385,8 @@ begin
DoDataFunction:=ADataFunction; DoDataFunction:=ADataFunction;
end; end;
inc(FCount); inc(FCount);
if (AKeyWord='') or not IsValidIdent(AKeyWord) then
FHasOnlyIdentifiers:=false;
end; end;
procedure TBaseKeyWordFunctionList.Add(List: TBaseKeyWordFunctionList); procedure TBaseKeyWordFunctionList.Add(List: TBaseKeyWordFunctionList);
@ -512,8 +521,20 @@ end;
{ TKeyWordFunctionList } { TKeyWordFunctionList }
function TKeyWordFunctionList.DoIdentifier(Identifier: PChar): boolean; function TKeyWordFunctionList.DoIdentifier(Identifier: PChar): boolean;
procedure RaiseNonIdentifiers;
var
i: Integer;
begin
debugln(['RaiseNonIdentifiers DoIdentifier does not work on this list. Name=',Name]);
for i:=0 to FMaxHashIndex do
debugln([' ',i,'=',FItems[i].KeyWord]);
RaiseCatchableException('TKeyWordFunctionList.DoIdentifier');
end;
var i: integer; var i: integer;
begin begin
if not FHasOnlyIdentifiers then RaiseNonIdentifiers;
if not FSorted then Sort; if not FSorted then Sort;
i:=KeyWordToHashIndex(Identifier); i:=KeyWordToHashIndex(Identifier);
if i>=0 then begin if i>=0 then begin
@ -822,7 +843,7 @@ begin
KeyWordLists:=TFPList.Create; KeyWordLists:=TFPList.Create;
IsKeyWordMethodSpecifier:=TKeyWordFunctionList.Create; IsKeyWordMethodSpecifier:=TKeyWordFunctionList.Create('IsKeyWordMethodSpecifier');
KeyWordLists.Add(IsKeyWordMethodSpecifier); KeyWordLists.Add(IsKeyWordMethodSpecifier);
with IsKeyWordMethodSpecifier do begin with IsKeyWordMethodSpecifier do begin
Add('ABSTRACT' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('ABSTRACT' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -855,7 +876,7 @@ begin
Add('VARARGS' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('VARARGS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsKeyWordProcedureSpecifier:=TKeyWordFunctionList.Create; IsKeyWordProcedureSpecifier:=TKeyWordFunctionList.Create('IsKeyWordProcedureSpecifier');
KeyWordLists.Add(IsKeyWordProcedureSpecifier); KeyWordLists.Add(IsKeyWordProcedureSpecifier);
with IsKeyWordProcedureSpecifier do begin with IsKeyWordProcedureSpecifier do begin
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -893,7 +914,7 @@ begin
Add('WEAKEXTERNAL' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('WEAKEXTERNAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsKeyWordProcedureTypeSpecifier:=TKeyWordFunctionList.Create; IsKeyWordProcedureTypeSpecifier:=TKeyWordFunctionList.Create('IsKeyWordProcedureTypeSpecifier');
KeyWordLists.Add(IsKeyWordProcedureTypeSpecifier); KeyWordLists.Add(IsKeyWordProcedureTypeSpecifier);
with IsKeyWordProcedureTypeSpecifier do begin with IsKeyWordProcedureTypeSpecifier do begin
Add('STDCALL' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('STDCALL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -916,7 +937,7 @@ begin
Add('IS' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('IS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsKeyWordCallingConvention:=TKeyWordFunctionList.Create; IsKeyWordCallingConvention:=TKeyWordFunctionList.Create('IsKeyWordCallingConvention');
KeyWordLists.Add(IsKeyWordCallingConvention); KeyWordLists.Add(IsKeyWordCallingConvention);
with IsKeyWordCallingConvention do begin with IsKeyWordCallingConvention do begin
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -928,7 +949,7 @@ begin
// Note: 'inline' and 'is nested' are not a calling specifiers // Note: 'inline' and 'is nested' are not a calling specifiers
end; end;
IsKeyWordProcedureBracketSpecifier:=TKeyWordFunctionList.Create; IsKeyWordProcedureBracketSpecifier:=TKeyWordFunctionList.Create('IsKeyWordProcedureBracketSpecifier');
KeyWordLists.Add(IsKeyWordProcedureBracketSpecifier); KeyWordLists.Add(IsKeyWordProcedureBracketSpecifier);
with IsKeyWordProcedureBracketSpecifier do begin with IsKeyWordProcedureBracketSpecifier do begin
Add('ALIAS' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('ALIAS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -941,7 +962,7 @@ begin
Add('SAFECALL' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('SAFECALL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsKeyWordSection:=TKeyWordFunctionList.Create; IsKeyWordSection:=TKeyWordFunctionList.Create('IsKeyWordSection');
KeyWordLists.Add(IsKeyWordSection); KeyWordLists.Add(IsKeyWordSection);
with IsKeyWordSection do begin with IsKeyWordSection do begin
Add('PROGRAM',{$ifdef FPC}@{$endif}AllwaysTrue); Add('PROGRAM',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -954,7 +975,7 @@ begin
Add('FINALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue); Add('FINALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsKeyWordInConstAllowed:=TKeyWordFunctionList.Create; IsKeyWordInConstAllowed:=TKeyWordFunctionList.Create('IsKeyWordInConstAllowed');
KeyWordLists.Add(IsKeyWordInConstAllowed); KeyWordLists.Add(IsKeyWordInConstAllowed);
with IsKeyWordInConstAllowed do begin with IsKeyWordInConstAllowed do begin
Add('NOT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('NOT',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -973,7 +994,7 @@ begin
Add('IN',{$ifdef FPC}@{$endif}AllwaysTrue); Add('IN',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsKeyWord:=TKeyWordFunctionList.Create; WordIsKeyWord:=TKeyWordFunctionList.Create('WordIsKeyWord');
KeyWordLists.Add(WordIsKeyWord); KeyWordLists.Add(WordIsKeyWord);
with WordIsKeyWord do begin with WordIsKeyWord do begin
//Add('ON',{$ifdef FPC}@{$endif}AllwaysTrue); // not for Delphi //Add('ON',{$ifdef FPC}@{$endif}AllwaysTrue); // not for Delphi
@ -1048,7 +1069,7 @@ begin
Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsDelphiKeyWord:=TKeyWordFunctionList.Create; WordIsDelphiKeyWord:=TKeyWordFunctionList.Create('WordIsDelphiKeyWord');
KeyWordLists.Add(WordIsDelphiKeyWord); KeyWordLists.Add(WordIsDelphiKeyWord);
with WordIsDelphiKeyWord do begin with WordIsDelphiKeyWord do begin
Add('AS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('AS',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1115,7 +1136,7 @@ begin
Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsMacPasKeyWord:=TKeyWordFunctionList.Create; WordIsMacPasKeyWord:=TKeyWordFunctionList.Create('WordIsMacPasKeyWord');
KeyWordLists.Add(WordIsMacPasKeyWord); KeyWordLists.Add(WordIsMacPasKeyWord);
with WordIsMacPasKeyWord do begin with WordIsMacPasKeyWord do begin
//Add('ON',{$ifdef FPC}@{$endif}AllwaysTrue); // not for Delphi //Add('ON',{$ifdef FPC}@{$endif}AllwaysTrue); // not for Delphi
@ -1190,7 +1211,7 @@ begin
Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
AllKeyWords:=TKeyWordFunctionList.Create; AllKeyWords:=TKeyWordFunctionList.Create('AllKeyWords');
KeyWordLists.Add(AllKeyWords); KeyWordLists.Add(AllKeyWords);
AllKeyWords.Add(WordIsKeyWord); AllKeyWords.Add(WordIsKeyWord);
with AllKeyWords do begin with AllKeyWords do begin
@ -1200,7 +1221,7 @@ begin
Add('OUT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('OUT',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
IsWordBuiltInFunc:=TKeyWordFunctionList.Create; IsWordBuiltInFunc:=TKeyWordFunctionList.Create('IsWordBuiltInFunc');
KeyWordLists.Add(IsWordBuiltInFunc); KeyWordLists.Add(IsWordBuiltInFunc);
with IsWordBuiltInFunc do begin with IsWordBuiltInFunc do begin
Add('LOW' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('LOW' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1234,7 +1255,7 @@ begin
Add('OBJCSELECTOR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('OBJCSELECTOR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsTermOperator:=TKeyWordFunctionList.Create; WordIsTermOperator:=TKeyWordFunctionList.Create('WordIsTermOperator');
KeyWordLists.Add(WordIsTermOperator); KeyWordLists.Add(WordIsTermOperator);
with WordIsTermOperator do begin with WordIsTermOperator do begin
Add('+',{$ifdef FPC}@{$endif}AllwaysTrue); Add('+',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1253,7 +1274,7 @@ begin
Add('IN',{$ifdef FPC}@{$endif}AllwaysTrue); Add('IN',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsPropertySpecifier:=TKeyWordFunctionList.Create; WordIsPropertySpecifier:=TKeyWordFunctionList.Create('WordIsPropertySpecifier');
KeyWordLists.Add(WordIsPropertySpecifier); KeyWordLists.Add(WordIsPropertySpecifier);
with WordIsPropertySpecifier do begin with WordIsPropertySpecifier do begin
Add('INDEX',{$ifdef FPC}@{$endif}AllwaysTrue); Add('INDEX',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1266,7 +1287,7 @@ begin
Add('DISPID',{$ifdef FPC}@{$endif}AllwaysTrue); Add('DISPID',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsBlockKeyWord:=TKeyWordFunctionList.Create; WordIsBlockKeyWord:=TKeyWordFunctionList.Create('WordIsBlockKeyWord');
KeyWordLists.Add(WordIsBlockKeyWord); KeyWordLists.Add(WordIsBlockKeyWord);
with WordIsBlockKeyWord do begin with WordIsBlockKeyWord do begin
Add('ASM',{$ifdef FPC}@{$endif}AllwaysTrue); Add('ASM',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1285,7 +1306,7 @@ begin
Add('UNTIL',{$ifdef FPC}@{$endif}AllwaysTrue); Add('UNTIL',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
EndKeyWordFuncList:=TKeyWordFunctionList.Create; EndKeyWordFuncList:=TKeyWordFunctionList.Create('EndKeyWordFuncList');
KeyWordLists.Add(EndKeyWordFuncList); KeyWordLists.Add(EndKeyWordFuncList);
with EndKeyWordFuncList do begin with EndKeyWordFuncList do begin
Add('BEGIN',{$ifdef FPC}@{$endif}AllwaysTrue); Add('BEGIN',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1295,7 +1316,7 @@ begin
Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue); Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
PackedTypesKeyWordFuncList:=TKeyWordFunctionList.Create; PackedTypesKeyWordFuncList:=TKeyWordFunctionList.Create('PackedTypesKeyWordFuncList');
KeyWordLists.Add(PackedTypesKeyWordFuncList); KeyWordLists.Add(PackedTypesKeyWordFuncList);
with PackedTypesKeyWordFuncList do begin with PackedTypesKeyWordFuncList do begin
Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1305,7 +1326,7 @@ begin
Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue); Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
BitPackedTypesKeyWordFuncList:=TKeyWordFunctionList.Create; BitPackedTypesKeyWordFuncList:=TKeyWordFunctionList.Create('BitPackedTypesKeyWordFuncList');
KeyWordLists.Add(BitPackedTypesKeyWordFuncList); KeyWordLists.Add(BitPackedTypesKeyWordFuncList);
with BitPackedTypesKeyWordFuncList do begin with BitPackedTypesKeyWordFuncList do begin
Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1315,7 +1336,7 @@ begin
Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue); Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
GenericTypesKeyWordFuncList:=TKeyWordFunctionList.Create; GenericTypesKeyWordFuncList:=TKeyWordFunctionList.Create('GenericTypesKeyWordFuncList');
KeyWordLists.Add(GenericTypesKeyWordFuncList); KeyWordLists.Add(GenericTypesKeyWordFuncList);
with GenericTypesKeyWordFuncList do begin with GenericTypesKeyWordFuncList do begin
Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1325,7 +1346,7 @@ begin
Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue); Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
BlockStatementStartKeyWordFuncList:=TKeyWordFunctionList.Create; BlockStatementStartKeyWordFuncList:=TKeyWordFunctionList.Create('BlockStatementStartKeyWordFuncList');
KeyWordLists.Add(BlockStatementStartKeyWordFuncList); KeyWordLists.Add(BlockStatementStartKeyWordFuncList);
with BlockStatementStartKeyWordFuncList do begin with BlockStatementStartKeyWordFuncList do begin
Add('BEGIN' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('BEGIN' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1335,7 +1356,7 @@ begin
Add('CASE' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('CASE' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
UnexpectedKeyWordInBeginBlock:=TKeyWordFunctionList.Create; UnexpectedKeyWordInBeginBlock:=TKeyWordFunctionList.Create('UnexpectedKeyWordInBeginBlock');
KeyWordLists.Add(UnexpectedKeyWordInBeginBlock); KeyWordLists.Add(UnexpectedKeyWordInBeginBlock);
with UnexpectedKeyWordInBeginBlock do begin with UnexpectedKeyWordInBeginBlock do begin
Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1359,7 +1380,7 @@ begin
Add('VAR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('VAR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
UnexpectedKeyWordInAsmBlock:=TKeyWordFunctionList.Create; UnexpectedKeyWordInAsmBlock:=TKeyWordFunctionList.Create('UnexpectedKeyWordInAsmBlock');
KeyWordLists.Add(UnexpectedKeyWordInAsmBlock); KeyWordLists.Add(UnexpectedKeyWordInAsmBlock);
with UnexpectedKeyWordInAsmBlock do begin with UnexpectedKeyWordInAsmBlock do begin
Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('CLASS',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1382,7 +1403,7 @@ begin
Add('VAR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('VAR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
UnexpectedKeyWordInBrackets:=TKeyWordFunctionList.Create; UnexpectedKeyWordInBrackets:=TKeyWordFunctionList.Create('UnexpectedKeyWordInBrackets');
KeyWordLists.Add(UnexpectedKeyWordInBrackets); KeyWordLists.Add(UnexpectedKeyWordInBrackets);
with UnexpectedKeyWordInBrackets do begin with UnexpectedKeyWordInBrackets do begin
Add('BEGIN',{$ifdef FPC}@{$endif}AllwaysTrue); Add('BEGIN',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1400,7 +1421,7 @@ begin
Add('END',{$ifdef FPC}@{$endif}AllwaysTrue); Add('END',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLogicalBlockStart:=TKeyWordFunctionList.Create; WordIsLogicalBlockStart:=TKeyWordFunctionList.Create('WordIsLogicalBlockStart');
KeyWordLists.Add(WordIsLogicalBlockStart); KeyWordLists.Add(WordIsLogicalBlockStart);
with WordIsLogicalBlockStart do begin with WordIsLogicalBlockStart do begin
Add('(',{$ifdef FPC}@{$endif}AllwaysTrue); Add('(',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1433,7 +1454,7 @@ begin
Add('UNIT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('UNIT',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLogicalBlockEnd:=TKeyWordFunctionList.Create; WordIsLogicalBlockEnd:=TKeyWordFunctionList.Create('WordIsLogicalBlockEnd');
KeyWordLists.Add(WordIsLogicalBlockEnd); KeyWordLists.Add(WordIsLogicalBlockEnd);
with WordIsLogicalBlockEnd do begin with WordIsLogicalBlockEnd do begin
Add(')',{$ifdef FPC}@{$endif}AllwaysTrue); Add(')',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1446,14 +1467,14 @@ begin
Add('FINALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue); Add('FINALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLogicalBlockMiddle:=TKeyWordFunctionList.Create; WordIsLogicalBlockMiddle:=TKeyWordFunctionList.Create('WordIsLogicalBlockMiddle');
KeyWordLists.Add(WordIsLogicalBlockMiddle); KeyWordLists.Add(WordIsLogicalBlockMiddle);
with WordIsLogicalBlockMiddle do begin with WordIsLogicalBlockMiddle do begin
Add('FINALLY',{$ifdef FPC}@{$endif}AllwaysTrue); Add('FINALLY',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('EXCEPT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('EXCEPT',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsBlockStatementStart:=TKeyWordFunctionList.Create; WordIsBlockStatementStart:=TKeyWordFunctionList.Create('WordIsBlockStatementStart');
KeyWordLists.Add(WordIsBlockStatementStart); KeyWordLists.Add(WordIsBlockStatementStart);
with WordIsBlockStatementStart do begin with WordIsBlockStatementStart do begin
Add('(',{$ifdef FPC}@{$endif}AllwaysTrue); Add('(',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1467,7 +1488,7 @@ begin
Add('UNIT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('UNIT',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsBlockStatementEnd:=TKeyWordFunctionList.Create; WordIsBlockStatementEnd:=TKeyWordFunctionList.Create('WordIsBlockStatementEnd');
KeyWordLists.Add(WordIsBlockStatementEnd); KeyWordLists.Add(WordIsBlockStatementEnd);
with WordIsBlockStatementEnd do begin with WordIsBlockStatementEnd do begin
Add(')',{$ifdef FPC}@{$endif}AllwaysTrue); Add(')',{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1477,14 +1498,14 @@ begin
Add('UNTIL',{$ifdef FPC}@{$endif}AllwaysTrue); Add('UNTIL',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsBlockStatementMiddle:=TKeyWordFunctionList.Create; WordIsBlockStatementMiddle:=TKeyWordFunctionList.Create('WordIsBlockStatementMiddle');
KeyWordLists.Add(WordIsBlockStatementMiddle); KeyWordLists.Add(WordIsBlockStatementMiddle);
with WordIsBlockStatementMiddle do begin with WordIsBlockStatementMiddle do begin
Add('FINALLY',{$ifdef FPC}@{$endif}AllwaysTrue); Add('FINALLY',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('EXCEPT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('EXCEPT',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsBinaryOperator:=TKeyWordFunctionList.Create; WordIsBinaryOperator:=TKeyWordFunctionList.Create('WordIsBinaryOperator');
KeyWordLists.Add(WordIsBinaryOperator); KeyWordLists.Add(WordIsBinaryOperator);
with WordIsBinaryOperator do begin with WordIsBinaryOperator do begin
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1509,14 +1530,14 @@ begin
Add('AS' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('AS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLvl1Operator:=TKeyWordFunctionList.Create; WordIsLvl1Operator:=TKeyWordFunctionList.Create('WordIsLvl1Operator');
KeyWordLists.Add(WordIsLvl1Operator); KeyWordLists.Add(WordIsLvl1Operator);
with WordIsLvl1Operator do begin with WordIsLvl1Operator do begin
Add('NOT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('NOT',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('@' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('@' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLvl2Operator:=TKeyWordFunctionList.Create; WordIsLvl2Operator:=TKeyWordFunctionList.Create('WordIsLvl2Operator');
KeyWordLists.Add(WordIsLvl2Operator); KeyWordLists.Add(WordIsLvl2Operator);
with WordIsLvl2Operator do begin with WordIsLvl2Operator do begin
Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1529,7 +1550,7 @@ begin
Add('AS' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('AS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLvl3Operator:=TKeyWordFunctionList.Create; WordIsLvl3Operator:=TKeyWordFunctionList.Create('WordIsLvl3Operator');
KeyWordLists.Add(WordIsLvl3Operator); KeyWordLists.Add(WordIsLvl3Operator);
with WordIsLvl3Operator do begin with WordIsLvl3Operator do begin
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1538,7 +1559,7 @@ begin
Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue); Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsLvl4Operator:=TKeyWordFunctionList.Create; WordIsLvl4Operator:=TKeyWordFunctionList.Create('WordIsLvl4Operator');
KeyWordLists.Add(WordIsLvl4Operator); KeyWordLists.Add(WordIsLvl4Operator);
with WordIsLvl4Operator do begin with WordIsLvl4Operator do begin
Add('=' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('=' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1551,7 +1572,7 @@ begin
Add('IS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('IS',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsBooleanOperator:=TKeyWordFunctionList.Create; WordIsBooleanOperator:=TKeyWordFunctionList.Create('WordIsBooleanOperator');
KeyWordLists.Add(WordIsBooleanOperator); KeyWordLists.Add(WordIsBooleanOperator);
with WordIsBooleanOperator do begin with WordIsBooleanOperator do begin
Add('=' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('=' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1564,7 +1585,7 @@ begin
Add('IS',{$ifdef FPC}@{$endif}AllwaysTrue); Add('IS',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsOrdNumberOperator:=TKeyWordFunctionList.Create; WordIsOrdNumberOperator:=TKeyWordFunctionList.Create('WordIsOrdNumberOperator');
KeyWordLists.Add(WordIsOrdNumberOperator); KeyWordLists.Add(WordIsOrdNumberOperator);
with WordIsOrdNumberOperator do begin with WordIsOrdNumberOperator do begin
Add('OR' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('OR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1576,7 +1597,7 @@ begin
Add('MOD',{$ifdef FPC}@{$endif}AllwaysTrue); Add('MOD',{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsNumberOperator:=TKeyWordFunctionList.Create; WordIsNumberOperator:=TKeyWordFunctionList.Create('WordIsNumberOperator');
KeyWordLists.Add(WordIsNumberOperator); KeyWordLists.Add(WordIsNumberOperator);
with WordIsNumberOperator do begin with WordIsNumberOperator do begin
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1584,7 +1605,7 @@ begin
Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue);
end; end;
WordIsPredefinedFPCIdentifier:=TKeyWordFunctionList.Create; WordIsPredefinedFPCIdentifier:=TKeyWordFunctionList.Create('WordIsPredefinedFPCIdentifier');
KeyWordLists.Add(WordIsPredefinedFPCIdentifier); KeyWordLists.Add(WordIsPredefinedFPCIdentifier);
with WordIsPredefinedFPCIdentifier do begin with WordIsPredefinedFPCIdentifier do begin
Add('ANSISTRING' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('ANSISTRING' ,{$ifdef FPC}@{$endif}AllwaysTrue);
@ -1625,7 +1646,7 @@ begin
// functions // functions
WordIsPredefinedFPCIdentifier.Add(IsWordBuiltInFunc); WordIsPredefinedFPCIdentifier.Add(IsWordBuiltInFunc);
WordIsPredefinedDelphiIdentifier:=TKeyWordFunctionList.Create; WordIsPredefinedDelphiIdentifier:=TKeyWordFunctionList.Create('WordIsPredefinedDelphiIdentifier');
KeyWordLists.Add(WordIsPredefinedDelphiIdentifier); KeyWordLists.Add(WordIsPredefinedDelphiIdentifier);
with WordIsPredefinedDelphiIdentifier do begin with WordIsPredefinedDelphiIdentifier do begin
Add('ANSISTRING' ,{$ifdef FPC}@{$endif}AllwaysTrue); Add('ANSISTRING' ,{$ifdef FPC}@{$endif}AllwaysTrue);

View File

@ -1563,7 +1563,8 @@ begin
else if pphIsType in ParseAttr then else if pphIsType in ParseAttr then
IsSpecifier:=IsKeyWordProcedureTypeSpecifier.DoIdentifier(@Src[CurPos.StartPos]) IsSpecifier:=IsKeyWordProcedureTypeSpecifier.DoIdentifier(@Src[CurPos.StartPos])
else else
IsSpecifier:=IsKeyWordProcedureSpecifier.DoIdentifier(@Src[CurPos.StartPos]); IsSpecifier:=IsKeyWordProcedureSpecifier.DoItCaseInsensitive(Src,
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos);
end else end else
IsSpecifier:=false; IsSpecifier:=false;
if IsSpecifier then begin if IsSpecifier then begin
@ -1784,7 +1785,9 @@ begin
end; end;
end; end;
if CurPos.StartPos>SrcLen then break; if CurPos.StartPos>SrcLen then break;
if not WordIsTermOperator.DoIdentifier(@Src[CurPos.StartPos]) then begin if not WordIsTermOperator.DoItCaseInsensitive(Src,CurPos.StartPos,
CurPos.EndPos-CurPos.StartPos)
then begin
// not a operator // not a operator
break; break;
end; end;
@ -2282,7 +2285,8 @@ begin
//DebugLn('[TPascalParserTool.DoAtom] A ',DbgS(CurKeyWordFuncList)); //DebugLn('[TPascalParserTool.DoAtom] A ',DbgS(CurKeyWordFuncList));
if (CurPos.StartPos<=SrcLen) and (CurPos.EndPos>CurPos.StartPos) then begin if (CurPos.StartPos<=SrcLen) and (CurPos.EndPos>CurPos.StartPos) then begin
if IsIdentStartChar[Src[CurPos.StartPos]] then if IsIdentStartChar[Src[CurPos.StartPos]] then
Result:=KeyWordFuncList.DoIdentifier(@Src[CurPos.StartPos]) Result:=KeyWordFuncList.DoItCaseInsensitive(Src,CurPos.StartPos,
CurPos.EndPos-CurPos.StartPos)
else begin else begin
if Src[CurPos.StartPos] in ['(','['] then if Src[CurPos.StartPos] in ['(','['] then
ReadTilBracketClose(true); ReadTilBracketClose(true);
@ -2659,7 +2663,8 @@ function TPascalParserTool.ReadTilBlockStatementEnd(
begin begin
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then
Result:=ReadTilBracketClose(ExceptionOnNotFound) Result:=ReadTilBracketClose(ExceptionOnNotFound)
else if WordIsBlockStatementStart.DoIdentifier(@Src[CurPos.StartPos]) else if WordIsBlockStatementStart.DoItCaseInsensitive(Src,CurPos.StartPos,
CurPos.EndPos-CurPos.StartPos)
then then
Result:=ReadTilBlockEnd(false,false) Result:=ReadTilBlockEnd(false,false)
else else

View File

@ -352,7 +352,7 @@ procedure BuildBlockKeyWordFuncList;
var BlockWord: TBlockKeyword; var BlockWord: TBlockKeyword;
begin begin
if BlockKeywordFuncList=nil then begin if BlockKeywordFuncList=nil then begin
BlockKeywordFuncList:=TKeyWordFunctionList.Create; BlockKeywordFuncList:=TKeyWordFunctionList.Create('StdCodeTools.BlockKeywordFuncList');
for BlockWord:=Low(TBlockKeyword) to High(TBlockKeyword) do for BlockWord:=Low(TBlockKeyword) to High(TBlockKeyword) do
with BlockKeywordFuncList do with BlockKeywordFuncList do
Add(BlockKeywords[BlockWord],{$ifdef FPC}@{$endif}AllwaysTrue); Add(BlockKeywords[BlockWord],{$ifdef FPC}@{$endif}AllwaysTrue);