Thread: [Qtcsharp-patches] Bugtussle/src/Writers CWriter.cs,1.9,1.10 KylixWriter.cs,1.9,1.10
Status: Inactive
Brought to you by:
manyoso
|
From: Andreas H. <ah...@us...> - 2004-10-01 11:33:43
|
Update of /cvsroot/qtcsharp/Bugtussle/src/Writers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15328/src/Writers Modified Files: CWriter.cs KylixWriter.cs Log Message: Changed overrideHooks with Value return type. Index: KylixWriter.cs =================================================================== RCS file: /cvsroot/qtcsharp/Bugtussle/src/Writers/KylixWriter.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** KylixWriter.cs 21 Sep 2004 16:57:44 -0000 1.9 --- KylixWriter.cs 1 Oct 2004 11:33:31 -0000 1.10 *************** *** 209,213 **** //cw.WriteLine(" {$DEFINE QSW} // extended WideString support is disabled due to a method-implementation bug (fpc 1.9.5)"); cw.WriteLine("{$ELSE}"); ! cw.WriteLine(" {$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}"); if(weakPackageUnit) cw.WriteLine(" {$WEAKPACKAGEUNIT ON}"); --- 209,213 ---- //cw.WriteLine(" {$DEFINE QSW} // extended WideString support is disabled due to a method-implementation bug (fpc 1.9.5)"); cw.WriteLine("{$ELSE}"); ! cw.WriteLine(" {$A4,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}"); if(weakPackageUnit) cw.WriteLine(" {$WEAKPACKAGEUNIT ON}"); *************** *** 836,845 **** cw.Indent++; } - // free pascal has a bug that requires the class methods to be listed first - /*foreach(Method m in methodList) - if(!m.Name.StartsWith( "operator" ) && m.Static) - if( m.VirtualKind != VirtualKind.Override) - CreatePascalMethod(m, null, c, methodSignatures, false, "public_", inInterfaceSection); - */ foreach(Method m in methodList) if(!m.Name.StartsWith( "operator" ) /*&& !m.Static*/) --- 836,839 ---- *************** *** 858,866 **** cw.Indent++; } - /*foreach(Method m in methodList) - if (!m.Name.StartsWith( "operator") && m.Static) - if (m.VirtualKind != VirtualKind.Override) - CreatePascalMethod(m, null, c, methodSignatures, false, "", inInterfaceSection); - */ foreach(Method m in methodList) if(!m.Name.StartsWith( "operator") /*&& !m.Static*/) --- 852,855 ---- *************** *** 900,904 **** } - private void WriteDestructor(Class c, bool inInterfaceSection) { --- 889,892 ---- *************** *** 1057,1062 **** // paramstr = "; " + paramstr; sb = new StringBuilder(); ! Function cfunc = Function.GetValueRetFunction(m); ! if(cfunc.ReturnType.IsVoidValue) sb.Append("procedure"); else --- 1045,1049 ---- // paramstr = "; " + paramstr; sb = new StringBuilder(); ! if(m.ReturnType.IsVoidValue) sb.Append("procedure"); else *************** *** 1064,1069 **** //sb.AppendFormat("(Handle: {0}H{1})", rfullname, paramstr); sb.AppendFormat("({0})", paramstr); ! if(!cfunc.ReturnType.IsVoidValue) ! sb.AppendFormat(": {0}", TypeReferenceToString(cfunc.ReturnType, false, c)); //sb.Append("; cdecl"); sb.Append(" of object; cdecl"); --- 1051,1056 ---- //sb.AppendFormat("(Handle: {0}H{1})", rfullname, paramstr); sb.AppendFormat("({0})", paramstr); ! if(!m.ReturnType.IsVoidValue) ! sb.AppendFormat(": {0}", TypeReferenceToString(m.ReturnType, false, c)); //sb.Append("; cdecl"); sb.Append(" of object; cdecl"); *************** *** 2161,2166 **** // create function prototype for "m" string paramstr = ParametersToString(m.GetParameters(), ParameterStyle.DelphiNoDefaultDeclaration, c, false); ! if (paramstr != "") ! paramstr = "; " + paramstr; sb = new StringBuilder(); Function cfunc = Function.GetValueRetFunction(m); --- 2148,2153 ---- // create function prototype for "m" string paramstr = ParametersToString(m.GetParameters(), ParameterStyle.DelphiNoDefaultDeclaration, c, false); ! //if (paramstr != "") ! // paramstr = "; " + paramstr; sb = new StringBuilder(); Function cfunc = Function.GetValueRetFunction(m); *************** *** 2169,2177 **** else sb.Append("function"); ! sb.AppendFormat("(SignalHook: {0}{1})", GetSignalHookClassName(c), paramstr); if(!cfunc.ReturnType.IsVoidValue) sb.AppendFormat(": {0}", TypeReferenceToString(cfunc.ReturnType, false, c)); ! sb.Append("; cdecl"); ! cw.WriteLine("TSignalHookType{0}_{1} = {2};", rfullname, m.UniqueName, sb); } --- 2156,2165 ---- else sb.Append("function"); ! //sb.AppendFormat("(SignalHook: {0}{1})", GetSignalHookClassName(c), paramstr); ! sb.AppendFormat("({0})", paramstr); if(!cfunc.ReturnType.IsVoidValue) sb.AppendFormat(": {0}", TypeReferenceToString(cfunc.ReturnType, false, c)); ! sb.Append(" of object"); ! cw.WriteLine("TSignalHookType{0}_{1} = {2}; cdecl;", rfullname, m.UniqueName, sb); } *************** *** 2184,2188 **** { string signalName = m.UniqueName; ! cw.WriteLine( "procedure {0}(Hook: TSignalHookType{1}_{0}); cdecl;", signalName, rfullname); } --- 2172,2178 ---- { string signalName = m.UniqueName; ! //cw.WriteLine( "procedure {0}(Hook: TSignalHookType{1}_{0}); cdecl;", ! // signalName, rfullname); ! cw.WriteLine( "procedure {0}(Hook: TSignalHookType{1}_{0});", signalName, rfullname); } *************** *** 2206,2211 **** { string signalName = m.UniqueName; ! cw.WriteLine( "procedure {2}.{0}(Hook: TSignalHookType{1}_{0}); cdecl; external LibWrapper name Prefix+'{3}SignalHook_set{0}';", signalName, rfullname, GetSignalHookClassName(c), c.Name); } cw.WriteLine(); --- 2196,2211 ---- { string signalName = m.UniqueName; ! //cw.WriteLine( "procedure {2}.{0}(Hook: TSignalHookType{1}_{0}); cdecl; external LibWrapper name Prefix+'{3}SignalHook_set{0}';", ! // signalName, rfullname, GetSignalHookClassName(c), c.Name); ! cw.WriteLine( "procedure {2}_{0}(Handle: {2}; Data, Hook: Pointer); cdecl; external LibWrapper name Prefix+'{3}SignalHook_set{0}';", signalName, rfullname, GetSignalHookClassName(c), c.Name); + cw.WriteLine( "procedure {2}.{0}(Hook: TSignalHookType{1}_{0});", + signalName, rfullname, GetSignalHookClassName(c)); + cw.WriteLine("begin"); + cw.Indent++; + cw.WriteLine("{0}_{1}(Self, TMethod(Hook).Data, TMethod(Hook).Code);", GetSignalHookClassName(c), signalName); + cw.Indent--; + cw.WriteLine("end;"); + cw.WriteLine(); } cw.WriteLine(); Index: CWriter.cs =================================================================== RCS file: /cvsroot/qtcsharp/Bugtussle/src/Writers/CWriter.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CWriter.cs 20 Sep 2004 11:42:59 -0000 1.9 --- CWriter.cs 1 Oct 2004 11:33:31 -0000 1.10 *************** *** 332,344 **** constStr = "const"; - /* Templates with a "< type * >" do not work with a "const type &" - parameter. g - cc means that "const type*" and type*" do not match. - The solution is to remove the "const" for this case. */ - /*if ( c == null || - (c is Class && ((Class)c).Template == null) || - typeRef.Mode != PassByMode.ReferenceToPointer ) - sb.Append( "const " );*/ - switch ( typeRef.Mode ) { --- 332,335 ---- *************** *** 701,705 **** /* ANN: method.ExportName is used in the CSharpWriter. Isn't it ! possible to generate this name in the CSharpWriter either. So the CSharpWriter does not depend on the call order of CWriter and CSharpWriter. */ --- 692,696 ---- /* ANN: method.ExportName is used in the CSharpWriter. Isn't it ! possible to generate this name in the CSharpWriter, too. So the CSharpWriter does not depend on the call order of CWriter and CSharpWriter. */ *************** *** 1032,1036 **** // TYPE NAME(PARAMETERS) [const] // { ! // if (overrideHook.NAME) [return] [*/&]overrideHook.NAME(this[, PARAMETERS]); // [else [return] METHODOWNER::Name(PARAMETERS);] // } --- 1023,1033 ---- // TYPE NAME(PARAMETERS) [const] // { ! // if (overrideHook.NAME) [{ ! // RETTYPE returnValue = / return] ! // [*/&]overrideHook.NAME(overrideHookNAMEData[, PARAMETERS]); ! // [RETTYPE returnValueValue = returnValue; ! // delete &returnValue; ! // return returnValueValue; ! // }] // [else [return] METHODOWNER::Name(PARAMETERS);] // } *************** *** 1038,1042 **** string ConstFunction = m.Const ? " const" : ""; ! cw.WriteLine( /*"/*override{4}*/ "{0}{1}({2}){3} {{", TypeReferenceToString( "", m.ReturnType, ParameterStyle.CXXDeclaration ), m.Name, --- 1035,1039 ---- string ConstFunction = m.Const ? " const" : ""; ! cw.WriteLine( "/*override{4}*/ {0}{1}({2}){3} {{", TypeReferenceToString( "", m.ReturnType, ParameterStyle.CXXDeclaration ), m.Name, *************** *** 1047,1063 **** cw.Indent++; if (m.VirtualKind != VirtualKind.Pure ) // abstract methods have no base_xx method cw.Write( "if (overrideHook.{0}) ", m.UniqueName ); ! string paramstr = ParametersToString( m.GetParameters(), ParameterStyle.CXXtoCInvocation, null ); if ( paramstr != "" ) paramstr = ", " + paramstr; //cw.WriteLine("{2}{3}overrideHook.{0}(this{1});", ! cw.WriteLine("{2}{3}overrideHook.{0}(overrideHook.{0}Data{1});", m.UniqueName, paramstr, ! m.ReturnType.IsVoidValue ? "" : "return ", ! m.ReturnType.IsVoidValue ? "" : TypeReferenceToString( "", m.ReturnType, ParameterStyle.CtoCXXInvocation ) ); ! if (m.VirtualKind != VirtualKind.Pure ) // abstract methods have no base_xx method { cw.Write( "else "); --- 1044,1091 ---- cw.Indent++; + //Function cfunc = Function.GetValueRetFunction( m ); + Function cfunc = m; + if (m.VirtualKind != VirtualKind.Pure ) // abstract methods have no base_xx method cw.Write( "if (overrideHook.{0}) ", m.UniqueName ); ! string paramstr = ParametersToString( cfunc.GetParameters(), ParameterStyle.CXXtoCInvocation, null ); if ( paramstr != "" ) paramstr = ", " + paramstr; + + if ( Function.IsValueRetFunction( m ) ) + { + // Handle value return types. If a copy constructor exists, use it. + // If none exist, try to use the first parameter type as reference + // and create the return type object after the overrideHooks + // invocation. + if ( m.VirtualKind != VirtualKind.Pure ) + { + cw.WriteLine( "{" ); + cw.Indent++; + } + cw.Write( "{0} returnValue = ", m.ReturnType.Name ); // here "m." because we need the type name + } + //cw.WriteLine("{2}{3}overrideHook.{0}(this{1});", ! cw.WriteLine( "{2}{3}overrideHook.{0}(overrideHook.{0}Data{1});", m.UniqueName, paramstr, ! (Function.IsValueRetFunction( m ) || cfunc.ReturnType.IsVoidValue) ? "" : "return ", ! cfunc.ReturnType.IsVoidValue ? "" : TypeReferenceToString( "", cfunc.ReturnType, ParameterStyle.CtoCXXInvocation ) ); ! if ( Function.IsValueRetFunction( m ) ) ! { ! cw.WriteLine( "{0} returnValueValue = returnValue;", m.ReturnType.Name ); ! cw.WriteLine( "delete &returnValue;" ); ! cw.WriteLine( "return returnValueValue;" ); ! if ( m.VirtualKind != VirtualKind.Pure ) ! { ! cw.Indent--; ! cw.WriteLine( "}" ); ! } ! } ! // from here "m." because the cfunc stuff is complete ! ! if ( m.VirtualKind != VirtualKind.Pure ) // abstract methods have no base_xx method { cw.Write( "else "); *************** *** 1193,1197 **** /*cw.WriteLine( "typedef void(*destructorHookType)({0}* instPtr);", c.Destructor.Name.Substring( 1 ) );*/ ! cw.WriteLine( "typedef void(*destructorHookType)(void* instPtr);" ); cw.WriteLine( "destructorHookType destructor;" ); cw.WriteLine( "void* destructorData;" ); --- 1221,1225 ---- /*cw.WriteLine( "typedef void(*destructorHookType)({0}* instPtr);", c.Destructor.Name.Substring( 1 ) );*/ ! cw.WriteLine( "typedef void(*destructorHookType)(void* hookData);" ); cw.WriteLine( "destructorHookType destructor;" ); cw.WriteLine( "void* destructorData;" ); *************** *** 1200,1209 **** foreach ( Method m in ownVirtMethods ) { ! string paramstr = ParametersToString( m.GetParameters(), ParameterStyle.CDeclaration, c ); if ( paramstr != "" ) paramstr = ", " + paramstr; //cw.WriteLine( "typedef {0}(*{1}HookType)({2}{3}* instPtr{4});", ! cw.WriteLine( "typedef {0}(*{1}HookType)(void* instPtr{4});", ! TypeReferenceToString( "", m.ReturnType, ParameterStyle.CDeclaration, c ), m.UniqueName, ( m.Const ? "const " : "" ), --- 1228,1239 ---- foreach ( Method m in ownVirtMethods ) { ! /*Function cfunc = Function.GetValueRetFunction( m );*/ ! Function cfunc = m; ! string paramstr = ParametersToString( cfunc.GetParameters(), ParameterStyle.CDeclaration, c ); if ( paramstr != "" ) paramstr = ", " + paramstr; //cw.WriteLine( "typedef {0}(*{1}HookType)({2}{3}* instPtr{4});", ! cw.WriteLine( "typedef {0}(*{1}HookType)(void* hookData{4});", ! TypeReferenceToString( "", cfunc.ReturnType, ParameterStyle.CDeclaration, c ), m.UniqueName, ( m.Const ? "const " : "" ), *************** *** 1291,1299 **** cw.WriteLine(); - // pre-declare all hook classes - /*for ( int i = 0; i < signalClasses.Count; i++ ) - cw.WriteLine( "class {0};", GetSignalHookClassName( (Class)signalClasses[i] ) ); - cw.WriteLine();*/ - for ( int i = 0; i < signalClasses.Count; i++ ) WriteSignalsHook( (Class)signalClasses[i], true ); --- 1321,1324 ---- *************** *** 1374,1378 **** if ( parameters.Length > 0 ) parameters = ", " + parameters; ! cw.Write( "(*{0}{1}Hook)({2}*", m.UniqueName, c.Name, GetSignalHookClassName(c) ); cw.Write( parameters ); cw.WriteLine( ");" ); --- 1399,1404 ---- if ( parameters.Length > 0 ) parameters = ", " + parameters; ! //cw.Write( "(*{0}{1}Hook)({2}*", m.UniqueName, c.Name, GetSignalHookClassName(c) ); ! cw.Write( "(*{0}{1}Hook)(void* hookData", m.UniqueName, c.Name ); cw.Write( parameters ); cw.WriteLine( ");" ); *************** *** 1385,1389 **** --- 1411,1418 ---- cw.Indent++; foreach ( Method m in methods ) + { cw.WriteLine( "{0}Callback = 0;", m.UniqueName ); + cw.WriteLine( "{0}CallbackData = 0;", m.UniqueName ); + } cw.Indent--; cw.WriteLine( "}"); *************** *** 1392,1395 **** --- 1421,1425 ---- string signalName = m.UniqueName; cw.WriteLine( "{0}{1}Hook {0}Callback;", signalName, c.Name ); + cw.WriteLine( "void* {0}CallbackData;", signalName ); StringBuilder sb = new StringBuilder(); *************** *** 1400,1404 **** sb.Append( TypeReferenceToString( "", p.Type, ParameterStyle.CXXDeclaration, c ).Trim() ); } ! cw.WriteLine( "inline void set{0}({0}{1}Hook hook)", signalName, c.Name ); cw.WriteLine( "{" ); cw.Indent++; --- 1430,1435 ---- sb.Append( TypeReferenceToString( "", p.Type, ParameterStyle.CXXDeclaration, c ).Trim() ); } ! //cw.WriteLine( "inline void set{0}({0}{1}Hook hook)", signalName, c.Name ); ! cw.WriteLine( "inline void set{0}(void* hookData, {0}{1}Hook hook)", signalName, c.Name ); cw.WriteLine( "{" ); cw.Indent++; *************** *** 1406,1409 **** --- 1437,1443 ---- so we must typecast to (void*) and do the cast to (void**) in InstallSignalHook(). */ + //cw.WriteLine( "InstallSignalHook(&{2}Callback, (void*)hook, SIGNAL( {0}({1}) ), SLOT( {2}Slot({1}) ));", + // m.Name, sb.ToString(), signalName ); + cw.WriteLine( "{0}CallbackData = hookData;", signalName ); cw.WriteLine( "InstallSignalHook(&{2}Callback, (void*)hook, SIGNAL( {0}({1}) ), SLOT( {2}Slot({1}) ));", m.Name, sb.ToString(), signalName ); *************** *** 1422,1427 **** cw.Write( ParametersToString( m.GetParameters(), ParameterStyle.CXXDeclaration, c ) ); cw.Write( ") { " ); ! //cw.Write( "if( {0}Callback ) {0}Callback(this", signalName ); this "if" is not necessary because we connect only if hook != null ! cw.Write( "{0}Callback(this", signalName ); string parameters = ParametersToString( m.GetParameters(), ParameterStyle.CXXtoCXXInvocation, c ); if ( parameters.Length > 0 ) --- 1456,1461 ---- cw.Write( ParametersToString( m.GetParameters(), ParameterStyle.CXXDeclaration, c ) ); cw.Write( ") { " ); ! //cw.Write( "{0}Callback(this", signalName ); ! cw.Write( "{0}Callback({0}CallbackData ? {0}CallbackData : this", signalName ); string parameters = ParametersToString( m.GetParameters(), ParameterStyle.CXXtoCXXInvocation, c ); if ( parameters.Length > 0 ) *************** *** 1460,1466 **** // set functions ! cw.WriteLine( "void QTC_EXPORT {0}_set{1}({0}* instPtr, {0}::{1}{2}Hook hook) {{", GetSignalHookClassName(c), signalName, c.Name ); cw.Indent++; ! cw.WriteLine( "instPtr->set{0}(hook);", signalName ); cw.Indent--; cw.WriteLine( "}" ); --- 1494,1500 ---- // set functions ! cw.WriteLine( "void QTC_EXPORT {0}_set{1}({0}* instPtr, void* hookData, {0}::{1}{2}Hook hook) {{", GetSignalHookClassName(c), signalName, c.Name ); cw.Indent++; ! cw.WriteLine( "instPtr->set{0}(hookData, hook);", signalName ); cw.Indent--; cw.WriteLine( "}" ); |