Skip to content

Commit

Permalink
deal with pointer type var declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterVanNifterick committed Dec 13, 2016
1 parent 6ab415c commit dfb4753
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion C2Delphi.Forms.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface
Vcl.ActnList,
Vcl.PlatformDefaultStyleActnCtrls,
Vcl.ActnMan,
Vcl.Menus,

BCEditor.Types,
BCEditor.Editor.Base,
Expand All @@ -47,7 +48,7 @@ interface
{$ENDIF}

WvN.Pascal.Model,
WvN.Pascal.CReader, Vcl.Menus
WvN.Pascal.CReader
;


Expand Down
2 changes: 1 addition & 1 deletion WvN.Pascal.CReader.pas
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function c_inlinevardef(const c:string;out pas:string):boolean;
// varname : test
// vartype : int
// expr : 5 * 5 + xxx
m := TRegEx.Match(c,'^(?<indent>\s*)(?<vartype>'+rxType+')\s+(?<varname>'+rxID+')\s*=\s*(?<expr>.*)\s*;',[roSingleLine]);
m := TRegEx.Match(c,'^(?<indent>\s*)(?<vartype>'+rxType+')\s+(\*)?(?<varname>'+rxID+')\s*=\s*(?<expr>.*)\s*;',[roSingleLine]);
if m.Success then
begin
Result := True;
Expand Down
22 changes: 15 additions & 7 deletions WvN.Pascal.Model.pas
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function TVariableList.ToPascal(indent:Boolean): String;
else
if Indent then
// switched from list of consts to vars
Result := Result.Trim + sLineBreak + sLineBreak + cDirPascal[Items[I].Dir]
Result := Result.Trim + sLineBreak +'' + sLineBreak +'' + cDirPascal[Items[I].Dir]
else
Result := Result.Trim + cDirPascal[Items[I].Dir];

Expand All @@ -397,7 +397,7 @@ function TVariableList.ToPascal(indent:Boolean): String;
begin
Result := Result + Esc(Items[i].name.Trim) + ', ';
if align then
Result := Result + sLineBreak;
Result := Result + sLineBreak+'';
continue;
end;

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

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

if Indent then
Result := Result + sLineBreak+' ';

end;

Expand Down Expand Up @@ -953,9 +950,20 @@ function TPascalUnit.toPascal: string;
{ TArrayDef }

function TArrayDef1D.ToPascal: string;
var elms : string;
var elms : string; i:integer; it:TArray<string>;
begin
elms := ''.Join(', ', Items); // concat all elements into a comma separated string
setlength(it,length(items));
for i := 0 to high(items) do
begin
it[i] := items[i];
if it[i].EndsWith('.') then
it[i] := it[i] + '0';
if it[i].StartsWith('.') then
it[i] := '0'+it[i];

end;

elms := ''.Join(', ', it); // concat all elements into a comma separated string
elms := TRegEx.Replace(elms,'0[xX]([\da-fA-F]+)' ,'\$\1',[ roMultiLine ]); // convert possible hex to pascal hex
elms := elms.Replace('/*','{').Replace('*/','}');
elms := WrapText(elms,sLineBreak+' ',[','],70); // wrap long lines
Expand Down

0 comments on commit dfb4753

Please sign in to comment.