1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-24 18:22:25 -05:00
Simba/Projects/RUTIS Wrappers/main.pas

215 lines
4.9 KiB
ObjectPascal
Raw Normal View History

2010-09-05 14:31:56 -04:00
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, SynEdit, SynHighlighterPas,wrapfiles;
2010-09-05 14:31:56 -04:00
type
{ TfrmMain }
TfrmMain = class(TForm)
btnGo: TButton;
btnAdvanced: TButton;
2010-09-05 14:31:56 -04:00
pnlMain: TPanel;
Splitter1: TSplitter;
Splitter2: TSplitter;
eIn: TSynEdit;
eOut: TSynEdit;
eDebug: TSynEdit;
PasHL: TSynPasSyn;
procedure btnAdvancedClick(Sender: TObject);
2010-09-05 14:31:56 -04:00
procedure btnGoClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
2010-09-10 19:10:49 -04:00
procedure ConvertRT(Input, Dbg, Output : TStrings; procnames : TStrings = nil);
2010-09-05 14:31:56 -04:00
var
frmMain: TfrmMain;
implementation
uses
v_ideCodeParser;
{$R *.lfm}
{ TfrmMain }
2010-09-10 19:10:49 -04:00
procedure ConvertRT(Input, Dbg, Output : TStrings; procnames : TStrings = nil);
2010-09-05 14:31:56 -04:00
procedure Debug(s: string); overload;
begin
if (Trim(Output.Text) <> '') then
Dbg.Append(s)
2010-09-05 14:31:56 -04:00
else
Dbg.Text := s;
2010-09-05 14:31:56 -04:00
end;
procedure Debug(v: Variant); overload;
begin
Debug(string(v));
end;
procedure Write(s: string); overload;
begin
if (Trim(Output.Text) <> '') then
Output.Text := Output.Text + s
2010-09-05 14:31:56 -04:00
else
Output.Text := s;
2010-09-05 14:31:56 -04:00
end;
procedure Write(v: Variant); overload;
begin
Write(string(v));
end;
2010-09-10 19:10:49 -04:00
function FixName( str : string) : string;
begin
if (length(str) > 3) and (str[1] = 'p') and (str[2] = 's') and (str[3] = '_') then
result := Copy(str,4,length(str)-3);
end;
function PtrName ( str : string) : String;
begin
debug(str);
if (length(str) > 1) and (str[1] in ['T','t']) then
result := 'P' + copy(str,2,length(str)-1)
else
result := 'P' + str;
debug(result);
end;
2010-09-05 14:31:56 -04:00
var
p: TCodeParser;
m: TMemoryStream;
a, b, c: TDeclarationArray;
i, ii, iii, pc: Integer;
s: string;
2010-09-10 19:10:49 -04:00
rutiss,tmp : string;
2010-09-05 14:31:56 -04:00
d: TDeclaration;
Fail: Boolean;
begin
p := TCodeParser.Create;
m := TMemoryStream.Create;
try
Output.BeginUpdate;
Output.Clear;
Dbg.BeginUpdate;
Dbg.Clear;
2010-09-05 14:31:56 -04:00
Input.SaveToStream(m);
2010-09-05 14:31:56 -04:00
try
p.Run(m);
except on E : Exception do
Debug(e.Message);
end;
a := p.Items.GetItemsOfClass(TciProcedureDeclaration);
Debug('Start converting '+IntToStr(Length(a))+' methods!');
for i := 0 to High(a) do
with TciProcedureDeclaration(a[i]) do
begin
if (Name = nil) then
begin
Debug('No name found, skipping..');
Continue;
end;
2010-09-10 19:10:49 -04:00
s := 'procedure RUTIS_'+Name.ShortText+
'(Params: PRutisParamInfoArray; Result: PRutisParamInfo);'+LineEnding+
2010-09-05 14:31:56 -04:00
'begin'+LineEnding+' ';
d := Items.GetFirstItemOfClass(TciReturnType);
if (d <> nil) then
2010-09-10 19:10:49 -04:00
begin
s := s+PtrName(d.ShortText)+'(Result^.Data)^ := ';
rutiss := 'RutisEngine.RegExtMethod(''%s'',%s, [%s], '''+d.CleanText +''');';
end else
rutiss := 'RutisEngine.RegExtMethod(''%s'',%s, [%s], '''');';
2010-09-05 14:31:56 -04:00
s := s+Name.ShortText+'(';
pc := 0;
Fail := False;
b := GetParamDeclarations();
2010-09-10 19:10:49 -04:00
tmp := '';
2010-09-05 14:31:56 -04:00
for ii := 0 to High(b) do
begin
d := b[ii].Items.GetFirstItemOfClass(TciParameterType);
if (d = nil) then
begin
Debug('No parameter type found in '+Name.ShortText+', skipping..');
Fail := True;
Break;
end;
c := b[ii].Items.GetItemsOfClass(TciParameterName);
if (Length(c) < 1) then
begin
Debug('No parameter names found in '+Name.ShortText+', skipping..');
Fail := True;
Break;
end;
for iii := High(c) downto 0 do
begin
if (pc > 0) then
s := s+', ';
if b[ii] is TciVarParameter then
begin
tmp := tmp + #39 + 'var ' + d.ShortText + #39 +',';
s := s+PtrName(d.ShortText)+'(PPointer(Params^['+IntToStr(pc)+'].Data)^)^';
end else
begin
s := s+PtrName(d.ShortText)+'(Params^['+IntToStr(pc)+'].Data)^';
tmp := tmp + #39 + d.ShortText + #39 +',';
end;
2010-09-05 14:31:56 -04:00
Inc(pc);
end;
end;
2010-09-10 19:10:49 -04:00
if tmp <> '' then
setlength(tmp,length(tmp)-1);
2010-09-05 14:31:56 -04:00
if Fail then
Continue;
s := s+');'+LineEnding+'end;';
if (i > 0) then
s := LineEnding+s;
Write(s);
2010-09-10 19:10:49 -04:00
rutiss := Format(rutiss,[FixName(name.ShortText),'@RUTIS_' + name.ShortText,tmp]);
if procnames <> nil then
procnames.Add(rutiss);
2010-09-05 14:31:56 -04:00
Debug('Done "'+Name.ShortText+'"!');
2010-09-10 19:10:49 -04:00
Debug('Prog-name "' + rutiss + '"');
2010-09-05 14:31:56 -04:00
end;
finally
m.Free;
p.Free;
Output.EndUpdate;
Dbg.EndUpdate;
2010-09-05 14:31:56 -04:00
end;
Debug('Done :)');
end;
procedure TfrmMain.btnGoClick(Sender: TObject);
begin
ConvertRT(eIn.Lines,eDebug.Lines,eOut.Lines);
end;
procedure TfrmMain.btnAdvancedClick(Sender: TObject);
begin
WrapFilesForm.ShowModal;
end;
2010-09-05 14:31:56 -04:00
end.