diff --git a/components/codetools/ccodeparsertool.pas b/components/codetools/ccodeparsertool.pas index 33ed7874bd..e29dab5ae8 100644 --- a/components/codetools/ccodeparsertool.pas +++ b/components/codetools/ccodeparsertool.pas @@ -635,6 +635,7 @@ procedure TCCodeParserTool.ReadStruct; struct hidp_connadd_req { int ctrl_sock; } + struct SwsContext; // no content As variable: struct hidp_conninfo *ci; @@ -693,6 +694,8 @@ begin // using another struct CreateChildNode(ccnStructAlias); EndChildNode; + end else if AtomIsChar(';') then begin + // struct without content end else RaiseExpectedButAtomFound('{'); diff --git a/components/codetools/codetoolsstructs.pas b/components/codetools/codetoolsstructs.pas index b666faa048..0165737d36 100644 --- a/components/codetools/codetoolsstructs.pas +++ b/components/codetools/codetoolsstructs.pas @@ -35,7 +35,7 @@ unit CodeToolsStructs; interface uses - Classes, SysUtils, AVL_Tree, CodeCache, CodeAtom; + Classes, SysUtils, FileProcs, AVL_Tree, CodeCache, CodeAtom; type TResourcestringInsertPolicy = ( @@ -124,6 +124,7 @@ type property Strings[const s: string]: string read GetStrings write SetStrings; default; property CaseSensitive: boolean read FCaseSensitive; property Tree: TAVLTree read FTree; + procedure WriteDebugReport; end; function CompareStringToStringItems(Data1, Data2: Pointer): integer; @@ -426,5 +427,19 @@ begin end; end; +procedure TStringToStringTree.WriteDebugReport; +var + Node: TAVLTreeNode; + Item: PStringToStringTreeItem; +begin + DebugLn(['TStringToStringTree.WriteDebugReport ',Tree.Count]); + Node:=Tree.FindLowest; + while Node<>nil do begin + Item:=PStringToStringTreeItem(Node.Data); + DebugLn([Item^.Name,'=',Item^.Value]); + Node:=Tree.FindSuccessor(Node); + end; +end; + end. diff --git a/components/codetools/examples/h2pastest.lpr b/components/codetools/examples/h2pastest.lpr index 409b2b6206..87444f8069 100644 --- a/components/codetools/examples/h2pastest.lpr +++ b/components/codetools/examples/h2pastest.lpr @@ -87,7 +87,6 @@ begin Src:=Src+LineEnding; Src:=Src+CCode.Source; end; - Halt; // Step 2: create a temporary file Filename:='h2pasoutput.pas'; diff --git a/components/codetools/examples/scanexamples/test.h b/components/codetools/examples/scanexamples/test.h index 0bc9c47d1b..4a68bd231f 100644 --- a/components/codetools/examples/scanexamples/test.h +++ b/components/codetools/examples/scanexamples/test.h @@ -170,6 +170,8 @@ const char* (*item_name)(void* ctx); const struct AVOption *option; #if LIBAVUTIL_VERSION_INT < (50<<16) void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); +struct SwsContext; // SwsContext = record end; + #ifdef __cplusplus } diff --git a/components/codetools/h2pastool.pas b/components/codetools/h2pastool.pas index 65935fa470..edbd7e1edc 100644 --- a/components/codetools/h2pastool.pas +++ b/components/codetools/h2pastool.pas @@ -225,7 +225,7 @@ type procedure SimplifyDefineDirective(Node: TH2PDirectiveNode; var NextNode: TH2PDirectiveNode; var Changed: boolean); - procedure SimplifyIfDirective(Node: TH2PDirectiveNode; const Expression: string; + procedure SimplifyIfDirective(Node: TH2PDirectiveNode; Expression: string; var NextNode: TH2PDirectiveNode; var Changed: boolean); function SimplifyIfDirectiveExpression(var Expression: string): boolean; @@ -1604,7 +1604,7 @@ begin end; procedure TH2PasTool.SimplifyIfDirective(Node: TH2PDirectiveNode; - const Expression: string; var NextNode: TH2PDirectiveNode; + Expression: string; var NextNode: TH2PDirectiveNode; var Changed: boolean); begin if Node.H2PNode=nil then exit; @@ -1616,18 +1616,35 @@ begin then begin // no content DebugLn(['TH2PasTool.SimplifyIfDirective REMOVING empty if directive: ',Node.DescAsString(CTool)]); - if (NextNode=Node.NextBrother) and (NextNode.Desc=h2pdnEndIf) then + if NextNode.HasAsParent(Node) + or ((NextNode=Node.NextBrother) and (NextNode.Desc=h2pdnEndIf)) then NextNode:=TH2PDirectiveNode(NextNode.NextSkipChilds); DeleteDirectiveNode(Node,true,true); Changed:=true; - end else begin - + exit; + end; + + Changed:=SimplifyIfDirectiveExpression(Expression); + if Expression='0' then begin + // always false + DebugLn(['TH2PasTool.SimplifyIfDirective REMOVING directive, because always false: ',Node.DescAsString(CTool)]); + if NextNode.HasAsParent(Node) + or ((NextNode=Node.NextBrother) and (NextNode.Desc=h2pdnEndIf)) then + NextNode:=TH2PDirectiveNode(NextNode.NextSkipChilds); + DeleteDirectiveNode(Node,true,true); + Changed:=true; + exit; + end; + + if Changed and ((Node.Desc=h2pdnIf) or (Node.Desc=h2pdnElseIf)) then begin + Node.Expression:=Expression; end; end; function TH2PasTool.SimplifyIfDirectiveExpression(var Expression: string ): boolean; // returns true, if changed +// uses current Undefines and Defines var p: Integer; AtomStart: integer; @@ -1639,9 +1656,7 @@ begin ReadRawNextCAtom(Expression,p,AtomStart); if AtomStart>length(Expression) then break; CurAtom:=copy(Expression,AtomStart,p-AtomStart); - if (CurAtom='not') then begin - - end; + if CurAtom='' then ; until false; end; @@ -2040,6 +2055,7 @@ begin if Node=nil then exit; MacroName:=CTool.ExtractDirectiveFirstAtom(Node); if MacroName='' then exit; + //DebugLn(['TH2PasTool.UndefineEnclosingIFNDEF UNDEFINE ',MacroName]); Undefines.Add(MacroName,''); end; @@ -2068,6 +2084,7 @@ var Changed: Boolean; H2PNode: TH2PNode; begin + // Undefines.WriteDebugReport; repeat Changed:=false; InitMacros; @@ -2679,7 +2696,8 @@ end; procedure TH2PasTool.AddCommonCDefines; begin - Undefines['__cplusplus']:='1'; + Undefines['__cplusplus']:='1';// avoid C++ and use the easier c part + Defines['__GNUC__']:='1';// assume the GNUC compiler end; procedure TH2PasTool.ResetMacros;