mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 15:31:09 +02:00
codetools: h2p: implemented typedef struct
git-svn-id: trunk@14574 -
This commit is contained in:
parent
3a1499ea41
commit
fcb2e8f8cb
@ -191,6 +191,7 @@ type
|
||||
function ExtractEnumIDValue(EnumIDNode: TCodeTreeNode;
|
||||
WithDirectives: boolean = false): string;
|
||||
function ExtractStructName(StructNode: TCodeTreeNode): string;
|
||||
function ExtractTypedefName(TypedefNode: TCodeTreeNode): string;
|
||||
|
||||
procedure Replace(FromPos, ToPos: integer; const NewSrc: string);
|
||||
|
||||
@ -517,11 +518,15 @@ begin
|
||||
ReadNextAtom;
|
||||
if not AtomIsIdentifier then
|
||||
RaiseExpectedButAtomFound('identifier');
|
||||
CreateChildNode(ccnName);
|
||||
EndChildNode;
|
||||
end else if AtomIs('enum') then begin
|
||||
ReadEnum;
|
||||
ReadNextAtom;
|
||||
if not AtomIsIdentifier then
|
||||
RaiseExpectedButAtomFound('identifier');
|
||||
CreateChildNode(ccnName);
|
||||
EndChildNode;
|
||||
end else if SrcPos>SrcLen then
|
||||
RaiseException('missing declaration')
|
||||
else
|
||||
@ -1524,6 +1529,20 @@ begin
|
||||
Result:='';
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.ExtractTypedefName(TypedefNode: TCodeTreeNode
|
||||
): string;
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
Node:=TypedefNode.LastChild;
|
||||
while (Node<>nil) and (Node.Desc<>ccnName) do
|
||||
Node:=Node.PriorBrother;
|
||||
if Node=nil then
|
||||
Result:=''
|
||||
else
|
||||
Result:=GetIdentifier(@Src[Node.StartPos]);
|
||||
end;
|
||||
|
||||
function TCCodeParserTool.GetAtom: string;
|
||||
begin
|
||||
Result:=copy(Src,AtomStart,SrcPos-AtomStart);
|
||||
|
@ -107,7 +107,7 @@ struct hidp_connlist_req {
|
||||
#define SDP_ATTR_SVCNAME_PRIMARY 0x0000 + SDP_PRIMARY_LANG_BASE
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t type; // invalid pascal name
|
||||
union {
|
||||
uint16_t uuid16;
|
||||
uint32_t uuid32;
|
||||
|
@ -102,7 +102,7 @@ type
|
||||
Tree: TH2PTree;
|
||||
CTool: TCCodeParserTool;
|
||||
function Convert(CCode, PascalCode: TCodeBuffer): boolean;
|
||||
procedure BuildH2PTree(ParentNode: TH2PNode = nil);
|
||||
procedure BuildH2PTree(ParentNode: TH2PNode = nil; StartNode: TCodeTreeNode = nil);
|
||||
|
||||
function GetSimplePascalTypeOfCVar(CVarNode: TCodeTreeNode): string;
|
||||
function GetSimplePascalTypeOfCParameter(CParamNode: TCodeTreeNode): string;
|
||||
@ -274,7 +274,8 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TH2PasTool.BuildH2PTree(ParentNode: TH2PNode);
|
||||
procedure TH2PasTool.BuildH2PTree(ParentNode: TH2PNode;
|
||||
StartNode: TCodeTreeNode);
|
||||
var
|
||||
CNode: TCodeTreeNode;
|
||||
CurName: String;
|
||||
@ -289,12 +290,15 @@ var
|
||||
IsPointerToFunction: Boolean;
|
||||
begin
|
||||
//DebugLn(['TH2PasTool.BuildH2PTree ParentNode=',ParentNode.DescAsString]);
|
||||
if ParentNode<>nil then
|
||||
CNode:=ParentNode.CNode.FirstChild
|
||||
else begin
|
||||
if ParentNode<>nil then begin
|
||||
if StartNode=nil then
|
||||
StartNode:=ParentNode.CNode.FirstChild;
|
||||
end else begin
|
||||
Tree.Clear;
|
||||
CNode:=CTool.Tree.Root;
|
||||
if StartNode=nil then
|
||||
StartNode:=CTool.Tree.Root;
|
||||
end;
|
||||
CNode:=StartNode;
|
||||
while CNode<>nil do begin
|
||||
//DebugLn(['TH2PasTool.BuildH2PTree Current ParentNode=',ParentNode.DescAsString,' CNode=',CCNodeDescAsString(CNode.Desc)]);
|
||||
NextCNode:=CNode.NextSkipChilds;
|
||||
@ -305,6 +309,24 @@ begin
|
||||
ccnDirective:
|
||||
NextCNode:=CNode.Next;
|
||||
|
||||
ccnTypedef:
|
||||
if CNode.FirstChild<>nil then begin
|
||||
CurName:=CTool.ExtractTypedefName(CNode);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree Typedef name="',CurName,'"']);
|
||||
case CNode.FirstChild.Desc of
|
||||
ccnStruct:
|
||||
begin
|
||||
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnRecordType,'');
|
||||
DebugLn(['TH2PasTool.BuildH2PTree added record: ',TypeH2PNode.DescAsString]);
|
||||
// build recursively
|
||||
if CNode.FirstChild.FirstChild<>nil then
|
||||
BuildH2PTree(TypeH2PNode,CNode.FirstChild.FirstChild);
|
||||
end;
|
||||
else
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING typedef ',CCNodeDescAsString(CNode.FirstChild.Desc),' at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
end;
|
||||
|
||||
ccnVariable:
|
||||
begin
|
||||
CurName:=CTool.ExtractVariableName(CNode);
|
||||
@ -351,12 +373,12 @@ begin
|
||||
|
||||
if Ok then begin
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnProcedure,SimpleType,
|
||||
ParentNode,ParentNode=nil);
|
||||
nil,ParentNode=nil);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree function added: ',H2PNode.DescAsString]);
|
||||
// build recursively
|
||||
BuildH2PTree(H2PNode);
|
||||
end else begin
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING Function Name="',CurName,'" Type="',CurType,'"']);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING Function Name="',CurName,'" Type="',CurType,'" at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -380,7 +402,7 @@ begin
|
||||
ParentNode,false);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree added: ',H2PNode.DescAsString]);
|
||||
end else begin
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING parameter Name="',CurName,'" Type="',CurType,'"']);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING parameter Name="',CurName,'" Type="',CurType,'" at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -391,11 +413,11 @@ begin
|
||||
// this is an anonymous enum block => auto generate a name
|
||||
CurName:=CreatePascalNameFromCCode(CTool.Src,CNode.StartPos,CNode.EndPos);
|
||||
TypeH2PNode:=CreateAutoGeneratedH2PNode(CurName,CNode,ctnEnumerationType,'',
|
||||
ParentNode,ParentNode=nil);
|
||||
nil,ParentNode=nil);
|
||||
end else begin
|
||||
// this enum block has a name
|
||||
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnEnumerationType,'',
|
||||
ParentNode,ParentNode=nil);
|
||||
nil,ParentNode=nil);
|
||||
end;
|
||||
DebugLn(['TH2PasTool.BuildH2PTree added: ',TypeH2PNode.DescAsString]);
|
||||
|
||||
@ -417,20 +439,26 @@ begin
|
||||
CurName:=CTool.ExtractStructName(CNode);
|
||||
if CurName='' then begin
|
||||
// this is an anonymous struct => auto generate a name
|
||||
CurName:=CreatePascalNameFromCCode(CTool.Src,CNode.StartPos,CNode.EndPos);
|
||||
TypeH2PNode:=CreateAutoGeneratedH2PNode(CurName,CNode,ctnRecordType,'',
|
||||
ParentNode,ParentNode=nil);
|
||||
// ignore
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING anonymous struct at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end else begin
|
||||
// this struct has a name
|
||||
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnRecordType,'',
|
||||
ParentNode,ParentNode=nil);
|
||||
// create a type and a variable
|
||||
CurName:='T'+CurName;
|
||||
TypeH2PNode:=CreateAutoGeneratedH2PNode(CurName,CNode,ctnRecordType,'',
|
||||
nil,ParentNode=nil);
|
||||
// build recursively
|
||||
BuildH2PTree(TypeH2PNode);
|
||||
// create variable
|
||||
CurName:=CTool.ExtractStructName(CNode);
|
||||
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnVarDefinition,
|
||||
TypeH2PNode.PascalName,
|
||||
nil,ParentNode=nil);
|
||||
end;
|
||||
// build recursively
|
||||
BuildH2PTree(TypeH2PNode);
|
||||
end;
|
||||
ccnName: ;
|
||||
else
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING ',CCNodeDescAsString(CNode.Desc)]);
|
||||
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING ',CCNodeDescAsString(CNode.Desc),' at ',CTool.CleanPosToStr(CNode.StartPos)]);
|
||||
end;
|
||||
// next C node
|
||||
if (ParentNode<>nil) and (not ParentNode.CNode.HasAsChild(NextCNode)) then
|
||||
|
Loading…
Reference in New Issue
Block a user