codetools: h2p: implemented struct alias

git-svn-id: trunk@14576 -
This commit is contained in:
mattias 2008-03-18 16:58:12 +00:00
parent ff62c04c02
commit ad20039e2e
3 changed files with 36 additions and 23 deletions

View File

@ -57,13 +57,14 @@ const
ccnConstant = 6+ccnBase;// e.g. 1
ccnTypedef = 7+ccnBase;// e.g. typedef int TInt;
ccnStruct = 8+ccnBase;// e.g. struct{}
ccnUnion = 9+ccnBase;// e.g. union{}
ccnVariable = 10+ccnBase;// e.g. int i
ccnFunction = 11+ccnBase;// e.g. int i()
ccnName = 12+ccnBase;// e.g. i
ccnFuncParamList = 13+ccnBase;// e.g. ()
ccnFuncParameter = 14+ccnBase;// e.g. ()
ccnStatementBlock = 15+ccnBase;// e.g. {}
ccnStructAlias = 9+ccnBase;// e.g. struct name
ccnUnion = 10+ccnBase;// e.g. union{}
ccnVariable = 11+ccnBase;// e.g. int i
ccnFunction = 12+ccnBase;// e.g. int i()
ccnName = 13+ccnBase;// e.g. i
ccnFuncParamList = 14+ccnBase;// e.g. ()
ccnFuncParameter = 15+ccnBase;// e.g. ()
ccnStatementBlock = 16+ccnBase;// e.g. {}
type
TCCodeParserTool = class;
@ -227,6 +228,7 @@ begin
ccnConstant : Result:='constant';
ccnTypedef : Result:='typedef';
ccnStruct : Result:='struct';
ccnStructAlias : Result:='struct-alias';
ccnUnion : Result:='union';
ccnVariable : Result:='variable';
ccnFunction : Result:='function';
@ -454,6 +456,8 @@ begin
end;
end else if AtomIsIdentifier then begin
// using another struct
CreateChildNode(ccnStructAlias);
EndChildNode;
end else
RaiseExpectedButAtomFound('{');

View File

@ -112,9 +112,9 @@ typedef struct {
#define SDP_IS_UUID(x) ((x) == SDP_UUID16 || (x) == SDP_UUID32 || (x) ==SDP_UUID128)
typedef struct _sdp_list sdp_list_t;
struct _sdp_list {
sdp_list_t *next;
typedef struct struct1 struct2;
struct struct1 {
struct2 *next;
void *data;
};

View File

@ -288,6 +288,7 @@ var
StatementNode: TCodeTreeNode;
Ok: Boolean;
IsPointerToFunction: Boolean;
ChildNode: TCodeTreeNode;
begin
//DebugLn(['TH2PasTool.BuildH2PTree ParentNode=',ParentNode.DescAsString]);
if ParentNode<>nil then begin
@ -316,11 +317,25 @@ begin
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);
ChildNode:=CNode.FirstChild.FirstChild;
if (ChildNode<>nil)
and (ChildNode.Desc=ccnStructAlias) then begin
// this is a struct alias
CurType:=GetIdentifier(@CTool.Src[ChildNode.StartPos]);
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,
ctnTypeDefinition,CurType);
end else begin
// this is a new struct
TypeH2PNode:=CreateH2PNode(CurName,CurName,CNode,ctnRecordType,'');
DebugLn(['TH2PasTool.BuildH2PTree added record: ',TypeH2PNode.DescAsString]);
// build recursively
if ChildNode<>nil then
BuildH2PTree(TypeH2PNode,ChildNode);
end;
end;
ccnVariable:
begin
end;
else
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING typedef ',CCNodeDescAsString(CNode.FirstChild.Desc),' at ',CTool.CleanPosToStr(CNode.StartPos)]);
@ -472,17 +487,11 @@ begin
DebugLn(['TH2PasTool.BuildH2PTree SKIPPING anonymous struct at ',CTool.CleanPosToStr(CNode.StartPos)]);
end else begin
// this struct has a name
// create a type and a variable
CurName:='T'+CurName;
TypeH2PNode:=CreateAutoGeneratedH2PNode(CurName,CNode,ctnRecordType,'',
// create a type
TypeH2PNode:=CreateH2PNode(CurName,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;
end;