mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 04:39:22 +02:00
MG: implemented IgnoreErrorAfter position for codetools
git-svn-id: trunk@3362 -
This commit is contained in:
parent
e4c398a208
commit
7460fce057
@ -137,6 +137,7 @@ type
|
|||||||
// useful functions
|
// useful functions
|
||||||
function AtomPosition(StartPos, EndPos: integer): TAtomPosition;
|
function AtomPosition(StartPos, EndPos: integer): TAtomPosition;
|
||||||
function CodePosition(P: integer; Code: TCodeBuffer): TCodePosition;
|
function CodePosition(P: integer; Code: TCodeBuffer): TCodePosition;
|
||||||
|
function CodeXYPosition(X, Y: integer; Code: TCodeBuffer): TCodeXYPosition;
|
||||||
|
|
||||||
var
|
var
|
||||||
WordToAtomFlag: TWordToAtomFlag;
|
WordToAtomFlag: TWordToAtomFlag;
|
||||||
@ -159,6 +160,12 @@ begin
|
|||||||
Result.Code:=Code;
|
Result.Code:=Code;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CodeXYPosition(X, Y: integer; Code: TCodeBuffer): TCodeXYPosition;
|
||||||
|
begin
|
||||||
|
Result.X:=X;
|
||||||
|
Result.Y:=Y;
|
||||||
|
Result.Code:=Code;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TAtomRing }
|
{ TAtomRing }
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ interface
|
|||||||
|
|
||||||
{$I codetools.inc}
|
{$I codetools.inc}
|
||||||
|
|
||||||
|
{ $DEFINE ShowIgnoreError}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF MEM_CHECK}
|
{$IFDEF MEM_CHECK}
|
||||||
MemCheck,
|
MemCheck,
|
||||||
@ -57,7 +59,7 @@ type
|
|||||||
FOnGetGlobalWriteLockInfo: TOnGetWriteLockInfo;
|
FOnGetGlobalWriteLockInfo: TOnGetWriteLockInfo;
|
||||||
FOnSetGlobalWriteLock: TOnSetWriteLock;
|
FOnSetGlobalWriteLock: TOnSetWriteLock;
|
||||||
protected
|
protected
|
||||||
FIgnoreAfterCodeXY: TCodeXYPosition;
|
FIgnoreErrorAfter: TCodePosition;
|
||||||
KeyWordFuncList: TKeyWordFunctionList;
|
KeyWordFuncList: TKeyWordFunctionList;
|
||||||
FForceUpdateNeeded: boolean;
|
FForceUpdateNeeded: boolean;
|
||||||
function DefaultKeyWordFunc: boolean;
|
function DefaultKeyWordFunc: boolean;
|
||||||
@ -67,11 +69,14 @@ type
|
|||||||
procedure RaiseIdentExpectedButAtomFound;
|
procedure RaiseIdentExpectedButAtomFound;
|
||||||
procedure RaiseBracketOpenExpectedButAtomFound;
|
procedure RaiseBracketOpenExpectedButAtomFound;
|
||||||
procedure RaiseBracketCloseExpectedButAtomFound;
|
procedure RaiseBracketCloseExpectedButAtomFound;
|
||||||
procedure SetIgnoreAfterCodeXY(const AValue: TCodeXYPosition); virtual;
|
procedure SetIgnoreErrorAfter(const AValue: TCodePosition); virtual;
|
||||||
protected
|
protected
|
||||||
LastErrorMessage: string;
|
LastErrorMessage: string;
|
||||||
LastErrorCurPos: TAtomPosition;
|
LastErrorCurPos: TAtomPosition;
|
||||||
LastErrorPhase: integer;
|
LastErrorPhase: integer;
|
||||||
|
LastErrorValid: boolean;
|
||||||
|
LastErrorBehindIgnorePosition: boolean;
|
||||||
|
LastErrorCheckedForIgnored: boolean;
|
||||||
CurrentPhase: integer;
|
CurrentPhase: integer;
|
||||||
procedure RaiseException(const AMessage: string); virtual;
|
procedure RaiseException(const AMessage: string); virtual;
|
||||||
procedure RaiseExceptionFmt(const AMessage: string;
|
procedure RaiseExceptionFmt(const AMessage: string;
|
||||||
@ -124,14 +129,13 @@ type
|
|||||||
function FindLineEndOrCodeInFrontOfPosition(StartPos: integer;
|
function FindLineEndOrCodeInFrontOfPosition(StartPos: integer;
|
||||||
StopAtDirectives: boolean): integer;
|
StopAtDirectives: boolean): integer;
|
||||||
function FindFirstLineEndAfterInCode(StartPos: integer): integer;
|
function FindFirstLineEndAfterInCode(StartPos: integer): integer;
|
||||||
procedure ClearIgnoreAfterPosition;
|
|
||||||
|
|
||||||
function UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean;
|
function UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean;
|
||||||
procedure BeginParsing(DeleteNodes, OnlyInterfaceNeeded: boolean); virtual;
|
procedure BeginParsing(DeleteNodes, OnlyInterfaceNeeded: boolean); virtual;
|
||||||
procedure BeginParsingAndGetCleanPos(DeleteNodes,
|
procedure BeginParsingAndGetCleanPos(DeleteNodes,
|
||||||
OnlyInterfaceNeeded: boolean; CursorPos: TCodeXYPosition;
|
OnlyInterfaceNeeded: boolean; CursorPos: TCodeXYPosition;
|
||||||
var CleanCursorPos: integer);
|
var CleanCursorPos: integer);
|
||||||
|
|
||||||
function StringIsKeyWord(const Word: string): boolean;
|
function StringIsKeyWord(const Word: string): boolean;
|
||||||
|
|
||||||
procedure MoveCursorToNodeStart(ANode: TCodeTreeNode);
|
procedure MoveCursorToNodeStart(ANode: TCodeTreeNode);
|
||||||
@ -185,7 +189,14 @@ type
|
|||||||
property OnSetGlobalWriteLock: TOnSetWriteLock
|
property OnSetGlobalWriteLock: TOnSetWriteLock
|
||||||
read FOnSetGlobalWriteLock write FOnSetGlobalWriteLock;
|
read FOnSetGlobalWriteLock write FOnSetGlobalWriteLock;
|
||||||
|
|
||||||
property IgnoreAfterCodeXY: TCodeXYPosition read FIgnoreAfterCodeXY write SetIgnoreAfterCodeXY;
|
property IgnoreErrorAfter: TCodePosition
|
||||||
|
read FIgnoreErrorAfter write SetIgnoreErrorAfter;
|
||||||
|
procedure ClearIgnoreErrorAfter;
|
||||||
|
function IgnoreErrAfterPositionIsInFrontOfLastErrMessage: boolean;
|
||||||
|
function IgnoreErrorAfterValid: boolean;
|
||||||
|
function IgnoreErrorAfterCleanedPos: integer;
|
||||||
|
function LastErrorsInFrontOfCleanedPos(ACleanedPos: integer): boolean;
|
||||||
|
procedure RaiseLastErrorIfInFrontOfCleanedPos(ACleanedPos: integer);
|
||||||
|
|
||||||
procedure Clear; virtual;
|
procedure Clear; virtual;
|
||||||
function NodeDescToStr(Desc: integer): string;
|
function NodeDescToStr(Desc: integer): string;
|
||||||
@ -279,6 +290,7 @@ begin
|
|||||||
LastErrorMessage:=AMessage;
|
LastErrorMessage:=AMessage;
|
||||||
LastErrorCurPos:=CurPos;
|
LastErrorCurPos:=CurPos;
|
||||||
LastErrorPhase:=CurrentPhase;
|
LastErrorPhase:=CurrentPhase;
|
||||||
|
LastErrorValid:=true;
|
||||||
RaiseException(AMessage);
|
RaiseException(AMessage);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -290,7 +302,9 @@ end;
|
|||||||
|
|
||||||
procedure TCustomCodeTool.ClearLastError;
|
procedure TCustomCodeTool.ClearLastError;
|
||||||
begin
|
begin
|
||||||
LastErrorPhase:=0;
|
LastErrorPhase:=CodeToolPhaseNone;
|
||||||
|
LastErrorValid:=false;
|
||||||
|
LastErrorCheckedForIgnored:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomCodeTool.RaiseLastError;
|
procedure TCustomCodeTool.RaiseLastError;
|
||||||
@ -298,16 +312,20 @@ begin
|
|||||||
CurPos:=LastErrorCurPos;
|
CurPos:=LastErrorCurPos;
|
||||||
CurNode:=nil;
|
CurNode:=nil;
|
||||||
CurrentPhase:=LastErrorPhase;
|
CurrentPhase:=LastErrorPhase;
|
||||||
|
writeln('TCustomCodeTool.RaiseLastError "',LastErrorMessage,'"');
|
||||||
SaveRaiseException(LastErrorMessage);
|
SaveRaiseException(LastErrorMessage);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomCodeTool.SetScanner(NewScanner: TLinkScanner);
|
procedure TCustomCodeTool.SetScanner(NewScanner: TLinkScanner);
|
||||||
begin
|
begin
|
||||||
if NewScanner=FScanner then exit;
|
if NewScanner=FScanner then exit;
|
||||||
|
LastErrorCheckedForIgnored:=false;
|
||||||
Clear;
|
Clear;
|
||||||
FScanner:=NewScanner;
|
FScanner:=NewScanner; begin
|
||||||
if FScanner<>nil then
|
if Scanner<>nil then
|
||||||
FLastScannerChangeStep:=Scanner.ChangeStep;
|
FLastScannerChangeStep:=Scanner.ChangeStep;
|
||||||
|
Scanner.SetIgnoreErrorAfter(IgnoreErrorAfter.P,IgnoreErrorAfter.Code);
|
||||||
|
end;
|
||||||
FForceUpdateNeeded:=true;
|
FForceUpdateNeeded:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1400,6 +1418,92 @@ begin
|
|||||||
RaiseException(ctsCursorPosOutsideOfCode);
|
RaiseException(ctsCursorPosOutsideOfCode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomCodeTool.IgnoreErrAfterPositionIsInFrontOfLastErrMessage: boolean;
|
||||||
|
var
|
||||||
|
IgnoreErrorAfterCleanPos: integer;
|
||||||
|
begin
|
||||||
|
//writeln('TCustomCodeTool.IgnoreErrAfterPositionIsInFrontOfLastErrMessage ',
|
||||||
|
// ' LastErrorCheckedForIgnored=',LastErrorCheckedForIgnored,
|
||||||
|
// ' LastErrorBehindIgnorePosition=',LastErrorBehindIgnorePosition);
|
||||||
|
if LastErrorCheckedForIgnored then begin
|
||||||
|
Result:=LastErrorBehindIgnorePosition;
|
||||||
|
end else begin
|
||||||
|
if (Scanner<>nil) then begin
|
||||||
|
IgnoreErrorAfterCleanPos:=Scanner.IgnoreErrorAfterCleanedPos;
|
||||||
|
//writeln(' IgnoreErrorAfterCleanPos=',IgnoreErrorAfterCleanPos,
|
||||||
|
// ' LastErrorCurPos.EndPos=',LastErrorCurPos.EndPos,
|
||||||
|
// ' LastErrorPhase>CodeToolPhaseParse=',LastErrorPhase>CodeToolPhaseParse);
|
||||||
|
if IgnoreErrorAfterCleanPos>0 then begin
|
||||||
|
// ignore position in scanned code
|
||||||
|
// -> check if last error behind ignore position
|
||||||
|
if (not LastErrorValid)
|
||||||
|
or (IgnoreErrorAfterCleanPos<=LastErrorCurPos.EndPos) then
|
||||||
|
Result:=true
|
||||||
|
else
|
||||||
|
Result:=false;
|
||||||
|
end else
|
||||||
|
Result:=false;
|
||||||
|
end else
|
||||||
|
Result:=false;
|
||||||
|
LastErrorBehindIgnorePosition:=Result;
|
||||||
|
LastErrorCheckedForIgnored:=true;
|
||||||
|
end;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TCustomCodeTool.IgnoreErrAfterPositionIsInFrontOfLastErrMessage ',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCustomCodeTool.IgnoreErrorAfterValid: boolean;
|
||||||
|
begin
|
||||||
|
Result:=(Scanner<>nil) and (Scanner.IgnoreErrorAfterValid);
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TCustomCodeTool.IgnoreErrorAfterValid ',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCustomCodeTool.IgnoreErrorAfterCleanedPos: integer;
|
||||||
|
begin
|
||||||
|
if Scanner<>nil then
|
||||||
|
Result:=Scanner.IgnoreErrorAfterCleanedPos
|
||||||
|
else
|
||||||
|
Result:=-1;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TCustomCodeTool.IgnoreErrorAfterCleanedPos ',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCustomCodeTool.LastErrorsInFrontOfCleanedPos(ACleanedPos: integer
|
||||||
|
): boolean;
|
||||||
|
begin
|
||||||
|
if (Scanner<>nil) and Scanner.LastErrorsInFrontOfCleanedPos(ACleanedPos)
|
||||||
|
then
|
||||||
|
Result:=true
|
||||||
|
else if (LastErrorValid)
|
||||||
|
and (LastErrorCurPos.EndPos<=ACleanedPos) then
|
||||||
|
Result:=true
|
||||||
|
else
|
||||||
|
Result:=false;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TCustomCodeTool.LastErrorsInFrontOfCleanedPos ACleanedPos=',ACleanedPos,
|
||||||
|
Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomCodeTool.RaiseLastErrorIfInFrontOfCleanedPos(
|
||||||
|
ACleanedPos: integer);
|
||||||
|
begin
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TCustomCodeTool.RaiseLastErrorIfInFrontOfCleanedPos A ACleanedPos=',ACleanedPos,
|
||||||
|
' ');
|
||||||
|
{$ENDIF}
|
||||||
|
if Scanner<>nil then Scanner.RaiseLastErrorIfInFrontOfCleanedPos(ACleanedPos);
|
||||||
|
//writeln('TCustomCodeTool.RaiseLastErrorIfInFrontOfCleanedPos B ',LastErrorPhase<CodeToolPhaseTool,' ',LastErrorCurPos.EndPos);
|
||||||
|
if LastErrorValid
|
||||||
|
and (LastErrorCurPos.EndPos<=ACleanedPos) then
|
||||||
|
RaiseLastError;
|
||||||
|
//writeln('TCustomCodeTool.RaiseLastErrorIfInFrontOfCleanedPos END ');
|
||||||
|
end;
|
||||||
|
|
||||||
function TCustomCodeTool.StringIsKeyWord(const Word: string): boolean;
|
function TCustomCodeTool.StringIsKeyWord(const Word: string): boolean;
|
||||||
begin
|
begin
|
||||||
Result:=(Word<>'') and IsIdentStartChar[Word[1]]
|
Result:=(Word<>'') and IsIdentStartChar[Word[1]]
|
||||||
@ -1487,12 +1591,23 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomCodeTool.SetIgnoreAfterCodeXY(const AValue: TCodeXYPosition);
|
procedure TCustomCodeTool.SetIgnoreErrorAfter(const AValue: TCodePosition);
|
||||||
begin
|
begin
|
||||||
if (FIgnoreAfterCodeXY.Code=AValue.Code)
|
if (IgnoreErrorAfter.Code=AValue.Code)
|
||||||
and (FIgnoreAfterCodeXY.X=AValue.X)
|
and (IgnoreErrorAfter.P=AValue.P) then exit;
|
||||||
and (FIgnoreAfterCodeXY.Y=AValue.Y) then exit;
|
FIgnoreErrorAfter:=AValue;
|
||||||
FIgnoreAfterCodeXY:=AValue;
|
LastErrorCheckedForIgnored:=false;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
write('TCustomCodeTool.SetIgnoreErrorAfter ');
|
||||||
|
if FIgnoreErrorAfter.Code<>nil then
|
||||||
|
write(FIgnoreErrorAfter.Code.Filename)
|
||||||
|
else
|
||||||
|
write('nil');
|
||||||
|
write(' ',FIgnoreErrorAfter.P);
|
||||||
|
writeln('');
|
||||||
|
{$ENDIF}
|
||||||
|
if Scanner<>nil then
|
||||||
|
Scanner.SetIgnoreErrorAfter(IgnoreErrorAfter.P,IgnoreErrorAfter.Code);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomCodeTool.DefaultKeyWordFunc: boolean;
|
function TCustomCodeTool.DefaultKeyWordFunc: boolean;
|
||||||
@ -1729,9 +1844,9 @@ begin
|
|||||||
Result:=StartPos;
|
Result:=StartPos;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomCodeTool.ClearIgnoreAfterPosition;
|
procedure TCustomCodeTool.ClearIgnoreErrorAfter;
|
||||||
begin
|
begin
|
||||||
FIgnoreAfterCodeXY.Code:=nil;
|
IgnoreErrorAfter:=CodePosition(0,nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomCodeTool.UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean;
|
function TCustomCodeTool.UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean;
|
||||||
|
@ -49,7 +49,7 @@ interface
|
|||||||
|
|
||||||
{ $DEFINE CTDEBUG}
|
{ $DEFINE CTDEBUG}
|
||||||
{ $DEFINE ShowSearchPaths}
|
{ $DEFINE ShowSearchPaths}
|
||||||
{$DEFINE ShowTriedFiles}
|
{ $DEFINE ShowTriedFiles}
|
||||||
{ $DEFINE ShowTriedContexts}
|
{ $DEFINE ShowTriedContexts}
|
||||||
{ $DEFINE ShowTriedIdentifiers}
|
{ $DEFINE ShowTriedIdentifiers}
|
||||||
{ $DEFINE ShowExprEval}
|
{ $DEFINE ShowExprEval}
|
||||||
@ -59,6 +59,7 @@ interface
|
|||||||
{ $DEFINE ShowBaseTypeCache}
|
{ $DEFINE ShowBaseTypeCache}
|
||||||
{ $DEFINE ShowCacheDependencies}
|
{ $DEFINE ShowCacheDependencies}
|
||||||
{ $DEFINE ShowCollect}
|
{ $DEFINE ShowCollect}
|
||||||
|
{ $DEFINE IgnoreErrorAfterCursor}
|
||||||
|
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -765,13 +766,13 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
SkipChecks:=false;
|
SkipChecks:=false;
|
||||||
ActivateGlobalWriteLock;
|
ActivateGlobalWriteLock;
|
||||||
IgnoreAfterCodeXY:=CursorPos;
|
|
||||||
try
|
try
|
||||||
// build code tree
|
// build code tree
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln(DebugPrefix,'TFindDeclarationTool.FindDeclaration A CursorPos=',CursorPos.X,',',CursorPos.Y);
|
writeln(DebugPrefix,'TFindDeclarationTool.FindDeclaration A CursorPos=',CursorPos.X,',',CursorPos.Y);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos);
|
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
||||||
|
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}]);
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln(DebugPrefix,'TFindDeclarationTool.FindDeclaration C CleanCursorPos=',CleanCursorPos);
|
writeln(DebugPrefix,'TFindDeclarationTool.FindDeclaration C CleanCursorPos=',CleanCursorPos);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -847,7 +848,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
ClearIgnoreAfterPosition;
|
ClearIgnoreErrorAfter;
|
||||||
DeactivateGlobalWriteLock;
|
DeactivateGlobalWriteLock;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1328,9 +1329,10 @@ var
|
|||||||
BuildSubTreeForClass(ContextNode);
|
BuildSubTreeForClass(ContextNode);
|
||||||
end;
|
end;
|
||||||
if (ContextNode.LastChild<>nil) then begin
|
if (ContextNode.LastChild<>nil) then begin
|
||||||
if not (fdfSearchForward in Params.Flags) then
|
if not (fdfSearchForward in Params.Flags) then begin
|
||||||
|
RaiseLastErrorIfInFrontOfCleanedPos(ContextNode.EndPos);
|
||||||
ContextNode:=ContextNode.LastChild
|
ContextNode:=ContextNode.LastChild
|
||||||
else
|
end else
|
||||||
ContextNode:=ContextNode.FirstChild;
|
ContextNode:=ContextNode.FirstChild;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1464,8 +1466,10 @@ var
|
|||||||
// search next in prior/next brother
|
// search next in prior/next brother
|
||||||
if not (fdfSearchForward in Params.Flags) then
|
if not (fdfSearchForward in Params.Flags) then
|
||||||
ContextNode:=ContextNode.PriorBrother
|
ContextNode:=ContextNode.PriorBrother
|
||||||
else
|
else begin
|
||||||
|
RaiseLastErrorIfInFrontOfCleanedPos(ContextNode.NextBrother.EndPos);
|
||||||
ContextNode:=ContextNode.NextBrother;
|
ContextNode:=ContextNode.NextBrother;
|
||||||
|
end;
|
||||||
{$IFDEF ShowTriedIdentifiers}
|
{$IFDEF ShowTriedIdentifiers}
|
||||||
writeln('[TFindDeclarationTool.FindIdentifierInContext] Searching in Brother ContextNode=',ContextNode.DescAsString);
|
writeln('[TFindDeclarationTool.FindIdentifierInContext] Searching in Brother ContextNode=',ContextNode.DescAsString);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
@ -37,6 +37,8 @@ unit LinkScanner;
|
|||||||
|
|
||||||
{$I codetools.inc}
|
{$I codetools.inc}
|
||||||
|
|
||||||
|
{ $DEFINE ShowIgnoreErrorAfter}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -129,6 +131,8 @@ type
|
|||||||
FOnCheckFileOnDisk: TOnCheckFileOnDisk;
|
FOnCheckFileOnDisk: TOnCheckFileOnDisk;
|
||||||
FOnGetInitValues: TOnGetInitValues;
|
FOnGetInitValues: TOnGetInitValues;
|
||||||
FOnIncludeCode: TOnIncludeCode;
|
FOnIncludeCode: TOnIncludeCode;
|
||||||
|
FIgnoreErrorAfterCode: Pointer;
|
||||||
|
FIgnoreErrorAfterCursorPos: integer;
|
||||||
FInitValues: TExpressionEvaluator;
|
FInitValues: TExpressionEvaluator;
|
||||||
FInitValuesChangeStep: integer;
|
FInitValuesChangeStep: integer;
|
||||||
FSourceChangeSteps: TList; // list of PSourceChangeStep sorted with Code
|
FSourceChangeSteps: TList; // list of PSourceChangeStep sorted with Code
|
||||||
@ -226,6 +230,9 @@ type
|
|||||||
LastErrorSrcPos: integer;
|
LastErrorSrcPos: integer;
|
||||||
LastErrorCode: pointer;
|
LastErrorCode: pointer;
|
||||||
LastErrorIsValid: boolean;
|
LastErrorIsValid: boolean;
|
||||||
|
LastErrorBehindIgnorePosition: boolean;
|
||||||
|
LastErrorCheckedForIgnored: boolean;
|
||||||
|
CleanedIgnoreErrorAfterPosition: integer;
|
||||||
procedure RaiseExceptionFmt(const AMessage: string; args: array of const);
|
procedure RaiseExceptionFmt(const AMessage: string; args: array of const);
|
||||||
procedure RaiseException(const AMessage: string);
|
procedure RaiseException(const AMessage: string);
|
||||||
procedure ClearLastError;
|
procedure ClearLastError;
|
||||||
@ -244,6 +251,7 @@ type
|
|||||||
EndOfInterfaceFound: boolean;
|
EndOfInterfaceFound: boolean;
|
||||||
EndOfSourceFound: boolean;
|
EndOfSourceFound: boolean;
|
||||||
|
|
||||||
|
// links
|
||||||
property Links[Index: integer]: TSourceLink read GetLinks write SetLinks;
|
property Links[Index: integer]: TSourceLink read GetLinks write SetLinks;
|
||||||
function LinkCount: integer;
|
function LinkCount: integer;
|
||||||
function LinkIndexAtCleanPos(ACleanPos: integer): integer;
|
function LinkIndexAtCleanPos(ACleanPos: integer): integer;
|
||||||
@ -253,6 +261,7 @@ type
|
|||||||
function FindFirstSiblingLink(LinkIndex: integer): integer;
|
function FindFirstSiblingLink(LinkIndex: integer): integer;
|
||||||
function FindParentLink(LinkIndex: integer): integer;
|
function FindParentLink(LinkIndex: integer): integer;
|
||||||
|
|
||||||
|
// source mapping (Cleaned <-> Original)
|
||||||
function CleanedSrc: string;
|
function CleanedSrc: string;
|
||||||
function CursorToCleanPos(ACursorPos: integer; ACode: pointer;
|
function CursorToCleanPos(ACursorPos: integer; ACode: pointer;
|
||||||
var ACleanPos: integer): integer; // 0=valid CleanPos
|
var ACleanPos: integer): integer; // 0=valid CleanPos
|
||||||
@ -260,12 +269,40 @@ type
|
|||||||
// 1=CursorPos beyond scanned code
|
// 1=CursorPos beyond scanned code
|
||||||
function CleanedPosToCursor(ACleanedPos: integer; var ACursorPos: integer;
|
function CleanedPosToCursor(ACleanedPos: integer; var ACursorPos: integer;
|
||||||
var ACode: Pointer): boolean;
|
var ACode: Pointer): boolean;
|
||||||
|
function LastErrorsInFrontOfCleanedPos(ACleanedPos: integer): boolean;
|
||||||
|
procedure RaiseLastErrorIfInFrontOfCleanedPos(ACleanedPos: integer);
|
||||||
|
|
||||||
|
// ranges
|
||||||
function WholeRangeIsWritable(CleanStartPos, CleanEndPos: integer): boolean;
|
function WholeRangeIsWritable(CleanStartPos, CleanEndPos: integer): boolean;
|
||||||
procedure FindCodeInRange(CleanStartPos, CleanEndPos: integer;
|
procedure FindCodeInRange(CleanStartPos, CleanEndPos: integer;
|
||||||
UniqueSortedCodeList: TList);
|
UniqueSortedCodeList: TList);
|
||||||
procedure DeleteRange(CleanStartPos,CleanEndPos: integer);
|
procedure DeleteRange(CleanStartPos,CleanEndPos: integer);
|
||||||
|
|
||||||
|
// scanning
|
||||||
|
procedure Scan(TillInterfaceEnd, CheckFilesOnDisk: boolean);
|
||||||
|
function UpdateNeeded(OnlyInterfaceNeeded,
|
||||||
|
CheckFilesOnDisk: boolean): boolean;
|
||||||
|
procedure SetIgnoreErrorAfter(ACursorPos: integer; ACode: Pointer);
|
||||||
|
procedure ClearIgnoreErrorAfter;
|
||||||
|
function IgnoreErrAfterPositionIsInFrontOfLastErrMessage: boolean;
|
||||||
|
function IgnoreErrorAfterCleanedPos: integer;
|
||||||
|
function IgnoreErrorAfterValid: boolean;
|
||||||
|
|
||||||
|
function GuessMisplacedIfdefEndif(StartCursorPos: integer;
|
||||||
|
StartCode: pointer;
|
||||||
|
var EndCursorPos: integer; var EndCode: Pointer): boolean;
|
||||||
|
|
||||||
|
property ChangeStep: integer read FChangeStep;
|
||||||
|
|
||||||
|
// global write lock
|
||||||
|
procedure ActivateGlobalWriteLock;
|
||||||
|
procedure DeactivateGlobalWriteLock;
|
||||||
|
property OnGetGlobalWriteLockInfo: TOnGetWriteLockInfo
|
||||||
|
read FOnGetGlobalWriteLockInfo write FOnGetGlobalWriteLockInfo;
|
||||||
|
property OnSetGlobalWriteLock: TOnSetWriteLock
|
||||||
|
read FOnSetGlobalWriteLock write FOnSetGlobalWriteLock;
|
||||||
|
|
||||||
|
// properties
|
||||||
property OnGetSource: TOnGetSource read FOnGetSource write FOnGetSource;
|
property OnGetSource: TOnGetSource read FOnGetSource write FOnGetSource;
|
||||||
property OnLoadSource: TOnLoadSource read FOnLoadSource write FOnLoadSource;
|
property OnLoadSource: TOnLoadSource read FOnLoadSource write FOnLoadSource;
|
||||||
property OnDeleteSource: TOnDeleteSource
|
property OnDeleteSource: TOnDeleteSource
|
||||||
@ -294,22 +331,6 @@ type
|
|||||||
property ScanTillInterfaceEnd: boolean
|
property ScanTillInterfaceEnd: boolean
|
||||||
read FScanTillInterfaceEnd write SetScanTillInterfaceEnd;
|
read FScanTillInterfaceEnd write SetScanTillInterfaceEnd;
|
||||||
|
|
||||||
procedure Scan(TillInterfaceEnd, CheckFilesOnDisk: boolean);
|
|
||||||
function UpdateNeeded(OnlyInterfaceNeeded,
|
|
||||||
CheckFilesOnDisk: boolean): boolean;
|
|
||||||
function GuessMisplacedIfdefEndif(StartCursorPos: integer;
|
|
||||||
StartCode: pointer;
|
|
||||||
var EndCursorPos: integer; var EndCode: Pointer): boolean;
|
|
||||||
|
|
||||||
property ChangeStep: integer read FChangeStep;
|
|
||||||
|
|
||||||
procedure ActivateGlobalWriteLock;
|
|
||||||
procedure DeactivateGlobalWriteLock;
|
|
||||||
property OnGetGlobalWriteLockInfo: TOnGetWriteLockInfo
|
|
||||||
read FOnGetGlobalWriteLockInfo write FOnGetGlobalWriteLockInfo;
|
|
||||||
property OnSetGlobalWriteLock: TOnSetWriteLock
|
|
||||||
read FOnSetGlobalWriteLock write FOnSetGlobalWriteLock;
|
|
||||||
|
|
||||||
procedure Clear;
|
procedure Clear;
|
||||||
function ConsistencyCheck: integer;
|
function ConsistencyCheck: integer;
|
||||||
procedure WriteDebugReport;
|
procedure WriteDebugReport;
|
||||||
@ -890,8 +911,13 @@ var LastTokenType: TLSTokenType;
|
|||||||
s: string;
|
s: string;
|
||||||
begin
|
begin
|
||||||
if not UpdateNeeded(TillInterfaceEnd,CheckFilesOnDisk) then begin
|
if not UpdateNeeded(TillInterfaceEnd,CheckFilesOnDisk) then begin
|
||||||
// no input has changed -> the output is the same
|
// input is the same as last time -> output is the same
|
||||||
if LastErrorIsValid then RaiseLastError;
|
// -> if there was an error, raise it again
|
||||||
|
if LastErrorIsValid
|
||||||
|
and ((not IgnoreErrorAfterValid)
|
||||||
|
or (not IgnoreErrAfterPositionIsInFrontOfLastErrMessage))
|
||||||
|
then
|
||||||
|
RaiseLastError;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
@ -941,26 +967,35 @@ begin
|
|||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln('TLinkScanner.Scan F ',SrcLen);
|
writeln('TLinkScanner.Scan F ',SrcLen);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
repeat
|
try
|
||||||
ReadNextToken;
|
repeat
|
||||||
//writeln('TLinkScanner.Scan G "',copy(Src,TokenStart,SrcPos-TokenStart),'"');
|
ReadNextToken;
|
||||||
UpdateCleanedSource(SrcPos-1);
|
//writeln('TLinkScanner.Scan G "',copy(Src,TokenStart,SrcPos-TokenStart),'"');
|
||||||
if (SrcPos<=SrcLen+1) then begin
|
UpdateCleanedSource(SrcPos-1);
|
||||||
if (LastTokenType<>lsttEqual)
|
if (SrcPos<=SrcLen+1) then begin
|
||||||
and (TokenType=lsttEndOfInterface) then begin
|
if (LastTokenType<>lsttEqual)
|
||||||
EndOfInterfaceFound:=true
|
and (TokenType=lsttEndOfInterface) then begin
|
||||||
end else if (LastTokenType=lsttEnd) and (TokenType=lsttPoint) then begin
|
EndOfInterfaceFound:=true
|
||||||
EndOfInterfaceFound:=true;
|
end else if (LastTokenType=lsttEnd) and (TokenType=lsttPoint) then begin
|
||||||
EndOfSourceFound:=true;
|
EndOfInterfaceFound:=true;
|
||||||
|
EndOfSourceFound:=true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
LastTokenType:=TokenType;
|
||||||
|
end else
|
||||||
break;
|
break;
|
||||||
end;
|
until (SrcPos>SrcLen) or EndOfSourceFound
|
||||||
LastTokenType:=TokenType;
|
or (ScanTillInterfaceEnd and EndOfInterfaceFound);
|
||||||
end else
|
IncreaseChangeStep;
|
||||||
break;
|
FForceUpdateNeeded:=false;
|
||||||
until (SrcPos>SrcLen) or EndOfSourceFound
|
except
|
||||||
or (ScanTillInterfaceEnd and EndOfInterfaceFound);
|
if (not IgnoreErrorAfterValid)
|
||||||
IncreaseChangeStep;
|
or (not IgnoreErrAfterPositionIsInFrontOfLastErrMessage) then
|
||||||
FForceUpdateNeeded:=false;
|
raise;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TLinkScanner.Scan IGNORING ERROR: ',LastErrorMessage);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln('TLinkScanner.Scan END ',CleanedLen);
|
writeln('TLinkScanner.Scan END ',CleanedLen);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -1266,6 +1301,100 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLinkScanner.SetIgnoreErrorAfter(ACursorPos: integer; ACode: Pointer
|
||||||
|
);
|
||||||
|
begin
|
||||||
|
if (FIgnoreErrorAfterCode=ACode)
|
||||||
|
and (FIgnoreErrorAfterCursorPos=ACursorPos) then exit;
|
||||||
|
FIgnoreErrorAfterCode:=ACode;
|
||||||
|
FIgnoreErrorAfterCursorPos:=ACursorPos;
|
||||||
|
LastErrorCheckedForIgnored:=false;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
write('TLinkScanner.SetIgnoreErrorAfter ');
|
||||||
|
if FIgnoreErrorAfterCode<>nil then
|
||||||
|
write(OnGetFileName(Self,FIgnoreErrorAfterCode))
|
||||||
|
else
|
||||||
|
write('nil');
|
||||||
|
write(' ',FIgnoreErrorAfterCursorPos);
|
||||||
|
writeln('');
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLinkScanner.ClearIgnoreErrorAfter;
|
||||||
|
begin
|
||||||
|
SetIgnoreErrorAfter(0,nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLinkScanner.IgnoreErrAfterPositionIsInFrontOfLastErrMessage: boolean;
|
||||||
|
var
|
||||||
|
CleanResult: integer;
|
||||||
|
begin
|
||||||
|
//writeln('TLinkScanner.IgnoreErrAfterPositionIsInFrontOfLastErrMessage');
|
||||||
|
//writeln(' LastErrorCheckedForIgnored=',LastErrorCheckedForIgnored,
|
||||||
|
// ' LastErrorBehindIgnorePosition=',LastErrorBehindIgnorePosition);
|
||||||
|
if LastErrorCheckedForIgnored then
|
||||||
|
Result:=LastErrorBehindIgnorePosition
|
||||||
|
else begin
|
||||||
|
CleanedIgnoreErrorAfterPosition:=-1;
|
||||||
|
if (FIgnoreErrorAfterCode<>nil) and (FIgnoreErrorAfterCursorPos>0) then
|
||||||
|
begin
|
||||||
|
CleanResult:=CursorToCleanPos(FIgnoreErrorAfterCursorPos,
|
||||||
|
FIgnoreErrorAfterCode,CleanedIgnoreErrorAfterPosition);
|
||||||
|
//writeln(' CleanResult=',CleanResult,
|
||||||
|
// ' CleanedIgnoreErrorAfterPosition=',CleanedIgnoreErrorAfterPosition,
|
||||||
|
// ' FIgnoreErrorAfterCursorPos=',FIgnoreErrorAfterCursorPos);
|
||||||
|
if (CleanResult=0) or (CleanResult=-1)
|
||||||
|
or (not LastErrorIsValid) then begin
|
||||||
|
Result:=true;
|
||||||
|
end else begin
|
||||||
|
Result:=false;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
Result:=false;
|
||||||
|
end;
|
||||||
|
LastErrorBehindIgnorePosition:=Result;
|
||||||
|
LastErrorCheckedForIgnored:=true;
|
||||||
|
end;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TLinkScanner.IgnoreErrAfterPositionIsInFrontOfLastErrMessage Result=',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLinkScanner.IgnoreErrorAfterCleanedPos: integer;
|
||||||
|
begin
|
||||||
|
if IgnoreErrAfterPositionIsInFrontOfLastErrMessage then
|
||||||
|
Result:=CleanedIgnoreErrorAfterPosition
|
||||||
|
else
|
||||||
|
Result:=-1;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TLinkScanner.IgnoreErrorAfterCleanedPos Result=',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLinkScanner.IgnoreErrorAfterValid: boolean;
|
||||||
|
begin
|
||||||
|
Result:=(FIgnoreErrorAfterCode<>nil);
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TLinkScanner.IgnoreErrorAfterValid Result=',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLinkScanner.LastErrorsInFrontOfCleanedPos(ACleanedPos: integer
|
||||||
|
): boolean;
|
||||||
|
begin
|
||||||
|
Result:=LastErrorIsValid and (CleanedLen>ACleanedPos);
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TLinkScanner.LastErrorsInFrontOfCleanedPos Result=',Result);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLinkScanner.RaiseLastErrorIfInFrontOfCleanedPos(ACleanedPos: integer
|
||||||
|
);
|
||||||
|
begin
|
||||||
|
if LastErrorsInFrontOfCleanedPos(ACleanedPos) then
|
||||||
|
RaiseLastError;
|
||||||
|
end;
|
||||||
|
|
||||||
{-------------------------------------------------------------------------------
|
{-------------------------------------------------------------------------------
|
||||||
function TLinkScanner.GuessMisplacedIfdefEndif
|
function TLinkScanner.GuessMisplacedIfdefEndif
|
||||||
Params: StartCursorPos: integer; StartCode: pointer;
|
Params: StartCursorPos: integer; StartCode: pointer;
|
||||||
@ -2525,12 +2654,14 @@ begin
|
|||||||
LastErrorMessage:=AMessage;
|
LastErrorMessage:=AMessage;
|
||||||
LastErrorSrcPos:=SrcPos;
|
LastErrorSrcPos:=SrcPos;
|
||||||
LastErrorCode:=Code;
|
LastErrorCode:=Code;
|
||||||
|
LastErrorCheckedForIgnored:=false;
|
||||||
raise ELinkScannerError.Create(Self,AMessage);
|
raise ELinkScannerError.Create(Self,AMessage);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLinkScanner.ClearLastError;
|
procedure TLinkScanner.ClearLastError;
|
||||||
begin
|
begin
|
||||||
LastErrorIsValid:=false;
|
LastErrorIsValid:=false;
|
||||||
|
LastErrorCheckedForIgnored:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLinkScanner.RaiseLastError;
|
procedure TLinkScanner.RaiseLastError;
|
||||||
|
@ -265,7 +265,7 @@ begin
|
|||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln('TMethodJumpingCodeTool.FindJumpPoint A CursorPos=',CursorPos.X,',',CursorPos.Y);
|
writeln('TMethodJumpingCodeTool.FindJumpPoint A CursorPos=',CursorPos.X,',',CursorPos.Y);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos);
|
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
|
||||||
GetLineInfo(CleanCursorPos,LineStart,LineEnd,FirstAtomStart,LastAtomEnd);
|
GetLineInfo(CleanCursorPos,LineStart,LineEnd,FirstAtomStart,LastAtomEnd);
|
||||||
if CleanCursorPos<FirstAtomStart then CleanCursorPos:=FirstAtomStart;
|
if CleanCursorPos<FirstAtomStart then CleanCursorPos:=FirstAtomStart;
|
||||||
if CleanCursorPos>=LastAtomEnd then CleanCursorPos:=LastAtomEnd-1;
|
if CleanCursorPos>=LastAtomEnd then CleanCursorPos:=LastAtomEnd-1;
|
||||||
|
@ -35,6 +35,8 @@ interface
|
|||||||
|
|
||||||
{$I codetools.inc}
|
{$I codetools.inc}
|
||||||
|
|
||||||
|
{ $DEFINE ShowIgnoreErrorAfter}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF MEM_CHECK}
|
{$IFDEF MEM_CHECK}
|
||||||
MemCheck,
|
MemCheck,
|
||||||
@ -83,6 +85,9 @@ type
|
|||||||
|
|
||||||
TTreeRange = (trInterface, trAll, trTillCursor);
|
TTreeRange = (trInterface, trAll, trTillCursor);
|
||||||
|
|
||||||
|
TBuildTreeFlag = (btSetIgnoreErrorPos,btKeepIgnoreErrorPos);
|
||||||
|
TBuildTreeFlags = set of TBuildTreeFlag;
|
||||||
|
|
||||||
TPascalParserTool = class(TMultiKeyWordListCodeTool)
|
TPascalParserTool = class(TMultiKeyWordListCodeTool)
|
||||||
private
|
private
|
||||||
protected
|
protected
|
||||||
@ -179,13 +184,14 @@ type
|
|||||||
|
|
||||||
procedure BuildTree(OnlyInterfaceNeeded: boolean); virtual;
|
procedure BuildTree(OnlyInterfaceNeeded: boolean); virtual;
|
||||||
procedure BuildTreeAndGetCleanPos(TreeRange: TTreeRange;
|
procedure BuildTreeAndGetCleanPos(TreeRange: TTreeRange;
|
||||||
CursorPos: TCodeXYPosition; var CleanCursorPos: integer);
|
CursorPos: TCodeXYPosition; var CleanCursorPos: integer;
|
||||||
|
BuildTreeFlags: TBuildTreeFlags);
|
||||||
procedure BuildSubTreeForClass(ClassNode: TCodeTreeNode); virtual;
|
procedure BuildSubTreeForClass(ClassNode: TCodeTreeNode); virtual;
|
||||||
procedure BuildSubTreeForBeginBlock(BeginNode: TCodeTreeNode); virtual;
|
procedure BuildSubTreeForBeginBlock(BeginNode: TCodeTreeNode); virtual;
|
||||||
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode); virtual;
|
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode); virtual;
|
||||||
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
|
procedure BuildSubTreeForProcHead(ProcNode: TCodeTreeNode;
|
||||||
var FunctionResult: TCodeTreeNode);
|
var FunctionResult: TCodeTreeNode);
|
||||||
|
|
||||||
function DoAtom: boolean; override;
|
function DoAtom: boolean; override;
|
||||||
|
|
||||||
function ExtractPropName(PropNode: TCodeTreeNode;
|
function ExtractPropName(PropNode: TCodeTreeNode;
|
||||||
@ -435,9 +441,12 @@ begin
|
|||||||
writeln('TPascalParserTool.BuildTree A');
|
writeln('TPascalParserTool.BuildTree A');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if not UpdateNeeded(OnlyInterfaceNeeded) then begin
|
if not UpdateNeeded(OnlyInterfaceNeeded) then begin
|
||||||
// input has not changed
|
// input is the same as last time -> output is the same
|
||||||
// -> if there was an error, raise it again
|
// -> if there was an error, raise it again
|
||||||
if LastErrorPhase in [CodeToolPhaseScan,CodeToolPhaseParse] then
|
if (LastErrorPhase in [CodeToolPhaseScan,CodeToolPhaseParse])
|
||||||
|
and ((not IgnoreErrorAfterValid)
|
||||||
|
or (not IgnoreErrAfterPositionIsInFrontOfLastErrMessage))
|
||||||
|
then
|
||||||
RaiseLastError;
|
RaiseLastError;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -455,48 +464,60 @@ begin
|
|||||||
ImplementationSectionFound:=false;
|
ImplementationSectionFound:=false;
|
||||||
EndOfSourceFound:=false;
|
EndOfSourceFound:=false;
|
||||||
|
|
||||||
ReadNextAtom;
|
try
|
||||||
if UpAtomIs('UNIT') then
|
|
||||||
CurSection:=ctnUnit
|
|
||||||
else if UpAtomIs('PROGRAM') then
|
|
||||||
CurSection:=ctnProgram
|
|
||||||
else if UpAtomIs('PACKAGE') then
|
|
||||||
CurSection:=ctnPackage
|
|
||||||
else if UpAtomIs('LIBRARY') then
|
|
||||||
CurSection:=ctnLibrary
|
|
||||||
else
|
|
||||||
SaveRaiseExceptionFmt(ctsNoPascalCodeFound,[GetAtom]);
|
|
||||||
CreateChildNode;
|
|
||||||
CurNode.Desc:=CurSection;
|
|
||||||
ReadNextAtom; // read source name
|
|
||||||
AtomIsIdentifier(true);
|
|
||||||
ReadNextAtom; // read ';'
|
|
||||||
if (CurPos.Flag<>cafSemicolon) then
|
|
||||||
RaiseCharExpectedButAtomFound(';');
|
|
||||||
if CurSection=ctnUnit then begin
|
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
CurNode.EndPos:=CurPos.StartPos;
|
if UpAtomIs('UNIT') then
|
||||||
EndChildNode;
|
CurSection:=ctnUnit
|
||||||
if not UpAtomIs('INTERFACE') then
|
else if UpAtomIs('PROGRAM') then
|
||||||
RaiseStringExpectedButAtomFound('"interface"');
|
CurSection:=ctnProgram
|
||||||
|
else if UpAtomIs('PACKAGE') then
|
||||||
|
CurSection:=ctnPackage
|
||||||
|
else if UpAtomIs('LIBRARY') then
|
||||||
|
CurSection:=ctnLibrary
|
||||||
|
else
|
||||||
|
SaveRaiseExceptionFmt(ctsNoPascalCodeFound,[GetAtom]);
|
||||||
CreateChildNode;
|
CreateChildNode;
|
||||||
CurSection:=ctnInterface;
|
|
||||||
CurNode.Desc:=CurSection;
|
CurNode.Desc:=CurSection;
|
||||||
end;
|
ReadNextAtom; // read source name
|
||||||
InterfaceSectionFound:=true;
|
AtomIsIdentifier(true);
|
||||||
ReadNextAtom;
|
ReadNextAtom; // read ';'
|
||||||
if UpAtomIs('USES') then
|
if (CurPos.Flag<>cafSemicolon) then
|
||||||
ReadUsesSection(true);
|
RaiseCharExpectedButAtomFound(';');
|
||||||
repeat
|
if CurSection=ctnUnit then begin
|
||||||
//writeln('[TPascalParserTool.BuildTree] ALL '+GetAtom);
|
ReadNextAtom;
|
||||||
if not DoAtom then break;
|
CurNode.EndPos:=CurPos.StartPos;
|
||||||
if CurSection=ctnNone then begin
|
EndChildNode;
|
||||||
EndOfSourceFound:=true;
|
if not UpAtomIs('INTERFACE') then
|
||||||
break;
|
RaiseStringExpectedButAtomFound('"interface"');
|
||||||
|
CreateChildNode;
|
||||||
|
CurSection:=ctnInterface;
|
||||||
|
CurNode.Desc:=CurSection;
|
||||||
end;
|
end;
|
||||||
|
InterfaceSectionFound:=true;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
until (CurPos.StartPos>SrcLen);
|
if UpAtomIs('USES') then
|
||||||
FForceUpdateNeeded:=false;
|
ReadUsesSection(true);
|
||||||
|
repeat
|
||||||
|
//writeln('[TPascalParserTool.BuildTree] ALL '+GetAtom);
|
||||||
|
if not DoAtom then break;
|
||||||
|
if CurSection=ctnNone then begin
|
||||||
|
EndOfSourceFound:=true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
ReadNextAtom;
|
||||||
|
until (CurPos.StartPos>SrcLen);
|
||||||
|
FForceUpdateNeeded:=false;
|
||||||
|
except
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TPascalParserTool.BuildTree ',MainFilename,' ERROR: ',LastErrorMessage);
|
||||||
|
{$ENDIF}
|
||||||
|
if (not IgnoreErrorAfterValid)
|
||||||
|
or (not IgnoreErrAfterPositionIsInFrontOfLastErrMessage) then
|
||||||
|
raise;
|
||||||
|
{$IFDEF ShowIgnoreErrorAfter}
|
||||||
|
writeln('TPascalParserTool.BuildTree ',MainFilename,' IGNORING ERROR: ',LastErrorMessage);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
writeln('[TPascalParserTool.BuildTree] END');
|
writeln('[TPascalParserTool.BuildTree] END');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -3671,13 +3692,30 @@ end;
|
|||||||
|
|
||||||
procedure TPascalParserTool.BuildTreeAndGetCleanPos(
|
procedure TPascalParserTool.BuildTreeAndGetCleanPos(
|
||||||
TreeRange: TTreeRange; CursorPos: TCodeXYPosition;
|
TreeRange: TTreeRange; CursorPos: TCodeXYPosition;
|
||||||
var CleanCursorPos: integer);
|
var CleanCursorPos: integer; BuildTreeFlags: TBuildTreeFlags);
|
||||||
var Dummy: integer;
|
var
|
||||||
|
Dummy: integer;
|
||||||
|
IgnorePos: TCodePosition;
|
||||||
begin
|
begin
|
||||||
|
if (btSetIgnoreErrorPos in BuildTreeFlags) then begin
|
||||||
|
if (CursorPos.Code<>nil) then begin
|
||||||
|
IgnorePos.Code:=CursorPos.Code;
|
||||||
|
IgnorePos.Code.LineColToPosition(CursorPos.Y,CursorPos.X,IgnorePos.P);
|
||||||
|
if IgnorePos.P<1 then IgnorePos.Code:=nil;
|
||||||
|
IgnoreErrorAfter:=IgnorePos;
|
||||||
|
end else
|
||||||
|
ClearIgnoreErrorAfter;
|
||||||
|
end
|
||||||
|
else if (btKeepIgnoreErrorPos in BuildTreeFlags) then
|
||||||
|
ClearIgnoreErrorAfter;
|
||||||
|
|
||||||
if (TreeRange=trTillCursor) and (not UpdateNeeded(true)) then begin
|
if (TreeRange=trTillCursor) and (not UpdateNeeded(true)) then begin
|
||||||
// interface tree is valid
|
// interface tree is valid
|
||||||
// -> if there was an error, raise it again
|
// -> if there was an error, raise it again
|
||||||
if LastErrorPhase in [CodeToolPhaseScan,CodeToolPhaseParse] then
|
if (LastErrorPhase in [CodeToolPhaseScan,CodeToolPhaseParse])
|
||||||
|
and ((not IgnoreErrorAfterValid)
|
||||||
|
or (not IgnoreErrAfterPositionIsInFrontOfLastErrMessage))
|
||||||
|
then
|
||||||
RaiseLastError;
|
RaiseLastError;
|
||||||
// check if cursor is in interface
|
// check if cursor is in interface
|
||||||
Dummy:=CaretToCleanPos(CursorPos, CleanCursorPos);
|
Dummy:=CaretToCleanPos(CursorPos, CleanCursorPos);
|
||||||
@ -3685,12 +3723,12 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
BuildTree(TreeRange=trInterface);
|
BuildTree(TreeRange=trInterface);
|
||||||
if not EndOfSourceFound then
|
if (not IgnoreErrorAfterValid) and (not EndOfSourceFound) then
|
||||||
SaveRaiseException(ctsEndOfSourceNotFound);
|
SaveRaiseException(ctsEndOfSourceNotFound);
|
||||||
// find the CursorPos in cleaned source
|
// find the CursorPos in cleaned source
|
||||||
Dummy:=CaretToCleanPos(CursorPos, CleanCursorPos);
|
Dummy:=CaretToCleanPos(CursorPos, CleanCursorPos);
|
||||||
if (Dummy<>0) and (Dummy<>-1) then
|
if (Dummy<>0) and (Dummy<>-1) then
|
||||||
SaveRaiseException(ctsCursorPosOutsideOfCode);
|
RaiseException(ctsCursorPosOutsideOfCode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPascalParserTool.FindTypeNodeOfDefinition(
|
function TPascalParserTool.FindTypeNodeOfDefinition(
|
||||||
|
@ -38,6 +38,8 @@ interface
|
|||||||
|
|
||||||
{$I codetools.inc}
|
{$I codetools.inc}
|
||||||
|
|
||||||
|
{ $DEFINE IgnoreErrorAfterCursor}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$IFDEF MEM_CHECK}
|
{$IFDEF MEM_CHECK}
|
||||||
MemCheck,
|
MemCheck,
|
||||||
@ -1471,16 +1473,21 @@ var
|
|||||||
CleanCursorPos, LinkIndex, NewCleanPos: integer;
|
CleanCursorPos, LinkIndex, NewCleanPos: integer;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos);
|
try
|
||||||
LinkIndex:=Scanner.LinkIndexAtCleanPos(CleanCursorPos);
|
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
||||||
LinkIndex:=Scanner.FindParentLink(LinkIndex);
|
[{$IFDEF IgnoreErrorAfterCursor}btSetIgnoreErrorPos{$ENDIF}]);
|
||||||
if LinkIndex<0 then
|
LinkIndex:=Scanner.LinkIndexAtCleanPos(CleanCursorPos);
|
||||||
// this is no include file
|
LinkIndex:=Scanner.FindParentLink(LinkIndex);
|
||||||
exit;
|
if LinkIndex<0 then
|
||||||
NewPos.Code:=TCodeBuffer(Scanner.Links[LinkIndex].Code);
|
// this is no include file
|
||||||
// calculate the directive end bracket
|
exit;
|
||||||
NewCleanPos:=Scanner.Links[LinkIndex].CleanedPos+Scanner.LinkSize(LinkIndex)-1;
|
NewPos.Code:=TCodeBuffer(Scanner.Links[LinkIndex].Code);
|
||||||
Result:=CleanPosToCaretAndTopLine(NewCleanPos,NewPos,NewTopLine);
|
// calculate the directive end bracket
|
||||||
|
NewCleanPos:=Scanner.Links[LinkIndex].CleanedPos+Scanner.LinkSize(LinkIndex)-1;
|
||||||
|
Result:=CleanPosToCaretAndTopLine(NewCleanPos,NewPos,NewTopLine);
|
||||||
|
finally
|
||||||
|
ClearIgnoreErrorAfter;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.ReadTilGuessedUnclosedBlock(
|
function TStandardCodeTool.ReadTilGuessedUnclosedBlock(
|
||||||
|
Loading…
Reference in New Issue
Block a user