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 ...'); DebugLn(' CompleteLocalIdentifierByParameter: B check if it is a parameter ...');
{$ENDIF} {$ENDIF}
// check parameter syntax // check parameter syntax
if not CheckParameterSyntax(CursorNode,CleanCursorPos, if not CheckParameterSyntax(CursorNode.StartPos,CleanCursorPos,
VarNameRange,ProcNameAtom,ParameterIndex) VarNameRange,ProcNameAtom,ParameterIndex)
then then
exit; exit;

View File

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

View File

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

View File

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