codetools: fixed rangechecking

git-svn-id: trunk@57114 -
This commit is contained in:
mattias 2018-01-18 21:23:38 +00:00
parent f00551aab4
commit cab4029da6
8 changed files with 38 additions and 38 deletions

View File

@ -1942,6 +1942,8 @@ begin
Result:=copy(Source,AtomStart,Position-AtomStart); Result:=copy(Source,AtomStart,Position-AtomStart);
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure ReadRawNextPascalAtom(const Source: string; procedure ReadRawNextPascalAtom(const Source: string;
var Position: integer; out AtomStart: integer; NestedComments: boolean; var Position: integer; out AtomStart: integer; NestedComments: boolean;
SkipDirectives: boolean); SkipDirectives: boolean);
@ -1949,8 +1951,6 @@ var
Len:integer; Len:integer;
SrcPos, SrcStart, SrcAtomStart: PChar; SrcPos, SrcStart, SrcAtomStart: PChar;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Len:=length(Source); Len:=length(Source);
if Position>Len then begin if Position>Len then begin
Position:=Len+1; Position:=Len+1;
@ -1962,8 +1962,8 @@ begin
ReadRawNextPascalAtom(SrcPos,SrcAtomStart,SrcStart+len,NestedComments,SkipDirectives); ReadRawNextPascalAtom(SrcPos,SrcAtomStart,SrcStart+len,NestedComments,SkipDirectives);
Position:=SrcPos-SrcStart+1; Position:=SrcPos-SrcStart+1;
AtomStart:=SrcAtomStart-SrcStart+1; AtomStart:=SrcAtomStart-SrcStart+1;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
procedure ReadRawNextPascalAtom(var Position: PChar; out AtomStart: PChar; procedure ReadRawNextPascalAtom(var Position: PChar; out AtomStart: PChar;
const SrcEnd: PChar; NestedComments: boolean; SkipDirectives: boolean); const SrcEnd: PChar; NestedComments: boolean; SkipDirectives: boolean);

View File

@ -1861,6 +1861,8 @@ begin
{$ENDIF} {$ENDIF}
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
function TCCodeParserTool.ReadTilBracketClose( function TCCodeParserTool.ReadTilBracketClose(
ExceptionOnNotFound: boolean): boolean; ExceptionOnNotFound: boolean): boolean;
// AtomStart must be on bracket open // AtomStart must be on bracket open
@ -1881,8 +1883,6 @@ begin
exit; exit;
end; end;
StartPos:=AtomStart; StartPos:=AtomStart;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
repeat repeat
ReadRawNextCAtom(Src,SrcPos,AtomStart); ReadRawNextCAtom(Src,SrcPos,AtomStart);
if AtomStart>SrcLen then begin if AtomStart>SrcLen then begin
@ -1903,8 +1903,8 @@ begin
if Src[AtomStart]=CloseBracket then exit(true); if Src[AtomStart]=CloseBracket then exit(true);
end; end;
until false; until false;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
function TCCodeParserTool.AtomIs(const s: shortstring): boolean; function TCCodeParserTool.AtomIs(const s: shortstring): boolean;
var var

View File

@ -1012,14 +1012,14 @@ begin
Result:=true; Result:=true;
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure TCustomCodeTool.ReadNextAtom; procedure TCustomCodeTool.ReadNextAtom;
var var
c1, c2: char; c1, c2: char;
CommentLvl: integer; CommentLvl: integer;
p: PChar; p: PChar;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
if LastAtoms.HasNext then begin if LastAtoms.HasNext then begin
//debugln(['TCustomCodeTool.ReadNextAtom HASNEXT ',LastAtoms.NextCount]); //debugln(['TCustomCodeTool.ReadNextAtom HASNEXT ',LastAtoms.NextCount]);
LastAtoms.MoveToNext(CurPos); LastAtoms.MoveToNext(CurPos);
@ -1372,9 +1372,9 @@ begin
until (CurPos.EndPos>SrcLen) or (not IsIdentChar[Src[CurPos.EndPos]]); until (CurPos.EndPos>SrcLen) or (not IsIdentChar[Src[CurPos.EndPos]]);
end; end;
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
LastAtoms.Add(CurPos); LastAtoms.Add(CurPos);
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
procedure TCustomCodeTool.ReadPriorAtom; procedure TCustomCodeTool.ReadPriorAtom;
var var

View File

@ -1748,6 +1748,8 @@ begin
Parse(Code,NestedComments); Parse(Code,NestedComments);
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure TCompilerDirectivesTree.Parse(aCode: TCodeBuffer; procedure TCompilerDirectivesTree.Parse(aCode: TCodeBuffer;
aNestedComments: boolean); aNestedComments: boolean);
@ -1760,8 +1762,6 @@ var
DirectiveName: PChar; DirectiveName: PChar;
Node: TCodeTreeNode; Node: TCodeTreeNode;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
if (Code=aCode) and (NestedComments=aNestedComments) and (not UpdateNeeded) if (Code=aCode) and (NestedComments=aNestedComments) and (not UpdateNeeded)
then begin then begin
if FLastErrorMsg<>'' then if FLastErrorMsg<>'' then
@ -1797,8 +1797,8 @@ begin
if CurNode<>Tree.Root then if CurNode<>Tree.Root then
RaiseDanglingIFDEF; RaiseDanglingIFDEF;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
function TCompilerDirectivesTree.UpdateNeeded: boolean; function TCompilerDirectivesTree.UpdateNeeded: boolean;
begin begin

View File

@ -1798,6 +1798,8 @@ begin
end; end;
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure TLinkScanner.ReadNextToken; procedure TLinkScanner.ReadNextToken;
var var
c1: char; c1: char;
@ -1806,8 +1808,6 @@ var
p: PChar; p: PChar;
begin begin
//DebugLn([' TLinkScanner.ReadNextToken SrcPos=',SrcPos,' SrcLen=',SrcLen,' "',dbgstr(Src,SrcPos,5),'"']); //DebugLn([' TLinkScanner.ReadNextToken SrcPos=',SrcPos,' SrcLen=',SrcLen,' "',dbgstr(Src,SrcPos,5),'"']);
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
if (SrcPos>SrcLen) and ReturnFromIncludeFileAndIsEnd then exit; if (SrcPos>SrcLen) and ReturnFromIncludeFileAndIsEnd then exit;
//DebugLn([' TLinkScanner.ReadNextToken SrcPos=',SrcPos,' SrcLen=',SrcLen,' "',copy(Src,SrcPos,5),'"']); //DebugLn([' TLinkScanner.ReadNextToken SrcPos=',SrcPos,' SrcLen=',SrcLen,' "',copy(Src,SrcPos,5),'"']);
// Skip all spaces and comments // Skip all spaces and comments
@ -2012,8 +2012,8 @@ begin
then inc(p); then inc(p);
SrcPos:=p-PChar(Src)+1; SrcPos:=p-PChar(Src)+1;
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
procedure TLinkScanner.Scan(Range: TLinkScannerRange; CheckFilesOnDisk: boolean); procedure TLinkScanner.Scan(Range: TLinkScannerRange; CheckFilesOnDisk: boolean);
var var

View File

@ -98,22 +98,24 @@ begin
end; end;
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure ReadTilCLineEnd(const Source: string; var Position: integer); procedure ReadTilCLineEnd(const Source: string; var Position: integer);
var var
Len: Integer; Len: Integer;
AtomStart: Integer; AtomStart: Integer;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Len:=length(Source); Len:=length(Source);
if Position>Len then exit; if Position>Len then exit;
AtomStart:=Position; AtomStart:=Position;
while (AtomStart<=Len) and (not (Source[AtomStart] in [#10,#13])) do while (AtomStart<=Len) and (not (Source[AtomStart] in [#10,#13])) do
ReadRawNextCAtom(Source,Position,AtomStart); ReadRawNextCAtom(Source,Position,AtomStart);
Position:=AtomStart; Position:=AtomStart;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
function ReadTilCBracketClose(const Source: string; var Position: integer function ReadTilCBracketClose(const Source: string; var Position: integer
): boolean; ): boolean;
// Position must start on a bracket // Position must start on a bracket
@ -125,8 +127,6 @@ var
AtomStart: LongInt; AtomStart: LongInt;
StartPos: LongInt; StartPos: LongInt;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Result:=false; Result:=false;
Len:=length(Source); Len:=length(Source);
if Position>Len then exit; if Position>Len then exit;
@ -159,14 +159,14 @@ begin
if Source[AtomStart]=CloseBracket then exit(true); if Source[AtomStart]=CloseBracket then exit(true);
end; end;
until false; until false;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure ReadNextCAtom(const Source: string; var Position: integer; out procedure ReadNextCAtom(const Source: string; var Position: integer; out
AtomStart: integer); AtomStart: integer);
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
repeat repeat
ReadRawNextCAtom(Source,Position,AtomStart); ReadRawNextCAtom(Source,Position,AtomStart);
if AtomStart>length(Source) then exit; if AtomStart>length(Source) then exit;
@ -181,17 +181,17 @@ begin
exit; exit;
end; end;
until false; until false;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure ReadRawNextCAtom(const Source: string; var Position: integer; procedure ReadRawNextCAtom(const Source: string; var Position: integer;
out AtomStart: integer); out AtomStart: integer);
var var
Len:integer; Len:integer;
c1,c2:char; c1,c2:char;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Len:=length(Source); Len:=length(Source);
// read til next atom // read til next atom
while (Position<=Len) do begin while (Position<=Len) do begin
@ -375,15 +375,15 @@ begin
end; end;
end; end;
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
function IsCDecimalNumber(const Source: string; Position: integer): boolean; function IsCDecimalNumber(const Source: string; Position: integer): boolean;
var var
l: Integer; l: Integer;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Result:=false; Result:=false;
l:=length(Source); l:=length(Source);
if (Position<1) or (Position>l) or (not IsNumberChar[Source[Position]]) if (Position<1) or (Position>l) or (not IsNumberChar[Source[Position]])
@ -397,8 +397,8 @@ begin
inc(Position); inc(Position);
if Source[Position]='.' then exit; if Source[Position]='.' then exit;
Result:=true; Result:=true;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
function IsCHexNumber(const Source: string; Position: integer): boolean; function IsCHexNumber(const Source: string; Position: integer): boolean;
begin begin
@ -412,6 +412,8 @@ begin
and (Source[Position]='0') and (Source[Position+1] in ['0'..'7']); and (Source[Position]='0') and (Source[Position+1] in ['0'..'7']);
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
function ExtractCCode(const Source: string; StartPos: integer; function ExtractCCode(const Source: string; StartPos: integer;
EndPos: integer): string; EndPos: integer): string;
var var
@ -420,8 +422,6 @@ var
SrcLen: Integer; SrcLen: Integer;
AtomStart: integer; AtomStart: integer;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
Result:=Source; Result:=Source;
DstPos:=1; DstPos:=1;
SrcPos:=StartPos; SrcPos:=StartPos;
@ -453,8 +453,8 @@ begin
raise Exception.Create(''); raise Exception.Create('');
end; end;
SetLength(Result,DstPos-1); SetLength(Result,DstPos-1);
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
function ExtractCodeFromMakefile(const Source: string): string; function ExtractCodeFromMakefile(const Source: string): string;
// remove comments, empty lines, double spaces, replace newline chars with #10 // remove comments, empty lines, double spaces, replace newline chars with #10

View File

@ -1260,6 +1260,7 @@ begin
end; end;
end; end;
{$R-}
procedure TPPU.ReadHeader; procedure TPPU.ReadHeader;
var var
cpu: tsystemcpu; cpu: tsystemcpu;
@ -1292,11 +1293,9 @@ begin
FEntryPos:=0; FEntryPos:=0;
FillByte(FEntry,SizeOf(FEntry),0); FillByte(FEntry,SizeOf(FEntry),0);
{$R-}
cpu:=tsystemcpu(FHeader.cpu); cpu:=tsystemcpu(FHeader.cpu);
if (cpu<low(tsystemcpu)) or (cpu>high(tsystemcpu)) then if (cpu<low(tsystemcpu)) or (cpu>high(tsystemcpu)) then
cpu:=tsystemcpu(FHeader.cpu); cpu:=tsystemcpu(FHeader.cpu);
{$R+}
FSizeOfAInt:=CpuAluBitSize[cpu] div 8; FSizeOfAInt:=CpuAluBitSize[cpu] div 8;
FSizeOfASizeInt:=CpuAddrBitSize[cpu] div 8; FSizeOfASizeInt:=CpuAddrBitSize[cpu] div 8;
@ -1304,6 +1303,7 @@ begin
DumpHeader(''); DumpHeader('');
{$ENDIF} {$ENDIF}
end; end;
{$R+}
procedure TPPU.ReadInterfaceHeader; procedure TPPU.ReadInterfaceHeader;
var var

View File

@ -668,6 +668,8 @@ begin
Items[i].AdjustPosition(APosition); Items[i].AdjustPosition(APosition);
end; end;
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
procedure TSourceLog.BuildLineRanges; procedure TSourceLog.BuildLineRanges;
var var
line:integer; line:integer;
@ -676,8 +678,6 @@ var
SrcStart: PChar; SrcStart: PChar;
p: PChar; p: PChar;
begin begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
//DebugLn(['[TSourceLog.BuildLineRanges] A Self=',DbgS(Self),',LineCount=',FLineCount,' Len=',SourceLength]); //DebugLn(['[TSourceLog.BuildLineRanges] A Self=',DbgS(Self),',LineCount=',FLineCount,' Len=',SourceLength]);
if FLineCount>=0 then exit; if FLineCount>=0 then exit;
// build line range list // build line range list
@ -718,8 +718,8 @@ begin
inc(FLineCount); inc(FLineCount);
ReAllocMem(FLineRanges,FLineCount*SizeOf(TLineRange)); ReAllocMem(FLineRanges,FLineCount*SizeOf(TLineRange));
//DebugLn('[TSourceLog.BuildLineRanges] END ',FLineCount); //DebugLn('[TSourceLog.BuildLineRanges] END ',FLineCount);
{$IFDEF RangeChecking}{$R+}{$ENDIF}
end; end;
{$IFDEF RangeChecking}{$R+}{$ENDIF}
procedure TSourceLog.LineColToPosition(Line, Column: integer; procedure TSourceLog.LineColToPosition(Line, Column: integer;
out Position: integer); out Position: integer);