codetools: optimized TLinkScanner.ReadNextToken

git-svn-id: trunk@25734 -
This commit is contained in:
mattias 2010-05-28 18:12:02 +00:00
parent 6ddd7b8a04
commit c620d9cf20

View File

@ -1035,7 +1035,7 @@ begin
break; break;
end; end;
end; end;
p:=@Src[SrcPos]; SrcPos:=p-PChar(Src)+1;
TokenStart:=SrcPos; TokenStart:=SrcPos;
TokenType:=lsttNone; TokenType:=lsttNone;
// read token // read token
@ -1044,11 +1044,11 @@ begin
'_','A'..'Z','a'..'z': '_','A'..'Z','a'..'z':
begin begin
// keyword or identifier // keyword or identifier
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) while IsIdentChar[p^] do
and (IsIdentChar[Src[SrcPos]]) do inc(p);
inc(SrcPos);
TokenType:=lsttWord; TokenType:=lsttWord;
SrcPos:=p-PChar(Src)+1;
if FMacrosOn then begin if FMacrosOn then begin
MacroID:=IndexOfMacro(@Src[TokenStart],false); MacroID:=IndexOfMacro(@Src[TokenStart],false);
if MacroID>=0 then begin if MacroID>=0 then begin
@ -1059,29 +1059,40 @@ begin
'''','#': '''','#':
begin begin
TokenType:=lsttStringConstant; TokenType:=lsttStringConstant;
while (SrcPos<=SrcLen) do begin while true do begin
case (Src[SrcPos]) of case p^ of
#0:
begin
SrcPos:=p-PChar(Src)+1;
if SrcPos>SrcLen then break;
inc(p);
end;
'#': '#':
begin begin
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) while IsNumberChar[p^] do
and (IsNumberChar[Src[SrcPos]]) do inc(p);
inc(SrcPos);
end; end;
'''': '''':
begin begin
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) do begin while true do begin
case Src[SrcPos] of case p^ of
#0:
begin
SrcPos:=p-PChar(Src)+1;
if SrcPos>SrcLen then break;
inc(p);
end;
'''': '''':
begin begin
inc(SrcPos); inc(p);
break; break;
end; end;
#10,#13: #10,#13:
break; break;
else else
inc(SrcPos); inc(p);
end; end;
end; end;
end; end;
@ -1089,39 +1100,41 @@ begin
break; break;
end; end;
end; end;
SrcPos:=p-PChar(Src)+1;
end; end;
'0'..'9': '0'..'9':
begin begin
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) and (IsNumberChar[Src[SrcPos]]) do while IsNumberChar[p^] do
inc(SrcPos); inc(p);
if (SrcPos<SrcLen) and (Src[SrcPos]='.') and (Src[SrcPos+1]<>'.') if (p^='.') and (p[1]<>'.') then begin
then begin
// real type number // real type number
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) and (IsNumberChar[Src[SrcPos]]) do while IsNumberChar[p^] do
inc(SrcPos); inc(p);
if (SrcPos<=SrcLen) and (Src[SrcPos] in ['E','e']) then begin if (p^ in ['E','e']) then begin
// read exponent // read exponent
inc(SrcPos); inc(p);
if (SrcPos<=SrcLen) and (Src[SrcPos] in ['-','+']) then inc(SrcPos); if (p^ in ['-','+']) then inc(p);
while (SrcPos<=SrcLen) and (IsNumberChar[Src[SrcPos]]) do while IsNumberChar[p^] do
inc(SrcPos); inc(p);
end; end;
end; end;
SrcPos:=p-PChar(Src)+1;
end; end;
'%': '%': // boolean
begin begin
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) and (Src[SrcPos] in ['0'..'1']) do while p^ in ['0'..'1'] do
inc(SrcPos); inc(p);
SrcPos:=p-PChar(Src)+1;
end; end;
'$': '$': // hex
begin begin
inc(SrcPos); inc(p);
while (SrcPos<=SrcLen) while IsHexNumberChar[p^] do
and (IsHexNumberChar[Src[SrcPos]]) do inc(p);
inc(SrcPos); SrcPos:=p-PChar(Src)+1;
end; end;
'=': '=':
begin begin
@ -1145,17 +1158,15 @@ begin
end; end;
else else
inc(SrcPos); inc(SrcPos);
if SrcPos<=SrcLen then begin c2:=Src[SrcPos];
c2:=Src[SrcPos]; // test for double char operators
// test for double char operators // :=, +=, -=, /=, *=, <>, <=, >=, **, ><, ..
// :=, +=, -=, /=, *=, <>, <=, >=, **, ><, .. if ((c2='=') and (IsEqualOperatorStartChar[c1]))
if ((c2='=') and (IsEqualOperatorStartChar[c1])) or ((c1='<') and (c2='>'))
or ((c1='<') and (c2='>')) or ((c1='>') and (c2='<'))
or ((c1='>') and (c2='<')) or ((c1='.') and (c2='.'))
or ((c1='.') and (c2='.')) or ((c1='*') and (c2='*'))
or ((c1='*') and (c2='*')) then inc(SrcPos);
then inc(SrcPos);
end;
end; end;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF} {$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
end; end;