mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 00:19:22 +02:00
codetools: h2p: converting __BYTE_ORDER macro
git-svn-id: trunk@14672 -
This commit is contained in:
parent
f5b5cdd091
commit
eeeb05193c
@ -227,6 +227,7 @@ type
|
|||||||
procedure SimplifyIfDirective(Node: TH2PDirectiveNode; const Expression: string;
|
procedure SimplifyIfDirective(Node: TH2PDirectiveNode; const Expression: string;
|
||||||
var NextNode: TH2PDirectiveNode;
|
var NextNode: TH2PDirectiveNode;
|
||||||
var Changed: boolean);
|
var Changed: boolean);
|
||||||
|
function SimplifyIfDirectiveExpression(var Expression: string): boolean;
|
||||||
procedure SimplifyMacroRedefinition(var Node: TH2PDirectiveNode;
|
procedure SimplifyMacroRedefinition(var Node: TH2PDirectiveNode;
|
||||||
const NewValue: string; NewStatus: TH2PMacroStatus;
|
const NewValue: string; NewStatus: TH2PMacroStatus;
|
||||||
var NextNode: TH2PDirectiveNode; var Changed: boolean);
|
var NextNode: TH2PDirectiveNode; var Changed: boolean);
|
||||||
@ -787,6 +788,8 @@ begin
|
|||||||
DirNode:=CreateH2PDirectiveNode(H2PNode,h2pdnDefine);
|
DirNode:=CreateH2PDirectiveNode(H2PNode,h2pdnDefine);
|
||||||
DirNode.MacroName:=MacroName;
|
DirNode.MacroName:=MacroName;
|
||||||
DirNode.MacroParams:=MacroParamList;
|
DirNode.MacroParams:=MacroParamList;
|
||||||
|
if MacroValue='__BYTE_ORDER' then
|
||||||
|
MacroValue:='FPC';
|
||||||
DirNode.Expression:=MacroValue;
|
DirNode.Expression:=MacroValue;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
@ -942,6 +945,27 @@ var
|
|||||||
Add(NewToken,GetAtom);
|
Add(NewToken,GetAtom);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure Replace(const OldText,NewText: string);
|
||||||
|
var
|
||||||
|
l: Integer;
|
||||||
|
begin
|
||||||
|
p:=1;
|
||||||
|
l:=length(OldText);
|
||||||
|
repeat
|
||||||
|
ReadRawNextCAtom(PasExpr,p,AtomStart);
|
||||||
|
if AtomStart>length(PasExpr) then break;
|
||||||
|
if CompareMem(@PasExpr[AtomStart],@OldText[1],l)
|
||||||
|
and ((not IsIdentChar[OldText[l]])
|
||||||
|
or (AtomStart+l>length(PasExpr))
|
||||||
|
or (not IsIdentChar[PasExpr[AtomStart+l]]))
|
||||||
|
then begin
|
||||||
|
DebugLn(['TH2PasTool.ConvertCToPascalDirectiveExpression.Replace Old="',OldText,'" New="',NewText,'"']);
|
||||||
|
PasExpr:=copy(PasExpr,1,AtomStart-1)
|
||||||
|
+NewText+copy(PasExpr,AtomStart+length(OldText),length(PasExpr));
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
PasExpr:='';
|
PasExpr:='';
|
||||||
@ -972,8 +996,8 @@ begin
|
|||||||
ErrorMsg:='missing operator';
|
ErrorMsg:='missing operator';
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Add(ttValue);
|
|
||||||
if AtomIs('defined') then begin
|
if AtomIs('defined') then begin
|
||||||
|
Add(ttValue);
|
||||||
// read defined(name)
|
// read defined(name)
|
||||||
ReadRawNextCAtom(CCode,p,AtomStart);
|
ReadRawNextCAtom(CCode,p,AtomStart);
|
||||||
if not AtomIs('(') then begin
|
if not AtomIs('(') then begin
|
||||||
@ -987,13 +1011,19 @@ begin
|
|||||||
ErrorExpectedButFound('identifier');
|
ErrorExpectedButFound('identifier');
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Add(ttValue);
|
// convert defined(__BYTE_ORDER) to defined(FPC)
|
||||||
|
if AtomIs('__BYTE_ORDER') then
|
||||||
|
Add(ttValue,'FPC')
|
||||||
|
else
|
||||||
|
Add(ttValue);
|
||||||
ReadRawNextCAtom(CCode,p,AtomStart);
|
ReadRawNextCAtom(CCode,p,AtomStart);
|
||||||
if not AtomIs(')') then begin
|
if not AtomIs(')') then begin
|
||||||
ErrorExpectedButFound(')');
|
ErrorExpectedButFound(')');
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Add(ttBracketClose);
|
Add(ttBracketClose);
|
||||||
|
end else begin
|
||||||
|
Add(ttValue);
|
||||||
end;
|
end;
|
||||||
end else if AtomIs('+') or AtomIs('-') or AtomIs('!') then begin
|
end else if AtomIs('+') or AtomIs('-') or AtomIs('!') then begin
|
||||||
if LastToken in [ttValue,ttBracketClose] then begin
|
if LastToken in [ttValue,ttBracketClose] then begin
|
||||||
@ -1047,6 +1077,12 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
until false;
|
until false;
|
||||||
|
|
||||||
|
// now convert a few common things:
|
||||||
|
Replace('__BYTE_ORDER=__LITTLE_ENDIAN','defined(ENDIAN_LITTLE)');
|
||||||
|
Replace('__LITTLE_ENDIAN=__BYTE_ORDER','defined(ENDIAN_LITTLE)');
|
||||||
|
Replace('__BYTE_ORDER=__BIG_ENDIAN','defined(ENDIAN_BIG)');
|
||||||
|
Replace('__BIG_ENDIAN=__BYTE_ORDER','defined(ENDIAN_BIG)');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TH2PasTool.WriteStr(const Line: string);
|
procedure TH2PasTool.WriteStr(const Line: string);
|
||||||
@ -1478,10 +1514,30 @@ begin
|
|||||||
DeleteDirectiveNode(Node,true,true);
|
DeleteDirectiveNode(Node,true,true);
|
||||||
Changed:=true;
|
Changed:=true;
|
||||||
end else begin
|
end else begin
|
||||||
DebugLn(['TH2PasTool.SimplifyIfDirective AAA1 Node=',Node.DescAsString(CTool),' Node.NextBrother=',TH2PDirectiveNode(Node.NextBrother).DescAsString(CTool)]);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TH2PasTool.SimplifyIfDirectiveExpression(var Expression: string
|
||||||
|
): boolean;
|
||||||
|
// returns true, if changed
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
AtomStart: integer;
|
||||||
|
CurAtom: String;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
p:=1;
|
||||||
|
repeat
|
||||||
|
ReadRawNextCAtom(Expression,p,AtomStart);
|
||||||
|
if AtomStart>length(Expression) then break;
|
||||||
|
CurAtom:=copy(Expression,AtomStart,p-AtomStart);
|
||||||
|
if (CurAtom='not') then begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
|
||||||
function TH2PasTool.MacroValueIsConstant(Node: TH2PDirectiveNode;
|
function TH2PasTool.MacroValueIsConstant(Node: TH2PDirectiveNode;
|
||||||
out PasType, PasExpression: string): boolean;
|
out PasType, PasExpression: string): boolean;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user