Skip site navigation (1)Skip section navigation (2)
Date:      15 Apr 2002 00:10:01 -0700
From:      Max Okumoto <okumoto@ucsd.edu>
To:        freebsd-libh@FreeBSD.ORG
Subject:   cleanup of HSystem 2nd try (stage 1) 
Message-ID:  <hfn0w55tfa.fsf@multivac.sdsc.edu>

next in thread | raw e-mail | index | archive | help
 
Ok only one type of change at at time. :-)  
 
* (include/HSystem.hh, lib/tcl/tcl_interface_gen.cc) Created types 
   and use them to make code more readable. 

Index: include/HSystem.hh
===================================================================
RCS file: /home/libh/cvs/libh/include/HSystem.hh,v
retrieving revision 1.5
diff -u -r1.5 HSystem.hh
--- include/HSystem.hh	2002/04/11 23:35:52	1.5
+++ include/HSystem.hh	2002/04/15 03:58:12
@@ -50,8 +50,15 @@
 
 class HSystem
 {
+    /*
+     * Types used to simplify code.
+     */
+    typedef LanguageInterface::Object::ClassDescription		ClassDesc;
+    typedef LanguageInterface::Object::MethodDescription	MethodDesc;
+    typedef LanguageInterface::Object::CallbackDescription	CallBackDesc;
+
   public:
-     typedef list<const LanguageInterface::Object::ClassDescription*> Descriptions;
+     typedef list<const ClassDesc *> Descriptions;
      typedef set<string> Includes;
      typedef list<const char*> CommandAccessToRegister;
      typedef list<pair<string,string> > StaticMethods;
@@ -61,7 +68,7 @@
      HSystem( const HSystem& aHSystem )
           : name( aHSystem.name ) {}
 
-     void add_class( const LanguageInterface::Object::ClassDescription* class_desc, const string& include_file )
+     void add_class(const ClassDesc *class_desc, const string& include_file)
           {
                descriptions.push_back( class_desc );
                includes.insert( include_file );
@@ -82,12 +89,12 @@
      bool operator == ( const HSystem& toCompare ) const { return name == toCompare.name; }
 
   private:
-     void gen_class_header( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     void gen_callback_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     void gen_dynamic_methods_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     void gen_static_method_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     string gen_result_to_obj( LanguageInterface::Object::MethodDescription::Value t );
-     string gen_method_argument( LanguageInterface::Object::MethodDescription::Value t, int argno, int method_argno, bool last_arg_in_set_method );
+     void gen_class_header(ostream& out, const ClassDesc *cd);
+     void gen_callback_interfaces(ostream& out, const ClassDesc *cd);
+     void gen_dynamic_methods_interfaces(ostream& out, const ClassDesc *cd);
+     void gen_static_method_interfaces(ostream& out, const ClassDesc *cd);
+     string gen_result_to_obj(MethodDesc::Value t );
+     string gen_method_argument(MethodDesc::Value t, int argno, int method_argno, bool last_arg_in_set_method );
 
 }; // class HSystem
 
Index: lib/tcl/tcl_interface_gen.cc
===================================================================
RCS file: /home/libh/cvs/libh/lib/tcl/tcl_interface_gen.cc,v
retrieving revision 1.8
diff -u -r1.8 tcl_interface_gen.cc
--- lib/tcl/tcl_interface_gen.cc	2002/04/13 23:10:53	1.8
+++ lib/tcl/tcl_interface_gen.cc	2002/04/15 03:58:14
@@ -105,11 +105,11 @@
 
 } /* HSystem::gen_header */
 
-void HSystem::gen_class_header( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void HSystem::gen_class_header( ostream& out, const ClassDesc *aClassDescription )
 {
 	out << "class " << replace_chars( aClassDescription->name, ':', '_' ) << "Access : ";
 	if ( aClassDescription->parents[0] ) {
-		for ( const LanguageInterface::Object::ClassDescription* const* pd = aClassDescription->parents; *pd; ++pd ) {
+		for ( const ClassDesc *const* pd = aClassDescription->parents; *pd; ++pd ) {
 			if ( pd != aClassDescription->parents )
 				out << ", ";
 			out << "public " << replace_chars( (*pd)->name, ':', '_' ) << "Access";
@@ -124,14 +124,14 @@
 
 } /* HSystem::gen_class_header */
 
-void HSystem::gen_callback_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void HSystem::gen_callback_interfaces( ostream& out, const ClassDesc *aClassDescription )
 {
 	if ( aClassDescription->has_callbacks() ) {
 		out << "	virtual void activate_callback( Tcl_Interp* interp, Tcl_Obj* aCommand, Tcl_Obj* aUserData, Tcl_Obj* aArg, LanguageInterface::SpecificCallbackData& aSpecificCallbackData )\n"
 		<< "		{\n"
 		<< "			/* cerr << \"" << aClassDescription->name << " activate_callback\" << endl; */\n"
 		<< "			";
-		for ( const LanguageInterface::Object::CallbackDescription* cd = aClassDescription->callbacks; cd->type; ++cd ) {
+		for ( const CallBackDesc *cd = aClassDescription->callbacks; cd->type; ++cd ) {
 			out << "if ( dynamic_cast<" << cd->type << "*>( &aSpecificCallbackData ) != 0 ) {\n"
 			<< "				" << cd->type << "& scd = dynamic_cast<" << cd->type << "&>( aSpecificCallbackData );\n"
 			<< "				Tcl_Obj* toEval = Tcl_NewObj();\n"
@@ -165,7 +165,7 @@
 
 } /* HSystem::gen_callback_interfaces */
 
-void HSystem::gen_dynamic_methods_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void HSystem::gen_dynamic_methods_interfaces( ostream& out, const ClassDesc *aClassDescription )
 {
 	out << "	static int methodCommand( ClientData obj, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] )\n"
 	<< "		{\n"
@@ -194,7 +194,7 @@
 	<< "			}\n"
 	<< "			else ";
 
-	for ( const LanguageInterface::Object::MethodDescription* method = aClassDescription->methods; method->name; ++method ) {
+	for ( const MethodDesc* method = aClassDescription->methods; method->name; ++method ) {
 		if ( method->dynamic() ) {
 			cout << '\t' << method->name << endl;
 			out << "if ( !strcmp( method, \"" << method->name << "\" ) ) {\n";
@@ -211,14 +211,14 @@
 			for ( int argno = 0; argno < max_args; ++argno ) {
 				if ( !method->getOrSet() || argno != max_args - 1 ) {
 					out << prefix << LanguageInterface::method_argument_type( method->args[argno], false ) << " a" << to_string( argno );
-					if ( method->args[argno] == LanguageInterface::Object::MethodDescription::vtList || method->args[argno] == LanguageInterface::Object::MethodDescription::vtListRef || method->args[argno] == LanguageInterface::Object::MethodDescription::vtListPtr )
+					if ( method->args[argno] == MethodDesc::vtList || method->args[argno] == MethodDesc::vtListRef || method->args[argno] == MethodDesc::vtListPtr )
 						out << ";\n" << prefix << gen_method_argument( method->args[argno], argno + 3, argno + 1, false ) << ";\n";
 					else
 						out << " = " << gen_method_argument( method->args[argno], argno + 3, argno + 1, false ) << ";\n";
 				}
 			}
 
-			const bool result_present = method->result != LanguageInterface::Object::MethodDescription::vtVoid;
+			const bool result_present = method->result != MethodDesc::vtVoid;
 			if ( method->getOrSet() ) {
 				if ( method->setReturnsOld() ) {
 					out << prefix << "const " << LanguageInterface::method_result_type( method->result, false ) << " result_object = object_t->" << method->name_to_call << "( ";
@@ -231,7 +231,7 @@
 
 					out << prefix << "if ( objc - 3 == " << max_args << " ) { /* set requested */\n";
 					out << prefix << "	" << LanguageInterface::method_argument_type( method->args[max_args - 1], false ) << " a" << to_string( max_args - 1 );
-					if ( method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtList || method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtListRef || method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtListPtr )
+					if ( method->args[max_args - 1] == MethodDesc::vtList || method->args[max_args - 1] == MethodDesc::vtListRef || method->args[max_args - 1] == MethodDesc::vtListPtr )
 						out << ";\n" << prefix << "	" << gen_method_argument( method->args[max_args - 1], max_args + 2, max_args, true ) << ";\n";
 					else
 						out << " = " << gen_method_argument( method->args[max_args - 1], max_args + 2, max_args, true ) << ";\n";
@@ -247,7 +247,7 @@
 				else if ( method->setReturnsNew() ) {
 					out << prefix << "if ( objc - 3 == " << max_args << " ) { /* set requested */\n";
 					out << prefix << "	" << LanguageInterface::method_argument_type( method->args[max_args - 1], false ) << " a" << to_string( max_args - 1 );
-					if ( method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtList || method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtListRef || method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtListPtr )
+					if ( method->args[max_args - 1] == MethodDesc::vtList || method->args[max_args - 1] == MethodDesc::vtListRef || method->args[max_args - 1] == MethodDesc::vtListPtr )
 						out << ";\n" << prefix << "	" << gen_method_argument( method->args[max_args - 1], max_args + 2, max_args, true ) << ";\n";
 					else
 						out << " = " << gen_method_argument( method->args[max_args - 1], max_args + 2, max_args, true ) << ";\n";
@@ -270,7 +270,7 @@
 				else {
 					out << prefix << "if ( objc - 3 == " << max_args << " ) { /* set requested */\n";
 					out << prefix << "	" << LanguageInterface::method_argument_type( method->args[max_args - 1], false ) << " a" << to_string( max_args - 1 );
-					if ( method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtList || method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtListRef || method->args[max_args - 1] == LanguageInterface::Object::MethodDescription::vtListPtr )
+					if ( method->args[max_args - 1] == MethodDesc::vtList || method->args[max_args - 1] == MethodDesc::vtListRef || method->args[max_args - 1] == MethodDesc::vtListPtr )
 						out << ";\n" << prefix << "	" << gen_method_argument( method->args[max_args - 1], max_args + 2, max_args, true ) << ";\n";
 					else
 						out << " = " << gen_method_argument( method->args[max_args - 1], max_args + 2, max_args, true ) << ";\n";
@@ -322,7 +322,7 @@
 
 	if ( aClassDescription->parents[0] ) {
 		out << "if ( ";
-		for ( const LanguageInterface::Object::ClassDescription* const* pd = aClassDescription->parents; *pd; ++pd ) {
+		for ( const ClassDesc *const* pd = aClassDescription->parents; *pd; ++pd ) {
 			if ( pd != aClassDescription->parents )
 				out << " && ";
 			out << replace_chars( (*pd)->name, ':', '_' ) << "Access::methodCommand_object( object, method, master_interpreter, interp, objc, objv ) == TCL_ERROR";
@@ -342,11 +342,11 @@
 
 } /* HSystem::gen_dynamic_methods_interfaces */
 
-void HSystem::gen_static_method_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void HSystem::gen_static_method_interfaces( ostream& out, const ClassDesc *aClassDescription )
 {
 	if ( aClassDescription->staticMethods() > 0 ) {
 		out << "  public:\n";
-		for ( const LanguageInterface::Object::MethodDescription* method = aClassDescription->methods; method->name; ++method ) {
+		for ( const MethodDesc* method = aClassDescription->methods; method->name; ++method ) {
 			if ( !method->dynamic() ) {
 				cout << '\t' << method->name << endl;
 
@@ -364,20 +364,20 @@
 
 				int min_args, max_args;
 				method->numberOfArgs( min_args, max_args );
-				const int max_args_in_call = method->args[max_args-1] == LanguageInterface::Object::MethodDescription::vtLanguageInterface ? max_args - 1 : max_args;
+				const int max_args_in_call = method->args[max_args-1] == MethodDesc::vtLanguageInterface ? max_args - 1 : max_args;
 				out << "				if ( objc - 2 < " << min_args << " || objc - 2 > " << max_args_in_call << " ) \n"
 				<< "					return error( interp, \"Wrong number of arguments: \", \"" << aClassDescription->name << "::" << method->name << "\", \" (was \", to_string( objc - 2 ).c_str(), \", expected " << ( min_args < max_args_in_call ? to_string( min_args ) + " to " + to_string( max_args_in_call ) : to_string( max_args_in_call ) ) << ")\", 0 );\n";
 				out << "				const char* method = \"" << method->name << "\";\n";
 				string prefix = "				";
 				for ( int argno = 0; argno < max_args; ++argno ) {
 					out << prefix << LanguageInterface::method_argument_type( method->args[argno], false ) << " a" << to_string( argno );
-					if ( method->args[argno] == LanguageInterface::Object::MethodDescription::vtList || method->args[argno] == LanguageInterface::Object::MethodDescription::vtListRef || method->args[argno] == LanguageInterface::Object::MethodDescription::vtListPtr )
+					if ( method->args[argno] == MethodDesc::vtList || method->args[argno] == MethodDesc::vtListRef || method->args[argno] == MethodDesc::vtListPtr )
 						out << ";\n" << prefix << gen_method_argument( method->args[argno], argno + 2, argno + 1, false ) << ";\n";
 					else
 						out << " = " << gen_method_argument( method->args[argno], argno + 2, argno + 1, false ) << ";\n";
 				}
 				out << prefix;
-				if ( method->result != LanguageInterface::Object::MethodDescription::vtVoid )
+				if ( method->result != MethodDesc::vtVoid )
 					out << LanguageInterface::method_result_type( method->result, false ) << " result_object = ";
 				out << aClassDescription->cxx_name << "::" << method->name_to_call << "( ";
 				for ( int argno = 0; argno < max_args; ++argno ) {
@@ -386,7 +386,7 @@
 						out << ", ";
 				}
 				out << " );\n";
-				if ( method->result != LanguageInterface::Object::MethodDescription::vtVoid ) {
+				if ( method->result != MethodDesc::vtVoid ) {
 					out << "				Tcl_SetObjResult( interp, " << gen_result_to_obj( method->result ) << " );\n";
 				}
 				else {
@@ -458,35 +458,35 @@
 } /* HSystem::gen_footer */
 
 
-string HSystem::gen_result_to_obj( LanguageInterface::Object::MethodDescription::Value t )
+string HSystem::gen_result_to_obj( MethodDesc::Value t )
 {
-	switch ( (LanguageInterface::Object::MethodDescription::ValueType)t ) {
-	case LanguageInterface::Object::MethodDescription::vtVoid:
+	switch ( (MethodDesc::ValueType)t ) {
+	case MethodDesc::vtVoid:
 		return("Tcl_NewObj()");
-	case LanguageInterface::Object::MethodDescription::vtChar:
-	case LanguageInterface::Object::MethodDescription::vtUChar:
-	case LanguageInterface::Object::MethodDescription::vtShort:
-	case LanguageInterface::Object::MethodDescription::vtUShort:
-	case LanguageInterface::Object::MethodDescription::vtInt:
-	case LanguageInterface::Object::MethodDescription::vtUInt:
-	case LanguageInterface::Object::MethodDescription::vtLong:
-	case LanguageInterface::Object::MethodDescription::vtULong:
-	case LanguageInterface::Object::MethodDescription::vtLongLong:
-	case LanguageInterface::Object::MethodDescription::vtULongLong:
-	case LanguageInterface::Object::MethodDescription::vtBool:
-	case LanguageInterface::Object::MethodDescription::vtFloat:
-	case LanguageInterface::Object::MethodDescription::vtDouble:
-	case LanguageInterface::Object::MethodDescription::vtLongDouble:
-	case LanguageInterface::Object::MethodDescription::vtString:
-	case LanguageInterface::Object::MethodDescription::vtObject:
+	case MethodDesc::vtChar:
+	case MethodDesc::vtUChar:
+	case MethodDesc::vtShort:
+	case MethodDesc::vtUShort:
+	case MethodDesc::vtInt:
+	case MethodDesc::vtUInt:
+	case MethodDesc::vtLong:
+	case MethodDesc::vtULong:
+	case MethodDesc::vtLongLong:
+	case MethodDesc::vtULongLong:
+	case MethodDesc::vtBool:
+	case MethodDesc::vtFloat:
+	case MethodDesc::vtDouble:
+	case MethodDesc::vtLongDouble:
+	case MethodDesc::vtString:
+	case MethodDesc::vtObject:
 		return("tclLanguageInterface->cxx2tcl( result_object )");
-	case LanguageInterface::Object::MethodDescription::vtList:
-	case LanguageInterface::Object::MethodDescription::vtListRef:
-	case LanguageInterface::Object::MethodDescription::vtListPtr:
+	case MethodDesc::vtList:
+	case MethodDesc::vtListRef:
+	case MethodDesc::vtListPtr:
 		return("tclLanguageInterface->list2tcl( interp, result_object )");
-	case LanguageInterface::Object::MethodDescription::vtLanguageInterface:
+	case MethodDesc::vtLanguageInterface:
 		throw LanguageInterface::Error( string( "vtLanguageInterface cannot be used as method return type for method " ) + (const char*)t );
-	case LanguageInterface::Object::MethodDescription::vtCallbackData:
+	case MethodDesc::vtCallbackData:
 		return("tclLanguageInterface->callbackData2tcl( interp, result_object )");
 	}
 
@@ -495,56 +495,56 @@
 } /* HSystem::gen_result_to_obj */
 
 
-string HSystem::gen_method_argument( LanguageInterface::Object::MethodDescription::Value t, int argno, int method_argno, bool last_arg_in_set_method )
+string HSystem::gen_method_argument( MethodDesc::Value t, int argno, int method_argno, bool last_arg_in_set_method )
 {
 	string result;
-	if ( t.optional() && t != LanguageInterface::Object::MethodDescription::vtList && t != LanguageInterface::Object::MethodDescription::vtListRef && t != LanguageInterface::Object::MethodDescription::vtListPtr && !last_arg_in_set_method ) {
+	if ( t.optional() && t != MethodDesc::vtList && t != MethodDesc::vtListRef && t != MethodDesc::vtListPtr && !last_arg_in_set_method ) {
 		result += string( "( objc - 1 < " ) + to_string( argno ) + " ) ? " + t.defaultValue() + " : ";
 	}
 
-	switch ( (LanguageInterface::Object::MethodDescription::ValueType)t ) {
-	case LanguageInterface::Object::MethodDescription::vtVoid:
+	switch ( (MethodDesc::ValueType)t ) {
+	case MethodDesc::vtVoid:
 		return("void");
-	case LanguageInterface::Object::MethodDescription::vtChar:
-	case LanguageInterface::Object::MethodDescription::vtUChar:
+	case MethodDesc::vtChar:
+	case MethodDesc::vtUChar:
 		result += string( "*Tcl_GetStringFromObj( objv[" ) + to_string( argno ) + "], 0 )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtShort:
-	case LanguageInterface::Object::MethodDescription::vtUShort:
-	case LanguageInterface::Object::MethodDescription::vtInt:
-	case LanguageInterface::Object::MethodDescription::vtUInt:
+	case MethodDesc::vtShort:
+	case MethodDesc::vtUShort:
+	case MethodDesc::vtInt:
+	case MethodDesc::vtUInt:
 		result += string( "TclLanguageInterface::tcl_obj2int( interp, objv[" ) + to_string( argno ) + "], method, " + to_string( method_argno ) + " )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtLong:
-	case LanguageInterface::Object::MethodDescription::vtULong:
-	case LanguageInterface::Object::MethodDescription::vtLongLong:
-	case LanguageInterface::Object::MethodDescription::vtULongLong:
+	case MethodDesc::vtLong:
+	case MethodDesc::vtULong:
+	case MethodDesc::vtLongLong:
+	case MethodDesc::vtULongLong:
 		result += string( "TclLanguageInterface::tcl_obj2long( interp, objv[" ) + to_string( argno ) + "], method, " + to_string( method_argno ) + " )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtBool:
+	case MethodDesc::vtBool:
 		result += string( "TclLanguageInterface::tcl_obj2bool( interp, objv[" ) + to_string( argno ) + "], method, " + to_string( method_argno ) + " )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtFloat:
-	case LanguageInterface::Object::MethodDescription::vtDouble:
-	case LanguageInterface::Object::MethodDescription::vtLongDouble:
+	case MethodDesc::vtFloat:
+	case MethodDesc::vtDouble:
+	case MethodDesc::vtLongDouble:
 		result += string( "TclLanguageInterface::tcl_obj2double( interp, objv[" ) + to_string( argno ) + "], method, " + to_string( method_argno ) + " )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtString:
+	case MethodDesc::vtString:
 		result += string( "TclLanguageInterface::to_string( objv[" ) + to_string( argno ) + "] )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtObject:
+	case MethodDesc::vtObject:
 		result += string( "tclLanguageInterface->tcl2object( objv[" ) + to_string( argno ) + "], (" + (const char*)t + "*)0, method, " + to_string( method_argno ) + " )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtList:
-	case LanguageInterface::Object::MethodDescription::vtListRef:
-	case LanguageInterface::Object::MethodDescription::vtListPtr:
+	case MethodDesc::vtList:
+	case MethodDesc::vtListRef:
+	case MethodDesc::vtListPtr:
 		if ( t.optional() && !last_arg_in_set_method )
 			result += string( "( objc - 1 < " ) + to_string( argno ) + " ) ? ( a" + to_string( method_argno - 1 ) + " = " + t.defaultValue() + " ) : ";
 		result += string( "tclLanguageInterface->tcl2list( a" ) + to_string( method_argno - 1 ) + ", interp, objv[" + to_string( argno ) + "], method, " + to_string( method_argno ) + " )";
 		break;
-	case LanguageInterface::Object::MethodDescription::vtLanguageInterface:
+	case MethodDesc::vtLanguageInterface:
 		return("tclLanguageInterface");
-	case LanguageInterface::Object::MethodDescription::vtCallbackData:
+	case MethodDesc::vtCallbackData:
 		result += string( "tclLanguageInterface->tcl2callbackData( interp, objv[" ) + to_string( argno ) + "] )";
 		break;
 	default:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-libh" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?hfn0w55tfa.fsf>