mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 09:40:20 +02:00
* Add webidl2pas
git-svn-id: trunk@39293 -
This commit is contained in:
parent
e655b9137b
commit
bfc5d63fde
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -17213,6 +17213,8 @@ utils/pas2js/samples/hello.pas svneol=native#text/plain
|
||||
utils/pas2js/samples/ifdemo.pp svneol=native#text/plain
|
||||
utils/pas2js/samples/repeatdemo.pp svneol=native#text/plain
|
||||
utils/pas2js/samples/whiledemo.pp svneol=native#text/plain
|
||||
utils/pas2js/webidl2pas.lpi svneol=native#text/plain
|
||||
utils/pas2js/webidl2pas.pp svneol=native#text/plain
|
||||
utils/pas2ut/Makefile svneol=native#text/plain
|
||||
utils/pas2ut/Makefile.fpc svneol=native#text/plain
|
||||
utils/pas2ut/Makefile.fpc.fpcmake svneol=native#text/plain
|
||||
|
@ -31,11 +31,13 @@ begin
|
||||
P.Dependencies.Add('fcl-passrc');
|
||||
P.Dependencies.Add('pastojs');
|
||||
P.Dependencies.Add('fcl-web');
|
||||
P.Dependencies.Add('webidl');
|
||||
PT:=P.Targets.AddProgram('pas2js.pp');
|
||||
PT:=P.Targets.AddLibrary('pas2jslib.pp');
|
||||
PT:=P.Targets.AddUnit('httpcompiler.pp');
|
||||
PT:=P.Targets.AddProgram('compileserver.pp');
|
||||
PT.Dependencies.AddUnit('httpcompiler');
|
||||
PT:=P.Targets.AddProgram('webidl2pas.pp');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
64
utils/pas2js/webidl2pas.lpi
Normal file
64
utils/pas2js/webidl2pas.lpi
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<SaveOnlyProjectUnits Value="True"/>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
<SaveJumpHistory Value="False"/>
|
||||
<SaveFoldState Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="WebIDL To Pascal converter Application"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="0"/>
|
||||
</RunParams>
|
||||
<Units Count="1">
|
||||
<Unit0>
|
||||
<Filename Value="webidl2pas.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="webidl2pas"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<UseHeaptrc Value="True"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
190
utils/pas2js/webidl2pas.pp
Normal file
190
utils/pas2js/webidl2pas.pp
Normal file
@ -0,0 +1,190 @@
|
||||
program webidl2pas;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Classes, SysUtils, CustApp, webidltopas, pascodegen
|
||||
{ you can add units after this };
|
||||
|
||||
type
|
||||
|
||||
{ TWebIDLToPasApplication }
|
||||
|
||||
TWebIDLToPasApplication = class(TCustomApplication)
|
||||
private
|
||||
FWebIDLToPas: TWebIDLToPas;
|
||||
function Checkoption(Var O: TCOnversionOPtions; C: TCOnversionOPtion;
|
||||
const AShort: Char; const aLong: String): Boolean;
|
||||
procedure DoConvertLog(Sender: TObject; LogType: TCodegenLogType; const Msg: String);
|
||||
function GetInputFileName: String;
|
||||
function GetOutputFileName: String;
|
||||
function GetUnitName: String;
|
||||
procedure SetinputFileName(AValue: String);
|
||||
procedure SetOutputFileName(AValue: String);
|
||||
procedure SetunitName(AValue: String);
|
||||
protected
|
||||
procedure DoRun; override;
|
||||
Protected
|
||||
Property WebIDLToPas : TWebIDLToPas Read FWebIDLToPas;
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure WriteHelp(Const Msg : string); virtual;
|
||||
Property UnitName : String Read GetUnitName Write SetunitName;
|
||||
property InputFileName : String Read GetInputFileName Write SetinputFileName;
|
||||
property OutputFileName : String Read GetOutputFileName Write SetOutputFileName;
|
||||
end;
|
||||
|
||||
{ TWebIDLToPasApplication }
|
||||
|
||||
function TWebIDLToPasApplication.GetInputFileName: String;
|
||||
begin
|
||||
Result:=FWebIDLToPas.InputFileName;
|
||||
end;
|
||||
|
||||
procedure TWebIDLToPasApplication.DoConvertLog(Sender: TObject;
|
||||
LogType: TCodegenLogType; const Msg: String);
|
||||
begin
|
||||
Writeln(Msg);
|
||||
end;
|
||||
|
||||
function TWebIDLToPasApplication.GetOutputFileName: String;
|
||||
begin
|
||||
Result:=FWebIDLToPas.OutputFileName
|
||||
end;
|
||||
|
||||
function TWebIDLToPasApplication.GetUnitName: String;
|
||||
begin
|
||||
Result:=FWebIDLToPas.OutputUnitName;
|
||||
end;
|
||||
|
||||
procedure TWebIDLToPasApplication.SetinputFileName(AValue: String);
|
||||
begin
|
||||
FWebIDLToPas.InputFileName:=aValue;
|
||||
end;
|
||||
|
||||
procedure TWebIDLToPasApplication.SetOutputFileName(AValue: String);
|
||||
begin
|
||||
FWebIDLToPas.OutputFileName:=aValue;
|
||||
end;
|
||||
|
||||
procedure TWebIDLToPasApplication.SetunitName(AValue: String);
|
||||
begin
|
||||
FWebIDLToPas.OutputUnitName:=aValue;
|
||||
end;
|
||||
|
||||
Function TWebIDLToPasApplication.Checkoption(Var O : TCOnversionOPtions;C : TCOnversionOPtion; Const AShort : Char; Const aLong : String) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=HasOption(aShort,ALong);
|
||||
if Result then
|
||||
Include(O,C);
|
||||
end;
|
||||
|
||||
procedure TWebIDLToPasApplication.DoRun;
|
||||
|
||||
var
|
||||
A,ErrorMsg: String;
|
||||
O : TConversionOptions;
|
||||
|
||||
begin
|
||||
|
||||
Terminate;
|
||||
// quick check parameters
|
||||
ErrorMsg:=CheckOptions('hi:o:u:m:n:vx:t:ced::p', ['help','input:','output:','unitname:','include:','implementation:','verbose','extra:','typealiases:','constexternal','expandunionargs','dicttoclass::','optionsinheader']);
|
||||
if (ErrorMsg<>'') or HasOption('h','help') then
|
||||
begin
|
||||
WriteHelp(ErrorMsg);
|
||||
Exit;
|
||||
end;
|
||||
O:=[];
|
||||
Checkoption(O,coExternalConst,'c','constexternal');
|
||||
Checkoption(O,coExpandUnionTypeArgs,'e','expandunionargs');
|
||||
CheckOption(O,coaddOptionsToheader,'p','optionsinheader');
|
||||
if Checkoption(O,coDictionaryAsClass,'d','dicttoclass') then
|
||||
FWebIDLToPas.DictionaryClassParent:=GetOptionValue('d','dicttoclass');
|
||||
FWebIDLToPas.Options:=O;
|
||||
InputFileName:=GetOptionValue('i','input');
|
||||
OutputFileName:=GetOptionValue('o','output');
|
||||
UnitName:=GetOptionValue('u','unitname');
|
||||
FWebIDLToPas.Verbose:=HasOption('v','verbose');
|
||||
if hasoption('n','include') then
|
||||
FWebIDLToPas.IncludeInterfaceCode.LoadFromFile(GetOptionValue('n','include'));
|
||||
if hasoption('m','implementation') then
|
||||
FWebIDLToPas.IncludeImplementationCode.LoadFromFile(GetOptionValue('m','implementation'));
|
||||
FWebIDLToPas.ExtraUnits:=GetOPtionValue('x','extra');
|
||||
A:=GetOptionValue('t','typealiases');
|
||||
if (Copy(A,1,1)='@') then
|
||||
begin
|
||||
Delete(A,1,1);
|
||||
FWebIDLToPas.TypeAliases.LoadFromFile(A);
|
||||
end
|
||||
else
|
||||
FWebIDLToPas.TypeAliases.CommaText:=A;
|
||||
if UnitName='' then
|
||||
UnitName:=ChangeFileExt(ExtractFileName(InputFileName),'');
|
||||
if OutputFileName='' then
|
||||
begin
|
||||
if (UnitName<>'') then
|
||||
OutputFileName:=ExtractFilePath(InputFileName)+UnitName+'.pas';
|
||||
end;
|
||||
FWebIDLToPas.Execute;
|
||||
// stop program loop
|
||||
Terminate;
|
||||
end;
|
||||
|
||||
constructor TWebIDLToPasApplication.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
StopOnException:=True;
|
||||
FWebIDLToPas:=TWebIDLToPas.Create(Self);
|
||||
FWebIDLToPas.OnLog:=@DoConvertLog;
|
||||
FWebIDLToPas.ClassPrefix:='TJS';
|
||||
FWebIDLToPas.ClassSuffix:='';
|
||||
FWebIDLToPas.KeywordSuffix:='_';
|
||||
FWebIDLToPas.KeywordPrefix:='';
|
||||
end;
|
||||
|
||||
destructor TWebIDLToPasApplication.Destroy;
|
||||
begin
|
||||
FreeAndNil(FWebIDLToPas);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TWebIDLToPasApplication.WriteHelp(const Msg: string);
|
||||
begin
|
||||
{ add your help code here }
|
||||
if (Msg<>'') then
|
||||
Writeln(StdErr,'Error : ',Msg);
|
||||
writeln(StdErr,'Usage: ', ExeName, ' [options]');
|
||||
Writeln(StdErr,'Where option is one or more of');
|
||||
Writeln(StdErr,'-h --help this help text');
|
||||
Writeln(StdErr,'-c --constexternal Write consts as external const (no value)');
|
||||
Writeln(StdErr,'-e --expandunionargs Add overloads for all Union typed function arguments');
|
||||
Writeln(StdErr,'-d --dicttoclass[=Parent] Write dictionaries as classes');
|
||||
Writeln(StdErr,'-i --input=FileName input webidl file');
|
||||
Writeln(StdErr,'-m --implementation=Filename include file as implementation');
|
||||
Writeln(StdErr,'-n --include=Filename include file at end of interface');
|
||||
Writeln(StdErr,'-o --output=FileName output file. Defaults to unit name with .pas extension appended.');
|
||||
Writeln(StdErr,'-p --optionsinheader add options to header of generated file');
|
||||
|
||||
Writeln(StdErr,'-t --typealiases=alias A comma separated list of type aliases in Alias=Name form');
|
||||
Writeln(StdErr,' use @filename to load the aliases from file.');
|
||||
Writeln(StdErr,'-u --unitname=Name name for unit. Defaults to input file without extension.');
|
||||
Writeln(StdErr,'-v --verbose Output some diagnostic information');
|
||||
Writeln(StdErr,'-x --extra=units Extra units to put in uses clause (comma separated list)');
|
||||
ExitCode:=Ord(Msg<>'');
|
||||
end;
|
||||
|
||||
var
|
||||
Application: TWebIDLToPasApplication;
|
||||
begin
|
||||
Application:=TWebIDLToPasApplication.Create(nil);
|
||||
Application.Title:='WebIDL To Pascal converter Application';
|
||||
Application.Run;
|
||||
Application.Free;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user