fixed endless loop

git-svn-id: trunk@8824 -
This commit is contained in:
mattias 2006-02-25 21:20:39 +00:00
parent a85b8947c8
commit 7f9586348a
3 changed files with 42 additions and 10 deletions

View File

@ -32,6 +32,7 @@
- add missing forward proc bodies
- complete event assignments
- complete local variables
- complete local variables as parameter
- insert header comment for classes
ToDo:
@ -39,13 +40,13 @@
TList:
property Items[Index: integer]: AType accesstlist;
-> creates
property Items[Index: Type1]: Type2 read GetItems write SetItems;
property Items[Index: integer]: Type2 read GetItems write SetItems;
private FItems: TList;
private function GetItems(Index: Type1): Type2;
private function GetItems(Index: integer): Type2;
begin
Result:=Type2(FItems[Index]);
end;
private procedure SetItems(Index: Type1; const AValue: Type2);
private procedure SetItems(Index: integer; const AValue: Type2);
begin
FItems[Index]:=Type2;
end;
@ -889,9 +890,9 @@ begin
exit;
if not IsValidIdent(GetAtom(VarNameAtom)) then exit;
{$IFDEF CTDEBUG}
{ $IFDEF CTDEBUG}
DebugLn(' CompleteLocalVariableAsParameter VarNameAtom=',GetAtom(VarNameAtom),' ProcNameAtom=',GetAtom(ProcNameAtom),' ParameterIndex=',dbgs(ParameterIndex));
{$ENDIF}
{ $ENDIF}
// search variable
ActivateGlobalWriteLock;
@ -908,9 +909,9 @@ begin
RaiseExceptionFmt(ctsIdentifierAlreadyDefined,[GetAtom]);
end;
{$IFDEF CTDEBUG}
{ $IFDEF CTDEBUG}
DebugLn(' CompleteLocalVariableAsParameter: Find declaration of parameter list ... Identifier="',GetAtom(ProcNameAtom),'"');
{$ENDIF}
{ $ENDIF}
// find declaration of parameter list
Params.ContextNode:=CursorNode;
Params.SetIdentifier(Self,@Src[ProcNameAtom.StartPos],nil);
@ -928,6 +929,7 @@ begin
end;
NewType:='';
if Params.NewNode<>nil then begin
DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter Proc/PropNode=',Params.NewNode.DescAsString,' ',copy(Params.NewCodeTool.Src,Params.NewNode.StartPos,50));
ParameterNode:=Params.NewCodeTool.FindNthParameterNode(Params.NewNode,
ParameterIndex);
if (ParameterNode=nil)
@ -936,6 +938,7 @@ begin
exit;
end;
if ParameterNode<>nil then begin
DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter ParameterNode=',ParameterNode.DescAsString,' ',copy(Params.NewCodeTool.Src,ParameterNode.StartPos,50));
TypeNode:=FindTypeNodeOfDefinition(ParameterNode);
if TypeNode=nil then begin
DebugLn(' CompleteLocalVariableAsParameter Parameter has no type');
@ -943,6 +946,7 @@ begin
end;
NewType:=copy(Params.NewCodeTool.Src,TypeNode.StartPos,
TypeNode.EndPos-TypeNode.StartPos);
DebugLn('TCodeCompletionCodeTool.CompleteLocalVariableAsParameter NewType=',NewType);
if NewType='' then
RaiseException('CompleteLocalVariableAsParameter Internal error: NewType=""');
end;
@ -2952,7 +2956,7 @@ begin
// test if undeclared local variable as parameter
Result:=CompleteLocalVariableAsParameter(CleanCursorPos,OldTopLine,CursorNode,
NewPos,NewTopLine,SourceChangeCache);
NewPos,NewTopLine,SourceChangeCache);
if Result then exit;
// test if method body

View File

@ -3702,6 +3702,7 @@ var
CodeContexts:=TCodeContextInfo.Create;
CodeContexts.Add(CreateExpressionType(xtContext,xtNone,
CreateFindContext(Tool,Node)));
//DebugLn('AddContext ',node.DescAsString,' ',copy(Src,Node.StartPos,Node.EndPos-Node.StartPos));
end;
function CheckContextIsParameter(var Ok: boolean): boolean;
@ -6914,7 +6915,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
repeat
ReadNextAtom;
if CurPos.Flag=cafWord then begin
if CheckIdentifierAndParameterList then exit(true);
if CheckIdentifierAndParameterList() then exit(true);
end;
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin
if CheckBrackets then exit(true);
@ -6924,6 +6925,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
=(CurPos.Flag=cafRoundBracketClose)
then begin
// closing bracket found, but the variable was not in them
//DebugLn('CheckBrackets bracket closed');
exit(false);
end else begin
// invalid closing bracket found
@ -6988,17 +6990,21 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
end;
if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen])
and (LastAtoms.GetValueAt(0).Flag=cafWord) then begin
//DebugLn('CheckIdentifierAndParameterList check word+bracket');
UndoReadNextAtom;
if CheckIdentifierAndParameterList then exit(true);
if CheckIdentifierAndParameterList() then exit(true);
end;
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin
//DebugLn('CheckIdentifierAndParameterList check bracket open');
if CheckBrackets then exit(true);
end;
if CurPos.Flag in [cafRoundBracketClose,cafEdgedBracketClose] then begin
//DebugLn('CheckIdentifierAndParameterList check bracket close');
if (BracketAtom.Flag=cafRoundBracketOpen)
=(CurPos.Flag=cafRoundBracketClose)
then begin
// parameter list ended in front of Variable => continue search
//DebugLn('CheckIdentifierAndParameterList parm list ended in front of cursor');
exit;
end else begin
// invalid closing bracket found
@ -7010,6 +7016,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
ParameterStart:=CurPos.EndPos;
inc(CurParameterIndex);
end;
//DebugLn('CheckIdentifierAndParameterList ',GetAtom);
until (CurPos.EndPos>CleanCursorPos) or (CurPos.Flag=cafNone);
end;
end;

View File

@ -274,6 +274,7 @@ procedure ConvertEndianBigDoubleToLRSExtended(BigEndianDouble,
function ReadLRSByte(s: TStream): byte;
function ReadLRSWord(s: TStream): word;
function ReadLRSShortInt(s: TStream): shortint;
function ReadLRSInteger(s: TStream): integer;
function ReadLRSCardinal(s: TStream): cardinal;
function ReadLRSInt64(s: TStream): int64;
@ -286,6 +287,7 @@ function ReadLRSEndianLittleExtendedAsDouble(s: TStream): Double;
function ReadLRSValueType(s: TStream): TValueType;
function ReadLRSInt64MB(s: TStream): int64;// multibyte
procedure WriteLRSShortInt(s: TStream; const i: shortint);
procedure WriteLRSWord(s: TStream; const w: word);
procedure WriteLRSInteger(s: TStream; const i: integer);
procedure WriteLRSCardinal(s: TStream; const c: cardinal);
@ -2468,6 +2470,16 @@ begin
{$ENDIF}
end;
function ReadLRSShortInt(s: TStream): shortint;
begin
Result:=0;
{$IFDEF FPC_BIG_ENDIAN}
Result:=shortint(ReadLRSWord(s));
{$ELSE}
s.Read(Result,2);
{$ENDIF}
end;
function ReadLRSInteger(s: TStream): integer;
begin
Result:=0;
@ -2681,6 +2693,15 @@ begin
s.Write(e[0],10);
end;
procedure WriteLRSShortInt(s: TStream; const i: shortint);
begin
{$IFDEF FPC_LITTLE_ENDIAN}
s.Write(i,2);
{$ELSE}
WriteLRSReversedShortInt(s,Word(i));
{$ENDIF}
end;
procedure WriteLRSWord(s: TStream; const w: word);
begin
{$IFDEF FPC_LITTLE_ENDIAN}