codetools: h2p: implemented union

git-svn-id: trunk@14575 -
This commit is contained in:
mattias 2008-03-18 16:40:41 +00:00
parent fcb2e8f8cb
commit ff62c04c02
3 changed files with 53 additions and 9 deletions

View File

@ -191,6 +191,7 @@ type
function ExtractEnumIDValue(EnumIDNode: TCodeTreeNode;
WithDirectives: boolean = false): string;
function ExtractStructName(StructNode: TCodeTreeNode): string;
function ExtractUnionName(UnionNode: TCodeTreeNode): string;
function ExtractTypedefName(TypedefNode: TCodeTreeNode): string;
procedure Replace(FromPos, ToPos: integer; const NewSrc: string);
@ -1529,6 +1530,17 @@ begin
Result:='';
end;
function TCCodeParserTool.ExtractUnionName(UnionNode: TCodeTreeNode): string;
var
NameNode: TCodeTreeNode;
begin
NameNode:=UnionNode.FirstChild;
if (NameNode<>nil) and (NameNode.Desc=ccnName) then
Result:=GetIdentifier(@Src[NameNode.StartPos])
else
Result:='';
end;
function TCCodeParserTool.ExtractTypedefName(TypedefNode: TCodeTreeNode
): string;
var

View File

@ -62,12 +62,6 @@ typedef struct {
uint8_t b[6]; // implicit type
} __attribute__((packed)) bdaddr_t;
/* Copy, swap, convert BD Address */
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
{
return memcmp(ba1, ba2, sizeof(bdaddr_t));
}
void baswap(bdaddr_t *dst, const bdaddr_t *src);
bdaddr_t *strtoba(const char *str);
int baprintf(const char *format, ...);
@ -155,6 +149,13 @@ char *const c; // A constant pointer to a character
const char *const d; // A constant pointer to a constant character
const char *e; // A pointer to a constant character. The pointer may be modified.
/* Copy, swap, convert BD Address */
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
{
return memcmp(ba1, ba2, sizeof(bdaddr_t));
}
#ifdef __cplusplus
}
#endif

View File

@ -328,7 +328,37 @@ begin
end;
ccnVariable:
begin
if (CNode.FirstChild<>nil) and (CNode.FirstChild.Desc=ccnUnion)
then begin
CurName:=CTool.ExtractVariableName(CNode);
if (ParentNode<>nil) and (ParentNode.PascalDesc=ctnRecordType)
then begin
// create a pascal 'record case'
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnRecordCase,'',
ParentNode,false);
DebugLn(['TH2PasTool.BuildH2PTree added record case for nested union']);
// build recursively the record cases
if CNode.FirstChild.FirstChild<>nil then
BuildH2PTree(TypeH2PNode,CNode.FirstChild.FirstChild);
end else if (CurName<>'') and (ParentNode=nil) then begin
// this union has a name
// create a record type
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnRecordCase,'',
nil,true);
DebugLn(['TH2PasTool.BuildH2PTree added record type for union: ',TypeH2PNode.DescAsString]);
// build recursively
if CNode.FirstChild.FirstChild<>nil then
BuildH2PTree(TypeH2PNode,CNode.FirstChild.FirstChild);
// create variable
CurName:=CTool.ExtractUnionName(CNode);
H2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnVarDefinition,
TypeH2PNode.PascalName,
nil,ParentNode=nil);
DebugLn(['TH2PasTool.BuildH2PTree added variable for union: ',H2PNode.DescAsString]);
end else begin
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING union variable at ',CTool.CleanPosToStr(CNode.StartPos)]);
end;
end else begin
CurName:=CTool.ExtractVariableName(CNode);
CurType:=CTool.ExtractVariableType(CNode);
SimpleType:=GetSimplePascalTypeOfCVar(CNode);
@ -438,8 +468,7 @@ begin
begin
CurName:=CTool.ExtractStructName(CNode);
if CurName='' then begin
// this is an anonymous struct => auto generate a name
// ignore
// this is an anonymous struct -> ignore
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING anonymous struct at ',CTool.CleanPosToStr(CNode.StartPos)]);
end else begin
// this struct has a name
@ -456,7 +485,9 @@ begin
nil,ParentNode=nil);
end;
end;
ccnName: ;
else
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING ',CCNodeDescAsString(CNode.Desc),' at ',CTool.CleanPosToStr(CNode.StartPos)]);
end;