codetools: TFindDeclarationTool.CheckParameterSyntax: check comments

git-svn-id: trunk@39956 -
This commit is contained in:
mattias 2013-01-24 19:39:25 +00:00
parent 84b225d357
commit e9f840669c
4 changed files with 75 additions and 37 deletions

View File

@ -2114,7 +2114,7 @@ begin
DebugLn(' CompleteLocalIdentifierByParameter: B check if it is a parameter ...');
{$ENDIF}
// check parameter syntax
if not CheckParameterSyntax(CursorNode,CleanCursorPos,
if not CheckParameterSyntax(CursorNode.StartPos,CleanCursorPos,
VarNameRange,ProcNameAtom,ParameterIndex)
then
exit;

View File

@ -66,6 +66,7 @@ interface
{ $DEFINE ShowProcSearch}
{ $DEFINE VerboseFindDeclarationFail}
{ $DEFINE DebugAddToolDependency}
{ $DEFINE VerboseCPS}
{$IFDEF CTDEBUG}{$DEFINE DebugPrefix}{$ENDIF}
{$IFDEF ShowTriedIdentifiers}{$DEFINE DebugPrefix}{$ENDIF}
@ -723,8 +724,8 @@ type
Params: TFindDeclarationParams): TTypeCompatibility;
function IsBaseCompatible(const TargetType, ExpressionType: TExpressionType;
Params: TFindDeclarationParams): TTypeCompatibility;
function CheckParameterSyntax(CursorNode: TCodeTreeNode;
CleanCursorPos: integer; out ParameterAtom, ProcNameAtom: TAtomPosition;
function CheckParameterSyntax(StartPos, CleanCursorPos: integer;
out ParameterAtom, ProcNameAtom: TAtomPosition;
out ParameterIndex: integer): boolean;
protected
function CheckDirectoryCache: boolean;
@ -9180,7 +9181,7 @@ begin
{$ENDIF}
end;
function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
function TFindDeclarationTool.CheckParameterSyntax(StartPos,
CleanCursorPos: integer; out ParameterAtom, ProcNameAtom: TAtomPosition; out
ParameterIndex: integer): boolean;
// check for Identifier(expr,expr,...,expr,VarName
@ -9328,21 +9329,30 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
end;
end;
var
CommentStart: integer;
CommentEnd: integer;
begin
{$IFDEF CheckNodeTool}CheckNodeTool(CursorNode);{$ENDIF}
Result:=false;
ParameterAtom:=CleanAtomPosition;
ProcNameAtom:=CleanAtomPosition;
ParameterIndex:=0;
//DebugLn('TFindDeclarationTool.CheckParameterSyntax START');
if StartPos<1 then exit;
// read code in front to find ProcName and check the syntax
MoveCursorToNodeStart(CursorNode);
MoveCursorToCleanPos(StartPos);
repeat
ReadNextAtom;
{$IFDEF VerboseCPS}DebugLn('TCodeCompletionCodeTool.CheckParameterSyntax ',GetAtom,' ',dbgs(CurPos.EndPos),'<',dbgs(CleanCursorPos));{$ENDIF}
if CurPos.EndPos>CleanCursorPos then exit;
if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen])
{$IFDEF VerboseCPS}DebugLn('TFindDeclarationTool.CheckParameterSyntax ',GetAtom,' at ',CleanPosToStr(CurPos.StartPos),' ',dbgs(CurPos.EndPos),'<',dbgs(CleanCursorPos));{$ENDIF}
if CurPos.EndPos>CleanCursorPos then begin
if LastAtoms.Count=0 then exit;
if not CleanPosIsInComment(CleanCursorPos,LastAtoms.GetValueAt(0).EndPos,
CommentStart,CommentEnd,false) then exit;
// cursor in a comment
// => parse within the comment
MoveCursorToCleanPos(CommentStart);
end else if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen])
and (LastAtoms.GetValueAt(0).Flag=cafWord) then begin
UndoReadNextAtom;
if CheckIdentifierAndParameterList then exit(true);

View File

@ -2673,11 +2673,11 @@ var
exit;
end;
// check if cursor is in a parameter list
if not CheckParameterSyntax(CursorNode, CleanCursorPos,
if not CheckParameterSyntax(CursorNode.StartPos, CleanCursorPos,
VarNameAtom, ProcNameAtom, ParameterIndex)
then begin
if VarNameAtom.StartPos=0 then ;
//DebugLn(['TIdentCompletionTool.FindCodeContext.CheckContextIsParameter not in a parameter list']);
DebugLn(['TIdentCompletionTool.FindCodeContext.CheckContextIsParameter not in a parameter list']);
exit;
end;
//DebugLn('CheckContextIsParameter Variable=',GetAtom(VarNameAtom),' Proc=',GetAtom(ProcNameAtom),' ParameterIndex=',dbgs(ParameterIndex));

View File

@ -60,7 +60,8 @@ type
public
// comments
function CleanPosIsInComment(CleanPos, CleanCodePosInFront: integer;
var CommentStart, CommentEnd: integer): boolean;
var CommentStart, CommentEnd: integer;
OuterCommentBounds: boolean = true): boolean;
// general extraction
function ExtractNode(ANode: TCodeTreeNode;
@ -255,9 +256,11 @@ begin
end;
function TPascalReaderTool.CleanPosIsInComment(CleanPos,
CleanCodePosInFront: integer; var CommentStart, CommentEnd: integer
): boolean;
CleanCodePosInFront: integer; var CommentStart, CommentEnd: integer;
OuterCommentBounds: boolean): boolean;
var CommentLvl, CurCommentPos: integer;
CurEnd: Integer;
CurCommentInnerEnd: Integer;
begin
Result:=false;
if CleanPos>SrcLen then exit;
@ -270,23 +273,29 @@ begin
if CurPos.StartPos>CleanPos then begin
//DebugLn(['TPascalReaderTool.CleanPosIsInComment ',GetATom,' StartPos=',CurPos.StartPos,' CleanPos=',CleanPos]);
// CleanPos between two atoms -> parse space between for comments
CommentStart:=CleanCodePosInFront;
CommentEnd:=CurPos.StartPos;
if CommentEnd>SrcLen then CommentEnd:=SrcLen+1;
while CommentStart<CommentEnd do begin
if LastAtoms.Count>0 then
CommentStart:=LastAtoms.GetValueAt(0).EndPos
else
CommentStart:=CleanCodePosInFront;
CurEnd:=CurPos.StartPos;
if CurEnd>SrcLen then CurEnd:=SrcLen+1;
while CommentStart<CurEnd do begin
if IsCommentStartChar[Src[CommentStart]] then begin
CurCommentPos:=CommentStart;
case Src[CurCommentPos] of
CurCommentInnerEnd:=CurEnd;
case Src[CommentStart] of
'{':
begin
inc(CurCommentPos);
if (CurCommentPos<CommentEnd) and (Src[CurCommentPos]=#3) then begin
if (CurCommentPos<=SrcLen) and (Src[CurCommentPos]=#3) then begin
// codetools skip comment
inc(CurCommentPos);
while (CurCommentPos<CommentEnd) do begin
if not OuterCommentBounds then CommentStart:=CurCommentPos;
while (CurCommentPos<CurEnd) do begin
if (Src[CurCommentPos]=#3)
and (CurCommentPos+1<CommentEnd) and (Src[CurCommentPos+1]='}')
and (CurCommentPos+1<CurEnd) and (Src[CurCommentPos+1]='}')
then begin
CurCommentInnerEnd:=CurCommentPos;
inc(CurCommentPos,2);
break;
end;
@ -294,48 +303,67 @@ begin
end;
end else begin
// pascal comment
if not OuterCommentBounds then CommentStart:=CurCommentPos;
CommentLvl:=1;
while (CurCommentPos<CommentEnd) and (CommentLvl>0) do begin
while (CurCommentPos<CurEnd) do begin
case Src[CurCommentPos] of
'{': if Scanner.NestedComments then inc(CommentLvl);
'}': dec(CommentLvl);
'}':
begin
dec(CommentLvl);
if (CommentLvl=0) then begin
CurCommentInnerEnd:=CurCommentPos;
inc(CurCommentPos);
break;
end;
end;
end;
inc(CurCommentPos);
end;
end;
end;
'/': // Delphi comment
if (CurCommentPos<CommentEnd-1) and (Src[CurCommentPos+1]='/') then
if (CurCommentPos<SrcLen) and (Src[CurCommentPos+1]='/') then
begin
inc(CurCommentPos,2);
while (CurCommentPos<CommentEnd)
if not OuterCommentBounds then CommentStart:=CurCommentPos;
while (CurCommentPos<CurEnd)
and (not (Src[CurCommentPos] in [#10,#13])) do
inc(CurCommentPos);
CurCommentInnerEnd:=CurCommentPos;
inc(CurCommentPos);
if (CurCommentPos<CommentEnd)
if (CurCommentPos<CurEnd)
and (Src[CurCommentPos] in [#10,#13])
and (Src[CurCommentPos-1]<>Src[CurCommentPos]) then
inc(CurCommentPos);
end else
break;
'(': // old turbo pascal comment
if (CurCommentPos<CommentEnd-1) and (Src[CurCommentPos+1]='*') then
'(': // Turbo pascal comment
if (CurCommentPos<SrcLen) and (Src[CurCommentPos+1]='*') then
begin
inc(CurCommentPos,3);
while (CurCommentPos<CommentEnd)
and ((Src[CurCommentPos-1]<>'*') or (Src[CurCommentPos]<>')'))
do
inc(CurCommentPos,2);
if not OuterCommentBounds then CommentStart:=CurCommentPos;
while (CurCommentPos<CurEnd) do begin
if (Src[CurCommentPos]='*') and (CurCommentPos+1<CurEnd)
and (Src[CurCommentPos+1]=')') then
begin
CurCommentInnerEnd:=CurCommentPos;
inc(CurCommentPos,2);
break;
end;
inc(CurCommentPos);
inc(CurCommentPos);
end;
end else
break;
end;
if (CurCommentPos>CommentStart) and (CleanPos<CurCommentPos) then
begin
// CleanPos in comment
CommentEnd:=CurCommentPos;
Result:=true;
exit;
if OuterCommentBounds then
CommentEnd:=CurCommentPos
else
CommentEnd:=CurCommentInnerEnd;
exit(true);
end;
CommentStart:=CurCommentPos;
end else if IsSpaceChar[Src[CommentStart]] then begin