mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-01 12:52:33 +02:00
codetools: h2p: implemented nested function types
git-svn-id: trunk@14657 -
This commit is contained in:
parent
33fceb4802
commit
66c97d67f0
@ -211,6 +211,8 @@ type
|
||||
function ExtractVariableType(VarNode: TCodeTreeNode;
|
||||
WithDirectives: boolean = false): string;
|
||||
function ExtractFunctionName(FuncNode: TCodeTreeNode): string;
|
||||
function GetFunctionParamListNode(Node: TCodeTreeNode): TCodeTreeNode;
|
||||
function ExtractFunctionParamList(FuncNode: TCodeTreeNode): string;
|
||||
function ExtractFunctionType(FuncNode: TCodeTreeNode;
|
||||
WithDirectives: boolean = false): string;
|
||||
function ExtractFunctionResultType(FuncNode: TCodeTreeNode;
|
||||
@ -238,6 +240,7 @@ type
|
||||
procedure IncreaseChangeStep;
|
||||
procedure WriteDebugReport;
|
||||
procedure CheckNodeTool(Node: TCodeTreeNode);
|
||||
function NodeAsString(Node: TCodeTreeNode): string;
|
||||
|
||||
property ChangeStep: integer read FChangeStep;
|
||||
end;
|
||||
@ -1549,6 +1552,26 @@ begin
|
||||
Result:=copy(Src,NameNode.StartPos,NameNode.EndPos-NameNode.StartPos);
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.GetFunctionParamListNode(Node: TCodeTreeNode
|
||||
): TCodeTreeNode;
|
||||
begin
|
||||
Result:=Node.FirstChild;
|
||||
while (Result<>nil) and (Result.Desc<>ccnFuncParamList) do
|
||||
Result:=Result.NextBrother;
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.ExtractFunctionParamList(FuncNode: TCodeTreeNode
|
||||
): string;
|
||||
var
|
||||
ParamsNode: TCodeTreeNode;
|
||||
begin
|
||||
ParamsNode:=GetFunctionParamListNode(FuncNode);
|
||||
if (ParamsNode=nil) then
|
||||
Result:=''
|
||||
else
|
||||
Result:=ExtractCode(ParamsNode.StartPos,ParamsNode.EndPos);
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.ExtractFunctionType(FuncNode: TCodeTreeNode;
|
||||
WithDirectives: boolean): string;
|
||||
var
|
||||
@ -1885,7 +1908,7 @@ begin
|
||||
if Tree<>nil then begin
|
||||
Node:=Tree.Root;
|
||||
while Node<>nil do begin
|
||||
DebugLn([GetIndentStr(Node.GetLevel*2)+CCNodeDescAsString(Node.Desc)]);
|
||||
DebugLn([GetIndentStr(Node.GetLevel*2)+NodeAsString(Node)]);
|
||||
Node:=Node.Next;
|
||||
end;
|
||||
end;
|
||||
@ -1906,6 +1929,15 @@ begin
|
||||
RaiseForeignNode;
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.NodeAsString(Node: TCodeTreeNode): string;
|
||||
begin
|
||||
case Node.Desc of
|
||||
ccnName: Result:=copy(Src,Node.StartPos,Node.EndPos-Node.StartPos);
|
||||
else Result:='';
|
||||
end;
|
||||
Result:=CCNodeDescAsString(Node.Desc)+'('+Result+' at '+CleanPosToStr(Node.StartPos)+')';
|
||||
end;
|
||||
|
||||
procedure InternalFinal;
|
||||
var
|
||||
i: Integer;
|
||||
|
@ -63,10 +63,9 @@ begin
|
||||
|
||||
Tool:=TH2PasTool.Create;
|
||||
Tool.SourceName:=ExtractFileNameOnly(PasCode.Filename);
|
||||
Tool.Defines['__cplusplus']:='1';
|
||||
Tool.Convert(CCode,PasCode);
|
||||
//Tool.WriteDebugReport;
|
||||
//Tool.WriteH2PNodeReport;
|
||||
Tool.WriteH2PNodeReport;
|
||||
Tool.WriteH2PDirectivesNodeReport;
|
||||
writeln;
|
||||
writeln('=============================================');
|
||||
|
@ -73,7 +73,7 @@ int bafprintf(FILE *stream, const char *format, ...);
|
||||
int basprintf(char *str, const char *format, ...);
|
||||
int basnprintf(char *str, size_t size, const char *format, ...);
|
||||
int hci_send_req(int dd, struct hci_request *req, int timeout); // implicit struct
|
||||
//int hci_for_each_dev(int flag, int(*func)(int dd, int dev_id, long arg), long arg); // implicit function type
|
||||
int hci_for_each_dev(int flag, int(*func)(int dd, int dev_id, long arg), long arg); // implicit function type
|
||||
|
||||
void *bt_malloc(size_t size);
|
||||
void bt_free(void *ptr);
|
||||
|
@ -584,6 +584,8 @@ var
|
||||
StatementNode: TCodeTreeNode;
|
||||
TypeH2PNode: TH2PNode;
|
||||
H2PNode: TH2PNode;
|
||||
SubTypeName: String;
|
||||
ParamsNode: TCodeTreeNode;
|
||||
begin
|
||||
CurName:=CTool.ExtractFunctionName(CNode);
|
||||
CurType:=CTool.ExtractFunctionResultType(CNode);
|
||||
@ -608,11 +610,28 @@ begin
|
||||
end;
|
||||
|
||||
if Ok then begin
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnProcedure,SimpleType,
|
||||
nil,false);
|
||||
DebugLn(['TH2PasTool.ConvertFunction function added: ',H2PNode.DescAsString(CTool)]);
|
||||
// build recursively
|
||||
BuildH2PTree(H2PNode);
|
||||
if IsPointerToFunction then begin
|
||||
// create proc type
|
||||
ParamsNode:=CTool.GetFunctionParamListNode(CNode);
|
||||
SubTypeName:=CreatePascalNameFromCCode(CurName+CTool.ExtractFunctionParamList(CNode));
|
||||
TypeH2PNode:=CreateH2PNode(SubTypeName,'',nil,ctnProcedureType,SimpleType,
|
||||
nil,true);
|
||||
DebugLn(['TH2PasTool.ConvertFunction function type added: ',TypeH2PNode.DescAsString(CTool)]);
|
||||
// create variable
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnVarDefinition,SubTypeName,
|
||||
ParentNode,ParentNode=nil);
|
||||
DebugLn(['TH2PasTool.ConvertFunction variable added: ',H2PNode.DescAsString(CTool)]);
|
||||
// build parameters recursively
|
||||
if ParamsNode.FirstChild<>nil then
|
||||
BuildH2PTree(TypeH2PNode,ParamsNode.FirstChild);
|
||||
end else begin
|
||||
// create proc
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnProcedure,SimpleType,
|
||||
nil,false);
|
||||
DebugLn(['TH2PasTool.ConvertFunction function added: ',H2PNode.DescAsString(CTool)]);
|
||||
// build parameters recursively
|
||||
BuildH2PTree(H2PNode);
|
||||
end;
|
||||
end else begin
|
||||
DebugLn(['TH2PasTool.ConvertFunction SKIPPING Function Name="',CurName,'" Type="',CurType,'" at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
@ -1627,7 +1646,7 @@ begin
|
||||
CTool:=TCCodeParserTool.Create;
|
||||
// pare C header file
|
||||
CTool.Parse(CCode);
|
||||
//CTool.WriteDebugReport;
|
||||
CTool.WriteDebugReport;
|
||||
|
||||
BuildH2PTree;
|
||||
|
||||
|
@ -343,7 +343,7 @@ begin
|
||||
inc(Position);
|
||||
if Position<=Len then begin
|
||||
c2:=Source[Position];
|
||||
// test for double char operators :=, +=, -=, /=, *=, !=, ==, <=, >=, ^^, ::
|
||||
// test for double char operators
|
||||
if ((c1=#13) and (c2=#10))
|
||||
or ((c2='=') and (c1 in ['=','!','<','>','+','-','*','/','&','|']))
|
||||
or ((c1=':') and (c2=':'))
|
||||
|
Loading…
Reference in New Issue
Block a user