mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 03:16:10 +02:00
codetools: h2p: implemented typedef function pointers
git-svn-id: trunk@14577 -
This commit is contained in:
parent
ad20039e2e
commit
70de988f83
@ -182,7 +182,8 @@ type
|
||||
function ExtractFunctionType(FuncNode: TCodeTreeNode;
|
||||
WithDirectives: boolean = false): string;
|
||||
function ExtractFunctionResultType(FuncNode: TCodeTreeNode;
|
||||
WithDirectives: boolean = false): string;
|
||||
WithDirectives: boolean = false;
|
||||
WithBrackets: boolean = true): string;
|
||||
function IsPointerToFunction(FuncNode: TCodeTreeNode): boolean;
|
||||
function ExtractParameterName(ParamNode: TCodeTreeNode): string;
|
||||
function ExtractParameterType(ParamNode: TCodeTreeNode;
|
||||
@ -1384,9 +1385,11 @@ begin
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.ExtractFunctionResultType(FuncNode: TCodeTreeNode;
|
||||
WithDirectives: boolean): string;
|
||||
WithDirectives: boolean; WithBrackets: boolean): string;
|
||||
var
|
||||
NameNode: TCodeTreeNode;
|
||||
p: Integer;
|
||||
CurAtomStart: integer;
|
||||
begin
|
||||
NameNode:=GetFirstNameNode(FuncNode);
|
||||
if (NameNode=nil) then begin
|
||||
@ -1414,6 +1417,22 @@ begin
|
||||
Result:=Result+ExtractCode(NameNode.EndPos,FuncNode.EndPos,
|
||||
WithDirectives);
|
||||
end;
|
||||
|
||||
if not WithBrackets then begin
|
||||
p:=1;
|
||||
repeat
|
||||
ReadRawNextCAtom(Result,p,CurAtomStart);
|
||||
if CurAtomStart>length(Result) then break;
|
||||
if Result[CurAtomStart]='(' then begin
|
||||
p:=CurAtomStart;
|
||||
if ReadTilCBracketClose(Result,p) then begin
|
||||
Result:=copy(Result,1,CurAtomStart-1)
|
||||
+copy(Result,p,length(Result));
|
||||
end;
|
||||
break;
|
||||
end;
|
||||
until false;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.IsPointerToFunction(FuncNode: TCodeTreeNode
|
||||
@ -1553,9 +1572,13 @@ begin
|
||||
Node:=TypedefNode.LastChild;
|
||||
while (Node<>nil) and (Node.Desc<>ccnName) do
|
||||
Node:=Node.PriorBrother;
|
||||
if Node=nil then
|
||||
Result:=''
|
||||
else
|
||||
if Node=nil then begin
|
||||
if (TypedefNode.FirstChild<>nil)
|
||||
and (TypedefNode.FirstChild.Desc=ccnFunction) then
|
||||
Result:=ExtractFunctionName(TypedefNode.FirstChild)
|
||||
else
|
||||
Result:='';
|
||||
end else
|
||||
Result:=GetIdentifier(@Src[Node.StartPos]);
|
||||
end;
|
||||
|
||||
|
@ -118,7 +118,7 @@ struct struct1 {
|
||||
void *data;
|
||||
};
|
||||
|
||||
typedef void(*sdp_list_func_t)(void *, void *);
|
||||
typedef void(*procedure_type)(void *, void *);
|
||||
|
||||
complex operator+(complex, complex);
|
||||
|
||||
|
@ -314,8 +314,10 @@ begin
|
||||
if CNode.FirstChild<>nil then begin
|
||||
CurName:=CTool.ExtractTypedefName(CNode);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree Typedef name="',CurName,'"']);
|
||||
case CNode.FirstChild.Desc of
|
||||
ccnStruct:
|
||||
ChildNode:=CNode.FirstChild;
|
||||
case ChildNode.Desc of
|
||||
|
||||
ccnStruct: // typedef struct
|
||||
begin
|
||||
ChildNode:=CNode.FirstChild.FirstChild;
|
||||
if (ChildNode<>nil)
|
||||
@ -333,11 +335,33 @@ begin
|
||||
BuildH2PTree(TypeH2PNode,ChildNode);
|
||||
end;
|
||||
end;
|
||||
ccnVariable:
|
||||
|
||||
ccnFunction: // typedef function
|
||||
begin
|
||||
|
||||
CurName:=CTool.ExtractFunctionName(ChildNode);
|
||||
CurType:=CTool.ExtractFunctionResultType(ChildNode,false,false);
|
||||
IsPointerToFunction:=CTool.IsPointerToFunction(ChildNode);
|
||||
SimpleType:=GetSimplePascalResultTypeOfCFunction(ChildNode);
|
||||
if IsPointerToFunction and (SimpleType='') then begin
|
||||
// this function has a complex result type
|
||||
TypeH2PNode:=GetH2PNodeForComplexType(ChildNode);
|
||||
if TypeH2PNode<>nil then
|
||||
SimpleType:=TypeH2PNode.PascalName;
|
||||
end;
|
||||
if IsPointerToFunction and (SimpleType<>'') then begin
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnProcedureType,SimpleType,
|
||||
nil,true);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree function type added: ',H2PNode.DescAsString]);
|
||||
// build recursively
|
||||
if ChildNode.FirstChild<>nil then
|
||||
BuildH2PTree(H2PNode,ChildNode.FirstChild);
|
||||
end else begin
|
||||
DebugLn(['TH2PasTool.BuildH2PTree typdef function CurName=',CurName,' CurType=',CTool.ExtractFunctionResultType(ChildNode),' SimpleType=',SimpleType]);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING typedef ',CCNodeDescAsString(ChildNode.Desc),' at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
end;
|
||||
else
|
||||
|
||||
else // typedef
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING typedef ',CCNodeDescAsString(CNode.FirstChild.Desc),' at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
end;
|
||||
@ -418,7 +442,7 @@ begin
|
||||
|
||||
if Ok then begin
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnProcedure,SimpleType,
|
||||
nil,ParentNode=nil);
|
||||
nil,false);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree function added: ',H2PNode.DescAsString]);
|
||||
// build recursively
|
||||
BuildH2PTree(H2PNode);
|
||||
@ -528,7 +552,7 @@ end;
|
||||
function TH2PasTool.GetSimplePascalResultTypeOfCFunction(
|
||||
CFuncNode: TCodeTreeNode): string;
|
||||
begin
|
||||
Result:=CTool.ExtractFunctionResultType(CFuncNode);
|
||||
Result:=CTool.ExtractFunctionResultType(CFuncNode,false,false);
|
||||
if Result='' then exit;
|
||||
Result:=ConvertSimpleCTypeToPascalType(Result,true);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user