From c936345d90399683fed9f62f2a69eca82d722200 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Tue, 1 Feb 2011 02:05:53 +0000 Subject: [PATCH] chelper: updated objc converting. fixing Caption issue with the Chelper options window, #18529 git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1479 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/chelper/cconvert.lpr | 29 +++++++++++- components/chelper/ctopasconvert.pas | 13 +++--- components/chelper/extconvdialog.lfm | 45 +++++++++--------- components/chelper/extconvdialog.pas | 2 +- components/chelper/textparsingutils.pas | 62 +++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 32 deletions(-) diff --git a/components/chelper/cconvert.lpr b/components/chelper/cconvert.lpr index 7ebea01b1..a54d74796 100644 --- a/components/chelper/cconvert.lpr +++ b/components/chelper/cconvert.lpr @@ -30,6 +30,7 @@ var ConfigFileRO : Boolean = false; ParseAll : Boolean = false; ShowCodeSize : Boolean = False; // show the size of code processed + isPascalUnit : Boolean = False; // convert to pascal unit function StringFromFile(const FileName: AnsiString): AnsiString; var @@ -71,8 +72,10 @@ begin end else if p='-o' then begin inc(i); OutputFile:=ParamStr(i); - end else if p='-all' then - ParseAll:=True; + end else if p='-all' then begin + ParseAll:=True + end else if p='-pasunit' then + isPascalUnit:=True; inc(i); end; end; @@ -88,6 +91,7 @@ begin writeln(' -defines filename - macros definition file. should be in C-preprocessor format'); writeln(' -showunparsed - writes out unprased entities by their classname (for debugging only)'); writeln(' -codesize - show two numbers of the code processed (used by Chelper)'); + writeln(' -pasunit - generates a pascal unit'); end; procedure ReadParams(var InputFileName: String); @@ -106,6 +110,22 @@ begin InputFileName:=ParamStr(ParamCount); end; + +function GetPascalUnitName(const UnitName: String): String; +begin + Result:=ChangeFileExt(UnitName, ''); +end; + +procedure AddPascalUnit(outs: TStrings; const UnitName: String); +begin + if not Assigned(outs) then Exit; + outs.Insert(0, 'unit '+UnitName+';'); + outs.Insert(1, ''); + outs.Insert(2, 'interface'); + outs.Add( 'implementation'); + outs.Add( 'end.'); +end; + var inps, outs : TStringList; i : Integer; @@ -135,6 +155,11 @@ begin if ShowCodeSize then outs.Insert(0, Format('%d %d', [p.Y,p.X])); if err.isError then outs.Insert(0, Format('error %d %d %s',[err.ErrorPos.Y, err.ErrorPos. X, err.ErrorMsg]) ); + if isPascalUnit then begin + AddPascalUnit(outs, GetPascalUnitName(fn)); + end; + + if OutputFile<>'' then outs.SaveToFile(OutputFile) else diff --git a/components/chelper/ctopasconvert.pas b/components/chelper/ctopasconvert.pas index 90c395f63..0401896d1 100644 --- a/components/chelper/ctopasconvert.pas +++ b/components/chelper/ctopasconvert.pas @@ -743,11 +743,11 @@ const begin SetPasSection(wr, 'type'); if cent.isCategory then begin - wr.W(cent.Name + ' = objccategory'); + wr.W(cent.Name + ' = objccategory external '); if cent.SuperClass<>'' then wr.W('('+cent.SuperClass+')'); wr.Wln; end else begin - wr.W(cent.Name + ' = objcclass'); + wr.W(cent.Name + ' = objcclass external '); if cent.SuperClass<>'' then wr.W('('+cent.SuperClass); if cent.Protocols.Count>0 then begin if cent.SuperClass='' then wr.W('(id, ') @@ -781,7 +781,7 @@ begin WriteObjCMethods(cent.Methods); wr.DecIdent; end; - wr.Wln('end external;'); + wr.Wln('end;'); end; procedure TCodeConvertor.WriteObjCProtocol(cent:TObjCProtocol); @@ -794,7 +794,7 @@ begin for i:=0 to cent.Names.Count-1 do wr.Wln(cent.Names[i]+'Protocol = objcprotocol; external name '''+cent.Names[i]+''';'); end else begin - wr.W(cent.Names[0]+'Protocol = objcprotocol'); + wr.W(cent.Names[0]+'Protocol = objcprotocol external'); if cent.Protocols.Count>0 then begin wr.W('('); @@ -809,7 +809,7 @@ begin wr.DecIdent; end; wr.W('end; '); - wr.Wln(' external name '''+cent.Names[0]+''';'); + wr.Wln(' name '''+cent.Names[0]+''';'); end; end; @@ -819,7 +819,7 @@ var begin SetPasSection(wr, 'type'); for i:=0 to cent.ClassList.Count-1 do - wr.WLn(cent.ClassList[i] +' = objcclass; external;'); + wr.WLn(cent.ClassList[i] +' = objcclass external;'); end; @@ -1349,6 +1349,7 @@ begin xp:='((1 shl ('+PasExp(x)+'))-1)'; // returns true, if x is single number expression. V is the value of the number wr.W( GetIdFromPart(st.fields[i].v.FirstName) + ' : 0..'+xp+';'); + WriteLnCommentForOffset(st.fields[i].v.Offset); end else WriteFuncOrVar(st.fields[i].v, False, True); end; diff --git a/components/chelper/extconvdialog.lfm b/components/chelper/extconvdialog.lfm index a772f0bf5..e19597a53 100644 --- a/components/chelper/extconvdialog.lfm +++ b/components/chelper/extconvdialog.lfm @@ -8,28 +8,28 @@ object CtoPasConfig: TCtoPasConfig ClientWidth = 668 OnClose = FormClose OnResize = FormResize - LCLVersion = '0.9.29' + LCLVersion = '0.9.31' object Notebook1: TNotebook Left = 16 Height = 559 Top = 8 Width = 635 - Anchors = [akTop, akLeft, akRight, akBottom] PageIndex = 0 + Anchors = [akTop, akLeft, akRight, akBottom] TabOrder = 0 + TabStop = True object pageMain: TPage - Caption = 'Main' - ClientWidth = 629 - ClientHeight = 520 + ClientWidth = 635 + ClientHeight = 559 object Panel1: TPanel Left = 0 Height = 228 Top = 0 - Width = 629 + Width = 635 Align = alTop BevelOuter = bvNone ClientHeight = 228 - ClientWidth = 629 + ClientWidth = 635 TabOrder = 0 object Label1: TLabel Left = 6 @@ -107,9 +107,9 @@ object CtoPasConfig: TCtoPasConfig AnchorSideLeft.Side = asrBottom AnchorSideRight.Control = btnSelect Left = 64 - Height = 21 + Height = 22 Top = 172 - Width = 388 + Width = 394 Anchors = [akTop, akLeft, akRight] BorderSpacing.Left = 6 BorderSpacing.Right = 6 @@ -117,7 +117,7 @@ object CtoPasConfig: TCtoPasConfig end object btnSelect: TButton AnchorSideRight.Control = btnEdit - Left = 458 + Left = 464 Height = 20 Top = 172 Width = 70 @@ -129,7 +129,7 @@ object CtoPasConfig: TCtoPasConfig TabOrder = 5 end object btnEdit: TButton - Left = 548 + Left = 554 Height = 20 Top = 172 Width = 70 @@ -143,7 +143,7 @@ object CtoPasConfig: TCtoPasConfig Left = 325 Height = 22 Top = 100 - Width = 293 + Width = 299 Anchors = [akTop, akLeft, akRight] TabOrder = 7 end @@ -161,21 +161,21 @@ object CtoPasConfig: TCtoPasConfig end object Panel2: TPanel Left = 0 - Height = 292 + Height = 331 Top = 228 - Width = 629 + Width = 635 Align = alClient Alignment = taLeftJustify BevelOuter = bvNone - ClientHeight = 292 - ClientWidth = 629 + ClientHeight = 331 + ClientWidth = 635 TabOrder = 1 object Splitter1: TSplitter Cursor = crVSplit Left = 0 Height = 5 Top = 0 - Width = 629 + Width = 635 Align = alTop ResizeAnchor = akTop end @@ -189,9 +189,9 @@ object CtoPasConfig: TCtoPasConfig end object Memo1: TMemo Left = 6 - Height = 242 + Height = 281 Top = 44 - Width = 617 + Width = 623 Align = alBottom Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Left = 6 @@ -204,7 +204,7 @@ object CtoPasConfig: TCtoPasConfig Left = 476 Height = 20 Top = 14 - Width = 147 + Width = 153 Anchors = [akTop, akLeft, akRight] AutoSize = True Caption = 'Reset to defaults' @@ -214,9 +214,8 @@ object CtoPasConfig: TCtoPasConfig end end object pageConverter: TPage - Caption = 'Converter' - ClientWidth = 616 - ClientHeight = 382 + ClientWidth = 2464 + ClientHeight = 1528 object edtExtTool: TEdit AnchorSideTop.Control = chkUseExternal AnchorSideTop.Side = asrBottom diff --git a/components/chelper/extconvdialog.pas b/components/chelper/extconvdialog.pas index edce62aa3..4e1bedd95 100644 --- a/components/chelper/extconvdialog.pas +++ b/components/chelper/extconvdialog.pas @@ -55,7 +55,7 @@ type var CtoPasConfig: TCtoPasConfig; -function ShowConfigDialog: TCtoPasConfig; +function ShowConfigDialog : TCtoPasConfig; implementation diff --git a/components/chelper/textparsingutils.pas b/components/chelper/textparsingutils.pas index c285ad322..69e4edb85 100644 --- a/components/chelper/textparsingutils.pas +++ b/components/chelper/textparsingutils.pas @@ -55,6 +55,35 @@ function SkipLine(const s: AnsiString; var index: Integer): AnsiString; procedure OffsetToLinePos(const t: AnsiString; Offset: Integer; var P: TPoint); + +type + TRange = record stofs, endofs : Integer; end; + + { TSubBuffer } + + TSubBuffer = class(TObject) + Ranges : array of TRange; + RangesCount : Integer; + Name : string; + Tag : TObject; + constructor Create(const AName: string; ATag: TObject); + end; + + { TTextBuffer } + + TTextBuffer = class(TObject) + private + function GetSubBuffer(i: Integer): TSubBuffer; + protected + function GetCount: Integer; + public + buffer: String; + constructor Create(const Abuffer: String=''; const aname: string = ''; aobj: TObject = nil); + procedure InsertSubBuffer(pos: Integer; const ABuffer: string; const AName: string = ''; ATag: TObject = ''); + property SubBuffer[i: Integer]: TSubBuffer read GetSubBuffer; + property Count: Integer read GetCount; + end; + implementation function ScanWhile(const s: AnsiString; var index: Integer; const ch: TCharSet): AnsiString; @@ -168,5 +197,38 @@ begin P.X := Offset - le + 1; end; +{ TTextBuffer } + +function TTextBuffer.GetSubBuffer(i: Integer): TSubBuffer; +begin + Result:=nil; +end; + +function TTextBuffer.GetCount: Integer; +begin + Result:=0; +end; + +constructor TTextBuffer.Create(const Abuffer: String; const aname: string; + aobj: TObject); +begin + if abuffer<>'' then + InsertSubBuffer(1, abuffer, aname, aobj); +end; + +procedure TTextBuffer.InsertSubBuffer(pos: Integer; const ABuffer: string; const AName: string; ATag: TObject); +begin + +end; + +{ TSubBuffer } + +constructor TSubBuffer.Create(const AName: string; ATag: TObject); +begin + inherited Create; + Name:=AName; + Tag:=ATag; +end; + end.