mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 18:29:12 +02:00
codetools: h2p: implemented converting c hex numbers
git-svn-id: trunk@14648 -
This commit is contained in:
parent
271e95a54b
commit
647adc1d77
@ -1410,6 +1410,7 @@ function TH2PasTool.MacroValueIsConstant(Node: TH2PDirectiveNode;
|
|||||||
var
|
var
|
||||||
AtomStart: integer;
|
AtomStart: integer;
|
||||||
p: Integer;
|
p: Integer;
|
||||||
|
CurAtom: String;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
PasType:='';
|
PasType:='';
|
||||||
@ -1418,11 +1419,31 @@ begin
|
|||||||
repeat
|
repeat
|
||||||
ReadRawNextCAtom(PasExpression,p,AtomStart);
|
ReadRawNextCAtom(PasExpression,p,AtomStart);
|
||||||
if AtomStart>length(PasExpression) then break;
|
if AtomStart>length(PasExpression) then break;
|
||||||
|
DebugLn(['TH2PasTool.MacroValueIsConstant AAA1 ',copy(PasExpression,AtomStart,p-AtomStart)]);
|
||||||
if IsIdentStartChar[PasExpression[AtomStart]] then begin
|
if IsIdentStartChar[PasExpression[AtomStart]] then begin
|
||||||
exit;
|
exit;
|
||||||
|
end else if IsCHexNumber(PasExpression,AtomStart) then begin
|
||||||
|
// hex number
|
||||||
|
// replace 0x with $
|
||||||
|
DebugLn(['TH2PasTool.MacroValueIsConstant AAA2']);
|
||||||
|
PasExpression:=copy(PasExpression,1,AtomStart-1)
|
||||||
|
+'$'+copy(PasExpression,AtomStart+2,length(PasExpression));
|
||||||
|
dec(p);
|
||||||
|
end else if IsCDecimalNumber(PasExpression,AtomStart) then begin
|
||||||
|
// decimal number
|
||||||
end else if PasExpression[AtomStart]='"' then begin
|
end else if PasExpression[AtomStart]='"' then begin
|
||||||
PasExpression[AtomStart]:='''';
|
PasExpression[AtomStart]:='''';
|
||||||
PasExpression[p-1]:='''';
|
PasExpression[p-1]:='''';
|
||||||
|
end else begin
|
||||||
|
CurAtom:=copy(PasExpression,AtomStart,p-AtomStart);
|
||||||
|
if (CurAtom='(') or (CurAtom=')')
|
||||||
|
or (CurAtom='+') or (CurAtom='-') then begin
|
||||||
|
// same in pascal
|
||||||
|
end else begin
|
||||||
|
DebugLn(['TH2PasTool.MacroValueIsConstant AAA3 ',CurAtom]);
|
||||||
|
// unknown
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
until false;
|
until false;
|
||||||
Result:=true;
|
Result:=true;
|
||||||
|
@ -42,7 +42,9 @@ procedure ReadNextCAtom(const Source: string;
|
|||||||
var Position: integer; out AtomStart: integer);
|
var Position: integer; out AtomStart: integer);
|
||||||
procedure ReadRawNextCAtom(const Source: string;
|
procedure ReadRawNextCAtom(const Source: string;
|
||||||
var Position: integer; out AtomStart: integer);
|
var Position: integer; out AtomStart: integer);
|
||||||
|
function IsCDecimalNumber(const Source: string; Position: integer): boolean;
|
||||||
|
function IsCHexNumber(const Source: string; Position: integer): boolean;
|
||||||
|
|
||||||
function ExtractCodeFromMakefile(const Source: string): string;
|
function ExtractCodeFromMakefile(const Source: string): string;
|
||||||
|
|
||||||
function CConstantToInt64(const s: string; out i: int64): boolean;
|
function CConstantToInt64(const s: string; out i: int64): boolean;
|
||||||
@ -273,7 +275,18 @@ begin
|
|||||||
inc(Position);
|
inc(Position);
|
||||||
end;
|
end;
|
||||||
'0'..'9': // number
|
'0'..'9': // number
|
||||||
begin
|
if (Source[Position+1]='x') then begin
|
||||||
|
inc(Position);
|
||||||
|
// hex number
|
||||||
|
repeat
|
||||||
|
inc(Position);
|
||||||
|
until (Position>Len) or (not IsHexNumberChar[Source[Position]]);
|
||||||
|
end else if (Source[Position+1] in ['0'..'7']) then begin
|
||||||
|
// octal number
|
||||||
|
repeat
|
||||||
|
inc(Position);
|
||||||
|
until (Position>Len) or (not (Source[Position] in ['0'..'7']));
|
||||||
|
end else begin
|
||||||
inc(Position);
|
inc(Position);
|
||||||
// read numbers
|
// read numbers
|
||||||
while (Position<=Len) and (Source[Position] in ['0'..'9']) do
|
while (Position<=Len) and (Source[Position] in ['0'..'9']) do
|
||||||
@ -345,6 +358,34 @@ begin
|
|||||||
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
|
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
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]])
|
||||||
|
then exit;
|
||||||
|
// check octal and hex number
|
||||||
|
if (Source[Position]='0') and (Source[Position] in ['x','0'..'9'])
|
||||||
|
then exit;
|
||||||
|
// check float
|
||||||
|
inc(Position);
|
||||||
|
while (Position<=l) and (IsNumberChar[Source[Position]]) do
|
||||||
|
inc(Position);
|
||||||
|
if Source[Position]='.' then exit;
|
||||||
|
Result:=true;
|
||||||
|
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function IsCHexNumber(const Source: string; Position: integer): boolean;
|
||||||
|
begin
|
||||||
|
Result:=(Position>=1) and (Position<length(Source))
|
||||||
|
and (Source[Position]='0') and (Source[Position+1]='x');
|
||||||
|
end;
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user