mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 01:49:27 +02:00
MG: find declaration will now check procs param lists
git-svn-id: trunk@627 -
This commit is contained in:
parent
4e53ea1b36
commit
e382970758
@ -136,6 +136,7 @@ const
|
||||
ctnsNone = 0;
|
||||
ctnsForwardDeclaration = 1;
|
||||
ctnsNeedJITParsing = 2;
|
||||
ctnsHasDefaultValue = 4;
|
||||
|
||||
type
|
||||
TCodeTreeNode = class
|
||||
|
@ -111,7 +111,9 @@ type
|
||||
function AtomIsWord: boolean;
|
||||
function AtomIsKeyWord: boolean;
|
||||
function AtomIsNumber: boolean;
|
||||
function AtomIsRealNumber: boolean;
|
||||
function AtomIsStringConstant: boolean;
|
||||
function AtomIsCharConstant: boolean;
|
||||
function AtomIsIdentifier(ExceptionOnNotFound: boolean): boolean;
|
||||
function LastAtomIs(BackIndex: integer;
|
||||
const AnAtom: shortstring): boolean; // 0=current, 1=prior current, ...
|
||||
@ -429,12 +431,57 @@ begin
|
||||
and (Src[CurPos.StartPos] in ['0'..'9','%','$']);
|
||||
end;
|
||||
|
||||
function TCustomCodeTool.AtomIsRealNumber: boolean;
|
||||
var i: integer;
|
||||
begin
|
||||
Result:=false;
|
||||
i:=CurPos.StartPos;
|
||||
if (i<=SrcLen) and (IsNumberChar[Src[i]]) then begin
|
||||
while (i<=SrcLen) and (IsNumberChar[Src[i]]) do
|
||||
inc(i);
|
||||
if (i<=SrcLen) and (Src[i]='.') then
|
||||
Result:=true;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCustomCodeTool.AtomIsStringConstant: boolean;
|
||||
begin
|
||||
Result:=(CurPos.StartPos<=SrcLen)
|
||||
and (Src[CurPos.StartPos] in ['''','#']);
|
||||
end;
|
||||
|
||||
function TCustomCodeTool.AtomIsCharConstant: boolean;
|
||||
var i: integer;
|
||||
begin
|
||||
Result:=false;
|
||||
if (CurPos.StartPos<=SrcLen) then begin
|
||||
case Src[CurPos.StartPos] of
|
||||
|
||||
'#':
|
||||
begin
|
||||
i:=CurPos.StartPos+1;
|
||||
while (i<=SrcLen) and (IsNumberChar[Src[i]]) do
|
||||
inc(i);
|
||||
if (i<=SrcLen)
|
||||
and (not (Src[i] in ['''','#'])) then
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
'''':
|
||||
begin
|
||||
if (CurPos.StartPos+2<=SrcLen) and (Src[CurPos.StartPos+1]<>'''')
|
||||
and (Src[CurPos.StartPos+2]='''') then begin
|
||||
// a single char
|
||||
if (CurPos.StartPos+2<SrcLen)
|
||||
and (not (Src[CurPos.StartPos+3] in ['''','#'])) then
|
||||
Result:=true;
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCustomCodeTool.LastAtomIs(BackIndex: integer;
|
||||
const AnAtom: shortstring): boolean;
|
||||
var ap: TAtomPosition;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -51,11 +51,13 @@ type
|
||||
function KeyWordToHashIndex(const AKeyWord: shortstring): integer;
|
||||
function KeyWordToHashIndex(const ASource: string;
|
||||
AStart, ALen: integer): integer;
|
||||
function KeyWordToHashIndex(Identifier: PChar): integer;
|
||||
public
|
||||
DefaultKeyWordFunction: TKeyWordFunction;
|
||||
function DoIt(const AKeyWord: shortstring): boolean;
|
||||
function DoIt(const ASource: string;
|
||||
KeyWordStart, KeyWordLen: integer): boolean;
|
||||
function DoIt(Identifier: PChar): boolean;
|
||||
function DoItUppercase(const AnUpperSource: string;
|
||||
KeyWordStart, KeyWordLen: integer): boolean;
|
||||
procedure Clear;
|
||||
@ -82,6 +84,12 @@ var
|
||||
WordIsPropertySpecifier,
|
||||
WordIsBlockKeyWord,
|
||||
WordIsLogicalBlockStart,
|
||||
WordIsBinaryOperator,
|
||||
WordIsLvl1Operator, WordIsLvl2Operator, WordIsLvl3Operator, WordIsLvl4Operator,
|
||||
WordIsBooleanOperator,
|
||||
WordIsOrdNumberOperator,
|
||||
WordIsNumberOperator,
|
||||
WordIsPredefinedIdentifier,
|
||||
UnexpectedKeyWordInBeginBlock: TKeyWordFunctionList;
|
||||
UpChars: array[char] of char;
|
||||
|
||||
@ -93,6 +101,7 @@ implementation
|
||||
|
||||
var
|
||||
CharToHash: array[char] of integer;
|
||||
IsIdentChar: array[char] of boolean;
|
||||
|
||||
function UpperCaseStr(const s: string): string;
|
||||
var i, l: integer;
|
||||
@ -168,6 +177,19 @@ begin
|
||||
if Result>FMaxHashIndex then Result:=-1;
|
||||
end;
|
||||
|
||||
function TKeyWordFunctionList.KeyWordToHashIndex(Identifier: PChar): integer;
|
||||
var i: integer;
|
||||
begin
|
||||
Result:=0;
|
||||
i:=20;
|
||||
while (i>0) and IsIdentChar[Identifier[0]] do begin
|
||||
inc(Result,CharToHash[Identifier[0]]);
|
||||
dec(i);
|
||||
inc(Identifier);
|
||||
end;
|
||||
if Result>FMaxHashIndex then Result:=-1;
|
||||
end;
|
||||
|
||||
function TKeyWordFunctionList.DoIt(const AKeyWord: shortstring): boolean;
|
||||
var i: integer;
|
||||
begin
|
||||
@ -231,6 +253,48 @@ begin
|
||||
Result:=DefaultKeyWordFunction();
|
||||
end;
|
||||
|
||||
function TKeyWordFunctionList.DoIt(Identifier: PChar): boolean;
|
||||
// checks
|
||||
var i, KeyPos, KeyWordLen: integer;
|
||||
KeyWordFuncItem: TKeyWordFunctionListItem;
|
||||
IdentifierEnd, WordPos: PChar;
|
||||
begin
|
||||
if not FSorted then Sort;
|
||||
i:=KeyWordToHashIndex(Identifier);
|
||||
IdentifierEnd:=Identifier;
|
||||
while IsIdentChar[IdentifierEnd[0]] do inc(IdentifierEnd);
|
||||
KeyWordLen:=(Integer(IdentifierEnd)-Integer(Identifier));
|
||||
dec(IdentifierEnd);
|
||||
if i>=0 then begin
|
||||
i:=FBucketStart[i];
|
||||
if i>=0 then begin
|
||||
repeat
|
||||
KeyWordFuncItem:=TKeyWordFunctionListItem(FItems[i]);
|
||||
if length(KeyWordFuncItem.KeyWord)=KeyWordLen then begin
|
||||
KeyPos:=KeyWordLen;
|
||||
WordPos:=IdentifierEnd;
|
||||
while (KeyPos>=1)
|
||||
and (KeyWordFuncItem.KeyWord[KeyPos]=UpChars[WordPos[0]]) do
|
||||
begin
|
||||
dec(KeyPos);
|
||||
dec(WordPos);
|
||||
end;
|
||||
if KeyPos<1 then begin
|
||||
if Assigned(KeyWordFuncItem.DoIt) then
|
||||
Result:=KeyWordFuncItem.DoIt()
|
||||
else
|
||||
Result:=DefaultKeyWordFunction();
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
if (KeyWordFuncItem.IsLast) then break;
|
||||
inc(i);
|
||||
until false;
|
||||
end;
|
||||
end;
|
||||
Result:=DefaultKeyWordFunction();
|
||||
end;
|
||||
|
||||
function TKeyWordFunctionList.DoItUppercase(const AnUpperSource: string;
|
||||
// use this function if ASource upcased
|
||||
KeyWordStart, KeyWordLen: integer): boolean;
|
||||
@ -393,7 +457,9 @@ begin
|
||||
else CharToHash[c]:=0;
|
||||
end;
|
||||
UpChars[c]:=upcase(c);
|
||||
IsIdentChar[c]:=(c in ['a'..'z','A'..'Z','0'..'9','_']);
|
||||
end;
|
||||
|
||||
KeyWordLists:=TList.Create;
|
||||
IsKeyWordMethodSpecifier:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(IsKeyWordMethodSpecifier);
|
||||
@ -648,6 +714,119 @@ begin
|
||||
Add('INITIALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('FINALIZATION',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsBinaryOperator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsBinaryOperator);
|
||||
with WordIsBinaryOperator do begin
|
||||
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('-' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('/' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('DIV',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('MOD',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('AND',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('OR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHL',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHR',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('IN' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('>' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<>' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('>=' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<=' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('IS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('AS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsLvl1Operator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsLvl1Operator);
|
||||
with WordIsLvl1Operator do begin
|
||||
Add('NOT',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('@' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsLvl2Operator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsLvl2Operator);
|
||||
with WordIsLvl2Operator do begin
|
||||
Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('/' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('DIV',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('MOD',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('AND',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHL',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHR',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('AS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsLvl3Operator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsLvl3Operator);
|
||||
with WordIsLvl3Operator do begin
|
||||
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('-' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('OR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('XOR',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsLvl4Operator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsLvl4Operator);
|
||||
with WordIsLvl4Operator do begin
|
||||
Add('<' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('>' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<>',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('>=',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<=',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('IN',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('IS',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsBooleanOperator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsBooleanOperator);
|
||||
with WordIsBooleanOperator do begin
|
||||
Add('<' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('>' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<>',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('>=',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('<=',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('IN',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('IS',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsOrdNumberOperator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsOrdNumberOperator);
|
||||
with WordIsOrdNumberOperator do begin
|
||||
Add('OR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('XOR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('AND',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHL',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHR',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('DIV',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('MOD',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsNumberOperator:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsNumberOperator);
|
||||
with WordIsNumberOperator do begin
|
||||
Add('+' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('-' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('*' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
WordIsPredefinedIdentifier:=TKeyWordFunctionList.Create;
|
||||
KeyWordLists.Add(WordIsPredefinedIdentifier);
|
||||
with WordIsPredefinedIdentifier do begin
|
||||
Add('INT64' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('CARDINAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('QWORD' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('BOOLEAN' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('BYTEBOOL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('LONGBOOL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('CHAR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('REAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SINGLE' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('DOUBLE' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('EXTENDED' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('COMP' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('CURRENCY' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('STRING' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('SHORTSTRING',{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('ANSISTRING' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('WIDESTRING' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('TRUE' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('FALSE' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
Add('NIL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure InternalFinal;
|
||||
|
@ -919,6 +919,7 @@ function TPascalParserTool.ReadParamList(ExceptionOnError, Extract: boolean;
|
||||
Attr: TProcHeadAttributes): boolean;
|
||||
var CloseBracket: char;
|
||||
Desc: TCodeTreeNodeDesc;
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
Result:=false;
|
||||
if AtomIsChar('(') or AtomIsChar('[') then begin
|
||||
@ -985,6 +986,15 @@ begin
|
||||
ExtractNextAtom(phpWithDefaultValues in Attr,Attr);
|
||||
ReadConstant(ExceptionOnError,
|
||||
Extract and (phpWithDefaultValues in Attr),Attr);
|
||||
if (phpCreateNodes in Attr) then begin
|
||||
Node:=CurNode;
|
||||
Node.SubDesc:=Node.SubDesc+ctnsHasDefaultValue;
|
||||
Node:=Node.PriorBrother;
|
||||
while (Node<>nil) and (Node.FirstChild=nil) do begin
|
||||
Node.SubDesc:=Node.SubDesc+ctnsHasDefaultValue;
|
||||
Node:=Node.PriorBrother;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
if (phpCreateNodes in Attr) then begin
|
||||
@ -1100,6 +1110,7 @@ function TPascalParserTool.ReadTilProcedureHeadEnd(
|
||||
proc specifiers with parameters:
|
||||
message <id or number>
|
||||
external <id or number> name <id>
|
||||
external <id or number> index <id>
|
||||
[alias: <string constant>]
|
||||
}
|
||||
var IsSpecifier: boolean;
|
||||
@ -2381,7 +2392,7 @@ var IsFunction: boolean;
|
||||
begin
|
||||
IsFunction:=UpAtomIs('FUNCTION');
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnProcedure;
|
||||
CurNode.Desc:=ctnProcedureType;
|
||||
ReadNextAtom;
|
||||
if AtomIsChar('(') then begin
|
||||
// read parameter list
|
||||
@ -2568,7 +2579,6 @@ begin
|
||||
ReadNextAtom;
|
||||
if AtomIsChar('(') then begin
|
||||
// an enumeration -> read all enums
|
||||
CreateChildNode; // begin enumeration
|
||||
CurNode.Desc:=ctnEnumerationType;
|
||||
repeat
|
||||
ReadNextAtom; // read enum name
|
||||
@ -2589,7 +2599,6 @@ begin
|
||||
RaiseException(') expected, but '+GetAtom+' found');
|
||||
until false;
|
||||
CurNode.EndPos:=CurPos.EndPos;
|
||||
EndChildNode; // close enumeration
|
||||
ReadNextAtom;
|
||||
end else
|
||||
RaiseException('invalid type');
|
||||
|
Loading…
Reference in New Issue
Block a user