You've already forked lazarus-ccr
ws_helper generator :
when option "-y" ( easy access interface generation ) is specified, ws_helper no longer blocks on invalid methods, it just skip them. Better implementation of the proxy for easy access interface methods git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1021 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -223,7 +223,17 @@ function DeduceEasyInterfaceForDocStyle(
|
|||||||
const AContainer : TwstPasTreeContainer
|
const AContainer : TwstPasTreeContainer
|
||||||
): TPasClassType;
|
): TPasClassType;
|
||||||
|
|
||||||
procedure HandleProc(const AIntf : TPasClassType; const AMethod : TPasProcedure);
|
function IsFinallyAClassType(const AElt : TPasElement) : Boolean;
|
||||||
|
begin
|
||||||
|
Result := ( AElt <> nil ) and
|
||||||
|
( AElt.InheritsFrom(TPasClassType) or
|
||||||
|
( AElt.InheritsFrom(TPasType) and
|
||||||
|
GetUltimeType(TPasType(AElt)).InheritsFrom(TPasClassType)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function HandleProc(const AIntf : TPasClassType; const AMethod : TPasProcedure) : Boolean;
|
||||||
var
|
var
|
||||||
locMethod : TPasProcedure;
|
locMethod : TPasProcedure;
|
||||||
locProcType : TPasProcedureType;
|
locProcType : TPasProcedureType;
|
||||||
@@ -234,23 +244,24 @@ function DeduceEasyInterfaceForDocStyle(
|
|||||||
locArg : TPasArgument;
|
locArg : TPasArgument;
|
||||||
locIsFunction : Boolean;
|
locIsFunction : Boolean;
|
||||||
begin
|
begin
|
||||||
|
Result := False;
|
||||||
if ( AMethod.ProcType.Args.Count < 1 ) then
|
if ( AMethod.ProcType.Args.Count < 1 ) then
|
||||||
raise Exception.CreateFmt('Invalid "Document style" method, one parameter expected : %s.%s.',[AIntf.Name,AMethod.Name]);
|
Exit;
|
||||||
locElt := TPasArgument(AMethod.ProcType.Args[0]).ArgType;
|
locElt := TPasArgument(AMethod.ProcType.Args[0]).ArgType;
|
||||||
if locElt.InheritsFrom(TPasUnresolvedTypeRef) then
|
if locElt.InheritsFrom(TPasUnresolvedTypeRef) then
|
||||||
locElt := AContainer.FindElement(locElt.Name);
|
locElt := AContainer.FindElement(locElt.Name);
|
||||||
if ( locElt = nil ) then
|
if ( locElt = nil ) then
|
||||||
raise Exception.CreateFmt('Invalid "Document style" method, class type parameter expected, nil founded : %s.%s.',[AIntf.Name,AMethod.Name]);
|
Exit;
|
||||||
if ( not locElt.InheritsFrom(TPasClassType) ) then
|
if not IsFinallyAClassType(locElt) then
|
||||||
raise Exception.CreateFmt('Invalid "Document style" method, class type parameter expected : %s.%s => %s',[AIntf.Name,AMethod.Name,locElt.ElementTypeName]);
|
Exit;
|
||||||
locRawInParam := TPasClassType(locElt);
|
locRawInParam := TPasClassType(locElt);
|
||||||
locIsFunction := False;
|
locIsFunction := False;
|
||||||
if AMethod.InheritsFrom(TPasFunction) then begin
|
if AMethod.InheritsFrom(TPasFunction) then begin
|
||||||
locElt := TPasFunctionType(AMethod.ProcType).ResultEl.ResultType;
|
locElt := TPasFunctionType(AMethod.ProcType).ResultEl.ResultType;
|
||||||
if locElt.InheritsFrom(TPasUnresolvedTypeRef) then
|
if locElt.InheritsFrom(TPasUnresolvedTypeRef) then
|
||||||
locElt := AContainer.FindElement(locElt.Name);
|
locElt := AContainer.FindElement(locElt.Name);
|
||||||
if ( locElt = nil ) or ( not locElt.InheritsFrom(TPasClassType) ) then
|
if not IsFinallyAClassType(locElt) then
|
||||||
raise Exception.CreateFmt('Invalid "Document style" method, class type result expected : %s.%s.',[AIntf.Name,AMethod.Name]);
|
Exit;
|
||||||
locRawOutParam := TPasClassType(locElt);
|
locRawOutParam := TPasClassType(locElt);
|
||||||
q := locRawOutParam.Members.Count;
|
q := locRawOutParam.Members.Count;
|
||||||
if ( q > 0 ) then begin
|
if ( q > 0 ) then begin
|
||||||
@@ -295,16 +306,19 @@ function DeduceEasyInterfaceForDocStyle(
|
|||||||
TPasFunctionType(locProcType).ResultEl := TPasResultElement(AContainer.CreateElement(TPasResultElement,'Result',locProcType,'',0));
|
TPasFunctionType(locProcType).ResultEl := TPasResultElement(AContainer.CreateElement(TPasResultElement,'Result',locProcType,'',0));
|
||||||
TPasFunctionType(locProcType).ResultEl.ResultType := locResProp.VarType; locResProp.VarType.AddRef();
|
TPasFunctionType(locProcType).ResultEl.ResultType := locResProp.VarType; locResProp.VarType.AddRef();
|
||||||
end;
|
end;
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
locRes : TPasClassType;
|
locRes : TPasClassType;
|
||||||
i, c : PtrInt;
|
i, c : PtrInt;
|
||||||
g : TGuid;
|
g : TGuid;
|
||||||
e : TPasElement;
|
e : TPasElement;
|
||||||
|
procCount : Integer;
|
||||||
begin
|
begin
|
||||||
if ( ARawInt.ObjKind <> okInterface ) then
|
if ( ARawInt.ObjKind <> okInterface ) then
|
||||||
raise Exception.CreateFmt('Interface expected : "%s".',[ARawInt.Name]);
|
raise Exception.CreateFmt('Interface expected : "%s".',[ARawInt.Name]);
|
||||||
|
procCount := 0;
|
||||||
locRes := TPasClassType(AContainer.CreateElement(TPasClassType,Format('%s%s',[ARawInt.Name,sEASY_ACCESS_INTERFACE_PREFIX]),nil,'',0));
|
locRes := TPasClassType(AContainer.CreateElement(TPasClassType,Format('%s%s',[ARawInt.Name,sEASY_ACCESS_INTERFACE_PREFIX]),nil,'',0));
|
||||||
try
|
try
|
||||||
locRes.ObjKind := okInterface;
|
locRes.ObjKind := okInterface;
|
||||||
@@ -314,10 +328,14 @@ begin
|
|||||||
if ( c > 0 ) then begin
|
if ( c > 0 ) then begin
|
||||||
for i := 0 to ( c - 1 ) do begin
|
for i := 0 to ( c - 1 ) do begin
|
||||||
e := TPasElement(ARawInt.Members[i]);
|
e := TPasElement(ARawInt.Members[i]);
|
||||||
if e.InheritsFrom(TPasProcedure) then
|
if e.InheritsFrom(TPasProcedure) and
|
||||||
HandleProc(locRes,TPasProcedure(e));
|
HandleProc(locRes,TPasProcedure(e))
|
||||||
|
then
|
||||||
|
Inc(procCount);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
if ( procCount = 0 ) then
|
||||||
|
FreeAndNil(locRes);
|
||||||
except
|
except
|
||||||
FreeAndNil(locRes);
|
FreeAndNil(locRes);
|
||||||
raise;
|
raise;
|
||||||
@@ -419,9 +437,8 @@ begin
|
|||||||
intf := elt as TPasClassType;
|
intf := elt as TPasClassType;
|
||||||
binding := SymbolTable.FindBinding(intf);
|
binding := SymbolTable.FindBinding(intf);
|
||||||
intfEasy := nil;
|
intfEasy := nil;
|
||||||
if ( binding.BindingStyle = bsDocument ) then begin
|
if ( binding.BindingStyle = bsDocument ) then
|
||||||
intfEasy := DeduceEasyInterfaceForDocStyle(intf,SymbolTable);
|
intfEasy := DeduceEasyInterfaceForDocStyle(intf,SymbolTable);
|
||||||
end;
|
|
||||||
GenerateProxyIntf(intf,intfEasy,binding);
|
GenerateProxyIntf(intf,intfEasy,binding);
|
||||||
GenerateProxyImp(intf,intfEasy,binding);
|
GenerateProxyImp(intf,intfEasy,binding);
|
||||||
end;
|
end;
|
||||||
@@ -667,7 +684,10 @@ Var
|
|||||||
elt := prm.ArgType;
|
elt := prm.ArgType;
|
||||||
if elt.InheritsFrom(TPasUnresolvedTypeRef) then
|
if elt.InheritsFrom(TPasUnresolvedTypeRef) then
|
||||||
elt := SymbolTable.FindElement(SymbolTable.GetExternalName(elt));
|
elt := SymbolTable.FindElement(SymbolTable.GetExternalName(elt));
|
||||||
if elt.InheritsFrom(TPasUnresolvedTypeRef) or SymbolTable.IsOfType(TPasType(elt),TPasClassType) then begin
|
if elt.InheritsFrom(TPasUnresolvedTypeRef) or
|
||||||
|
SymbolTable.IsOfType(TPasType(elt),TPasClassType) or
|
||||||
|
SymbolTable.IsOfType(TPasType(elt),TPasArrayType)
|
||||||
|
then begin
|
||||||
Result := True;
|
Result := True;
|
||||||
Break;
|
Break;
|
||||||
end;
|
end;
|
||||||
@@ -694,8 +714,11 @@ Var
|
|||||||
DecIndent();
|
DecIndent();
|
||||||
Indent(); WriteLn('end;');
|
Indent(); WriteLn('end;');
|
||||||
end else begin
|
end else begin
|
||||||
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) then begin
|
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) or
|
||||||
|
SymbolTable.IsOfType(TPasType(elt),TPasArrayType)
|
||||||
|
then begin
|
||||||
Indent(); WriteLn('%s := %s.%s;',[sTEMP_OBJ,sINPUT_PARAM,prm.Name]);
|
Indent(); WriteLn('%s := %s.%s;',[sTEMP_OBJ,sINPUT_PARAM,prm.Name]);
|
||||||
|
Indent(); WriteLn('%s.%s := nil;',[sINPUT_PARAM,prm.Name]);
|
||||||
Indent(); WriteLn('%s.Free();',[sTEMP_OBJ]);
|
Indent(); WriteLn('%s.Free();',[sTEMP_OBJ]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -720,7 +743,9 @@ Var
|
|||||||
Indent(); WriteLn('TObject(%s.%s) := nil;',[sINPUT_PARAM,prm.Name]);
|
Indent(); WriteLn('TObject(%s.%s) := nil;',[sINPUT_PARAM,prm.Name]);
|
||||||
DecIndent();
|
DecIndent();
|
||||||
end else begin
|
end else begin
|
||||||
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) then begin
|
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) or
|
||||||
|
SymbolTable.IsOfType(TPasType(elt),TPasArrayType)
|
||||||
|
then begin
|
||||||
Indent(); WriteLn('%s.%s := nil;',[sINPUT_PARAM,prm.Name]);
|
Indent(); WriteLn('%s.%s := nil;',[sINPUT_PARAM,prm.Name]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -738,7 +763,9 @@ Var
|
|||||||
DecIndent();
|
DecIndent();
|
||||||
DecIndent();
|
DecIndent();
|
||||||
end else begin
|
end else begin
|
||||||
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) then begin
|
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) or
|
||||||
|
SymbolTable.IsOfType(TPasType(elt),TPasArrayType)
|
||||||
|
then begin
|
||||||
Indent(); WriteLn('if ( %s <> nil ) then',[sOUTPUT_PARAM]);
|
Indent(); WriteLn('if ( %s <> nil ) then',[sOUTPUT_PARAM]);
|
||||||
IncIndent();
|
IncIndent();
|
||||||
Indent(); WriteLn('%s.%s := nil;',[sOUTPUT_PARAM,origineResProp.Name]);
|
Indent(); WriteLn('%s.%s := nil;',[sOUTPUT_PARAM,origineResProp.Name]);
|
||||||
@@ -800,7 +827,27 @@ Var
|
|||||||
if origineIsFunc then begin
|
if origineIsFunc then begin
|
||||||
Indent(); WriteLn('%s := %s(%s);',[sOUTPUT_PARAM,origineMthd.Name,sINPUT_PARAM]);
|
Indent(); WriteLn('%s := %s(%s);',[sOUTPUT_PARAM,origineMthd.Name,sINPUT_PARAM]);
|
||||||
if localIsFunc then begin
|
if localIsFunc then begin
|
||||||
Indent(); WriteLn('Result := %s.%s;',[sOUTPUT_PARAM,origineResProp.Name]);
|
Indent(); WriteLn('if ( %s <> nil ) then',[sOUTPUT_PARAM]);
|
||||||
|
IncIndent();
|
||||||
|
Indent(); WriteLn('Result := %s.%s',[sOUTPUT_PARAM,origineResProp.Name]);
|
||||||
|
DecIndent();
|
||||||
|
elt := origineResProp.VarType;
|
||||||
|
if elt.InheritsFrom(TPasUnresolvedTypeRef) then
|
||||||
|
elt := SymbolTable.FindElement(SymbolTable.GetExternalName(elt));
|
||||||
|
Indent(); WriteLn('else');
|
||||||
|
IncIndent();
|
||||||
|
if elt.InheritsFrom(TPasUnresolvedTypeRef) then begin
|
||||||
|
Indent(); WriteLn('FillChar(Result,SizeOf(Result),#0);');
|
||||||
|
end else begin
|
||||||
|
if SymbolTable.IsOfType(TPasType(elt),TPasClassType) or
|
||||||
|
SymbolTable.IsOfType(TPasType(elt),TPasArrayType)
|
||||||
|
then begin
|
||||||
|
Indent(); WriteLn('Result := nil;');
|
||||||
|
end else begin
|
||||||
|
Indent(); WriteLn('FillChar(Result,SizeOf(Result),#0);');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
DecIndent();
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
Indent(); WriteLn('%s(%s);',[origineMthd.Name,sINPUT_PARAM]);
|
Indent(); WriteLn('%s(%s);',[origineMthd.Name,sINPUT_PARAM]);
|
||||||
@@ -3067,10 +3114,12 @@ begin
|
|||||||
locBinding := FSymbolTable.Binding[i];
|
locBinding := FSymbolTable.Binding[i];
|
||||||
if ( locBinding.BindingStyle = bsDocument ) then begin
|
if ( locBinding.BindingStyle = bsDocument ) then begin
|
||||||
clssTyp := DeduceEasyInterfaceForDocStyle(locBinding.Intf,FSymbolTable);
|
clssTyp := DeduceEasyInterfaceForDocStyle(locBinding.Intf,FSymbolTable);
|
||||||
try
|
if ( clssTyp <> nil ) then begin
|
||||||
GenerateIntf(clssTyp);
|
try
|
||||||
finally
|
GenerateIntf(clssTyp);
|
||||||
clssTyp.Release();
|
finally
|
||||||
|
clssTyp.Release();
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user