2006-08-26 00:35:42 +00:00
{
This unit is part of the Web Service Toolkit
Copyright ( c) 2 0 0 6 by Inoussa OUEDRAOGO
This program is free software; you can redistribute it and/ or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
( at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation, Inc. , 6 7 5 Mass Ave, Cambridge, MA 0 2 1 3 9 , USA.
}
2007-08-19 00:29:43 +00:00
{$INCLUDE wst_global.inc}
2006-08-26 00:35:42 +00:00
unit generator;
interface
uses
Classes, SysUtils,
2007-06-24 23:33:51 +00:00
PasTree,
2007-09-02 19:05:47 +00:00
pascal_parser_intf, source_utils, wst_types;
2006-08-26 00:35:42 +00:00
2006-11-12 13:31:22 +00:00
const
sWST_EXTENSION = 'wst' ;
type
2006-08-26 00:35:42 +00:00
2008-08-18 18:19:00 +00:00
TGeneratorOption = (
goDocumentWrappedParameter { .Net style wrapped parameters } ,
goGenerateDocAsComments { Documentation include in the XSD/WSDL schema will be generated as comments }
) ;
2008-07-03 16:15:03 +00:00
TGeneratorOptions = set of TGeneratorOption;
2006-08-26 00:35:42 +00:00
{ TBaseGenerator }
TBaseGenerator = class
2008-07-03 16:15:03 +00:00
FOptions : TGeneratorOptions;
2006-08-26 00:35:42 +00:00
Private
FSrcMngr : ISourceManager;
FCurrentStream : ISourceStream;
2007-06-24 23:33:51 +00:00
FSymbolTable: TwstPasTreeContainer;
2006-08-26 00:35:42 +00:00
Protected
procedure SetCurrentStream( AStream : ISourceStream) ;
procedure Indent( ) ;
function IncIndent( ) : Integer ;
function DecIndent( ) : Integer ;
procedure BeginAutoIndent( ) ;
procedure EndAutoIndent( ) ;
procedure Write( AText : String ) ; overload ;
procedure Write( AText : String ; Const AArgs : array of const ) ; overload ;
procedure WriteLn( AText : String ) ; overload ;
procedure WriteLn( AText : String ; Const AArgs : array of const ) ; overload ;
procedure NewLine( ) ;
2007-06-24 23:33:51 +00:00
function ExtractserviceName( AIntf : TPasElement) : String ;
2006-08-26 00:35:42 +00:00
Public
constructor Create(
2007-06-24 23:33:51 +00:00
ASymTable : TwstPasTreeContainer;
2006-08-26 00:35:42 +00:00
ASrcMngr : ISourceManager
) ;
procedure Execute( ) ; virtual ; abstract ;
2007-06-24 23:33:51 +00:00
property SymbolTable : TwstPasTreeContainer Read FSymbolTable;
2006-08-26 00:35:42 +00:00
property SrcMngr : ISourceManager Read FSrcMngr;
2008-07-03 16:15:03 +00:00
property Options : TGeneratorOptions read FOptions write FOptions;
2006-08-26 00:35:42 +00:00
End ;
{ TProxyGenerator }
TProxyGenerator = class( TBaseGenerator)
Private
FDecStream : ISourceStream;
2007-04-26 23:23:41 +00:00
FDecProcStream : ISourceStream;
2006-08-26 00:35:42 +00:00
FImpStream : ISourceStream;
2007-06-24 23:33:51 +00:00
function GenerateClassName( AIntf : TPasElement) : String ;
2006-08-26 00:35:42 +00:00
procedure GenerateUnitHeader( ) ;
procedure GenerateUnitImplementationHeader( ) ;
procedure GenerateUnitImplementationFooter( ) ;
2008-07-03 16:15:03 +00:00
procedure GenerateProxyIntf( AIntf, AEasyIntf : TPasClassType; ABinding : TwstBinding) ;
procedure GenerateProxyImp( AIntf, AEasyIntf : TPasClassType; ABinding : TwstBinding) ;
2006-08-26 00:35:42 +00:00
function GetDestUnitName( ) : string ;
Public
constructor Create(
2007-06-24 23:33:51 +00:00
ASymTable : TwstPasTreeContainer;
2006-08-26 00:35:42 +00:00
ASrcMngr : ISourceManager
) ;
procedure Execute( ) ; override ;
End ;
{ TStubGenerator }
TBinderGenerator = class( TBaseGenerator)
Private
FDecStream : ISourceStream;
FImpStream : ISourceStream;
2007-06-24 23:33:51 +00:00
function GenerateClassName( AIntf : TPasElement) : String ;
2006-08-26 00:35:42 +00:00
procedure GenerateUnitHeader( ) ;
procedure GenerateUnitImplementationHeader( ) ;
procedure GenerateUnitImplementationFooter( ) ;
2007-06-24 23:33:51 +00:00
procedure GenerateIntf( AIntf : TPasClassType) ;
procedure GenerateImp( AIntf : TPasClassType) ;
2006-08-26 00:35:42 +00:00
function GetDestUnitName( ) : string ;
Public
constructor Create(
2007-06-24 23:33:51 +00:00
ASymTable : TwstPasTreeContainer;
2006-08-26 00:35:42 +00:00
ASrcMngr : ISourceManager
) ;
procedure Execute( ) ; override ;
End ;
{ TImplementationGenerator }
TImplementationGenerator = class( TBaseGenerator)
Private
FDecStream : ISourceStream;
FImpStream : ISourceStream;
2007-06-24 23:33:51 +00:00
function GenerateClassName( AIntf : TPasElement) : String ;
2006-08-26 00:35:42 +00:00
procedure GenerateUnitHeader( ) ;
procedure GenerateUnitImplementationHeader( ) ;
procedure GenerateUnitImplementationFooter( ) ;
2007-06-24 23:33:51 +00:00
procedure GenerateIntf( AIntf : TPasClassType) ;
procedure GenerateImp( AIntf : TPasClassType) ;
2006-08-26 00:35:42 +00:00
function GetDestUnitName( ) : string ;
Public
constructor Create(
2007-06-24 23:33:51 +00:00
ASymTable : TwstPasTreeContainer;
2006-08-26 00:35:42 +00:00
ASrcMngr : ISourceManager
) ;
procedure Execute( ) ; override ;
End ;
2007-03-23 23:22:35 +00:00
{ TInftGenerator }
2006-08-26 00:35:42 +00:00
2007-03-23 23:22:35 +00:00
TInftGenerator = class( TBaseGenerator)
private
FDecStream : ISourceStream;
FImpStream : ISourceStream;
FImpTempStream : ISourceStream;
2007-04-17 00:52:02 +00:00
FImpLastStream : ISourceStream;
2007-08-19 00:29:43 +00:00
FRttiFunc : ISourceStream;
2008-08-01 21:38:55 +00:00
private
2008-08-18 18:19:00 +00:00
procedure WriteDocumetation( AElement : TPasElement) ;
procedure WriteDocIfEnabled( AElement : TPasElement) ; {$IFDEF USE_INLINE} inline ; {$ENDIF}
2008-08-01 21:38:55 +00:00
// Array handling helper routines
procedure WriteObjectArray( ASymbol : TPasArrayType) ;
procedure WriteSimpleTypeArray( ASymbol : TPasArrayType) ;
procedure WriteObjectCollection( ASymbol : TPasArrayType) ;
2007-03-23 23:22:35 +00:00
private
2007-06-24 23:33:51 +00:00
function GenerateIntfName( AIntf : TPasElement) : string ;
2007-03-23 23:22:35 +00:00
procedure GenerateUnitHeader( ) ;
procedure GenerateUnitImplementationHeader( ) ;
procedure GenerateUnitImplementationFooter( ) ;
2007-06-24 23:33:51 +00:00
procedure GenerateIntf( AIntf : TPasClassType) ;
procedure GenerateTypeAlias( ASymbol : TPasAliasType) ;
procedure GenerateClass( ASymbol : TPasClassType) ;
procedure GenerateEnum( ASymbol : TPasEnumType) ;
procedure GenerateArray( ASymbol : TPasArrayType) ;
2007-08-19 00:29:43 +00:00
procedure GenerateRecord( ASymbol : TPasRecordType) ;
2007-03-23 23:22:35 +00:00
2007-03-25 23:47:16 +00:00
procedure GenerateCustomMetadatas( ) ;
2007-03-23 23:22:35 +00:00
function GetDestUnitName( ) : string ;
2007-09-09 22:30:50 +00:00
procedure PrepareModule( ) ;
procedure InternalExecute( ) ;
2007-03-23 23:22:35 +00:00
public
procedure Execute( ) ; override ;
end ;
2006-08-26 00:35:42 +00:00
implementation
2007-06-24 23:33:51 +00:00
uses parserutils, Contnrs, logger_intf;
2006-08-26 00:35:42 +00:00
Const sPROXY_BASE_CLASS = 'TBaseProxy' ;
sBINDER_BASE_CLASS = 'TBaseServiceBinder' ;
sIMP_BASE_CLASS = 'TBaseServiceImplementation' ;
sSERIALIZER_CLASS = 'IFormatterClient' ;
2007-03-25 23:47:16 +00:00
//RETURN_PARAM_NAME = 'return';
2006-08-26 00:35:42 +00:00
RETURN_VAL_NAME = 'returnVal' ;
2007-03-23 23:22:35 +00:00
sNAME_SPACE = 'sNAME_SPACE' ;
2007-03-25 23:47:16 +00:00
sUNIT_NAME = 'sUNIT_NAME' ;
2007-08-19 00:29:43 +00:00
sRECORD_RTTI_DEFINE = 'WST_RECORD_RTTI' ;
2008-07-03 16:15:03 +00:00
sEASY_ACCESS_INTERFACE_PREFIX = 'Easy' ;
2006-08-26 00:35:42 +00:00
2008-09-10 16:02:05 +00:00
sPRM_NAME = 'locStrPrmName' ;
2006-08-26 00:35:42 +00:00
sLOC_SERIALIZER = 'locSerializer' ;
2008-07-03 16:15:03 +00:00
sINPUT_PARAM = 'inputParam' ;
sOUTPUT_PARAM = 'outputParam' ;
sTEMP_OBJ = 'tmpObj' ;
2008-08-18 18:19:00 +00:00
sDOCUMENTATION = 'documentation' ;
2008-09-10 16:02:05 +00:00
sLOC_CALL_CONTEXT = 'locCallContext' ;
2008-07-03 16:15:03 +00:00
function DeduceEasyInterfaceForDocStyle(
const ARawInt : TPasClassType;
const AContainer : TwstPasTreeContainer
) : TPasClassType;
procedure HandleProc( const AIntf : TPasClassType; const AMethod : TPasProcedure) ;
var
locMethod : TPasProcedure;
locProcType : TPasProcedureType;
locElt : TPasElement;
locRawInParam, locRawOutParam : TPasClassType;
k, q : PtrInt;
locProp, locResProp : TPasProperty;
locArg : TPasArgument;
locIsFunction : Boolean ;
begin
if ( AMethod. ProcType. Args. Count < 1 ) then
raise Exception. CreateFmt( 'Invalid "Document style" method, one parameter expected : %s.%s.' , [ AIntf. Name , AMethod. Name ] ) ;
locElt : = TPasArgument( AMethod. ProcType. Args[ 0 ] ) . ArgType;
if locElt. InheritsFrom( TPasUnresolvedTypeRef) then
locElt : = AContainer. FindElement( locElt. Name ) ;
if ( locElt = nil ) then
raise Exception. CreateFmt( 'Invalid "Document style" method, class type parameter expected, nil founded : %s.%s.' , [ AIntf. Name , AMethod. Name ] ) ;
if ( not locElt. InheritsFrom( TPasClassType) ) then
raise Exception. CreateFmt( 'Invalid "Document style" method, class type parameter expected : %s.%s => %s' , [ AIntf. Name , AMethod. Name , locElt. ElementTypeName] ) ;
locRawInParam : = TPasClassType( locElt) ;
locIsFunction : = False ;
if AMethod. InheritsFrom( TPasFunction) then begin
locElt : = TPasFunctionType( AMethod. ProcType) . ResultEl. ResultType;
if locElt. InheritsFrom( TPasUnresolvedTypeRef) then
locElt : = AContainer. FindElement( locElt. Name ) ;
if ( locElt = nil ) or ( not locElt. InheritsFrom( TPasClassType) ) then
raise Exception. CreateFmt( 'Invalid "Document style" method, class type result expected : %s.%s.' , [ AIntf. Name , AMethod. Name ] ) ;
locRawOutParam : = TPasClassType( locElt) ;
q : = locRawOutParam. Members. Count;
if ( q > 0 ) then begin
for k : = 0 to ( q - 1 ) do begin
if TPasElement( locRawOutParam. Members[ k] ) . InheritsFrom( TPasProperty) then begin
locProp : = TPasProperty( locRawOutParam. Members[ k] ) ;
if ( locProp. Visibility = visPublished ) then begin
locResProp : = locProp;
locIsFunction : = True ;
Break;
end ;
end ;
end ;
end ;
end ;
if locIsFunction then begin
locMethod : = TPasFunction( AContainer. CreateElement( TPasFunction, AMethod. Name , AIntf, '' , 0 ) ) ;
locMethod. ProcType : = TPasFunctionType( AContainer. CreateElement( TPasFunctionType, AMethod. ProcType. Name , locMethod, '' , 0 ) ) ;
end else begin
locMethod : = TPasProcedure( AContainer. CreateElement( TPasProcedure, AMethod. Name , AIntf, '' , 0 ) ) ;
locMethod. ProcType : = TPasProcedureType( AContainer. CreateElement( TPasProcedureType, AMethod. ProcType. Name , locMethod, '' , 0 ) ) ;
end ;
AIntf. Members. Add( locMethod) ;
q : = locRawInParam. Members. Count;
locProcType : = locMethod. ProcType;
if ( q > 0 ) then begin
for k : = 0 to ( q - 1 ) do begin
locElt : = TPasElement( locRawInParam. Members[ k] ) ;
if locElt. InheritsFrom( TPasProperty) then begin
locProp : = TPasProperty( locElt) ;
if ( locProp. Visibility = visPublished ) then begin
locArg : = TPasArgument( AContainer. CreateElement( TPasArgument, locProp. Name , locProcType, '' , 0 ) ) ;
locArg. ArgType : = locProp. VarType;
locArg. ArgType. AddRef( ) ;
locArg. Access : = argConst;
locProcType. Args. Add( locArg) ;
end ;
end ;
end ;
end ;
if locIsFunction then begin
TPasFunctionType( locProcType) . ResultEl : = TPasResultElement( AContainer. CreateElement( TPasResultElement, 'Result' , locProcType, '' , 0 ) ) ;
TPasFunctionType( locProcType) . ResultEl. ResultType : = locResProp. VarType; locResProp. VarType. AddRef( ) ;
end ;
end ;
var
locRes : TPasClassType;
i, c : PtrInt;
g : TGuid;
e : TPasElement;
begin
if ( ARawInt. ObjKind < > okInterface ) then
raise Exception. CreateFmt( 'Interface expected : "%s".' , [ ARawInt. Name ] ) ;
locRes : = TPasClassType( AContainer. CreateElement( TPasClassType, Format( '%s%s' , [ ARawInt. Name , sEASY_ACCESS_INTERFACE_PREFIX] ) , nil , '' , 0 ) ) ;
try
locRes. ObjKind : = okInterface;
if ( CreateGUID( g) = 0 ) then
locRes. InterfaceGUID : = GUIDToString( g) ;
c : = ARawInt. Members. Count;
if ( c > 0 ) then begin
for i : = 0 to ( c - 1 ) do begin
e : = TPasElement( ARawInt. Members[ i] ) ;
if e. InheritsFrom( TPasProcedure) then
HandleProc( locRes, TPasProcedure( e) ) ;
end ;
end ;
except
FreeAndNil( locRes) ;
raise ;
end ;
Result : = locRes;
end ;
2006-08-26 00:35:42 +00:00
{ TProxyGenerator }
2007-06-24 23:33:51 +00:00
function TProxyGenerator. GenerateClassName( AIntf: TPasElement) : String ;
2006-08-26 00:35:42 +00:00
begin
Result : = ExtractserviceName( AIntf) ;
Result : = Format( 'T%s_Proxy' , [ Result ] ) ;
end ;
procedure TProxyGenerator. GenerateUnitHeader( ) ;
begin
SetCurrentStream( FDecStream) ;
WriteLn( '{' ) ;
WriteLn( 'This unit has been produced by ws_helper.' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( ' Input unit name : "%s".' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( ' This unit name : "%s".' , [ GetDestUnitName( ) ] ) ;
WriteLn( ' Date : "%s".' , [ DateTimeToStr( Now( ) ) ] ) ;
WriteLn( '}' ) ;
2007-05-05 19:05:01 +00:00
WriteLn( '' ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'Unit %s;' , [ GetDestUnitName( ) ] ) ;
2007-05-05 19:05:01 +00:00
WriteLn( '{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}' ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'Interface' ) ;
WriteLn( '' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'Uses SysUtils, Classes, TypInfo, base_service_intf, service_intf, %s;' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( '' ) ;
WriteLn( 'Type' ) ;
WriteLn( '' ) ;
end ;
procedure TProxyGenerator. GenerateUnitImplementationHeader( ) ;
begin
SetCurrentStream( FImpStream) ;
WriteLn( '' ) ;
WriteLn( 'Implementation' ) ;
2006-11-12 13:31:22 +00:00
WriteLn( 'uses wst_resources_imp, metadata_repository;' ) ;
2006-08-26 00:35:42 +00:00
end ;
procedure TProxyGenerator. GenerateUnitImplementationFooter( ) ;
var
s : string ;
begin
SetCurrentStream( FImpStream) ;
NewLine( ) ;
WriteLn( 'initialization' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( ' {$i %s.%s}' , [ SymbolTable. CurrentModule. Name , sWST_EXTENSION] ) ;
2006-08-26 00:35:42 +00:00
NewLine( ) ;
2007-06-24 23:33:51 +00:00
s : = Format( 'Register_%s_ServiceMetadata' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( ' {$IF DECLARED(%s)}' , [ s] ) ;
WriteLn( ' %s();' , [ s] ) ;
2007-05-05 19:05:01 +00:00
WriteLn( ' {$IFEND}' ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'End.' ) ;
end ;
constructor TProxyGenerator. Create(
2007-06-24 23:33:51 +00:00
ASymTable : TwstPasTreeContainer;
2006-08-26 00:35:42 +00:00
ASrcMngr : ISourceManager
) ;
begin
Inherited Create( ASymTable, ASrcMngr) ;
FDecStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.dec' ) ;
2007-04-26 23:23:41 +00:00
FDecProcStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.dec_proc' ) ;
2006-08-26 00:35:42 +00:00
FImpStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.imp' ) ;
end ;
procedure TProxyGenerator. Execute( ) ;
Var
i, c : Integer ;
2007-06-24 23:33:51 +00:00
intf : TPasClassType;
elt : TPasElement;
ls : TList;
2008-07-03 16:15:03 +00:00
binding : TwstBinding;
intfEasy : TPasClassType;
HandleEasyIntf : Boolean ;
2006-08-26 00:35:42 +00:00
begin
2008-07-03 16:15:03 +00:00
HandleEasyIntf : = ( goDocumentWrappedParameter in Self. Options ) ;
2006-08-26 00:35:42 +00:00
GenerateUnitHeader( ) ;
GenerateUnitImplementationHeader( ) ;
2007-06-24 23:33:51 +00:00
ls : = SymbolTable. CurrentModule. InterfaceSection. Declarations;
c : = Pred( ls. Count) ;
2008-07-03 16:15:03 +00:00
if HandleEasyIntf then begin
for i : = 0 to c do begin
elt : = TPasElement( ls[ i] ) ;
if ( elt is TPasClassType ) and ( TPasClassType( elt) . ObjKind = okInterface ) then begin
intf : = elt as TPasClassType;
binding : = SymbolTable. FindBinding( intf) ;
intfEasy : = nil ;
if ( binding. BindingStyle = bsDocument ) then begin
intfEasy : = DeduceEasyInterfaceForDocStyle( intf, SymbolTable) ;
end ;
GenerateProxyIntf( intf, intfEasy, binding) ;
GenerateProxyImp( intf, intfEasy, binding) ;
end ;
end ;
end else begin
for i : = 0 to c do begin
elt : = TPasElement( ls[ i] ) ;
if ( elt is TPasClassType ) and ( TPasClassType( elt) . ObjKind = okInterface ) then begin
intf : = elt as TPasClassType;
GenerateProxyIntf( intf, nil , binding) ;
GenerateProxyImp( intf, nil , binding) ;
end ;
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
GenerateUnitImplementationFooter( ) ;
2007-04-26 23:23:41 +00:00
FSrcMngr. Merge( GetDestUnitName( ) + '.pas' , [ FDecStream, FDecProcStream, FImpStream] ) ;
2007-06-24 23:33:51 +00:00
FDecStream : = nil ;
FImpStream : = nil ;
2006-08-26 00:35:42 +00:00
end ;
function TProxyGenerator. GetDestUnitName( ) : string ;
begin
2007-06-24 23:33:51 +00:00
Result : = Format( '%s_proxy' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
end ;
2008-07-03 16:15:03 +00:00
procedure TProxyGenerator. GenerateProxyIntf( AIntf, AEasyIntf : TPasClassType; ABinding : TwstBinding) ;
var
HandleEasyIntf : boolean ;
2006-08-26 00:35:42 +00:00
procedure WriteDec( ) ;
begin
Indent( ) ;
2008-07-03 16:15:03 +00:00
Write( '%s=class(%s,%s' , [ GenerateClassName( AIntf) , sPROXY_BASE_CLASS, AIntf. Name ] ) ;
if HandleEasyIntf then
Write( ',%s' , [ AEasyIntf. Name ] ) ;
WriteLn( ')' ) ;
2007-04-26 23:23:41 +00:00
FDecProcStream. IncIndent( ) ;
try
FDecProcStream. NewLine( ) ;
FDecProcStream. Indent( ) ;
2008-09-25 02:14:56 +00:00
FDecProcStream. WriteLn( 'Function wst_CreateInstance_%s(const AFormat : string = %s; const ATransport : string = %s; const AAddress : string = ' '' '):%s;' , [ AIntf. Name , QuotedStr( 'SOAP:' ) , QuotedStr( 'HTTP:' ) , AIntf. Name ] ) ;
2008-07-03 16:15:03 +00:00
if HandleEasyIntf then begin
FDecProcStream. Indent( ) ;
FDecProcStream. WriteLn(
2008-09-25 02:14:56 +00:00
'Function wst_CreateInstance_%s%s(const AFormat : string = %s; const ATransport : string = %s; const AAddress : string = ' '' '):%s%s;' ,
2008-07-03 16:15:03 +00:00
[ AIntf. Name , sEASY_ACCESS_INTERFACE_PREFIX, QuotedStr( 'SOAP:' ) , QuotedStr( 'HTTP:' ) , AIntf. Name , sEASY_ACCESS_INTERFACE_PREFIX]
) ;
end ;
2007-04-26 23:23:41 +00:00
finally
FDecProcStream. DecIndent( ) ;
end ;
2006-08-26 00:35:42 +00:00
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethod( AMthd : TPasProcedure) ;
2006-08-26 00:35:42 +00:00
Var
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prm : TPasArgument;
prms : TList;
2006-08-26 00:35:42 +00:00
Begin
Indent( ) ;
2007-06-24 23:33:51 +00:00
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
if AMthd. InheritsFrom( TPasFunction) then begin
Write( 'function ' )
end else begin
2006-08-26 00:35:42 +00:00
Write( 'procedure ' )
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
Write( '%s(' , [ AMthd. Name ] ) ;
If ( prmCnt > 0 ) Then Begin
IncIndent( ) ;
For k : = 0 To Pred( prmCnt) Do Begin
2007-06-24 23:33:51 +00:00
prm : = TPasArgument( prms[ k] ) ;
2006-08-26 00:35:42 +00:00
If ( k > 0 ) Then
Write( '; ' ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
Write( '%s %s : %s' , [ AccessNames[ prm. Access] , prm. Name , prm. ArgType. Name ] ) ;
2006-08-26 00:35:42 +00:00
End ;
DecIndent( ) ;
NewLine( ) ;
Indent( ) ;
End ;
Write( ')' ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
Write( ':%s' , [ TPasFunctionType( AMthd. ProcType) . ResultEl. ResultType. Name ] ) ;
end ;
2008-07-03 16:15:03 +00:00
Write( ';' ) ;
if HandleEasyIntf then
Write( 'overload;' ) ;
WriteLn( '' ) ;
2006-08-26 00:35:42 +00:00
End ;
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2006-08-26 00:35:42 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mthds : TList;
elt : TPasElement;
2006-08-26 00:35:42 +00:00
begin
2007-06-24 23:33:51 +00:00
if ( GetElementCount( AIntf. Members, TPasProcedure) = 0 ) then
2006-08-26 00:35:42 +00:00
Exit;
2008-07-03 16:15:03 +00:00
Indent( ) ;
WriteLn( 'Protected' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'class function GetServiceType() : PTypeInfo;override;' ) ;
mthds : = AIntf. Members;
for k : = 0 to Pred( mthds. Count) do begin
elt : = TPasElement( mthds[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethod( TPasProcedure( elt) ) ;
end ;
end ;
if HandleEasyIntf then begin
Indent( ) ; WriteLn( '// Easy acces methods' ) ;
mthds : = AEasyIntf. Members;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( mthds. Count) do begin
elt : = TPasElement( mthds[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethod( TPasProcedure( elt) ) ;
end ;
end ;
2008-07-03 16:15:03 +00:00
end ;
DecIndent( ) ;
2006-08-26 00:35:42 +00:00
end ;
begin
2008-07-03 16:15:03 +00:00
HandleEasyIntf : = ( goDocumentWrappedParameter in Self. Options ) and ( AEasyIntf < > nil ) ;
2006-08-26 00:35:42 +00:00
SetCurrentStream( FDecStream) ;
NewLine( ) ;
IncIndent( ) ;
WriteDec( ) ;
WriteMethods( ) ;
Indent( ) ; WriteLn( 'End;' ) ;
DecIndent( ) ;
end ;
2008-07-03 16:15:03 +00:00
procedure TProxyGenerator. GenerateProxyImp( AIntf, AEasyIntf : TPasClassType; ABinding : TwstBinding) ;
2006-08-26 00:35:42 +00:00
Var
strClassName : String ;
2008-07-03 16:15:03 +00:00
HandleEasyIntf : Boolean ;
2006-08-26 00:35:42 +00:00
procedure WriteDec( ) ;
begin
2007-04-26 23:23:41 +00:00
NewLine( ) ;
2008-09-25 02:14:56 +00:00
WriteLn( 'Function wst_CreateInstance_%s(const AFormat : string; const ATransport : string; const AAddress : string):%s;' , [ AIntf. Name , AIntf. Name ] ) ;
WriteLn( 'Var' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'locAdr : string;' ) ;
DecIndent( ) ;
2007-04-26 23:23:41 +00:00
WriteLn( 'Begin' ) ;
IncIndent( ) ;
2008-11-26 11:12:33 +00:00
Indent( ) ; WriteLn( 'locAdr := AAddress;' ) ;
2008-09-25 02:14:56 +00:00
Indent( ) ; WriteLn( 'if ( locAdr = ' '' ' ) then' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'locAdr := GetServiceDefaultAddress(TypeInfo(%s));' , [ AIntf. Name ] ) ;
DecIndent( ) ;
2007-04-26 23:23:41 +00:00
Indent( ) ;
WriteLn(
'Result := %s.Create(%s,AFormat+%s,ATransport + %s);' ,
[ strClassName, QuotedStr( AIntf. Name ) ,
Format( 'GetServiceDefaultFormatProperties(TypeInfo(%s))' , [ AIntf. Name ] ) ,
2008-09-25 02:14:56 +00:00
QuotedStr( 'address=' ) + ' + locAdr'
2007-04-26 23:23:41 +00:00
]
) ;
2008-07-03 16:15:03 +00:00
DecIndent( ) ;
2007-04-26 23:23:41 +00:00
WriteLn( 'End;' ) ;
NewLine( ) ;
2008-07-03 16:15:03 +00:00
if HandleEasyIntf then begin
WriteLn(
2008-09-25 02:14:56 +00:00
'Function wst_CreateInstance_%s%s(const AFormat : string; const ATransport : string; const AAddress : string):%s%s;' ,
2008-07-03 16:15:03 +00:00
[ AIntf. Name , sEASY_ACCESS_INTERFACE_PREFIX, AIntf. Name , sEASY_ACCESS_INTERFACE_PREFIX]
) ;
WriteLn( 'Begin' ) ;
IncIndent( ) ;
Indent( ) ;
WriteLn(
2008-09-25 02:14:56 +00:00
'Result := wst_CreateInstance_%s(AFormat,ATransport,AAddress) as %s%s;' ,
2008-07-03 16:15:03 +00:00
[ AIntf. Name , AIntf. Name , sEASY_ACCESS_INTERFACE_PREFIX]
) ;
DecIndent( ) ;
WriteLn( 'End;' ) ;
NewLine( ) ;
end ;
2007-06-24 23:33:51 +00:00
if ( GetElementCount( AIntf. Members, TPasProcedure) > 0 ) then
2006-08-26 00:35:42 +00:00
WriteLn( '{ %s implementation }' , [ strClassName] ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethodDec( AMthd : TPasProcedure) ;
2006-08-26 00:35:42 +00:00
Var
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prm : TPasArgument;
prms : TList;
2006-08-26 00:35:42 +00:00
Begin
2007-06-24 23:33:51 +00:00
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
if AMthd. InheritsFrom( TPasFunction) then begin
Write( 'function ' )
end else begin
Write( 'procedure ' ) ;
end ;
2006-08-26 00:35:42 +00:00
Write( '%s.%s(' , [ strClassName, AMthd. Name ] ) ;
If ( prmCnt > 0 ) Then Begin
IncIndent( ) ;
For k : = 0 To Pred( prmCnt) Do Begin
2007-06-24 23:33:51 +00:00
prm : = TPasArgument( prms[ k] ) ;
2006-08-26 00:35:42 +00:00
If ( k > 0 ) Then
Write( '; ' ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
Write( '%s %s : %s' , [ AccessNames[ prm. Access] , prm. Name , prm. ArgType. Name ] ) ;
2006-08-26 00:35:42 +00:00
End ;
DecIndent( ) ;
NewLine( ) ;
Indent( ) ;
End ;
Write( ')' ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
Write( ':%s' , [ TPasFunctionType( AMthd. ProcType) . ResultEl. ResultType. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
WriteLn( ';' ) ;
End ;
2008-07-03 16:15:03 +00:00
procedure WriteEasyMethodImp( AMthd : TPasProcedure) ;
var
prms : TList;
origineRes : TPasResultElement;
origineResProp : TPasProperty;
function HasObjectsArgs( ) : Boolean ;
var
k : PtrInt;
prm : TPasArgument;
elt : TPasElement;
begin
Result : = False ;
for k : = 0 to ( prms. Count - 1 ) do begin
prm : = TPasArgument( prms[ k] ) ;
elt : = prm. ArgType;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then
elt : = SymbolTable. FindElement( SymbolTable. GetExternalName( elt) ) ;
if elt. InheritsFrom( TPasUnresolvedTypeRef) or SymbolTable. IsOfType( TPasType( elt) , TPasClassType) then begin
Result : = True ;
Break;
end ;
end ;
end ;
procedure AssignArguments( ) ;
var
k : PtrInt;
prm : TPasArgument;
elt : TPasElement;
begin
for k : = 0 to ( prms. Count - 1 ) do begin
prm : = TPasArgument( prms[ k] ) ;
elt : = prm. ArgType;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then
elt : = SymbolTable. FindElement( SymbolTable. GetExternalName( elt) ) ;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then begin
Indent( ) ; WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind = tkClass ) then begin' , [ elt. Name ] ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s := TObject(%s.%s);' , [ sTEMP_OBJ, sINPUT_PARAM, prm. Name ] ) ;
Indent( ) ; WriteLn( '%s.Free();' , [ sTEMP_OBJ] ) ;
Indent( ) ; WriteLn( 'TObject(%s.%s) := nil;' , [ sINPUT_PARAM, prm. Name ] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
end else begin
if SymbolTable. IsOfType( TPasType( elt) , TPasClassType) then begin
Indent( ) ; WriteLn( '%s := %s.%s;' , [ sTEMP_OBJ, sINPUT_PARAM, prm. Name ] ) ;
Indent( ) ; WriteLn( '%s.Free();' , [ sTEMP_OBJ] ) ;
end ;
end ;
Indent( ) ; WriteLn( '%s.%s := %s;' , [ sINPUT_PARAM, prm. Name , prm. Name ] ) ;
end ;
end ;
procedure ClearArguments( ) ;
var
k : PtrInt;
prm : TPasArgument;
elt : TPasElement;
begin
for k : = 0 to ( prms. Count - 1 ) do begin
prm : = TPasArgument( prms[ k] ) ;
elt : = prm. ArgType;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then
elt : = SymbolTable. FindElement( SymbolTable. GetExternalName( elt) ) ;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then begin
Indent( ) ; WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind = tkClass ) then' , [ elt. Name ] ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'TObject(%s.%s) := nil;' , [ sINPUT_PARAM, prm. Name ] ) ;
DecIndent( ) ;
end else begin
if SymbolTable. IsOfType( TPasType( elt) , TPasClassType) then begin
Indent( ) ; WriteLn( '%s.%s := nil;' , [ sINPUT_PARAM, prm. Name ] ) ;
end ;
end ;
end ;
if AMthd. ProcType. InheritsFrom( TPasFunctionType) then begin
elt : = origineResProp. VarType;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then
elt : = SymbolTable. FindElement( SymbolTable. GetExternalName( elt) ) ;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then begin
Indent( ) ; WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind = tkClass ) then' , [ elt. Name ] ) ;
IncIndent( ) ;
2008-07-03 16:42:26 +00:00
Indent( ) ; WriteLn( 'if ( %s <> nil ) then' , [ sOUTPUT_PARAM] ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'TObject(%s.%s) := nil;' , [ sOUTPUT_PARAM, origineResProp. Name ] ) ;
DecIndent( ) ;
2008-07-03 16:15:03 +00:00
DecIndent( ) ;
end else begin
if SymbolTable. IsOfType( TPasType( elt) , TPasClassType) then begin
2008-07-03 16:42:26 +00:00
Indent( ) ; WriteLn( 'if ( %s <> nil ) then' , [ sOUTPUT_PARAM] ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s.%s := nil;' , [ sOUTPUT_PARAM, origineResProp. Name ] ) ;
DecIndent( ) ;
2008-07-03 16:15:03 +00:00
end ;
end ;
end ;
end ;
var
origineMthd : TPasProcedure;
origineIsFunc : Boolean ;
origineArgIN : TPasArgument;
prmCnt, k : Integer ;
prm : TPasArgument;
resPrm : TPasResultElement;
elt : TPasElement;
objArgs : Boolean ;
localIsFunc : boolean ;
begin
origineMthd : = FindMember( AIntf, AMthd. Name ) as TPasProcedure;
Assert ( origineMthd < > nil ) ;
origineArgIN : = TPasArgument( origineMthd. ProcType. Args[ 0 ] ) ;
origineIsFunc : = origineMthd. InheritsFrom( TPasFunction) ;
origineResProp : = nil ;
localIsFunc : = AMthd. InheritsFrom( TPasFunction) ;
if origineIsFunc then begin
origineRes : = TPasFunctionType( origineMthd. ProcType) . ResultEl;
for k : = 0 to ( TPasClassType( origineRes. ResultType) . Members. Count - 1 ) do begin
elt : = TPasElement( TPasClassType( origineRes. ResultType) . Members[ k] ) ;
if elt. InheritsFrom( TPasProperty) and ( TPasProperty( elt) . Visibility = visPublished ) then begin
origineResProp : = TPasProperty( elt) ;
Break;
end ;
end ;
Assert( localIsFunc or ( origineResProp = nil ) ) ;
end else begin
origineRes : = nil ;
end ;
prms : = AMthd. ProcType. Args;
objArgs : = HasObjectsArgs( ) ;
IncIndent( ) ;
WriteLn( 'var' ) ;
Indent( ) ; WriteLn( '%s : TObject;' , [ sTEMP_OBJ] ) ;
Indent( ) ; WriteLn( '%s : %s;' , [ sINPUT_PARAM, origineArgIN. ArgType. Name ] ) ;
if origineIsFunc then begin
Indent( ) ; WriteLn( '%s : %s;' , [ sOUTPUT_PARAM, origineRes. ResultType. Name ] ) ;
end ;
WriteLn( 'begin' ) ;
Indent( ) ; WriteLn( '%s := nil;' , [ sOUTPUT_PARAM] ) ;
Indent( ) ; WriteLn( '%s := %s.Create();' , [ sINPUT_PARAM, origineArgIN. ArgType. Name ] ) ;
Indent( ) ; WriteLn( 'try' ) ;
IncIndent( ) ;
prmCnt : = prms. Count;
if ( prmCnt > 0 ) then
AssignArguments( ) ;
if objArgs then begin
Indent( ) ; WriteLn( 'try' ) ;
IncIndent( ) ;
end ;
if origineIsFunc then begin
Indent( ) ; WriteLn( '%s := %s(%s);' , [ sOUTPUT_PARAM, origineMthd. Name , sINPUT_PARAM] ) ;
if localIsFunc then begin
Indent( ) ; WriteLn( 'Result := %s.%s;' , [ sOUTPUT_PARAM, origineResProp. Name ] ) ;
end ;
end else begin
Indent( ) ; WriteLn( '%s(%s);' , [ origineMthd. Name , sINPUT_PARAM] ) ;
end ;
if objArgs then begin
DecIndent( ) ;
Indent( ) ; WriteLn( 'finally' ) ;
IncIndent( ) ;
ClearArguments( ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
end ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'finally' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'FreeAndNil(%s);' , [ sINPUT_PARAM] ) ;
Indent( ) ; WriteLn( 'FreeAndNil(%s);' , [ sOUTPUT_PARAM] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethodImp( AMthd : TPasProcedure) ;
2006-08-26 00:35:42 +00:00
Var
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prm : TPasArgument;
resPrm : TPasResultElement;
prms : TList;
2006-08-26 00:35:42 +00:00
Begin
2007-12-19 23:31:52 +00:00
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
WriteLn( 'Var' ) ;
Indent( ) ; WriteLn( '%s : %s;' , [ sLOC_SERIALIZER, sSERIALIZER_CLASS] ) ;
2008-09-10 16:02:05 +00:00
Indent( ) ; WriteLn( '%s : ICallContext;' , [ sLOC_CALL_CONTEXT] ) ;
2007-12-19 23:31:52 +00:00
if ( prmCnt > 0 ) or AMthd. InheritsFrom( TPasFunction) then begin
Indent( ) ; WriteLn( '%s : %s;' , [ sPRM_NAME, 'string' ] ) ;
end ;
2007-04-02 13:19:48 +00:00
2006-08-26 00:35:42 +00:00
WriteLn( 'Begin' ) ;
2008-09-10 16:02:05 +00:00
Indent( ) ; WriteLn( '%s := Self as ICallContext;' , [ sLOC_CALL_CONTEXT] ) ;
2006-08-26 00:35:42 +00:00
Indent( ) ; WriteLn( '%s := GetSerializer();' , [ sLOC_SERIALIZER] ) ;
Indent( ) ; WriteLn( 'Try' ) ; IncIndent( ) ;
2008-09-10 16:02:05 +00:00
Indent( ) ; WriteLn( '%s.BeginCall(' '%s' ', GetTarget(),%s);' , [ sLOC_SERIALIZER, SymbolTable. GetExternalName( AMthd) , sLOC_CALL_CONTEXT] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 To Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
If ( prm. Access < > argOut ) Then Begin
Indent( ) ; WriteLn( '%s.Put(%s, TypeInfo(%s), %s);' , [ sLOC_SERIALIZER, QuotedStr( SymbolTable. GetExternalName( prm) ) , prm. ArgType. Name , prm. Name ] ) ;
2006-08-26 00:35:42 +00:00
End ;
End ;
DecIndent( ) ;
Indent( ) ; WriteLn( '%s.EndCall();' , [ sLOC_SERIALIZER] ) ;
WriteLn( '' ) ;
Indent( ) ; WriteLn( 'MakeCall();' ) ;
WriteLn( '' ) ;
2008-09-10 16:02:05 +00:00
Indent( ) ; WriteLn( '%s.BeginCallRead(%s);' , [ sLOC_SERIALIZER, sLOC_CALL_CONTEXT] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
resPrm : = TPasFunctionType( AMthd. ProcType) . ResultEl;
if SymbolTable. IsInitNeed( resPrm. ResultType) then begin
if SymbolTable. IsOfType( resPrm. ResultType, TPasClassType) or
SymbolTable. IsOfType( resPrm. ResultType, TPasArrayType)
2007-03-23 23:22:35 +00:00
then begin
Indent( ) ; WriteLn( 'TObject(Result) := Nil;' ) ;
2006-08-26 00:35:42 +00:00
end else begin
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( 'If ( PTypeInfo(TypeInfo(%s))^.Kind in [tkClass,tkInterface] ) Then' , [ resPrm. ResultType. Name ] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
Indent( ) ; WriteLn( 'Pointer(Result) := Nil;' ) ;
DecIndent( ) ;
end ;
end ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( '%s := %s;' , [ sPRM_NAME, QuotedStr( FSymbolTable. GetExternalName( resPrm) ) ] ) ;
Indent( ) ; WriteLn( '%s.Get(TypeInfo(%s), %s, %s);' , [ sLOC_SERIALIZER, resPrm. ResultType. Name , sPRM_NAME, 'Result' ] ) ;
end ;
2006-08-26 00:35:42 +00:00
//--------------------------------
for k : = 0 to Pred( prmCnt) do begin
2007-06-24 23:33:51 +00:00
prm : = TPasArgument( prms[ k] ) ;
if ( prm. Access = argOut ) then begin
if SymbolTable. IsInitNeed( prm. ArgType) then begin
if SymbolTable. IsOfType( prm. ArgType, TPasClassType) or
SymbolTable. IsOfType( prm. ArgType, TPasArrayType)
2007-03-23 23:22:35 +00:00
then begin
Indent( ) ; WriteLn( 'TObject(%s) := Nil;' , [ prm. Name ] ) ;
end else begin
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( 'If ( PTypeInfo(TypeInfo(%s))^.Kind in [tkClass,tkInterface] ) Then' , [ prm. ArgType. Name ] ) ;
2007-03-23 23:22:35 +00:00
IncIndent( ) ;
Indent( ) ; WriteLn( 'Pointer(%s) := Nil;' , [ prm. Name ] ) ;
DecIndent( ) ;
end ;
2006-08-26 00:35:42 +00:00
end ;
end ;
end ;
//--------------------------------
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
if ( prm. Access in [ argVar, argOut] ) then begin
Indent( ) ; WriteLn( '%s := %s;' , [ sPRM_NAME, QuotedStr( SymbolTable. GetExternalName( prm) ) ] ) ;
Indent( ) ; WriteLn( '%s.Get(TypeInfo(%s), %s, %s);' , [ sLOC_SERIALIZER, prm. ArgType. Name , sPRM_NAME, prm. Name ] ) ;
end ;
end ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
WriteLn( '' ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'Finally' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s.Clear();' , [ sLOC_SERIALIZER] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'End;' ) ; DecIndent( ) ;
WriteLn( 'End;' ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
procedure WriteTypeInfoMethod( ) ;
begin
NewLine( ) ;
WriteLn( 'class function %s.GetServiceType() : PTypeInfo;' , [ strClassName] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'result := TypeInfo(%s);' , [ AIntf. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
end ;
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2006-08-26 00:35:42 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mthds : TList;
elt : TPasElement;
2006-08-26 00:35:42 +00:00
begin
WriteTypeInfoMethod( ) ;
2007-06-24 23:33:51 +00:00
mthds : = AIntf. Members;
for k : = 0 to Pred( mthds. Count) do begin
elt : = TPasElement( mthds[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethodDec( TPasProcedure( elt) ) ;
WriteMethodImp( TPasProcedure( elt) ) ;
WriteLn( '' ) ;
end ;
end ;
2008-07-03 16:15:03 +00:00
if HandleEasyIntf then begin
mthds : = AEasyIntf. Members;
if ( mthds. Count > 0 ) then begin
for k : = 0 to Pred( mthds. Count) do begin
elt : = TPasElement( mthds[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethodDec( TPasProcedure( elt) ) ;
WriteEasyMethodImp( TPasProcedure( elt) ) ;
WriteLn( '' ) ;
end ;
end ;
end ;
end ;
2006-08-26 00:35:42 +00:00
end ;
begin
2008-07-03 16:15:03 +00:00
HandleEasyIntf : = ( goDocumentWrappedParameter in Self. Options ) and ( AEasyIntf < > nil ) ;
2006-08-26 00:35:42 +00:00
SetCurrentStream( FImpStream) ;
IncIndent( ) ;
While ( DecIndent( ) > 0 ) Do
;
strClassName : = GenerateClassName( AIntf) ;
NewLine( ) ;
WriteDec( ) ;
WriteMethods( ) ;
end ;
{ TBaseGenerator }
procedure TBaseGenerator. SetCurrentStream( AStream: ISourceStream) ;
begin
FCurrentStream : = AStream;
end ;
procedure TBaseGenerator. Indent( ) ;
begin
FCurrentStream. Indent( ) ;
end ;
function TBaseGenerator. IncIndent( ) : Integer ;
begin
Result : = FCurrentStream. IncIndent( ) ;
end ;
function TBaseGenerator. DecIndent( ) : Integer ;
begin
Result : = FCurrentStream. DecIndent( ) ;
end ;
procedure TBaseGenerator. BeginAutoIndent( ) ;
begin
FCurrentStream. BeginAutoIndent( ) ;
end ;
procedure TBaseGenerator. EndAutoIndent( ) ;
begin
FCurrentStream. EndAutoIndent( ) ;
end ;
procedure TBaseGenerator. Write( AText: String ) ;
begin
FCurrentStream. Write( AText) ;
end ;
procedure TBaseGenerator. Write( AText: String ; const AArgs: array of const ) ;
begin
Write( Format( AText, AArgs) ) ;
end ;
procedure TBaseGenerator. WriteLn( AText: String ) ;
begin
Write( AText+ sNEW_LINE) ;
end ;
procedure TBaseGenerator. WriteLn( AText: String ; const AArgs: array of const ) ;
begin
Write( AText+ sNEW_LINE, AArgs) ;
end ;
procedure TBaseGenerator. NewLine( ) ;
begin
WriteLn( '' ) ;
end ;
2007-06-24 23:33:51 +00:00
function TBaseGenerator. ExtractserviceName( AIntf: TPasElement) : String ;
2006-08-26 00:35:42 +00:00
begin
Result : = AIntf. Name ;
If upCase( Result [ 1 ] ) = 'I' Then
Delete( Result , 1 , 1 ) ;
end ;
2007-06-24 23:33:51 +00:00
constructor TBaseGenerator. Create( ASymTable: TwstPasTreeContainer; ASrcMngr: ISourceManager) ;
2006-08-26 00:35:42 +00:00
begin
Assert( Assigned( ASymTable) ) ;
Assert( Assigned( ASrcMngr) ) ;
FSrcMngr : = ASrcMngr;
FCurrentStream : = Nil ;
FSymbolTable : = ASymTable;
end ;
{ TBinderGenerator }
2007-06-24 23:33:51 +00:00
function TBinderGenerator. GenerateClassName( AIntf: TPasElement) : String ;
2006-08-26 00:35:42 +00:00
begin
Result : = ExtractserviceName( AIntf) ;
Result : = Format( 'T%s_ServiceBinder' , [ Result ] ) ;
end ;
procedure TBinderGenerator. GenerateUnitHeader( ) ;
begin
SetCurrentStream( FDecStream) ;
WriteLn( '{' ) ;
WriteLn( 'This unit has been produced by ws_helper.' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( ' Input unit name : "%s".' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( ' This unit name : "%s".' , [ GetDestUnitName( ) ] ) ;
WriteLn( ' Date : "%s".' , [ DateTimeToStr( Now( ) ) ] ) ;
WriteLn( '}' ) ;
WriteLn( 'unit %s;' , [ GetDestUnitName( ) ] ) ;
2007-05-05 19:05:01 +00:00
WriteLn( '{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}' ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'interface' ) ;
WriteLn( '' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'uses SysUtils, Classes, base_service_intf, server_service_intf, %s;' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( '' ) ;
WriteLn( 'type' ) ;
WriteLn( '' ) ;
end ;
procedure TBinderGenerator. GenerateUnitImplementationHeader( ) ;
begin
SetCurrentStream( FImpStream) ;
WriteLn( '' ) ;
WriteLn( 'Implementation' ) ;
2006-11-12 13:31:22 +00:00
WriteLn( 'uses TypInfo, wst_resources_imp,metadata_repository;' ) ;
2006-08-26 00:35:42 +00:00
end ;
procedure TBinderGenerator. GenerateUnitImplementationFooter( ) ;
var
s : string ;
begin
NewLine( ) ;
WriteLn( 'initialization' ) ;
NewLine( ) ;
2007-07-18 11:23:56 +00:00
WriteLn( ' {$i %s.%s}' , [ SymbolTable. CurrentModule. Name , sWST_EXTENSION] ) ;
NewLine( ) ;
s : = Format( 'Register_%s_ServiceMetadata' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( ' {$IF DECLARED(%s)}' , [ s] ) ;
WriteLn( ' %s();' , [ s] ) ;
2007-07-13 22:33:55 +00:00
WriteLn( ' {$IFEND}' ) ;
2006-08-26 00:35:42 +00:00
NewLine( ) ;
WriteLn( 'End.' ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure TBinderGenerator. GenerateIntf( AIntf: TPasClassType) ;
2006-08-26 00:35:42 +00:00
procedure WriteDec( ) ;
begin
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( '%s = class(%s)' , [ GenerateClassName( AIntf) , sBINDER_BASE_CLASS] ) ;
2006-08-26 00:35:42 +00:00
end ;
procedure WriteConstructor( ) ;
Begin
Indent( ) ;
WriteLn( 'constructor Create();' )
End ;
2007-06-24 23:33:51 +00:00
procedure WriteMethod( AMthd : TPasProcedure) ;
2006-08-26 00:35:42 +00:00
Begin
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'procedure %sHandler(AFormatter : IFormatterResponse; AContext : ICallContext);' , [ AMthd. Name ] )
2006-08-26 00:35:42 +00:00
End ;
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2006-08-26 00:35:42 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mbrs : TList;
elt : TPasElement;
2006-08-26 00:35:42 +00:00
begin
2007-06-24 23:33:51 +00:00
if ( GetElementCount( AIntf. Members, TPasProcedure) > 0 ) then begin
Indent( ) ; WriteLn( 'protected' ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
mbrs : = AIntf. Members;
for k : = 0 to Pred( mbrs. Count) do begin
elt : = TPasElement( mbrs[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethod( TPasProcedure( elt) ) ;
end ;
end ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( 'public' ) ;
2006-08-26 00:35:42 +00:00
Indent( ) ; WriteConstructor( ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
end ;
procedure GenerateFactoryClass( ) ;
Begin
NewLine( ) ;
IncIndent( ) ; BeginAutoIndent( ) ;
WriteLn( 'T%s_ServiceBinderFactory = class(TInterfacedObject,IItemFactory)' , [ ExtractserviceName( AIntf) ] ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'private' ) ;
IncIndent( ) ;
WriteLn( 'FInstance : IInterface;' ) ;
DecIndent( ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'protected' ) ;
IncIndent( ) ;
WriteLn( 'function CreateInstance():IInterface;' ) ;
DecIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'public' ) ;
IncIndent( ) ;
WriteLn( 'constructor Create();' ) ;
WriteLn( 'destructor Destroy();override;' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ; EndAutoIndent( ) ;
End ;
2007-06-24 23:33:51 +00:00
2006-08-26 00:35:42 +00:00
procedure GenerateRegistrationProc( ) ;
Begin
NewLine( ) ;
BeginAutoIndent( ) ;
IncIndent( ) ;
WriteLn( 'procedure Server_service_Register%sService();' , [ ExtractserviceName( AIntf) ] ) ;
DecIndent( ) ;
EndAutoIndent( ) ;
End ;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
IncIndent( ) ;
WriteDec( ) ;
WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( 'end;' ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
GenerateFactoryClass( ) ;
GenerateRegistrationProc( ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure TBinderGenerator. GenerateImp( AIntf: TPasClassType) ;
2006-08-26 00:35:42 +00:00
Var
strClassName : String ;
procedure WriteDec( ) ;
begin
2007-06-24 23:33:51 +00:00
if ( GetElementCount( AIntf. Members, TPasProcedure) > 0 ) then
2006-08-26 00:35:42 +00:00
WriteLn( '{ %s implementation }' , [ strClassName] ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethodDec( AMthd : TPasProcedure) ;
2006-08-26 00:35:42 +00:00
Begin
2007-06-24 23:33:51 +00:00
WriteLn( 'procedure %s.%sHandler(AFormatter : IFormatterResponse; AContext : ICallContext);' , [ strClassName, AMthd. Name ] ) ;
2006-08-26 00:35:42 +00:00
End ;
2007-06-24 23:33:51 +00:00
procedure WriteMethodImp( AMthd : TPasProcedure) ;
2006-08-26 00:35:42 +00:00
Var
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prm : TPasArgument;
prms : TList;
resElt : TPasResultElement;
2006-08-26 00:35:42 +00:00
strBuff : string ;
Begin
2007-06-24 23:33:51 +00:00
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
WriteLn( 'var' ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ; BeginAutoIndent( ) ;
WriteLn( 'cllCntrl : ICallControl;' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'objCntrl : IObjectControl;' ) ;
WriteLn( 'hasObjCntrl : Boolean;' ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'tmpObj : %s;' , [ AIntf. Name ] ) ;
WriteLn( 'callCtx : ICallContext;' ) ;
2007-06-24 23:33:51 +00:00
if ( prmCnt > 0 ) or AMthd. InheritsFrom( TPasFunction) then begin
2006-08-26 00:35:42 +00:00
WriteLn( '%s : string;' , [ sPRM_NAME] ) ;
2007-06-24 23:33:51 +00:00
end ;
2007-12-19 23:31:52 +00:00
WriteLn( 'procName,trgName : string;' ) ;
2007-06-24 23:33:51 +00:00
if ( prmCnt > 0 ) then begin
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
WriteLn( '%s : %s;' , [ prm. Name , prm. ArgType. Name ] ) ;
end ;
end ;
if AMthd. InheritsFrom( TPasFunction) then begin
WriteLn( '%s : %s;' , [ RETURN_VAL_NAME, TPasFunctionType( AMthd. ProcType) . ResultEl. ResultType. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ; EndAutoIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'begin' ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ; BeginAutoIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'callCtx := AContext;' ) ;
if AMthd. InheritsFrom( TPasFunction) then begin
resElt : = TPasFunctionType( AMthd. ProcType) . ResultEl;
if SymbolTable. IsInitNeed( resElt. ResultType) then begin
2007-09-02 19:05:47 +00:00
WriteLn( 'Fillchar(%s,SizeOf(%s),#0);' , [ RETURN_VAL_NAME, resElt. ResultType. Name ] ) ;
{ if ( SymbolTable. IsOfType( resElt. ResultType, TPasClassType) and
2007-06-24 23:33:51 +00:00
( TPasClassType( GetUltimeType( resElt. ResultType) ) . ObjKind = okClass )
) or
SymbolTable. IsOfType( resElt. ResultType, TPasArrayType)
then begin
WriteLn( 'TObject(%s) := nil;' , [ RETURN_VAL_NAME] ) ;
2007-09-02 19:05:47 +00:00
end else if SymbolTable. IsOfType( resElt. ResultType, TPasRecordType) then begin
WriteLn( 'Fillchar(%s,SizeOf(%s),#0);' , [ RETURN_VAL_NAME, resElt. ResultType. Name ] ) ;
2006-08-26 00:35:42 +00:00
end else begin
2007-06-24 23:33:51 +00:00
WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind in [tkClass,tkInterface] ) then' , [ resElt. ResultType. Name ] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'Pointer(%s) := nil;' , [ RETURN_VAL_NAME] ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
2007-09-02 19:05:47 +00:00
end ; }
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
if SymbolTable. IsInitNeed( prm. ArgType) then begin
2007-09-02 19:05:47 +00:00
WriteLn( 'Fillchar(%s,SizeOf(%s),#0);' , [ prm. Name , prm. ArgType. Name ] ) ;
{ if SymbolTable. IsOfType( prm. ArgType, TPasClassType) or
2007-06-24 23:33:51 +00:00
SymbolTable. IsOfType( prm. ArgType, TPasArrayType)
then begin
WriteLn( 'TObject(%s) := nil;' , [ prm. Name ] ) ;
2006-08-26 00:35:42 +00:00
end else begin
2007-06-24 23:33:51 +00:00
WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind in [tkClass,tkObject,tkInterface] ) then' , [ prm. ArgType. Name ] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'Pointer(%s) := nil;' , [ prm. Name ] ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
2007-09-02 19:05:47 +00:00
end ; }
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
NewLine( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
Write( '%s := %s;' , [ sPRM_NAME, QuotedStr( SymbolTable. GetExternalName( prm) ) ] ) ;
WriteLn( 'AFormatter.Get(TypeInfo(%s),%s,%s);' , [ prm. ArgType. Name , sPRM_NAME, prm. Name ] ) ;
if SymbolTable. IsInitNeed( prm. ArgType) then begin
if SymbolTable. IsOfType( prm. ArgType, TPasClassType) or SymbolTable. IsOfType( prm. ArgType, TPasArrayType) then begin
WriteLn( 'if Assigned(Pointer(%s)) then' , [ prm. Name ] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
WriteLn( 'callCtx.AddObjectToFree(TObject(%s));' , [ prm. Name ] ) ;
DecIndent( ) ;
end else begin
2007-06-24 23:33:51 +00:00
WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind = tkClass ) and Assigned(Pointer(%s)) then' , [ prm. ArgType. Name , prm. Name ] ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
WriteLn( 'callCtx.AddObjectToFree(TObject(%s));' , [ prm. Name ] ) ;
DecIndent( ) ;
end ;
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
NewLine( ) ;
WriteLn( 'tmpObj := Self.GetFactory().CreateInstance() as %s;' , [ AIntf. Name ] ) ;
WriteLn( 'if Supports(tmpObj,ICallControl,cllCntrl) then' ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( 'cllCntrl.SetCallContext(callCtx);' ) ;
WriteLn( 'hasObjCntrl := Supports(tmpObj,IObjectControl,objCntrl);' ) ;
WriteLn( 'if hasObjCntrl then' ) ;
Indent( ) ; WriteLn( 'objCntrl.Activate();' ) ;
WriteLn( 'try' ) ; IncIndent( ) ;
if AMthd. InheritsFrom( TPasFunction) then
Write( '%s := tmpObj.%s(' , [ RETURN_VAL_NAME, AMthd. Name ] )
else
Write( 'tmpObj.%s(' , [ AMthd. Name ] ) ;
strBuff : = '' ;
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
strBuff : = strBuff + Format( '%s,' , [ prm. Name ] ) ;
end ;
if ( prmCnt > 0 ) then
Delete( strBuff, Length( strBuff) , 1 ) ;
strBuff : = strBuff + ');' ;
EndAutoIndent( ) ;
WriteLn( strBuff) ;
BeginAutoIndent( ) ;
if AMthd. InheritsFrom( TPasFunction) then begin
if SymbolTable. IsInitNeed( resElt. ResultType) then begin
if SymbolTable. IsOfType( resElt. ResultType, TPasClassType) or SymbolTable. IsOfType( resElt. ResultType, TPasArrayType) then
WriteLn( 'if Assigned(TObject(%s)) then' , [ RETURN_VAL_NAME] )
else
WriteLn( 'if ( PTypeInfo(TypeInfo(%s))^.Kind = tkClass ) and Assigned(Pointer(%s)) then' , [ resElt. ResultType. Name , RETURN_VAL_NAME] ) ;
IncIndent( ) ;
WriteLn( 'callCtx.AddObjectToFree(TObject(%s));' , [ RETURN_VAL_NAME] ) ;
DecIndent( ) ;
end ;
end ;
NewLine( ) ;
2006-08-26 00:35:42 +00:00
2007-06-24 23:33:51 +00:00
WriteLn( 'procName := AFormatter.GetCallProcedureName();' ) ;
WriteLn( 'trgName := AFormatter.GetCallTarget();' ) ;
WriteLn( 'AFormatter.Clear();' ) ;
WriteLn( 'AFormatter.BeginCallResponse(procName,trgName);' ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
WriteLn( 'AFormatter.Put(%s,TypeInfo(%s),%s);' , [ QuotedStr( SymbolTable. GetExternalName( resElt) ) , resElt. ResultType. Name , RETURN_VAL_NAME] ) ;
end ;
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
if ( prm. Access in [ argOut, argVar] ) then
WriteLn( 'AFormatter.Put(%s,TypeInfo(%s),%s);' , [ QuotedStr( SymbolTable. GetExternalName( prm) ) , prm. ArgType. Name , prm. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'AFormatter.EndCallResponse();' ) ;
NewLine( ) ;
WriteLn( 'callCtx := nil;' ) ;
2006-08-26 00:35:42 +00:00
2007-06-24 23:33:51 +00:00
DecIndent( ) ;
WriteLn( 'finally' ) ;
WriteLn( ' if hasObjCntrl then' ) ;
WriteLn( ' objCntrl.Deactivate();' ) ;
WriteLn( ' Self.GetFactory().ReleaseInstance(tmpObj);' ) ;
WriteLn( 'end;' ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ; EndAutoIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'end;' ) ;
2006-08-26 00:35:42 +00:00
End ;
procedure WriteConstructor( ) ;
Var
k : Integer ;
2007-06-24 23:33:51 +00:00
mtd : TPasProcedure;
mtds : TList;
2006-08-26 00:35:42 +00:00
Begin
NewLine( ) ;
WriteLn( 'constructor %s.Create();' , [ strClassName] ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'begin' ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
BeginAutoIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'inherited Create(GetServiceImplementationRegistry().FindFactory(%s));' , [ QuotedStr( AIntf. Name ) ] ) ;
mtds : = AIntf. Members;
for k : = 0 to Pred( mtds. Count) do begin
if TPasElement( mtds[ k] ) . InheritsFrom( TPasProcedure) then begin
mtd : = TPasProcedure( mtds[ k] ) ;
2007-07-13 22:33:55 +00:00
WriteLn( 'RegisterVerbHandler(%s,{$IFDEF FPC}@{$ENDIF}%sHandler);' , [ QuotedStr( mtd. Name ) , mtd. Name ] ) ;
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
EndAutoIndent( ) ;
DecIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'end;' ) ;
2006-08-26 00:35:42 +00:00
NewLine( ) ;
End ;
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2006-08-26 00:35:42 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mtds : TList;
mtd : TPasProcedure;
2006-08-26 00:35:42 +00:00
begin
2007-06-24 23:33:51 +00:00
mtds : = AIntf. Members;
for k : = 0 to Pred( mtds. Count) do begin
if TPasElement( mtds[ k] ) . InheritsFrom( TPasProcedure) then begin
mtd : = TPasProcedure( mtds[ k] ) ;
WriteMethodDec( mtd) ;
WriteMethodImp( mtd) ;
WriteLn( '' ) ;
end ;
end ;
2006-08-26 00:35:42 +00:00
WriteConstructor( ) ;
end ;
procedure GenerateFactoryClass( ) ;
Var
strBuff : string ;
Begin
NewLine( ) ;
BeginAutoIndent( ) ;
strBuff : = Format( 'T%s_ServiceBinderFactory' , [ ExtractserviceName( AIntf) ] ) ;
WriteLn( '{ %s }' , [ strBuff] ) ;
2007-06-24 23:33:51 +00:00
NewLine( ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'function %s.CreateInstance():IInterface;' , [ strBuff] ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'begin' ) ;
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'Result := FInstance;' , [ strClassName] ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'constructor %s.Create();' , [ strBuff] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
WriteLn( 'FInstance := %s.Create() as IInterface;' , [ strClassName] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'destructor %s.Destroy();' , [ strBuff] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
WriteLn( 'FInstance := nil;' ) ;
WriteLn( 'inherited Destroy();' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
2006-08-26 00:35:42 +00:00
EndAutoIndent( ) ;
End ;
2007-06-24 23:33:51 +00:00
2006-08-26 00:35:42 +00:00
procedure GenerateRegistrationProc( ) ;
Var
strBuff : string ;
Begin
NewLine( ) ;
BeginAutoIndent( ) ;
strBuff : = ExtractserviceName( AIntf) ;
NewLine( ) ;
WriteLn( 'procedure Server_service_Register%sService();' , [ strBuff] ) ;
WriteLn( 'Begin' ) ;
IncIndent( ) ;
WriteLn( 'GetServerServiceRegistry().Register(%s,T%s_ServiceBinderFactory.Create() as IItemFactory);' , [ QuotedStr( AIntf. Name ) , strBuff] ) ;
DecIndent( ) ;
WriteLn( 'End;' ) ;
EndAutoIndent( ) ;
End ;
begin
SetCurrentStream( FImpStream) ;
IncIndent( ) ;
While ( DecIndent( ) > 0 ) Do
;
strClassName : = GenerateClassName( AIntf) ;
NewLine( ) ;
WriteDec( ) ;
WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
2006-08-26 00:35:42 +00:00
GenerateFactoryClass( ) ;
GenerateRegistrationProc( ) ;
end ;
function TBinderGenerator. GetDestUnitName( ) : string ;
begin
2007-06-24 23:33:51 +00:00
Result : = Format( '%s_binder' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
end ;
2007-06-24 23:33:51 +00:00
constructor TBinderGenerator. Create( ASymTable: TwstPasTreeContainer; ASrcMngr: ISourceManager) ;
2006-08-26 00:35:42 +00:00
begin
Inherited Create( ASymTable, ASrcMngr) ;
FDecStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.dec' ) ;
FImpStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.imp' ) ;
end ;
procedure TBinderGenerator. Execute( ) ;
Var
i, c : Integer ;
2007-06-24 23:33:51 +00:00
intf : TPasClassType;
typeList : TList;
elt : TPasElement;
2006-08-26 00:35:42 +00:00
begin
GenerateUnitHeader( ) ;
GenerateUnitImplementationHeader( ) ;
2007-07-12 14:46:45 +00:00
typeList : = SymbolTable. CurrentModule. InterfaceSection. Declarations;
2007-06-24 23:33:51 +00:00
c : = Pred( typeList. Count) ;
for i : = 0 to c do begin
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasClassType) and ( TPasClassType( elt) . ObjKind = okInterface ) then begin
intf : = TPasClassType( elt) ;
2006-08-26 00:35:42 +00:00
GenerateIntf( intf) ;
GenerateImp( intf) ;
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
GenerateUnitImplementationFooter( ) ;
FSrcMngr. Merge( GetDestUnitName( ) + '.pas' , [ FDecStream, FImpStream] ) ;
2007-06-24 23:33:51 +00:00
FDecStream : = nil ;
FImpStream : = nil ;
2006-08-26 00:35:42 +00:00
end ;
{ TImplementationGenerator }
2007-06-24 23:33:51 +00:00
function TImplementationGenerator. GenerateClassName( AIntf: TPasElement) : String ;
2006-08-26 00:35:42 +00:00
begin
Result : = ExtractserviceName( AIntf) ;
Result : = Format( 'T%s_ServiceImp' , [ Result ] ) ;
end ;
procedure TImplementationGenerator. GenerateUnitHeader( ) ;
begin
SetCurrentStream( FDecStream) ;
WriteLn( '{' ) ;
WriteLn( 'This unit has been produced by ws_helper.' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( ' Input unit name : "%s".' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( ' This unit name : "%s".' , [ GetDestUnitName( ) ] ) ;
WriteLn( ' Date : "%s".' , [ DateTimeToStr( Now( ) ) ] ) ;
WriteLn( '}' ) ;
WriteLn( 'Unit %s;' , [ GetDestUnitName( ) ] ) ;
2007-05-05 19:05:01 +00:00
WriteLn( '{$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF}' ) ;
2006-08-26 00:35:42 +00:00
WriteLn( 'Interface' ) ;
WriteLn( '' ) ;
WriteLn( 'Uses SysUtils, Classes, ' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( ' base_service_intf, server_service_intf, server_service_imputils, %s;' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
WriteLn( '' ) ;
WriteLn( 'Type' ) ;
WriteLn( '' ) ;
end ;
procedure TImplementationGenerator. GenerateUnitImplementationHeader( ) ;
begin
SetCurrentStream( FImpStream) ;
WriteLn( '' ) ;
WriteLn( 'Implementation' ) ;
2007-07-18 11:23:56 +00:00
WriteLn( 'uses config_objects;' ) ;
2006-08-26 00:35:42 +00:00
end ;
procedure TImplementationGenerator. GenerateUnitImplementationFooter( ) ;
begin
NewLine( ) ;
WriteLn( 'End.' ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure TImplementationGenerator. GenerateIntf( AIntf: TPasClassType) ;
2006-08-26 00:35:42 +00:00
procedure WriteDec( ) ;
begin
Indent( ) ;
WriteLn( '%s=class(%s,%s)' , [ GenerateClassName( AIntf) , sIMP_BASE_CLASS, AIntf. Name ] ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethod( AMthd : TPasProcedure) ;
var
2006-08-26 00:35:42 +00:00
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prm : TPasArgument;
prms : TList;
begin
2006-08-26 00:35:42 +00:00
Indent( ) ;
2007-06-24 23:33:51 +00:00
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
if AMthd. InheritsFrom( TPasFunction) then begin
Write( 'function ' )
end else begin
Write( 'procedure ' ) ;
end ;
2006-08-26 00:35:42 +00:00
Write( '%s(' , [ AMthd. Name ] ) ;
2007-06-24 23:33:51 +00:00
if ( prmCnt > 0 ) then begin
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
if ( k > 0 ) then
2006-08-26 00:35:42 +00:00
Write( '; ' ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
Write( '%s %s : %s' , [ AccessNames[ prm. Access] , prm. Name , prm. ArgType. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
Write( ')' ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
Write( ':%s' , [ TPasFunctionType( AMthd. ProcType) . ResultEl. ResultType. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
WriteLn( ';' ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2006-08-26 00:35:42 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mtds : TList;
elt : TPasElement;
2006-08-26 00:35:42 +00:00
begin
2007-06-24 23:33:51 +00:00
if ( GetElementCount( AIntf. Members, TPasProcedure) > 0 ) then begin
Indent( ) ; WriteLn( 'Protected' ) ;
IncIndent( ) ;
mtds : = AIntf. Members;
for k : = 0 to Pred( mtds. Count) do begin
elt : = TPasElement( mtds[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethod( TPasProcedure( elt) ) ;
end ;
end ;
DecIndent( ) ;
end ;
2006-08-26 00:35:42 +00:00
end ;
procedure GenerateRegistrationProc( ) ;
Begin
NewLine( ) ;
BeginAutoIndent( ) ;
IncIndent( ) ;
WriteLn( 'procedure Register%sImplementationFactory();' , [ ExtractserviceName( AIntf) ] ) ;
DecIndent( ) ;
EndAutoIndent( ) ;
End ;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
IncIndent( ) ;
WriteDec( ) ;
WriteMethods( ) ;
Indent( ) ; WriteLn( 'End;' ) ;
NewLine( ) ;
DecIndent( ) ;
GenerateRegistrationProc( ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure TImplementationGenerator. GenerateImp( AIntf: TPasClassType) ;
var
2006-08-26 00:35:42 +00:00
strClassName : String ;
procedure WriteDec( ) ;
begin
2007-06-24 23:33:51 +00:00
if ( GetElementCount( AIntf. Members, TPasProcedure) > 0 ) then begin
2006-08-26 00:35:42 +00:00
WriteLn( '{ %s implementation }' , [ strClassName] ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethodDec( AMthd : TPasProcedure) ;
var
2006-08-26 00:35:42 +00:00
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prms : TList;
prm : TPasArgument;
begin
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
if AMthd. InheritsFrom( TPasFunction) then begin
2006-08-26 00:35:42 +00:00
Write( 'function ' ) ;
2007-06-24 23:33:51 +00:00
end else begin
Write( 'procedure ' ) ;
end ;
2006-08-26 00:35:42 +00:00
Write( '%s.%s(' , [ strClassName, AMthd. Name ] ) ;
2007-06-24 23:33:51 +00:00
if ( prmCnt > 0 ) then begin
2006-08-26 00:35:42 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
if ( k > 0 ) then
2006-08-26 00:35:42 +00:00
Write( '; ' ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
Write( '%s %s : %s' , [ AccessNames[ prm. Access] , prm. Name , prm. ArgType. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
Write( ')' ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
Write( ':%s' , [ TPasFunctionType( AMthd. ProcType) . ResultEl. ResultType. Name ] ) ;
end ;
2006-08-26 00:35:42 +00:00
WriteLn( ';' ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
2007-06-24 23:33:51 +00:00
procedure WriteMethodImp( AMthd : TPasProcedure) ;
begin
2006-08-26 00:35:42 +00:00
WriteLn( 'Begin' ) ;
WriteLn( '// your code here' ) ;
WriteLn( 'End;' ) ;
2007-06-24 23:33:51 +00:00
end ;
2006-08-26 00:35:42 +00:00
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2006-08-26 00:35:42 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mbrs : TList;
elt : TPasElement;
mtd : TPasProcedure;
2006-08-26 00:35:42 +00:00
begin
2007-06-24 23:33:51 +00:00
mbrs : = AIntf. Members;
for k : = 0 to Pred( mbrs. Count) do begin
elt : = TPasElement( mbrs[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
mtd : = TPasProcedure( elt) ;
WriteMethodDec( mtd) ;
WriteMethodImp( mtd) ;
WriteLn( '' ) ;
end ;
end ;
2006-08-26 00:35:42 +00:00
end ;
procedure GenerateRegistrationProc( ) ;
Var
strBuff : string ;
Begin
NewLine( ) ;
BeginAutoIndent( ) ;
strBuff : = ExtractserviceName( AIntf) ;
NewLine( ) ;
WriteLn( 'procedure Register%sImplementationFactory();' , [ strBuff] ) ;
WriteLn( 'Begin' ) ;
IncIndent( ) ;
2007-07-18 11:23:56 +00:00
WriteLn( 'GetServiceImplementationRegistry().Register(%s,TImplementationFactory.Create(%s,wst_GetServiceConfigText(%s)) as IServiceImplementationFactory);' , [ QuotedStr( AIntf. Name ) , strClassName, QuotedStr( AIntf. Name ) ] ) ;
2006-08-26 00:35:42 +00:00
DecIndent( ) ;
WriteLn( 'End;' ) ;
EndAutoIndent( ) ;
End ;
begin
SetCurrentStream( FImpStream) ;
IncIndent( ) ;
While ( DecIndent( ) > 0 ) Do
;
strClassName : = GenerateClassName( AIntf) ;
NewLine( ) ;
WriteDec( ) ;
WriteMethods( ) ;
GenerateRegistrationProc( ) ;
end ;
function TImplementationGenerator. GetDestUnitName( ) : string ;
begin
2007-06-24 23:33:51 +00:00
Result : = Format( '%s_imp' , [ SymbolTable. CurrentModule. Name ] ) ;
2006-08-26 00:35:42 +00:00
end ;
2007-06-24 23:33:51 +00:00
constructor TImplementationGenerator. Create( ASymTable: TwstPasTreeContainer; ASrcMngr: ISourceManager) ;
2006-08-26 00:35:42 +00:00
begin
Inherited Create( ASymTable, ASrcMngr) ;
FDecStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.dec' ) ;
FImpStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.imp' ) ;
end ;
procedure TImplementationGenerator. Execute( ) ;
Var
i, c : Integer ;
2007-06-24 23:33:51 +00:00
intf : TPasClassType;
elt : TPasElement;
typeList : TList;
2006-08-26 00:35:42 +00:00
begin
GenerateUnitHeader( ) ;
GenerateUnitImplementationHeader( ) ;
2007-07-12 14:46:45 +00:00
typeList : = SymbolTable. CurrentModule. InterfaceSection. Declarations;
2007-06-24 23:33:51 +00:00
c : = Pred( typeList. Count) ;
for i : = 0 to c do begin
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasClassType) and ( TPasClassType( elt) . ObjKind = okInterface ) then begin
intf : = TPasClassType( elt) ;
2006-08-26 00:35:42 +00:00
GenerateIntf( intf) ;
GenerateImp( intf) ;
2007-06-24 23:33:51 +00:00
end ;
end ;
2006-08-26 00:35:42 +00:00
GenerateUnitImplementationFooter( ) ;
FSrcMngr. Merge( GetDestUnitName( ) + '.pas' , [ FDecStream, FImpStream] ) ;
2007-06-24 23:33:51 +00:00
FDecStream : = nil ;
FImpStream : = nil ;
2006-08-26 00:35:42 +00:00
end ;
2007-03-23 23:22:35 +00:00
{ TInftGenerator }
2008-08-18 18:19:00 +00:00
procedure TInftGenerator. WriteDocumetation( AElement : TPasElement) ;
var
pl : TStrings;
docString : string ;
i : PtrInt;
begin
pl : = FSymbolTable. Properties. FindList( AElement) ;
if ( pl < > nil ) then begin
i : = pl. IndexOfName( sDOCUMENTATION) ;
if ( i > = 0 ) then begin
docString: = StringReplace( DecodeLineBreak( pl. ValueFromIndex[ i] ) , #10 , sLineBreak, [ rfReplaceAll] ) ;
if not IsStrEmpty( docString) then begin
WriteLn( '{ %s' , [ AElement. Name ] ) ;
WriteLn( docString) ;
WriteLn( '}' ) ;
end ;
end ;
end ;
end ;
procedure TInftGenerator. WriteDocIfEnabled( AElement : TPasElement) ;
begin
if ( goGenerateDocAsComments in Options ) then
WriteDocumetation( AElement) ;
end ;
2008-08-01 21:38:55 +00:00
procedure TInftGenerator. WriteObjectArray( ASymbol : TPasArrayType) ;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2008-08-01 21:38:55 +00:00
IncIndent( ) ;
BeginAutoIndent( ) ;
try
WriteLn( '%s = class(TBaseObjectArrayRemotable)' , [ ASymbol. Name ] ) ;
WriteLn( 'private' ) ;
Indent( ) ; WriteLn( 'function GetItem(AIndex: Integer): %s;' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'public' ) ;
Indent( ) ; WriteLn( 'class function GetItemClass():TBaseRemotableClass;override;' ) ;
Indent( ) ; WriteLn( 'property Item[AIndex:Integer] : %s Read GetItem;Default;' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'end;' ) ;
finally
EndAutoIndent( ) ;
DecIndent( ) ;
end ;
SetCurrentStream( FImpStream) ;
NewLine( ) ;
WriteLn( '{ %s }' , [ ASymbol. Name ] ) ;
NewLine( ) ;
WriteLn( 'function %s.GetItem(AIndex: Integer): %s;' , [ ASymbol. Name , ASymbol. ElType. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result := %s(Inherited GetItem(AIndex));' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'class function %s.GetItemClass(): TBaseRemotableClass;' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result:= %s;' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
end ;
procedure TInftGenerator. WriteSimpleTypeArray( ASymbol : TPasArrayType) ;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2008-08-01 21:38:55 +00:00
IncIndent( ) ;
BeginAutoIndent( ) ;
try
WriteLn( '%s = class(TBaseSimpleTypeArrayRemotable)' , [ ASymbol. Name ] ) ;
WriteLn( 'private' ) ;
Indent( ) ; WriteLn( 'FData : array of %s;' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'private' ) ;
Indent( ) ; WriteLn( 'function GetItem(AIndex: Integer): %s;' , [ ASymbol. ElType. Name ] ) ;
Indent( ) ; WriteLn( 'procedure SetItem(AIndex: Integer; const AValue: %s);' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'protected' ) ;
Indent( ) ; WriteLn( 'function GetLength():Integer;override;' ) ;
Indent( ) ; WriteLn( 'procedure SaveItem(AStore : IFormatterBase;const AName : String;const AIndex : Integer);override;' ) ;
Indent( ) ; WriteLn( 'procedure LoadItem(AStore : IFormatterBase;const AIndex : Integer);override;' ) ;
WriteLn( 'public' ) ;
Indent( ) ; WriteLn( 'class function GetItemTypeInfo():PTypeInfo;override;' ) ;
Indent( ) ; WriteLn( 'procedure SetLength(const ANewSize : Integer);override;' ) ;
Indent( ) ; WriteLn( 'procedure Assign(Source: TPersistent); override;' ) ;
Indent( ) ; WriteLn( 'property Item[AIndex:Integer] : %s read GetItem write SetItem; default;' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'end;' ) ;
finally
EndAutoIndent( ) ;
DecIndent( ) ;
end ;
SetCurrentStream( FImpStream) ;
NewLine( ) ;
WriteLn( '{ %s }' , [ ASymbol. Name ] ) ;
NewLine( ) ;
WriteLn( 'function %s.GetItem(AIndex: Integer): %s;' , [ ASymbol. Name , ASymbol. ElType. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'CheckIndex(AIndex);' ) ;
Indent( ) ; WriteLn( 'Result := FData[AIndex];' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'procedure %s.SetItem(AIndex: Integer;const AValue: %S);' , [ ASymbol. Name , ASymbol. ElType. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'CheckIndex(AIndex);' ) ;
Indent( ) ; WriteLn( 'FData[AIndex] := AValue;' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'function %s.GetLength(): Integer;' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result := System.Length(FData);' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'procedure %s.SaveItem(AStore: IFormatterBase;const AName: String; const AIndex: Integer);' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'AStore.Put(%s,TypeInfo(%s),FData[AIndex]);' , [ QuotedStr( SymbolTable. GetArrayItemName( ASymbol) ) , ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
IncIndent( ) ;
WriteLn( 'procedure %s.LoadItem(AStore: IFormatterBase;const AIndex: Integer);' , [ ASymbol. Name ] ) ;
WriteLn( 'var' ) ;
Indent( ) ; WriteLn( 'sName : string;' ) ;
WriteLn( 'begin' ) ;
Indent( ) ; WriteLn( 'sName := %s;' , [ QuotedStr( SymbolTable. GetArrayItemName( ASymbol) ) ] ) ;
Indent( ) ; WriteLn( 'AStore.Get(TypeInfo(%s),sName,FData[AIndex]);' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'class function %s.GetItemTypeInfo(): PTypeInfo;' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result := TypeInfo(%s);' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
IncIndent( ) ;
WriteLn( 'procedure %s.SetLength(const ANewSize: Integer);' , [ ASymbol. Name ] ) ;
WriteLn( 'var' ) ;
Indent( ) ; WriteLn( 'i : Integer;' ) ;
WriteLn( 'begin' ) ;
Indent( ) ; WriteLn( 'if ( ANewSize < 0 ) then' ) ;
Indent( ) ; Indent( ) ; WriteLn( 'i := 0' ) ;
Indent( ) ; WriteLn( 'else' ) ;
Indent( ) ; Indent( ) ; WriteLn( 'i := ANewSize;' ) ;
Indent( ) ; WriteLn( 'System.SetLength(FData,i);' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
IncIndent( ) ;
WriteLn( 'procedure %s.Assign(Source: TPersistent);' , [ ASymbol. Name ] ) ;
WriteLn( 'var' ) ;
Indent( ) ; WriteLn( 'src : %s;' , [ ASymbol. Name ] ) ;
Indent( ) ; WriteLn( 'i, c : PtrInt;' ) ;
WriteLn( 'begin' ) ;
Indent( ) ; WriteLn( 'if Assigned(Source) and Source.InheritsFrom(%s) then begin' , [ ASymbol. Name ] ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'src := %s(Source);' , [ ASymbol. Name ] ) ;
Indent( ) ; WriteLn( 'c := src.Length;' ) ;
Indent( ) ; WriteLn( 'Self.SetLength(c);' ) ;
Indent( ) ; WriteLn( 'if ( c > 0 ) then begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'for i := 0 to Pred(c) do begin' ) ;
IncIndent( ) ; Indent( ) ; WriteLn( 'Self[i] := src[i];' ) ; DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'end else begin' ) ;
IncIndent( ) ; Indent( ) ; WriteLn( 'inherited Assign(Source);' ) ; DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
end ;
procedure TInftGenerator. WriteObjectCollection( ASymbol : TPasArrayType) ;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2008-08-01 21:38:55 +00:00
IncIndent( ) ;
BeginAutoIndent( ) ;
try
WriteLn( '%s = class(TObjectCollectionRemotable)' , [ ASymbol. Name ] ) ;
WriteLn( 'private' ) ;
Indent( ) ; WriteLn( 'function GetItem(AIndex: Integer): %s;' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'public' ) ;
Indent( ) ; WriteLn( 'class function GetItemClass():TBaseRemotableClass;override;' ) ;
Indent( ) ; WriteLn( 'function Add(): %s; {$IFDEF USE_INLINE}inline;{$ENDIF}' , [ ASymbol. ElType. Name ] ) ;
Indent( ) ; WriteLn( 'function AddAt(const APosition : Integer) : %s; {$IFDEF USE_INLINE}inline;{$ENDIF}' , [ ASymbol. ElType. Name ] ) ;
Indent( ) ; WriteLn( 'property Item[AIndex:Integer] : %s Read GetItem;Default;' , [ ASymbol. ElType. Name ] ) ;
WriteLn( 'end;' ) ;
finally
EndAutoIndent( ) ;
DecIndent( ) ;
end ;
SetCurrentStream( FImpStream) ;
NewLine( ) ;
WriteLn( '{ %s }' , [ ASymbol. Name ] ) ;
NewLine( ) ;
WriteLn( 'function %s.GetItem(AIndex: Integer): %s;' , [ ASymbol. Name , ASymbol. ElType. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result := %s(Inherited GetItem(AIndex));' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'class function %s.GetItemClass(): TBaseRemotableClass;' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result:= %s;' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'function %s.Add() : %s;' , [ ASymbol. Name , ASymbol. ElType. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result := %s(inherited Add());' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
NewLine( ) ;
WriteLn( 'function %s.AddAt(const APosition : Integer) : %s;' , [ ASymbol. Name , ASymbol. ElType. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'Result := %s(inherited AddAt(APosition));' , [ ASymbol. ElType. Name ] ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
end ;
2007-06-24 23:33:51 +00:00
function TInftGenerator. GenerateIntfName( AIntf: TPasElement) : string ;
2007-03-23 23:22:35 +00:00
begin
2008-08-18 18:19:00 +00:00
Result : = AIntf. Name ; //ExtractserviceName(AIntf);
2007-03-23 23:22:35 +00:00
end ;
procedure TInftGenerator. GenerateUnitHeader( ) ;
begin
SetCurrentStream( FDecStream) ;
WriteLn( '{' ) ;
WriteLn( 'This unit has been produced by ws_helper.' ) ;
2007-06-24 23:33:51 +00:00
WriteLn( ' Input unit name : "%s".' , [ SymbolTable. CurrentModule. Name ] ) ;
2007-03-23 23:22:35 +00:00
WriteLn( ' This unit name : "%s".' , [ GetDestUnitName( ) ] ) ;
WriteLn( ' Date : "%s".' , [ DateTimeToStr( Now( ) ) ] ) ;
WriteLn( '}' ) ;
WriteLn( 'unit %s;' , [ GetDestUnitName( ) ] ) ;
2007-08-19 00:29:43 +00:00
WriteLn( '{$IFDEF FPC}' ) ;
WriteLn( ' {$mode objfpc} {$H+}' ) ;
WriteLn( '{$ENDIF}' ) ;
WriteLn( '{$IFNDEF FPC}' ) ;
WriteLn( ' {$DEFINE WST_RECORD_RTTI}' ) ;
WriteLn( '{$ENDIF}' ) ;
2007-03-23 23:22:35 +00:00
WriteLn( 'interface' ) ;
WriteLn( '' ) ;
WriteLn( 'uses SysUtils, Classes, TypInfo, base_service_intf, service_intf;' ) ;
WriteLn( '' ) ;
WriteLn( 'const' ) ;
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( 'sNAME_SPACE = %s;' , [ QuotedStr( SymbolTable. GetExternalName( FSymbolTable. CurrentModule) ) ] ) ;
Indent( ) ; WriteLn( 'sUNIT_NAME = %s;' , [ QuotedStr( FSymbolTable. CurrentModule. Name ) ] ) ;
2007-03-23 23:22:35 +00:00
DecIndent( ) ;
WriteLn( '' ) ;
WriteLn( 'type' ) ;
WriteLn( '' ) ;
end ;
procedure TInftGenerator. GenerateUnitImplementationHeader( ) ;
begin
SetCurrentStream( FImpStream) ;
WriteLn( '' ) ;
WriteLn( 'Implementation' ) ;
2007-08-19 00:29:43 +00:00
WriteLn( 'uses metadata_repository, record_rtti, wst_types;' ) ;
2007-03-23 23:22:35 +00:00
FImpTempStream. WriteLn( 'initialization' ) ;
end ;
procedure TInftGenerator. GenerateUnitImplementationFooter( ) ;
begin
SetCurrentStream( FImpStream) ;
NewLine( ) ;
NewLine( ) ;
FImpTempStream. NewLine( ) ;
2007-04-17 00:52:02 +00:00
FImpLastStream. NewLine( ) ;
FImpLastStream. WriteLn( 'End.' ) ;
2007-03-23 23:22:35 +00:00
end ;
2007-06-24 23:33:51 +00:00
procedure TInftGenerator. GenerateIntf( AIntf: TPasClassType) ;
2007-03-23 23:22:35 +00:00
procedure WriteDec( ) ;
begin
Indent( ) ;
2007-04-26 23:23:41 +00:00
WriteLn( '%s = interface(IInvokable)' , [ GenerateIntfName( AIntf) ] ) ;
2007-04-02 13:19:48 +00:00
if not IsStrEmpty( AIntf. InterfaceGUID) then begin
Indent( ) ; Indent( ) ; WriteLn( '[%s]' , [ QuotedStr( AIntf. InterfaceGUID) ] ) ;
end ;
2007-03-23 23:22:35 +00:00
end ;
2007-06-24 23:33:51 +00:00
procedure WriteMethod( AMthd : TPasProcedure) ;
var
2007-03-23 23:22:35 +00:00
prmCnt, k : Integer ;
2007-06-24 23:33:51 +00:00
prm : TPasArgument;
prms : TList;
begin
2007-03-23 23:22:35 +00:00
Indent( ) ;
2007-06-24 23:33:51 +00:00
prms : = AMthd. ProcType. Args;
prmCnt : = prms. Count;
if AMthd. InheritsFrom( TPasFunction) then begin
2007-03-23 23:22:35 +00:00
Write( 'function ' ) ;
2007-06-24 23:33:51 +00:00
end else begin
Write( 'procedure ' ) ;
end ;
2007-03-23 23:22:35 +00:00
Write( '%s(' , [ AMthd. Name ] ) ;
2007-06-24 23:33:51 +00:00
if ( prmCnt > 0 ) then begin
2007-03-23 23:22:35 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( prmCnt) do begin
prm : = TPasArgument( prms[ k] ) ;
if ( k > 0 ) then
2007-03-23 23:22:35 +00:00
Write( '; ' ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
Write( '%s %s : %s' , [ AccessNames[ prm. Access] , prm. Name , prm. ArgType. Name ] ) ;
end ;
2007-03-23 23:22:35 +00:00
DecIndent( ) ;
NewLine( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
end ;
2007-03-23 23:22:35 +00:00
Write( ')' ) ;
2007-06-24 23:33:51 +00:00
if AMthd. InheritsFrom( TPasFunction) then begin
Write( ':%s' , [ TPasFunctionType( AMthd. ProcType) . ResultEl. ResultType. Name ] ) ;
end ;
2007-03-23 23:22:35 +00:00
WriteLn( ';' ) ;
2007-06-24 23:33:51 +00:00
end ;
2007-03-23 23:22:35 +00:00
procedure WriteMethods( ) ;
2007-06-24 23:33:51 +00:00
var
2007-03-23 23:22:35 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
mbrs : TList;
elt : TPasElement;
2007-03-23 23:22:35 +00:00
begin
2007-06-24 23:33:51 +00:00
IncIndent( ) ;
mbrs : = AIntf. Members;
for k : = 0 to Pred( mbrs. Count) do begin
elt : = TPasElement( mbrs[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteMethod( TPasProcedure( elt) ) ;
end ;
end ;
DecIndent( ) ;
2007-03-23 23:22:35 +00:00
end ;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
IncIndent( ) ;
WriteDec( ) ;
WriteMethods( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
end ;
2007-06-24 23:33:51 +00:00
procedure TInftGenerator. GenerateTypeAlias( ASymbol: TPasAliasType) ;
var
typeModifier : string ;
2007-03-23 23:22:35 +00:00
begin
try
SetCurrentStream( FDecStream) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2007-06-24 23:33:51 +00:00
if ASymbol. InheritsFrom( TPasTypeAliasType) then begin
typeModifier : = 'type ' ;
end else begin
typeModifier : = '' ;
end ;
2007-03-23 23:22:35 +00:00
NewLine( ) ;
IncIndent( ) ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( '%s = %s%s;' , [ ASymbol. Name , typeModifier, ASymbol. DestType. Name ] ) ;
2007-03-23 23:22:35 +00:00
DecIndent( ) ;
except
on e : Exception do
2007-06-24 23:33:51 +00:00
GetLogger. Log( mtError, 'TInftGenerator.GenerateTypeAlias()=' , [ ASymbol. Name , ' ;; ' , e. Message ] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
2007-06-24 23:33:51 +00:00
procedure TInftGenerator. GenerateClass( ASymbol: TPasClassType) ;
2007-03-23 23:22:35 +00:00
var
2007-06-24 23:33:51 +00:00
locClassPropNbr, locOptionalPropsNbr, locArrayPropsNbr, locPropCount : Integer ;
locPropList : TObjectList;
2007-03-23 23:22:35 +00:00
procedure Prepare( ) ;
var
k : Integer ;
2007-06-24 23:33:51 +00:00
elt : TPasElement;
p : TPasProperty;
2007-03-23 23:22:35 +00:00
begin
2007-06-24 23:33:51 +00:00
locPropCount : = 0 ;
2007-03-23 23:22:35 +00:00
locClassPropNbr : = 0 ;
2007-04-17 00:52:02 +00:00
locArrayPropsNbr : = 0 ;
2007-06-24 23:33:51 +00:00
locOptionalPropsNbr : = 0 ;
for k : = 0 to Pred( ASymbol. Members. Count) do begin
elt : = TPasElement( ASymbol. Members[ k] ) ;
if elt. InheritsFrom( TPasProperty) then begin
p : = TPasProperty( elt) ;
locPropList. Add( p) ;
Inc( locPropCount) ;
if SymbolTable. IsOfType( p. VarType, TPasClassType) then
Inc( locClassPropNbr) ;
if SymbolTable. IsOfType( p. VarType, TPasArrayType) then
Inc( locArrayPropsNbr) ;
if AnsiSameText( 'HAS' , Copy( p. StoredAccessorName, 1 , 3 ) ) then
Inc( locOptionalPropsNbr) ;
end ;
2007-03-23 23:22:35 +00:00
end ;
2007-04-17 00:52:02 +00:00
locClassPropNbr : = locClassPropNbr + locArrayPropsNbr;
2007-03-23 23:22:35 +00:00
end ;
procedure WriteDec( ) ;
var
2007-06-24 23:33:51 +00:00
decBuffer, s : string ;
elt : TPasElement;
ultimAnc, trueAncestor : TPasType;
2007-03-23 23:22:35 +00:00
begin
2007-06-24 23:33:51 +00:00
if Assigned( ASymbol. AncestorType) then begin
trueAncestor : = ASymbol. AncestorType;
if trueAncestor. InheritsFrom( TPasUnresolvedTypeRef) then begin
elt : = SymbolTable. FindElement( SymbolTable. GetExternalName( trueAncestor) ) ;
if elt. InheritsFrom( TPasType) then begin
trueAncestor : = TPasType( elt) ;
end ;
end ;
ultimAnc : = GetUltimeType( trueAncestor) ;
if ultimAnc. InheritsFrom( TPasNativeSimpleType) then begin
trueAncestor : = ultimAnc;
end ;
if trueAncestor. InheritsFrom( TPasNativeSimpleType) and
2007-12-29 00:58:19 +00:00
Assigned( TPasNativeSimpleType( trueAncestor) . ExtendableType)
2007-03-23 23:22:35 +00:00
then begin
2007-12-29 00:58:19 +00:00
trueAncestor : = TPasNativeSimpleType( trueAncestor) . ExtendableType;
2007-06-24 23:33:51 +00:00
end ;
s : = Format( '%s' , [ trueAncestor. Name ] ) ;
end else begin
s : = '' ; //'TBaseComplexRemotable';
end ;
if IsStrEmpty( s) then begin
decBuffer : = '' ;
2007-03-23 23:22:35 +00:00
end else begin
2007-06-24 23:33:51 +00:00
decBuffer : = Format( '(%s)' , [ s] ) ;
2007-03-23 23:22:35 +00:00
end ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( '%s = class%s' , [ ASymbol. Name , decBuffer] ) ;
2007-03-23 23:22:35 +00:00
end ;
2007-06-24 23:33:51 +00:00
procedure WritePropertyField( AProp : TPasProperty) ;
2007-03-23 23:22:35 +00:00
begin
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'F%s : %s;' , [ AProp. Name , AProp. VarType. Name ] ) ;
2007-03-23 23:22:35 +00:00
End ;
2007-06-24 23:33:51 +00:00
procedure WriteProperty( AProp : TPasProperty) ;
2007-03-23 23:22:35 +00:00
var
propName, locStore : string ;
begin
propName : = AProp. Name ;
2007-06-24 23:33:51 +00:00
if AnsiSameText( 'True' , AProp. StoredAccessorName) then begin
locStore : = '' ;
end else begin
locStore : = Format( ' stored %s' , [ AProp. StoredAccessorName] ) ;
2007-03-23 23:22:35 +00:00
end ;
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'property %s : %s read F%s write F%s%s;' , [ propName, AProp. VarType. Name , propName, propName, locStore] ) ;
if not AnsiSameText( AProp. Name , SymbolTable. GetExternalName( AProp) ) then begin
2007-04-17 00:52:02 +00:00
FImpLastStream. Indent( ) ;
2007-06-24 23:33:51 +00:00
FImpLastStream. WriteLn( 'GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].RegisterExternalPropertyName(%s,%s);' , [ ASymbol. Name , QuotedStr( AProp. Name ) , QuotedStr( SymbolTable. GetExternalName( AProp) ) ] ) ;
2007-03-23 23:22:35 +00:00
end ;
2007-06-24 23:33:51 +00:00
if SymbolTable. IsAttributeProperty( AProp) then begin
2007-04-17 00:52:02 +00:00
FImpLastStream. Indent( ) ;
FImpLastStream. WriteLn( '%s.RegisterAttributeProperty(%s);' , [ ASymbol. Name , QuotedStr( AProp. Name ) ] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
procedure WriteProperties( ) ;
2007-06-24 23:33:51 +00:00
var
2007-03-23 23:22:35 +00:00
k : Integer ;
2007-06-24 23:33:51 +00:00
p : TPasProperty;
2007-07-07 20:56:01 +00:00
//pt : TPasElement;
2007-03-23 23:22:35 +00:00
begin
2007-06-24 23:33:51 +00:00
if ( locPropCount > 0 ) then begin
2007-03-23 23:22:35 +00:00
Indent( ) ;
WriteLn( 'private' ) ;
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( locPropCount) do begin
p : = TPasProperty( locPropList[ k] ) ;
2007-07-07 20:56:01 +00:00
{ if p. VarType. InheritsFrom( TPasUnresolvedTypeRef) then begin
2007-06-24 23:33:51 +00:00
pt : = SymbolTable. FindElement( SymbolTable. GetExternalName( p. VarType) ) ;
if ( pt < > nil ) and pt. InheritsFrom( TPasType) and ( pt < > p. VarType ) then begin
p. VarType. Release( ) ;
p. VarType : = pt as TPasType;
p. VarType. AddRef( ) ;
end ;
2007-07-07 20:56:01 +00:00
end ; }
2007-03-23 23:22:35 +00:00
WritePropertyField( p) ;
end ;
DecIndent( ) ;
//
2007-06-24 23:33:51 +00:00
if ( locOptionalPropsNbr > 0 ) then begin
2007-03-23 23:22:35 +00:00
Indent( ) ;
WriteLn( 'private' ) ;
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( locPropCount) do begin
p : = TPasProperty( locPropList[ k] ) ;
if AnsiSameText( 'HAS' , Copy( p. StoredAccessorName, 1 , 3 ) ) then begin
2007-03-23 23:22:35 +00:00
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'function %s() : Boolean;' , [ p. StoredAccessorName] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
DecIndent( ) ;
end ;
//
2007-04-17 00:52:02 +00:00
if ( locArrayPropsNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
2007-03-23 23:22:35 +00:00
Indent( ) ;
WriteLn( 'public' ) ;
2007-04-17 00:52:02 +00:00
end ;
2007-06-24 23:33:51 +00:00
if ( locArrayPropsNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
2007-03-23 23:22:35 +00:00
IncIndent( ) ;
2007-04-17 00:52:02 +00:00
Indent( ) ; WriteLn( 'constructor Create();override;' ) ;
DecIndent( ) ;
end ;
2007-06-24 23:33:51 +00:00
if ( locArrayPropsNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
2007-04-17 00:52:02 +00:00
IncIndent( ) ;
Indent( ) ; WriteLn( 'destructor Destroy();override;' ) ;
2007-03-23 23:22:35 +00:00
DecIndent( ) ;
end ;
//
Indent( ) ;
WriteLn( 'published' ) ;
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
For k : = 0 To Pred( locPropCount) Do
WriteProperty( TPasProperty( locPropList[ k] ) ) ;
2007-03-23 23:22:35 +00:00
DecIndent( ) ;
end ;
end ;
procedure WriteImp( ) ;
var
k : Integer ;
2007-06-24 23:33:51 +00:00
p : TPasProperty;
ss : string ;
2007-08-13 15:50:55 +00:00
pte : TPasElement;
pt : TPasType;
2007-03-23 23:22:35 +00:00
begin
2007-06-24 23:33:51 +00:00
if ( locClassPropNbr > 0 ) then begin
2007-03-23 23:22:35 +00:00
NewLine( ) ;
WriteLn( '{ %s }' , [ ASymbol. Name ] ) ;
2007-06-24 23:33:51 +00:00
if ( locClassPropNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
2007-04-17 00:52:02 +00:00
NewLine( ) ;
WriteLn( 'constructor %s.Create();' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ;
WriteLn( 'inherited Create();' ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( locPropCount) do begin
p : = TPasProperty( locPropList[ k] ) ;
if SymbolTable. IsOfType( p. VarType, TPasClassType) or
SymbolTable. IsOfType( p. VarType, TPasArrayType)
then begin
2007-04-17 00:52:02 +00:00
Indent( ) ;
2007-06-24 23:33:51 +00:00
if AnsiSameText( p. Name , p. VarType. Name ) or
( SymbolTable. IsOfType( p. VarType, TPasClassType) and Assigned( FindMember( TPasClassType( ASymbol) , p. VarType. Name ) ) )
then
ss : = Format( '%s.%s' , [ SymbolTable. CurrentModule. Name , p. VarType. Name ] )
else
ss : = p. VarType. Name ;
WriteLn( 'F%s := %s.Create();' , [ p. Name , ss{p.VarType.Name} ] ) ;
2007-04-17 00:52:02 +00:00
end ;
end ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
end ;
2007-06-24 23:33:51 +00:00
if ( locArrayPropsNbr > 0 ) or ( locClassPropNbr > 0 ) then begin
2007-03-23 23:22:35 +00:00
NewLine( ) ;
WriteLn( 'destructor %s.Destroy();' , [ ASymbol. Name ] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for k : = 0 to Pred( locPropCount) do begin
p : = TPasProperty( locPropList[ k] ) ;
if SymbolTable. IsOfType( p. VarType, TPasClassType) or
SymbolTable. IsOfType( p. VarType, TPasArrayType)
then begin
2007-03-23 23:22:35 +00:00
Indent( ) ;
WriteLn( 'if Assigned(F%s) then' , [ p. Name ] ) ;
IncIndent( ) ;
Indent( ) ;
WriteLn( 'FreeAndNil(F%s);' , [ p. Name ] ) ;
DecIndent( ) ;
end ;
end ;
Indent( ) ;
WriteLn( 'inherited Destroy();' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
end ;
2007-06-24 23:33:51 +00:00
end ;
for k : = 0 to Pred( locPropCount) do begin
p : = TPasProperty( locPropList[ k] ) ;
if AnsiSameText( 'HAS' , Copy( p. StoredAccessorName, 1 , 3 ) ) then begin
NewLine( ) ;
WriteLn( 'function %s.%s() : Boolean;' , [ ASymbol. Name , p. StoredAccessorName] ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ;
2007-08-13 15:50:55 +00:00
pte : = FSymbolTable. FindElement( p. VarType. Name ) ;
if ( pte < > nil ) and pte. InheritsFrom( TPasType) then begin
pt : = pte as TPasType;
pt : = GetUltimeType( pt) ;
if pt. InheritsFrom( TPasEnumType) then begin
WriteLn( 'Result := True;' ) ;
end else if pt. InheritsFrom( TPasNativeSimpleType) and
( AnsiPos( 'string' , pt. Name ) > 0 )
then begin
WriteLn( 'Result := ( F%s <> ' '' ' );' , [ p. Name ] ) ;
end else if pt. InheritsFrom( TPasNativeSimpleType) and
( AnsiSameText( pt. Name , 'Single' ) or
AnsiSameText( pt. Name , 'Double' ) or
AnsiSameText( pt. Name , 'Extended' ) or
AnsiSameText( pt. Name , 'Currency' ) or
AnsiSameText( pt. Name , 'Real' ) or
AnsiSameText( pt. Name , 'Comp' )
)
then begin
WriteLn( 'Result := ( F%s <> 0 );' , [ p. Name ] ) ;
2008-12-17 21:29:09 +00:00
end else if pt. InheritsFrom( TPasClassType) then begin
WriteLn( 'Result := ( F%s <> nil );' , [ p. Name ] ) ;
2007-08-13 15:50:55 +00:00
end else begin
WriteLn( 'Result := ( F%s <> %s(0) );' , [ p. Name , p. VarType. Name ] ) ;
end ;
end else begin
WriteLn( 'Result := ( F%s <> %s(0) );' , [ p. Name , p. VarType. Name ] ) ;
end ;
2007-06-24 23:33:51 +00:00
DecIndent( ) ;
WriteLn( 'end;' ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
end ;
begin
2007-06-24 23:33:51 +00:00
locPropList : = TObjectList. Create( False ) ;
2007-03-23 23:22:35 +00:00
try
2007-06-24 23:33:51 +00:00
Prepare( ) ;
try
SetCurrentStream( FDecStream) ;
NewLine( ) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2007-06-24 23:33:51 +00:00
IncIndent( ) ;
WriteDec( ) ;
WriteProperties( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
2007-03-23 23:22:35 +00:00
2007-06-24 23:33:51 +00:00
FImpTempStream. Indent( ) ;
FImpTempStream. WriteLn( 'GetTypeRegistry().Register(%s,TypeInfo(%s),%s);' , [ sNAME_SPACE, ASymbol. Name , QuotedStr( SymbolTable. GetExternalName( ASymbol) ) ] ) ;
SetCurrentStream( FImpStream) ;
WriteImp( ) ;
except
on e : Exception do begin
GetLogger. Log( mtError, 'TInftGenerator.GenerateClass()=' , [ ASymbol. Name , ' ;; ' , e. Message ] ) ;
raise ;
end ;
end ;
finally
FreeAndNil( locPropList) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
2007-06-24 23:33:51 +00:00
procedure TInftGenerator. GenerateEnum( ASymbol: TPasEnumType) ;
2007-03-23 23:22:35 +00:00
var
2007-06-24 23:33:51 +00:00
itm : TPasEnumValue;
2007-03-23 23:22:35 +00:00
i : Integer ;
begin
try
SetCurrentStream( FDecStream) ;
NewLine( ) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2007-03-23 23:22:35 +00:00
IncIndent( ) ;
Indent( ) ; WriteLn( '%s = ( ' , [ ASymbol. Name ] ) ;
FImpTempStream. Indent( ) ;
2007-06-24 23:33:51 +00:00
FImpTempStream. WriteLn( 'GetTypeRegistry().Register(%s,TypeInfo(%s),%s);' , [ sNAME_SPACE, ASymbol. Name , QuotedStr( SymbolTable. GetExternalName( ASymbol) ) ] ) ;
2007-03-23 23:22:35 +00:00
IncIndent( ) ;
2007-06-24 23:33:51 +00:00
for i : = 0 to Pred( ASymbol. Values. Count) do begin
itm : = TPasEnumValue( ASymbol. Values[ i] ) ;
2007-03-23 23:22:35 +00:00
Indent( ) ;
if ( i > 0 ) then
WriteLn( ',%s' , [ itm. Name ] )
else
WriteLn( '%s' , [ itm. Name ] ) ;
2008-06-26 15:06:00 +00:00
if SymbolTable. HasExternalName( itm) and
( not AnsiSameText( itm. Name , SymbolTable. GetExternalName( itm, False ) ) )
then begin
2007-03-23 23:22:35 +00:00
FImpTempStream. Indent( ) ;
2008-06-26 15:06:00 +00:00
FImpTempStream. WriteLn( 'GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].RegisterExternalPropertyName(%s,%s);' , [ ASymbol. Name , QuotedStr( itm. Name ) , QuotedStr( SymbolTable. GetExternalName( itm, False ) ) ] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
DecIndent( ) ;
Indent( ) ; WriteLn( ');' ) ;
DecIndent( ) ;
except
on e : Exception do
2007-06-24 23:33:51 +00:00
GetLogger. Log( mtError, 'TInftGenerator.GenerateClass()=' , [ ASymbol. Name , ' ;; ' , e. Message ] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
2007-06-24 23:33:51 +00:00
procedure TInftGenerator. GenerateArray( ASymbol: TPasArrayType) ;
2007-03-23 23:22:35 +00:00
var
classItemArray : Boolean ;
2007-06-24 23:33:51 +00:00
eltType : TPasType;
2007-03-23 23:22:35 +00:00
begin
2007-06-24 23:33:51 +00:00
eltType : = ASymbol. ElType;
if eltType. InheritsFrom( TPasUnresolvedTypeRef) then begin
eltType : = SymbolTable. FindElement( SymbolTable. GetExternalName( eltType) ) as TPasType;
end ;
classItemArray : = SymbolTable. IsOfType( eltType, TPasClassType) or SymbolTable. IsOfType( eltType, TPasArrayType) ;
2007-03-23 23:22:35 +00:00
if classItemArray then begin
2008-08-01 21:38:55 +00:00
if FSymbolTable. IsCollection( ASymbol) then
WriteObjectCollection( ASymbol)
else
WriteObjectArray( ASymbol) ;
2007-03-23 23:22:35 +00:00
end else begin
2008-08-01 21:38:55 +00:00
WriteSimpleTypeArray( ASymbol) ;
2007-03-23 23:22:35 +00:00
end ;
2007-06-24 23:33:51 +00:00
2007-03-23 23:22:35 +00:00
FImpTempStream. Indent( ) ;
2007-06-24 23:33:51 +00:00
FImpTempStream. WriteLn( 'GetTypeRegistry().Register(%s,TypeInfo(%s),%s);' , [ sNAME_SPACE, ASymbol. Name , QuotedStr( SymbolTable. GetExternalName( ASymbol) ) ] ) ;
if ( SymbolTable. GetArrayItemName( ASymbol) < > SymbolTable. GetArrayItemExternalName( ASymbol) ) then begin
2007-04-02 13:19:48 +00:00
FImpTempStream. Indent( ) ;
FImpTempStream. WriteLn(
'GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].RegisterExternalPropertyName(sARRAY_ITEM,%s);' ,
2007-06-24 23:33:51 +00:00
[ ASymbol. Name , QuotedStr( SymbolTable. GetArrayItemExternalName( ASymbol) ) ]
2007-04-02 13:19:48 +00:00
) ;
end ;
2007-06-24 23:33:51 +00:00
if ( SymbolTable. GetArrayStyle( ASymbol) = asEmbeded ) then begin
2007-04-02 13:19:48 +00:00
FImpTempStream. Indent( ) ;
2007-03-25 23:47:16 +00:00
FImpTempStream. WriteLn(
2007-04-02 13:19:48 +00:00
'GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].RegisterExternalPropertyName(sARRAY_STYLE,sEmbedded);' ,
2007-06-24 23:33:51 +00:00
[ ASymbol. Name , QuotedStr( SymbolTable. GetArrayItemExternalName( ASymbol) ) ]
2007-03-25 23:47:16 +00:00
) ;
end ;
end ;
2007-08-19 00:29:43 +00:00
procedure TInftGenerator. GenerateRecord( ASymbol : TPasRecordType) ;
var
strFieldList : string ;
procedure WriteDec( ) ;
var
itm : TPasVariable;
i : PtrInt;
begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
2008-08-18 18:19:00 +00:00
WriteDocIfEnabled( ASymbol) ;
2007-08-19 00:29:43 +00:00
IncIndent( ) ;
Indent( ) ; WriteLn( '%s = record' , [ ASymbol. Name ] ) ;
IncIndent( ) ;
strFieldList : = '' ;
for i : = 0 to Pred( ASymbol. Members. Count) do begin
itm : = TPasVariable( ASymbol. Members[ i] ) ;
Indent( ) ;
WriteLn( '%s : %s;' , [ itm. Name , itm. VarType. Name ] ) ;
if ( i > 0 ) then
strFieldList : = Format( '%s;%s' , [ strFieldList, itm. Name ] )
else
strFieldList : = itm. Name ;
end ;
DecIndent( ) ;
Indent( ) ; WriteLn( 'end;' ) ;
DecIndent( ) ;
end ;
procedure WriteRTTI( ) ;
var
itm : TPasVariable;
k, c : PtrInt;
offsetLine, typeLine : string ;
begin
SetCurrentStream( FRttiFunc) ;
NewLine( ) ;
WriteLn( '{$IFDEF %s}' , [ sRECORD_RTTI_DEFINE] ) ;
WriteLn( 'function __%s_TYPEINFO_FUNC__() : PTypeInfo;' , [ ASymbol. Name ] ) ;
WriteLn( 'var' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'p : ^%s;' , [ ASymbol. Name ] ) ;
Indent( ) ; WriteLn( 'r : %s;' , [ ASymbol. Name ] ) ;
DecIndent( ) ;
WriteLn( 'begin' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'p := @r;' ) ;
Indent( ) ; WriteLn( 'Result := MakeRawTypeInfo(' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( ASymbol. Name ) ] ) ;
Indent( ) ; WriteLn( 'SizeOf(%s),' , [ ASymbol. Name ] ) ;
offsetLine : = '[ ' ;
typeLine : = '[ ' ;
c : = ASymbol. Members. Count;
if ( c > 0 ) then begin
k : = 1 ;
itm : = TPasVariable( ASymbol. Members[ ( k- 1 ) ] ) ;
offsetLine : = offsetLine + Format( 'PtrUInt(@(p^.%s)) - PtrUInt(p)' , [ itm. Name ] ) ;
typeLine : = typeLine + Format( 'TypeInfo(%s)' , [ itm. VarType. Name ] ) ;
Inc( k) ;
for k : = k to c do begin
itm : = TPasVariable( ASymbol. Members[ ( k- 1 ) ] ) ;
offsetLine : = offsetLine + Format( ', PtrUInt(@(p^.%s)) - PtrUInt(p)' , [ itm. Name ] ) ;
typeLine : = typeLine + Format( ', TypeInfo(%s)' , [ itm. VarType. Name ] ) ;
end ;
end ;
offsetLine : = offsetLine + ' ]' ;
typeLine : = typeLine + ' ]' ;
Indent( ) ; WriteLn( '%s,' , [ offsetLine] ) ;
Indent( ) ; WriteLn( '%s' , [ typeLine] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( ');' ) ;
DecIndent( ) ;
WriteLn( 'end;' ) ;
WriteLn( '{$ENDIF %s}' , [ sRECORD_RTTI_DEFINE] ) ;
end ;
2007-08-21 22:14:13 +00:00
procedure WriteAttributeProperties( ) ;
var
itm : TPasVariable;
k, c : PtrInt;
begin
c : = ASymbol. Members. Count;
for k : = 0 to Pred( c) do begin
itm : = TPasVariable( ASymbol. Members[ k] ) ;
if SymbolTable. IsAttributeProperty( itm) then begin
Indent( ) ;
WriteLn( 'RegisterAttributeProperty(TypeInfo(%s),%s);' , [ ASymbol. Name , QuotedStr( itm. Name ) ] ) ;
end ;
end ;
end ;
2007-08-19 00:29:43 +00:00
var
s : string ;
begin
try
WriteDec( ) ;
WriteRTTI( ) ;
SetCurrentStream( FImpLastStream) ;
NewLine( ) ;
Indent( ) ;
WriteLn(
'GetTypeRegistry().Register(%s,TypeInfo(%s),%s).RegisterExternalPropertyName(%s,%s);' ,
[ sNAME_SPACE, ASymbol. Name , QuotedStr( SymbolTable. GetExternalName( ASymbol) ) ,
QuotedStr( Format( '__FIELDS__' , [ ASymbol. Name ] ) ) , QuotedStr( strFieldList)
]
) ;
s : = 'GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)]' +
'.RegisterObject(' +
'FIELDS_STRING,' +
'TRecordRttiDataObject.Create(' +
'MakeRecordTypeInfo(%s),' +
'GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].GetExternalPropertyName(' '__FIELDS__' ')' +
')' +
');' ;
WriteLn( '{$IFNDEF %s}' , [ sRECORD_RTTI_DEFINE] ) ;
Indent( ) ; WriteLn( s, [ ASymbol. Name , Format( 'TypeInfo(%s)' , [ ASymbol. Name ] ) , ASymbol. Name ] ) ;
WriteLn( '{$ENDIF %s}' , [ sRECORD_RTTI_DEFINE] ) ;
WriteLn( '{$IFDEF %s}' , [ sRECORD_RTTI_DEFINE] ) ;
Indent( ) ; WriteLn( s, [ ASymbol. Name , Format( '__%s_TYPEINFO_FUNC__()' , [ ASymbol. Name ] ) , ASymbol. Name ] ) ;
WriteLn( '{$ENDIF %s}' , [ sRECORD_RTTI_DEFINE] ) ;
2007-08-21 22:14:13 +00:00
WriteAttributeProperties( ) ;
2007-08-19 00:29:43 +00:00
SetCurrentStream( FDecStream) ;
except
on e : Exception do
GetLogger. Log( mtError, 'TInftGenerator.GenerateRecord()=' , [ ASymbol. Name , ' ;; ' , e. Message ] ) ;
end ;
end ;
2007-03-25 23:47:16 +00:00
procedure TInftGenerator. GenerateCustomMetadatas( ) ;
2007-06-24 23:33:51 +00:00
procedure WriteOperationDatas( AInftDef : TPasClassType; AOp : TPasProcedure) ;
2007-03-25 23:47:16 +00:00
var
k : Integer ;
pl : TStrings;
begin
2007-06-24 23:33:51 +00:00
pl : = SymbolTable. Properties. FindList( AOp) ;
if ( pl < > nil ) then begin
for k : = 0 to Pred( pl. Count) do begin
if not IsStrEmpty( pl. ValueFromIndex[ k] ) then begin
Indent( ) ; WriteLn( 'mm.SetOperationCustomData(' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s,' , [ sUNIT_NAME] ) ;
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( AInftDef. Name ) ] ) ;
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( AOp. Name ) ] ) ;
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( pl. Names[ k] ) ] ) ;
Indent( ) ; WriteLn( '%s' , [ QuotedStr( pl. ValueFromIndex[ k] ) ] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( ');' ) ;
end ;
2007-03-25 23:47:16 +00:00
end ;
end ;
end ;
2007-06-24 23:33:51 +00:00
procedure WriteServiceDatas( ABinding : TwstBinding) ;
2007-03-25 23:47:16 +00:00
var
k : Integer ;
2007-06-24 23:33:51 +00:00
opList : TList;
elt : TPasElement;
2007-03-25 23:47:16 +00:00
begin
2007-06-24 23:33:51 +00:00
if not IsStrEmpty( ABinding. Address) then begin
2007-03-25 23:47:16 +00:00
Indent( ) ; WriteLn( 'mm.SetServiceCustomData(' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s,' , [ sUNIT_NAME] ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( ABinding. Intf. Name ) ] ) ;
2007-04-26 23:23:41 +00:00
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( 'TRANSPORT_Address' ) ] ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( '%s' , [ QuotedStr( ABinding. Address) ] ) ;
2007-03-25 23:47:16 +00:00
DecIndent( ) ;
Indent( ) ; WriteLn( ');' ) ;
end ;
2007-04-12 00:48:00 +00:00
2007-06-24 23:33:51 +00:00
if ( ABinding. BindingStyle = bsRPC ) then begin
2007-04-12 00:48:00 +00:00
Indent( ) ; WriteLn( 'mm.SetServiceCustomData(' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s,' , [ sUNIT_NAME] ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( ABinding. Intf. Name ) ] ) ;
2007-04-26 23:23:41 +00:00
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( 'FORMAT_Style' ) ] ) ;
2007-04-12 00:48:00 +00:00
Indent( ) ; WriteLn( '%s' , [ QuotedStr( 'rpc' ) ] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( ');' ) ;
2007-06-24 23:33:51 +00:00
end else if ( ABinding. BindingStyle = bsDocument ) then begin
2007-04-17 00:52:02 +00:00
Indent( ) ; WriteLn( 'mm.SetServiceCustomData(' ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( '%s,' , [ sUNIT_NAME] ) ;
2007-06-24 23:33:51 +00:00
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( ABinding. Intf. Name ) ] ) ;
2007-04-26 23:23:41 +00:00
Indent( ) ; WriteLn( '%s,' , [ QuotedStr( 'FORMAT_Style' ) ] ) ;
2007-04-17 00:52:02 +00:00
Indent( ) ; WriteLn( '%s' , [ QuotedStr( 'document' ) ] ) ;
DecIndent( ) ;
Indent( ) ; WriteLn( ');' ) ;
2007-04-12 00:48:00 +00:00
end ;
2007-03-25 23:47:16 +00:00
2007-06-24 23:33:51 +00:00
opList : = ABinding. Intf. Members;
for k : = 0 to Pred( opList. Count) do begin
elt : = TPasElement( opList[ k] ) ;
if elt. InheritsFrom( TPasProcedure) then begin
WriteOperationDatas( ABinding. Intf, TPasProcedure( elt) ) ;
end ;
2007-03-25 23:47:16 +00:00
end ;
end ;
var
i : Integer ;
begin
SetCurrentStream( FImpStream) ;
IncIndent( ) ;
NewLine( ) ; NewLine( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( 'procedure Register_%s_ServiceMetadata();' , [ SymbolTable. CurrentModule. Name ] ) ;
2007-03-25 23:47:16 +00:00
WriteLn( 'var' ) ;
Indent( ) ; WriteLn( 'mm : IModuleMetadataMngr;' ) ;
WriteLn( 'begin' ) ;
Indent( ) ; WriteLn( 'mm := GetModuleMetadataMngr();' ) ;
Indent( ) ; WriteLn( 'mm.SetRepositoryNameSpace(%s, %s);' , [ sUNIT_NAME, sNAME_SPACE] ) ;
2007-06-24 23:33:51 +00:00
for i : = 0 to Pred( SymbolTable. BindingCount) do begin
WriteServiceDatas( SymbolTable. Binding[ i] ) ;
2007-03-25 23:47:16 +00:00
end ;
WriteLn( 'end;' ) ;
DecIndent( ) ;
2007-03-23 23:22:35 +00:00
end ;
function TInftGenerator. GetDestUnitName( ) : string ;
begin
2007-06-24 23:33:51 +00:00
Result : = SymbolTable. CurrentModule. Name ;
2007-03-23 23:22:35 +00:00
end ;
2007-09-09 22:30:50 +00:00
procedure TInftGenerator. InternalExecute( ) ;
2007-09-02 19:05:47 +00:00
procedure SortRecords( AList : TList) ;
var
j, k : PtrInt;
ordr_ls, mbrLs, locLs : TList;
locMemberType : TPasType;
rec, locRec : TPasRecordType;
locStack : TStack;
locElt : TPasElement;
begin
if ( AList. Count > 0 ) then begin
locStack : = nil ;
locLs : = nil ;
ordr_ls : = TList. Create( ) ;
try
locStack : = TStack. Create( ) ;
locLs : = TList. Create( ) ;
for j : = 0 to Pred( AList. Count) do begin
rec : = TPasRecordType( AList[ j] ) ;
if ( ordr_ls. IndexOf( rec) = - 1 ) then begin
locStack. Push( rec) ;
while locStack. AtLeast( 1 ) do begin
locLs. Clear( ) ;
locRec : = TPasRecordType( locStack. Pop( ) ) ;
if ( ordr_ls. IndexOf( locRec) = - 1 ) then begin
mbrLs : = locRec. Members;
for k : = 0 to Pred( mbrLs. Count) do begin
locMemberType : = TPasVariable( mbrLs[ k] ) . VarType;
if locMemberType. InheritsFrom( TPasUnresolvedTypeRef) then begin
locElt : = SymbolTable. FindElement( SymbolTable. GetExternalName( locMemberType) ) ;
if Assigned( locElt) and locElt. InheritsFrom( TPasType) then begin
locMemberType : = locElt as TPasType;
end ;
end ;
if locMemberType. InheritsFrom( TPasRecordType) then begin
if ( ordr_ls. IndexOf( locMemberType) = - 1 ) then
locLs. Add( locMemberType) ;
end ;
end ; //for
if ( locLs. Count > 0 ) then begin
locStack. Push( locRec) ;
for k : = 0 to Pred( locLs. Count) do begin
locStack. Push( locLs[ k] ) ;
end ;
end else begin
ordr_ls. Add( locRec) ;
end ;
end ;
end ;
end ;
end ;
Assert( not locStack. AtLeast( 1 ) ) ;
AList. Clear( ) ;
for k : = 0 to Pred( ordr_ls. Count) do begin
AList. Add( ordr_ls[ k] ) ;
end ;
finally
FreeAndNil( locLs) ;
FreeAndNil( locStack) ;
FreeAndNil( ordr_ls) ;
end ;
end ;
end ;
2007-03-23 23:22:35 +00:00
var
2007-08-19 00:29:43 +00:00
i, c, j, k : PtrInt;
2007-06-24 23:33:51 +00:00
clssTyp : TPasClassType;
2007-03-23 23:22:35 +00:00
gnrClssLst : TObjectList;
objLst : TObjectList;
2007-06-24 23:33:51 +00:00
typeList : TList;
elt : TPasElement;
classAncestor : TPasElement;
2007-09-02 19:05:47 +00:00
tmpList : TList;
2007-09-09 22:30:50 +00:00
intfCount : PtrInt;
2008-07-03 16:15:03 +00:00
locBinding : TwstBinding;
2007-03-23 23:22:35 +00:00
begin
2007-09-09 22:30:50 +00:00
intfCount : = 0 ;
2007-03-23 23:22:35 +00:00
objLst : = nil ;
2007-09-02 19:05:47 +00:00
tmpList : = nil ;
2007-03-23 23:22:35 +00:00
gnrClssLst : = TObjectList. Create( False ) ;
try
GenerateUnitHeader( ) ;
GenerateUnitImplementationHeader( ) ;
2007-07-12 14:46:45 +00:00
typeList : = SymbolTable. CurrentModule. InterfaceSection. Declarations;
2007-06-24 23:33:51 +00:00
c : = Pred( typeList. Count) ;
2007-03-23 23:22:35 +00:00
SetCurrentStream( FDecStream) ;
IncIndent( ) ;
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasUnresolvedTypeRef) then begin
WriteLn( '// %s = unable to resolve this symbol.' , [ elt. Name ] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
DecIndent( ) ;
IncIndent( ) ;
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasType) and
( not elt. InheritsFrom( TPasAliasType) ) and
( ( SymbolTable. IsOfType( TPasType( elt) , TPasClassType) and ( TPasClassType( GetUltimeType( TPasType( elt) ) ) . ObjKind = okClass ) ) or
SymbolTable. IsOfType( TPasType( elt) , TPasArrayType)
)
2007-03-23 23:22:35 +00:00
then begin
Indent( ) ;
2007-06-24 23:33:51 +00:00
WriteLn( '%s = class;' , [ elt. Name ] ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
DecIndent( ) ;
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasEnumType) then begin
GenerateEnum( TPasEnumType( elt) ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
2007-09-02 19:05:47 +00:00
tmpList : = TList. Create( ) ;
2007-08-19 00:29:43 +00:00
for i : = 0 to c do begin
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasRecordType) then begin
2007-09-02 19:05:47 +00:00
tmpList. Add( elt) ;
end ;
end ;
if ( tmpList. Count > 0 ) then begin
SortRecords( tmpList) ;
for i : = 0 to Pred( tmpList. Count) do begin
GenerateRecord( TPasRecordType( tmpList[ i] ) ) ;
2007-08-19 00:29:43 +00:00
end ;
end ;
2007-03-23 23:22:35 +00:00
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasAliasType) then begin
GenerateTypeAlias( TPasAliasType( elt) ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
objLst : = TObjectList. Create( ) ;
objLst. OwnsObjects : = False ;
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasClassType) and ( TPasClassType( elt) . ObjKind = okClass ) then begin
clssTyp : = TPasClassType( elt) ;
2007-03-23 23:22:35 +00:00
if ( gnrClssLst. IndexOf( clssTyp) = - 1 ) then begin
2007-09-02 19:05:47 +00:00
objLst. Clear( ) ;
2007-03-23 23:22:35 +00:00
while Assigned( clssTyp) do begin
objLst. Add( clssTyp) ;
2007-06-24 23:33:51 +00:00
classAncestor : = clssTyp. AncestorType;
if Assigned( classAncestor) and classAncestor. InheritsFrom( TPasUnresolvedTypeRef) then begin
classAncestor : = SymbolTable. FindElement( SymbolTable. GetExternalName( classAncestor) ) ;
end ;
if Assigned( classAncestor) and classAncestor. InheritsFrom( TPasClassType) then begin
clssTyp : = classAncestor as TPasClassType;
2007-03-23 23:22:35 +00:00
end else begin
clssTyp : = nil ;
end ;
end ;
k : = Pred( objLst. Count) ;
for j : = 0 to k do begin
2007-06-24 23:33:51 +00:00
clssTyp : = objLst[ k- j] as TPasClassType;
2007-03-23 23:22:35 +00:00
if ( gnrClssLst. IndexOf( clssTyp) = - 1 ) then begin
2007-07-12 14:46:45 +00:00
if ( FSymbolTable. CurrentModule. InterfaceSection. Declarations. IndexOf( clssTyp) < > - 1 ) then begin
2007-03-23 23:22:35 +00:00
GenerateClass( clssTyp) ;
gnrClssLst. Add( clssTyp) ;
end ;
end ;
end ;
end ;
end ;
end ;
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasArrayType) then begin
GenerateArray( TPasArrayType( elt) ) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
for i : = 0 to c do begin
2007-06-24 23:33:51 +00:00
elt : = TPasElement( typeList[ i] ) ;
if elt. InheritsFrom( TPasClassType) and ( TPasClassType( elt) . ObjKind = okInterface ) then begin
GenerateIntf( TPasClassType( elt) ) ;
2007-09-09 22:30:50 +00:00
Inc( intfCount) ;
2007-03-23 23:22:35 +00:00
end ;
end ;
2008-07-03 16:15:03 +00:00
if ( goDocumentWrappedParameter in Self. Options ) then begin
c : = FSymbolTable. BindingCount;
if ( c > 0 ) then begin
for i : = 0 to ( c - 1 ) do begin
locBinding : = FSymbolTable. Binding[ i] ;
if ( locBinding. BindingStyle = bsDocument ) then begin
clssTyp : = DeduceEasyInterfaceForDocStyle( locBinding. Intf, FSymbolTable) ;
try
GenerateIntf( clssTyp) ;
finally
clssTyp. Release( ) ;
end ;
end ;
end ;
end ;
end ;
2007-09-09 22:30:50 +00:00
if ( intfCount > 0 ) then begin
SetCurrentStream( FDecStream) ;
NewLine( ) ;
IncIndent( ) ;
Indent( ) ; WriteLn( 'procedure Register_%s_ServiceMetadata();' , [ SymbolTable. CurrentModule. Name ] ) ;
DecIndent( ) ;
GenerateCustomMetadatas( ) ;
end ;
2007-08-19 00:29:43 +00:00
FImpLastStream. NewLine( ) ;
2007-03-23 23:22:35 +00:00
GenerateUnitImplementationFooter( ) ;
2007-08-19 00:29:43 +00:00
FSrcMngr. Merge( GetDestUnitName( ) + '.pas' , [ FDecStream, FImpStream, FRttiFunc, FImpTempStream, FImpLastStream] ) ;
2007-03-23 23:22:35 +00:00
FDecStream : = nil ;
FImpStream : = nil ;
FImpTempStream : = nil ;
2008-12-17 21:29:09 +00:00
FRttiFunc : = nil ;
FImpLastStream : = nil ;
2007-03-23 23:22:35 +00:00
finally
2007-09-02 19:05:47 +00:00
FreeAndNil( tmpList) ;
2007-03-23 23:22:35 +00:00
FreeAndNil( objLst) ;
FreeAndNil( gnrClssLst) ;
end ;
end ;
2007-09-09 22:30:50 +00:00
procedure TInftGenerator. PrepareModule( ) ;
begin
FDecStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.dec' ) ;
FImpStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.imp' ) ;
FImpTempStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.tmp_imp' ) ;
FImpLastStream : = SrcMngr. CreateItem( GetDestUnitName( ) + '.tmp_imp_last' ) ;
FRttiFunc : = SrcMngr. CreateItem( GetDestUnitName( ) + '.tmp_rtti_func' ) ;
FImpTempStream. IncIndent( ) ;
FImpLastStream. IncIndent( ) ;
end ;
procedure TInftGenerator. Execute( ) ;
var
oldCurrent, mdl : TPasModule;
i : PtrInt;
mdlList : TList;
begin
oldCurrent : = SymbolTable. CurrentModule;
try
mdlList : = SymbolTable. Package . Modules;
for i : = 0 to Pred( mdlList. Count) do begin
mdl : = TPasModule( mdlList[ i] ) ;
if not mdl. InheritsFrom( TPasNativeModule) then begin
SymbolTable. SetCurrentModule( mdl) ;
PrepareModule( ) ;
InternalExecute( ) ;
end ;
end ;
finally
SymbolTable. SetCurrentModule( oldCurrent) ;
end ;
end ;
2006-08-26 00:35:42 +00:00
end .