mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 10:50:53 +02:00
codetools: h2p: implemented parsing defines
git-svn-id: trunk@14586 -
This commit is contained in:
parent
baebd44d83
commit
bcc1df0450
@ -230,6 +230,8 @@ type
|
|||||||
function ExtractDirectiveAction(DirectiveNode: TCodeTreeNode): string;
|
function ExtractDirectiveAction(DirectiveNode: TCodeTreeNode): string;
|
||||||
function ExtractDirectiveFirstAtom(DirectiveNode: TCodeTreeNode): string;
|
function ExtractDirectiveFirstAtom(DirectiveNode: TCodeTreeNode): string;
|
||||||
function ExtractDirectiveParams(DirectiveNode: TCodeTreeNode): string;
|
function ExtractDirectiveParams(DirectiveNode: TCodeTreeNode): string;
|
||||||
|
function ExtractDefine(DefineNode: TCodeTreeNode;
|
||||||
|
out MacroName, MacroParamList, MacroValue: string): boolean;
|
||||||
|
|
||||||
procedure Replace(FromPos, ToPos: integer; const NewSrc: string);
|
procedure Replace(FromPos, ToPos: integer; const NewSrc: string);
|
||||||
|
|
||||||
@ -1826,6 +1828,44 @@ begin
|
|||||||
Result:=ExtractCode(AtomStart,DirectiveNode.EndPos);
|
Result:=ExtractCode(AtomStart,DirectiveNode.EndPos);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCCodeParserTool.ExtractDefine(DefineNode: TCodeTreeNode; out
|
||||||
|
MacroName, MacroParamList, MacroValue: string): boolean;
|
||||||
|
var
|
||||||
|
StartPos: LongInt;
|
||||||
|
EndPos: LongInt;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
MacroName:='';
|
||||||
|
MacroParamList:='';
|
||||||
|
MacroValue:='';
|
||||||
|
MoveCursorToPos(DefineNode.StartPos+1);
|
||||||
|
// read action
|
||||||
|
ReadRawNextAtom;
|
||||||
|
if not AtomIs('define') then exit;
|
||||||
|
// read first atom
|
||||||
|
ReadRawNextAtom;
|
||||||
|
MacroName:=GetAtom;
|
||||||
|
StartPos:=SrcPos;
|
||||||
|
// read param list
|
||||||
|
if (SrcPos<=SrcLen) and (Src[SrcPos]='(') then begin
|
||||||
|
StartPos:=SrcPos;
|
||||||
|
AtomStart:=SrcPos;
|
||||||
|
SrcPos:=AtomStart+1;
|
||||||
|
if not ReadTilBracketClose(false) then exit;
|
||||||
|
EndPos:=SrcPos;
|
||||||
|
MacroParamList:=ExtractCode(StartPos,EndPos);
|
||||||
|
StartPos:=EndPos;
|
||||||
|
end;
|
||||||
|
// read value
|
||||||
|
while (StartPos<=SrcLen) and (IsSpaceChar[Src[StartPos]]) do
|
||||||
|
inc(StartPos);
|
||||||
|
EndPos:=DefineNode.EndPos;
|
||||||
|
while (EndPos>StartPos) and (IsSpaceChar[Src[EndPos-1]]) do
|
||||||
|
dec(EndPos);
|
||||||
|
MacroValue:=copy(Src,StartPos,EndPos-StartPos);
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCCodeParserTool.GetAtom: string;
|
function TCCodeParserTool.GetAtom: string;
|
||||||
begin
|
begin
|
||||||
Result:=copy(Src,AtomStart,SrcPos-AtomStart);
|
Result:=copy(Src,AtomStart,SrcPos-AtomStart);
|
||||||
|
@ -541,6 +541,7 @@ var
|
|||||||
ErrorMsg: string;
|
ErrorMsg: string;
|
||||||
StartPos: LongInt;
|
StartPos: LongInt;
|
||||||
EndPos: LongInt;
|
EndPos: LongInt;
|
||||||
|
MacroName,MacroParamList,MacroValue: string;
|
||||||
begin
|
begin
|
||||||
Directive:=CTool.ExtractDirectiveAction(CNode);
|
Directive:=CTool.ExtractDirectiveAction(CNode);
|
||||||
if Directive='include' then begin
|
if Directive='include' then begin
|
||||||
@ -549,8 +550,15 @@ begin
|
|||||||
if icspInclude in IgnoreCParts then
|
if icspInclude in IgnoreCParts then
|
||||||
exit;
|
exit;
|
||||||
end else if Directive='define' then begin
|
end else if Directive='define' then begin
|
||||||
// #define FMAC(a,b) a here, then b
|
// #define macrofunction(a,b) a here, then b
|
||||||
// #define NONFMAC some text here
|
// #define simplemacro some text here
|
||||||
|
if CTool.ExtractDefine(CNode,MacroName,MacroParamList,MacroValue)
|
||||||
|
then begin
|
||||||
|
H2PNode:=CreateH2PNode('$'+Directive,'#'+Directive,CNode,ctnNone,
|
||||||
|
MacroName,ParentNode,false);
|
||||||
|
DebugLn(['TH2PasTool.ConvertDirective added: ',H2PNode.DescAsString]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end else if (Directive='undef') or (Directive='ifdef')
|
end else if (Directive='undef') or (Directive='ifdef')
|
||||||
or (Directive='ifndef') then begin
|
or (Directive='ifndef') then begin
|
||||||
// #undef NAME
|
// #undef NAME
|
||||||
|
Loading…
Reference in New Issue
Block a user