converted some silent sourcechangecache consistency checks to errors

git-svn-id: trunk@5065 -
This commit is contained in:
mattias 2004-01-14 23:17:12 +00:00
parent 3e62949c08
commit a2ee1be748
5 changed files with 138 additions and 20 deletions

View File

@ -893,15 +893,23 @@ end;
function TCodeToolManager.HandleException(AnException: Exception): boolean; function TCodeToolManager.HandleException(AnException: Exception): boolean;
var ErrorSrcTool: TCustomCodeTool; var ErrorSrcTool: TCustomCodeTool;
DirtyPos: Integer;
begin begin
fErrorMsg:=AnException.Message; fErrorMsg:=AnException.Message;
fErrorTopLine:=0; fErrorTopLine:=0;
if (AnException is ELinkScannerError) then begin if (AnException is ELinkScannerError) then begin
// linker error // link scanner error
fErrorCode:=TCodeBuffer(ELinkScannerError(AnException).Sender.Code); DirtyPos:=0;
if fErrorCode<>nil then begin if AnException is ELinkScannerEditError then begin
fErrorCode.AbsoluteToLineCol( fErrorCode:=TCodeBuffer(ELinkScannerEditError(AnException).Buffer);
ELinkScannerError(AnException).Sender.SrcPos,fErrorLine,fErrorColumn); if fErrorCode<>nil then
DirtyPos:=ELinkScannerEditError(AnException).BufferPos;
end else begin
fErrorCode:=TCodeBuffer(ELinkScannerError(AnException).Sender.Code);
DirtyPos:=ELinkScannerError(AnException).Sender.SrcPos;
end;
if (fErrorCode<>nil) and (DirtyPos>0) then begin
fErrorCode.AbsoluteToLineCol(DirtyPos,fErrorLine,fErrorColumn);
end; end;
end else if (AnException is ECodeToolError) then begin end else if (AnException is ECodeToolError) then begin
// codetool error // codetool error
@ -909,6 +917,9 @@ begin
fErrorCode:=ErrorSrcTool.ErrorPosition.Code; fErrorCode:=ErrorSrcTool.ErrorPosition.Code;
fErrorColumn:=ErrorSrcTool.ErrorPosition.X; fErrorColumn:=ErrorSrcTool.ErrorPosition.X;
fErrorLine:=ErrorSrcTool.ErrorPosition.Y; fErrorLine:=ErrorSrcTool.ErrorPosition.Y;
end else if (AnException is ESourceChangeCacheError) then begin
// SourceChangeCache error
fErrorCode:=nil;
end else begin end else begin
// unknown exception // unknown exception
FErrorMsg:=AnException.ClassName+': '+FErrorMsg; FErrorMsg:=AnException.ClassName+': '+FErrorMsg;

View File

@ -46,6 +46,7 @@ ResourceString
ctsIncludeFileNotFound = 'include file not found "%s"'; ctsIncludeFileNotFound = 'include file not found "%s"';
ctsErrorInDirectiveExpression = 'error in directive expression'; ctsErrorInDirectiveExpression = 'error in directive expression';
ctsIncludeCircleDetected = 'Include circle detected'; ctsIncludeCircleDetected = 'Include circle detected';
ctsfileIsReadOnly = 'file is read only';
ctsCommentEndNotFound = 'Comment end not found'; ctsCommentEndNotFound = 'Comment end not found';
// customcodetool // customcodetool

View File

@ -138,6 +138,13 @@ type
ELinkScannerAbort = class(ELinkScannerError) ELinkScannerAbort = class(ELinkScannerError)
end; end;
ELinkScannerEditError = class(ELinkScannerError)
Buffer: Pointer;
BufferPos: integer;
constructor Create(ASender: TLinkScanner; const AMessage: string;
ABuffer: Pointer; ABufferPos: integer);
end;
{ TLinkScanner } { TLinkScanner }
@ -264,10 +271,12 @@ type
LastErrorBehindIgnorePosition: boolean; LastErrorBehindIgnorePosition: boolean;
LastErrorCheckedForIgnored: boolean; LastErrorCheckedForIgnored: boolean;
CleanedIgnoreErrorAfterPosition: integer; 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 RaiseExceptionClass(const AMessage: string; procedure RaiseExceptionClass(const AMessage: string;
ExceptionClass: ELinkScannerErrors); ExceptionClass: ELinkScannerErrors);
procedure RaiseEditException(const AMessage: string; ABuffer: Pointer;
ABufferPos: integer);
procedure ClearLastError; procedure ClearLastError;
procedure RaiseLastError; procedure RaiseLastError;
procedure DoCheckAbort; procedure DoCheckAbort;
@ -311,7 +320,8 @@ type
procedure RaiseLastErrorIfInFrontOfCleanedPos(ACleanedPos: integer); procedure RaiseLastErrorIfInFrontOfCleanedPos(ACleanedPos: integer);
// ranges // ranges
function WholeRangeIsWritable(CleanStartPos, CleanEndPos: integer): boolean; function WholeRangeIsWritable(CleanStartPos, CleanEndPos: integer;
ErrorOnFail: boolean): 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);
@ -2780,20 +2790,37 @@ begin
end; end;
end; end;
function TLinkScanner.WholeRangeIsWritable(CleanStartPos, CleanEndPos: integer function TLinkScanner.WholeRangeIsWritable(CleanStartPos, CleanEndPos: integer;
): boolean; ErrorOnFail: boolean): boolean;
var ACode: Pointer;
procedure EditError(const AMessage: string; ACode: Pointer);
begin
if ErrorOnFail then
RaiseEditException(AMessage,ACode,0);
end;
var
ACode: Pointer;
LinkIndex: integer; LinkIndex: integer;
CodeIsReadOnly: boolean; CodeIsReadOnly: boolean;
begin begin
Result:=false; Result:=false;
if (CleanStartPos<1) or (CleanStartPos>=CleanEndPos) if (CleanStartPos<1) or (CleanStartPos>=CleanEndPos)
or (CleanEndPos>CleanedLen+1) or (not Assigned(FOnGetSourceStatus)) then exit; or (CleanEndPos>CleanedLen+1) or (not Assigned(FOnGetSourceStatus)) then begin
EditError('TLinkScanner.WholeRangeIsWritable: Invalid range',nil);
exit;
end;
LinkIndex:=LinkIndexAtCleanPos(CleanStartPos); LinkIndex:=LinkIndexAtCleanPos(CleanStartPos);
if LinkIndex<0 then exit; if LinkIndex<0 then begin
EditError('TLinkScanner.WholeRangeIsWritable: position out of scan range',nil);
exit;
end;
ACode:=FLinks[LinkIndex].Code; ACode:=FLinks[LinkIndex].Code;
FOnGetSourceStatus(Self,ACode,CodeIsReadOnly); FOnGetSourceStatus(Self,ACode,CodeIsReadOnly);
if CodeIsReadOnly then exit; if CodeIsReadOnly then begin
EditError(ctsfileIsReadOnly, ACode);
exit;
end;
repeat repeat
inc(LinkIndex); inc(LinkIndex);
if (LinkIndex>=LinkCount) or (FLinks[LinkIndex].CleanedPos>CleanEndPos) then if (LinkIndex>=LinkCount) or (FLinks[LinkIndex].CleanedPos>CleanEndPos) then
@ -2804,7 +2831,10 @@ begin
if ACode<>FLinks[LinkIndex].Code then begin if ACode<>FLinks[LinkIndex].Code then begin
ACode:=FLinks[LinkIndex].Code; ACode:=FLinks[LinkIndex].Code;
FOnGetSourceStatus(Self,ACode,CodeIsReadOnly); FOnGetSourceStatus(Self,ACode,CodeIsReadOnly);
if CodeIsReadOnly then exit; if CodeIsReadOnly then begin
EditError(ctsfileIsReadOnly, ACode);
exit;
end;
end; end;
until false; until false;
end; end;
@ -2892,6 +2922,12 @@ begin
raise ExceptionClass.Create(Self,AMessage); raise ExceptionClass.Create(Self,AMessage);
end; end;
procedure TLinkScanner.RaiseEditException(const AMessage: string;
ABuffer: Pointer; ABufferPos: integer);
begin
raise ELinkScannerEditError.Create(Self,AMessage,ABuffer,ABufferPos);
end;
procedure TLinkScanner.ClearLastError; procedure TLinkScanner.ClearLastError;
begin begin
LastErrorIsValid:=false; LastErrorIsValid:=false;
@ -3094,6 +3130,16 @@ begin
PSourceLinkMemManager.Free; PSourceLinkMemManager.Free;
end; end;
{ ELinkScannerEditError }
constructor ELinkScannerEditError.Create(ASender: TLinkScanner;
const AMessage: string; ABuffer: Pointer; ABufferPos: integer);
begin
inherited Create(ASender,AMessage);
Buffer:=ABuffer;
BufferPos:=ABufferPos;
end;
initialization initialization
InternalInit; InternalInit;

View File

@ -42,8 +42,8 @@ interface
{ $DEFINE CTDEBUG} { $DEFINE CTDEBUG}
uses uses
Classes, SysUtils, CodeCache, BasicCodeTools, SourceLog, LinkScanner, Classes, SysUtils, CodeToolsStrConsts, CodeCache, BasicCodeTools, SourceLog,
AVL_Tree, KeywordFuncLists; LinkScanner, AVL_Tree, KeywordFuncLists;
type type
{ TBeautifyCodeOptions } { TBeautifyCodeOptions }
@ -130,6 +130,9 @@ type
constructor Create; constructor Create;
end; end;
{ TSourceChangeCache }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// in front of and after a text change can be set a gap. // in front of and after a text change can be set a gap.
// A Gap is for example a space char or a newline. TSourceChangeLog will add // A Gap is for example a space char or a newline. TSourceChangeLog will add
@ -139,7 +142,6 @@ type
gtNewLine, // at least a newline gtNewLine, // at least a newline
gtEmptyLine // at least two newlines gtEmptyLine // at least two newlines
); );
TSourceChangeCacheEntry = class TSourceChangeCacheEntry = class
public public
@ -180,6 +182,8 @@ type
procedure SetMainScanner(NewScanner: TLinkScanner); procedure SetMainScanner(NewScanner: TLinkScanner);
function GetBuffersToModify(Index: integer): TCodeBuffer; function GetBuffersToModify(Index: integer): TCodeBuffer;
procedure UpdateBuffersToModify; procedure UpdateBuffersToModify;
protected
procedure RaiseException(const AMessage: string);
public public
BeautifyCodeOptions: TBeautifyCodeOptions; BeautifyCodeOptions: TBeautifyCodeOptions;
procedure BeginUpdate; procedure BeginUpdate;
@ -207,6 +211,15 @@ type
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
end; end;
{ ESourceChangeCacheError }
ESourceChangeCacheError = class(Exception)
public
Sender: TSourceChangeCache;
constructor Create(ASender: TSourceChangeCache; const AMessage: string);
end;
const const
AtomTypeNames: array[TAtomType] of shortstring = ( AtomTypeNames: array[TAtomType] of shortstring = (
@ -412,6 +425,35 @@ function TSourceChangeCache.ReplaceEx(FrontGap, AfterGap: TGapTyp;
FromPos, ToPos: integer; FromPos, ToPos: integer;
DirectCode: TCodeBuffer; FromDirectPos, ToDirectPos: integer; DirectCode: TCodeBuffer; FromDirectPos, ToDirectPos: integer;
const Text: string): boolean; const Text: string): boolean;
procedure RaiseDataInvalid;
begin
if MainScanner=nil then
RaiseException('TSourceChangeCache.ReplaceEx MainScanner=nil');
if FromPos>ToPos then
RaiseException('TSourceChangeCache.ReplaceEx FromPos>ToPos');
if FromPos<1 then
RaiseException('TSourceChangeCache.ReplaceEx FromPos<1');
if ToPos>MainScanner.CleanedLen+1 then
RaiseException('TSourceChangeCache.ReplaceEx ToPos>MainScanner.CleanedLen+1');
end;
procedure RaiseIntersectionFound;
begin
RaiseException('TSourceChangeCache.ReplaceEx '
+'IGNORED, because intersection found');
end;
procedure RaiseCodeReadOnly(Buffer: TCodeBuffer);
begin
RaiseException(ctsfileIsReadOnly+' '+Buffer.Filename);
end;
procedure RaiseNotInCleanCode;
begin
RaiseException('TSourceChangeCache.ReplaceEx not in clean code');
end;
var var
NewEntry: TSourceChangeCacheEntry; NewEntry: TSourceChangeCacheEntry;
p: pointer; p: pointer;
@ -441,6 +483,7 @@ begin
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln('TSourceChangeCache.ReplaceEx IGNORED, because data invalid'); writeln('TSourceChangeCache.ReplaceEx IGNORED, because data invalid');
{$ENDIF} {$ENDIF}
RaiseDataInvalid;
exit; exit;
end; end;
end else begin end else begin
@ -457,21 +500,24 @@ begin
IntersectionEntry.FromPos,'-',IntersectionEntry.ToPos, IntersectionEntry.FromPos,'-',IntersectionEntry.ToPos,
' IsDelete=',IntersectionEntry.IsDeleteOperation); ' IsDelete=',IntersectionEntry.IsDeleteOperation);
{$ENDIF} {$ENDIF}
RaiseIntersectionFound;
exit; exit;
end; end;
if ToPos>FromPos then begin if ToPos>FromPos then begin
// this is a delete operation -> check the whole range for writable buffers // this is a delete operation -> check the whole range for writable buffers
if not MainScanner.WholeRangeIsWritable(FromPos,ToPos) then exit; if not MainScanner.WholeRangeIsWritable(FromPos,ToPos,true) then exit;
end else if (DirectCode<>nil) and (FromDirectPos<ToDirectPos) then begin end else if (DirectCode<>nil) and (FromDirectPos<ToDirectPos) then begin
// this is a direct delete operation -> check if the DirectCode is writable // this is a direct delete operation -> check if the DirectCode is writable
if DirectCode.ReadOnly then exit; if DirectCode.ReadOnly then
RaiseCodeReadOnly(DirectCode);
end; end;
if DirectCode=nil then begin if DirectCode=nil then begin
if not MainScanner.CleanedPosToCursor(FromPos,FromDirectPos,p) then begin if not MainScanner.CleanedPosToCursor(FromPos,FromDirectPos,p) then begin
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln('TSourceChangeCache.ReplaceEx IGNORED, because not in clean pos'); writeln('TSourceChangeCache.ReplaceEx IGNORED, because not in clean pos');
{$ENDIF} {$ENDIF}
RaiseNotInCleanCode;
exit; exit;
end; end;
DirectCode:=TCodeBuffer(p); DirectCode:=TCodeBuffer(p);
@ -831,6 +877,11 @@ begin
FBuffersToModifyNeedsUpdate:=false; FBuffersToModifyNeedsUpdate:=false;
end; end;
procedure TSourceChangeCache.RaiseException(const AMessage: string);
begin
raise ESourceChangeCacheError.Create(Self,AMessage);
end;
{ TBeautifyCodeOptions } { TBeautifyCodeOptions }
constructor TBeautifyCodeOptions.Create; constructor TBeautifyCodeOptions.Create;
@ -1237,6 +1288,14 @@ begin
end; end;
{ ESourceChangeCacheError }
constructor ESourceChangeCacheError.Create(ASender: TSourceChangeCache;
const AMessage: string);
begin
inherited Create(AMessage);
Sender:=ASender;
end;
end. end.

View File

@ -2688,7 +2688,8 @@ function TStandardCodeTool.RenamePublishedVariable(const UpperClassName,
UpperOldVarName: string; const NewVarName, VarType: shortstring; UpperOldVarName: string; const NewVarName, VarType: shortstring;
ExceptionOnClassNotFound: boolean; ExceptionOnClassNotFound: boolean;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
var TypeNode, VarNode: TCodeTreeNode; var
TypeNode, VarNode: TCodeTreeNode;
begin begin
Result:=false; Result:=false;
VarNode:=FindPublishedVariable(UpperClassName,UpperOldVarName, VarNode:=FindPublishedVariable(UpperClassName,UpperOldVarName,