Skip to content

Commit dfb4753

Browse files
deal with pointer type var declarations
1 parent 6ab415c commit dfb4753

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

C2Delphi.Forms.Main.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface
2626
Vcl.ActnList,
2727
Vcl.PlatformDefaultStyleActnCtrls,
2828
Vcl.ActnMan,
29+
Vcl.Menus,
2930

3031
BCEditor.Types,
3132
BCEditor.Editor.Base,
@@ -47,7 +48,7 @@ interface
4748
{$ENDIF}
4849

4950
WvN.Pascal.Model,
50-
WvN.Pascal.CReader, Vcl.Menus
51+
WvN.Pascal.CReader
5152
;
5253

5354

WvN.Pascal.CReader.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ function c_inlinevardef(const c:string;out pas:string):boolean;
361361
// varname : test
362362
// vartype : int
363363
// expr : 5 * 5 + xxx
364-
m := TRegEx.Match(c,'^(?<indent>\s*)(?<vartype>'+rxType+')\s+(?<varname>'+rxID+')\s*=\s*(?<expr>.*)\s*;',[roSingleLine]);
364+
m := TRegEx.Match(c,'^(?<indent>\s*)(?<vartype>'+rxType+')\s+(\*)?(?<varname>'+rxID+')\s*=\s*(?<expr>.*)\s*;',[roSingleLine]);
365365
if m.Success then
366366
begin
367367
Result := True;

WvN.Pascal.Model.pas

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ function TVariableList.ToPascal(indent:Boolean): String;
377377
else
378378
if Indent then
379379
// switched from list of consts to vars
380-
Result := Result.Trim + sLineBreak + sLineBreak + cDirPascal[Items[I].Dir]
380+
Result := Result.Trim + sLineBreak +'' + sLineBreak +'' + cDirPascal[Items[I].Dir]
381381
else
382382
Result := Result.Trim + cDirPascal[Items[I].Dir];
383383

@@ -397,7 +397,7 @@ function TVariableList.ToPascal(indent:Boolean): String;
397397
begin
398398
Result := Result + Esc(Items[i].name.Trim) + ', ';
399399
if align then
400-
Result := Result + sLineBreak;
400+
Result := Result + sLineBreak+'';
401401
continue;
402402
end;
403403

@@ -429,11 +429,8 @@ function TVariableList.ToPascal(indent:Boolean): String;
429429

430430
// add a separator, unless it's the last argument
431431
if i < Count - 1 then
432-
// if Result[high(Result)]<>';' then
433432
Result := Result + ';';
434433

435-
if Indent then
436-
Result := Result + sLineBreak+' ';
437434

438435
end;
439436

@@ -953,9 +950,20 @@ function TPascalUnit.toPascal: string;
953950
{ TArrayDef }
954951

955952
function TArrayDef1D.ToPascal: string;
956-
var elms : string;
953+
var elms : string; i:integer; it:TArray<string>;
957954
begin
958-
elms := ''.Join(', ', Items); // concat all elements into a comma separated string
955+
setlength(it,length(items));
956+
for i := 0 to high(items) do
957+
begin
958+
it[i] := items[i];
959+
if it[i].EndsWith('.') then
960+
it[i] := it[i] + '0';
961+
if it[i].StartsWith('.') then
962+
it[i] := '0'+it[i];
963+
964+
end;
965+
966+
elms := ''.Join(', ', it); // concat all elements into a comma separated string
959967
elms := TRegEx.Replace(elms,'0[xX]([\da-fA-F]+)' ,'\$\1',[ roMultiLine ]); // convert possible hex to pascal hex
960968
elms := elms.Replace('/*','{').Replace('*/','}');
961969
elms := WrapText(elms,sLineBreak+' ',[','],70); // wrap long lines

0 commit comments

Comments
 (0)