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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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