codetools: h2p: implemented parameter type ...

git-svn-id: trunk@14572 -
This commit is contained in:
mattias 2008-03-18 15:09:39 +00:00
parent b8caa1a665
commit f483eda4a5
2 changed files with 25 additions and 3 deletions

View File

@ -129,7 +129,7 @@ typedef void(*sdp_list_func_t)(void *, void *);
complex operator+(complex, complex);
int y = 7;
float f(int){};
float internalfunc(int){};
int dim2[][3];
bool b1 = a==b;
char c = 'a';
@ -140,7 +140,7 @@ int *pi; // pointer to int
char ** ppc; // pointer to pointer to char
int* ap[15]; // array of 15 pointers to ints
int (*fp)(char*); // pointer to function taking a char* argument; returns an int
int * f(char*); // function taking a char* argument; returns a pointer to int
int * func1(char*); // function taking a char* argument; returns a pointer to int
int func2(int=3); // function taking an int argument or no argument; returns an int
unsigned short unsigned_short;
unsigned long long unsigned_long_long;

View File

@ -105,6 +105,7 @@ type
procedure BuildH2PTree(ParentNode: TH2PNode = nil);
function GetSimplePascalTypeOfCVar(CVarNode: TCodeTreeNode): string;
function GetSimplePascalTypeOfCParameter(CParamNode: TCodeTreeNode): string;
function GetSimplePascalResultTypeOfCFunction(CFuncNode: TCodeTreeNode): string;
function ConvertSimpleCTypeToPascalType(CType: string;
UseSingleIdentifierAsDefault: boolean): string;
@ -300,8 +301,10 @@ begin
case CNode.Desc of
ccnRoot, ccnExtern:
NextCNode:=CNode.Next;
ccnDirective:
NextCNode:=CNode.Next;
ccnVariable:
begin
CurName:=CTool.ExtractVariableName(CNode);
@ -321,6 +324,7 @@ begin
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING Variable Name="',CurName,'" Type="',CurType,'"']);
end;
end;
ccnFunction:
begin
CurName:=CTool.ExtractFunctionName(CNode);
@ -355,13 +359,15 @@ begin
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING Function Name="',CurName,'" Type="',CurType,'"']);
end;
end;
ccnFuncParamList:
NextCNode:=CNode.FirstChild;
ccnFuncParameter:
begin
CurName:=CTool.ExtractParameterName(CNode);
CurType:=CTool.ExtractParameterType(CNode);
SimpleType:=GetSimplePascalTypeOfCVar(CNode);
SimpleType:=GetSimplePascalTypeOfCParameter(CNode);
DebugLn(['TH2PasTool.BuildH2PTree Parameter: Name="',CurName,'" Type="',CurType,'" SimpleType="',SimpleType,'"']);
if SimpleType='' then begin
// this variable has a complex type
@ -377,6 +383,7 @@ begin
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING parameter Name="',CurName,'" Type="',CurType,'"']);
end;
end;
ccnEnumBlock:
begin
CurName:=CTool.ExtractEnumBlockName(CNode);
@ -404,6 +411,7 @@ begin
CNode:=CNode.NextBrother;
end;
end;
ccnStruct:
begin
CurName:=CTool.ExtractStructName(CNode);
@ -420,6 +428,9 @@ begin
// build recursively
BuildH2PTree(TypeH2PNode);
end;
ccnName: ;
else
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING ',CCNodeDescAsString(CNode.Desc)]);
end;
// next C node
if (ParentNode<>nil) and (not ParentNode.CNode.HasAsChild(NextCNode)) then
@ -435,6 +446,17 @@ begin
Result:=ConvertSimpleCTypeToPascalType(Result,true);
end;
function TH2PasTool.GetSimplePascalTypeOfCParameter(CParamNode: TCodeTreeNode
): string;
begin
Result:=CTool.ExtractParameterType(CParamNode);
if Result='' then exit;
if (Result='...') then
Result:='array of const'
else
Result:=ConvertSimpleCTypeToPascalType(Result,true);
end;
function TH2PasTool.GetSimplePascalResultTypeOfCFunction(
CFuncNode: TCodeTreeNode): string;
begin