Revision: 8055
http://armagetronad.svn.sourceforge.net/armagetronad/?rev=8055&view=rev
Author: z-man
Date: 2008-02-22 09:46:12 -0800 (Fri, 22 Feb 2008)
Log Message:
-----------
Phew, finally fully fixed the template master name generation. The template master is now always generated according to the specifications in the template, the CLIO_TEMPLATE_MASTER statement and especially the dummy class used for CLIO_TEMPLATE_NOMASTER have nothing to say.
Modified Paths:
--------------
private/z-man/clio/macros.cpp
private/z-man/clio/macros.hpp
private/z-man/clio/namespace.cpp
private/z-man/clio/tests/templates.test/output.txt
private/z-man/clio/tests/templates.test/test.cpp
private/z-man/clio/tests/templates.test/test.io
Modified: private/z-man/clio/macros.cpp
===================================================================
--- private/z-man/clio/macros.cpp 2008-02-22 15:44:23 UTC (rev 8054)
+++ private/z-man/clio/macros.cpp 2008-02-22 17:46:12 UTC (rev 8055)
@@ -3,10 +3,26 @@
#include "namespace.hpp"
#include <ctype.h>
+#include <iostream>
namespace clio
{
+void TransferToMasterBase::Transfer( IClassInfo const & instance, IClassInfo & master )
+{
+ // std::cout << instance.GetName( IClassInfo::Name_C ) << " -> " << master.GetName( IClassInfo::Name_C ) << "\n";
+
+ // copy info from template this class is supposed to be the master of
+ // master name is always the template name
+ master.SetName( IClassInfo::Name_IoRaw, instance.GetName( IClassInfo::Name_Template ) );
+
+ // master lives in the template's namespace
+ master.SetNestingParent( instance.GetNestingParent() );
+
+ // clear full IO name to have it regenerated
+ master.SetName( IClassInfo::Name_IoComplete, "" );
+}
+
// determines a classname automatically or from a user supplied name
std::string GetClassName( char const * automatic, char const * usersupplied )
{
Modified: private/z-man/clio/macros.hpp
===================================================================
--- private/z-man/clio/macros.hpp 2008-02-22 15:44:23 UTC (rev 8054)
+++ private/z-man/clio/macros.hpp 2008-02-22 17:46:12 UTC (rev 8055)
@@ -10,6 +10,7 @@
#include "templatearglist.hpp"
#include "codeinjection.hpp"
#include "namespace.hpp"
+#include "namemangling.hpp"
#include <string>
#include <ctype.h>
@@ -17,6 +18,22 @@
namespace clio
{
+// transfers data from template to its master
+struct TransferToMasterBase
+{
+ static void Transfer( IClassInfo const & instance, IClassInfo & master );
+};
+
+// transfers data from template to master
+template< class INSTANCE, class MASTER >
+struct TransferToMaster: public TransferToMasterBase
+{
+ static void Transfer()
+ {
+ TransferToMasterBase::Transfer( ClassInfo< INSTANCE >::Get(), ClassInfo< MASTER >::Get() );
+ }
+};
+
// determines a classname automatically or from a user supplied name
std::string GetClassName( char const * automatic, char const * usersupplied );
// same for a function name
@@ -225,17 +242,23 @@
{
// fetch relevant class info
IClassInfo & info = ClassInfo< CLASS >::Get();
- MasterClassInfoRegistrator<CLASS>::Register();
- // set the names
- info.SetName( IClassInfo::Name_C , cName );
- info.SetName( IClassInfo::Name_IoRaw, ioName );
+ // set the names (make sure they have not already been set by a slave class)
+ if ( strlen(cName) > 0 )
+ {
+ info.SetName( IClassInfo::Name_C , cName );
+ }
- // register namespace
- NameSpace * nameSpace = NameSpace::GetNameSpaceByClassName( cName );
- if ( nameSpace )
+ if( info.GetName( IClassInfo::Name_IoRaw ).size() == 0 && !info.GetNestingParent() )
{
- info.SetNestingParent( nameSpace );
+ info.SetName( IClassInfo::Name_IoRaw, ioName );
+
+ // register namespace
+ NameSpace * nameSpace = NameSpace::GetNameSpaceByClassName( info.GetName( IClassInfo::Name_C ) );
+ if ( nameSpace )
+ {
+ info.SetNestingParent( nameSpace );
+ }
}
// create a basic default factory
@@ -243,6 +266,9 @@
// process user defined class definition
((WRAPPER*)(0))->template clioPrivate_RegisterUser<WRAPPER>();
+
+ // register as master
+ MasterClassInfoRegistrator<CLASS>::Register();
}
};
@@ -349,30 +375,31 @@
} \
static void Register() \
{ \
- clio::RegisterOverloadedFunction< Master >( CLIO_FUNCTION_SIGNATURE_EX( <Master>,, &MasterClassInfoRegistrator::With, template ), INSTANTIATION ); \
+ clio::TransferToMaster< Class, Master >::Transfer(); \
+ clio::RegisterOverloadedFunction< Master >( CLIO_FUNCTION_SIGNATURE_EX( <Master>,, &MasterClassInfoRegistrator::With, template ), INSTANTIATION ); \
} \
}; \
} CLIO_FORCESEMICOLON(X)
-#define CLIO_TEMPLATE_CLASS_MASTER_EX( TEMPLATE, SIGNATURE, MASTER_SIGNATURE, MASTER_NAME, FUNCTION_NAME ) \
-CLIO_INSTANTIATE_TEMPLATE_EX( TEMPLATE, MASTER_SIGNATURE, MASTER_NAME ); \
+#define CLIO_TEMPLATE_CLASS_MASTER_EX( TEMPLATE, SIGNATURE, MASTER_SIGNATURE, FUNCTION_NAME ) \
+CLIO_INSTANTIATE_TEMPLATE_EX( TEMPLATE, MASTER_SIGNATURE, "" ); \
CLIO_TEMPLATE_CLASS_MASTER_BEGIN_EX( TEMPLATE, SIGNATURE, FUNCTION_NAME ) \
typedef TEMPLATE CLIO_TEMPLATE_ARGLIST_COMPLETE_SIGNATURE(MASTER_SIGNATURE) Master; \
CLIO_TEMPLATE_CLASS_MASTER_END_EX( TEMPLATE, SIGNATURE, FUNCTION_NAME )
#define CLIO_TEMPLATE_CLASS_MASTER( TEMPLATE, SIGNATURE, MASTER_SIGNATURE ) \
-CLIO_TEMPLATE_CLASS_MASTER_EX( TEMPLATE, SIGNATURE, MASTER_SIGNATURE, "", "With" )
+CLIO_TEMPLATE_CLASS_MASTER_EX( TEMPLATE, SIGNATURE, MASTER_SIGNATURE, "With" )
-#define CLIO_TEMPLATE_CLASS_NOMASTER_EX( TEMPLATE, SIGNATURE, MASTER, MASTER_NAME, FUNCTION_NAME ) \
+#define CLIO_TEMPLATE_CLASS_NOMASTER_EX( TEMPLATE, SIGNATURE, MASTER, FUNCTION_NAME ) \
CLIO_CLASS_SET_ABSTRACT( MASTER, true ); \
CLIO_CLASS_HEADER( MASTER ); \
-CLIO_CLASS_END_TEX( MASTER, (0,()), #TEMPLATE, MASTER_NAME, inline ){} \
+CLIO_CLASS_END_TEX( MASTER, (0,()), #TEMPLATE, "", inline ){} \
CLIO_TEMPLATE_CLASS_MASTER_BEGIN_EX( TEMPLATE, SIGNATURE, FUNCTION_NAME ) \
typedef MASTER Master; \
CLIO_TEMPLATE_CLASS_MASTER_END_EX( TEMPLATE, SIGNATURE, FUNCTION_NAME )
#define CLIO_TEMPLATE_CLASS_NOMASTER( TEMPLATE, SIGNATURE, MASTER ) \
-CLIO_TEMPLATE_CLASS_NOMASTER_EX( TEMPLATE, SIGNATURE, MASTER, "", "With" )
+CLIO_TEMPLATE_CLASS_NOMASTER_EX( TEMPLATE, SIGNATURE, MASTER, "With" )
#define CLIO_INSTANTIATE_EX( CLASS ) \
template class clio::InstantiatorHelperReal< clio::Instantiator< CLASS > >
@@ -388,7 +415,7 @@
if ( strlen( NAME ) > 0 ) \
info.SetName( IClassInfo::Name_IoRaw, NAME ); \
else \
- info.SetName( IClassInfo::Name_IoRaw, info.GetName( IClassInfo::Name_Template ) ); \
+ info.SetName( IClassInfo::Name_IoRaw, Uppercase( info.GetName( IClassInfo::Name_Template ).c_str() ) ); \
} \
}; \
} \
Modified: private/z-man/clio/namespace.cpp
===================================================================
--- private/z-man/clio/namespace.cpp 2008-02-22 15:44:23 UTC (rev 8054)
+++ private/z-man/clio/namespace.cpp 2008-02-22 17:46:12 UTC (rev 8055)
@@ -48,8 +48,31 @@
// splits a name into namespace and class name
static std::pair< std::string, std::string > Split( std::string base )
{
- // find the last :
- size_t lastColon = base.rfind( ':');
+ // find the last :, take care of <>
+ size_t lastColon = base.size();
+ int templateDepth = 0;
+ for( int i = base.size()-1; i > 0; --i )
+ {
+ switch(base[i])
+ {
+ case '>':
+ templateDepth++;
+ break;
+ case '<':
+ templateDepth--;
+ break;
+ case ':':
+ if ( templateDepth == 0 )
+ {
+ lastColon = i;
+ i = 0;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
if ( lastColon >= base.size() )
{
return std::pair< std::string, std::string >( "", base );
Modified: private/z-man/clio/tests/templates.test/output.txt
===================================================================
--- private/z-man/clio/tests/templates.test/output.txt 2008-02-22 15:44:23 UTC (rev 8054)
+++ private/z-man/clio/tests/templates.test/output.txt 2008-02-22 17:46:12 UTC (rev 8055)
@@ -1,3 +1,53 @@
+# testing whether template masters were correctly handled
+<<<< B XX With(Clio Int) clone type println
+B X_int
+<<<< B YY With(Clio Int) clone type println
+B Y_int
+<<<< NN With(Clio Int) clone type println
+NN_int
+<<<< B X_int type println
+B X_int
+<<<< B Y_int type println
+B Y_int
+
+# expecting errors on the next command block
+<<<< A Y
+
+ Exception: A does not respond to 'Y'
+
+<<<< A YY
+
+ Exception: A does not respond to 'YY'
+
+<<<< A Z
+<<<< A ZZ
+
+ Exception: A does not respond to 'ZZ'
+
+<<<< B ZZ
+
+ Exception: B does not respond to 'ZZ'
+
+<<<< TemplateTestBase
+
+ Exception: Object does not respond to 'TemplateTestBase'
+
+
+# some typename tests
+<<<< B XX type println
+B XX
+<<<< B YY type println
+B YY
+<<<< Clio Ref type println
+Clio Ref
+<<<< Base TemplateTestBase_Sequence_Object_3 type println
+Base TemplateTestBase_Sequence_Object_3
+<<<< TemplateTestBase_Sequence_Object_3 type println
+
+ Exception: Object does not respond to 'TemplateTestBase_Sequence_Object_3'
+
+
+
<<<< testObject := TemplateTest With( Number ) clone
<<<< testObject2 := TemplateTest With( Sequence ) clone
<<<< testObject3 := TemplateTest clone
@@ -2,2 +52,4 @@
<<<< testObject4 := Base TemplateTestBase clone
+<<<< testObject4 type println
+Base TemplateTestBase
<<<< writeln("Expecting error")
@@ -10,12 +62,12 @@
<<<< testObject4 := Base TemplateTestBase With( Sequence, Sequence, 2 ) clone
<<<< testObject4 type println
-TemplateTestBase With(Sequence,Sequence,2)
+Base TemplateTestBase With(Sequence,Sequence,2)
<<<< testObject4 h() println
2
<<<< testObject4 := Base TemplateTestBase With( Sequence, Sequence, 3 ) clone
<<<< testObject4 type println
-TemplateTestBase_Sequence_Object_3
+Base TemplateTestBase_Sequence_Object_3
<<<< testObject4 h() println
3
<<<< testObject f(1) println
Modified: private/z-man/clio/tests/templates.test/test.cpp
===================================================================
--- private/z-man/clio/tests/templates.test/test.cpp 2008-02-22 15:44:23 UTC (rev 8054)
+++ private/z-man/clio/tests/templates.test/test.cpp 2008-02-22 17:46:12 UTC (rev 8055)
@@ -46,11 +46,28 @@
TemplateTest< float > g(){ return TemplateTest< float >(); }
};
+// test namespace transfer of (non)master templatre
+namespace a
+{
+ template< class T > class X{};
+ template< class T > class Y{};
+ template< class T > class Z{};
+}
+template< class T > class NONAME{};
+
CLIO_TEMPLATE_SET_POLYMORPHIC( base::TemplateTestBase, (3,(class,class,int)), false );
CLIO_TEMPLATE_SET_POLYMORPHIC( TemplateTest, (1,(class)), true );
+void breakp()
+{
+ int x;
+ x = 0;
+}
+
CLIO_TEMPLATE_CLASS( base::TemplateTestBase, (3,(class,class,int)))
{
+ breakp();
+
CLIO_METHOD( h );
CLIO_METHOD( Create );
}
@@ -68,10 +85,12 @@
namespace blurb
{
-struct NoMaster{};
+struct NoMaster1{};
+struct NoMaster2{};
+struct NoMaster3{};
}
-CLIO_TEMPLATE_CLASS_NOMASTER( base::TemplateTestBase, (3,(class,class,int)), blurb::NoMaster );
+CLIO_TEMPLATE_CLASS_NOMASTER( base::TemplateTestBase, (3,(class,class,int)), blurb::NoMaster1 );
CLIO_TEMPLATE_CLASS_MASTER( TemplateTest, (1,(class)), (1,(clio::IoObjectPointer)) );
@@ -81,6 +100,18 @@
CLIO_INSTANTIATE_TEMPLATE(base::TemplateTestBase,(3,(std::string,clio::IoObjectPointer,3)),"TemplateTestBase_Sequence_Object_3");
+CLIO_TEMPLATE_CLASS_EX( a::X, (1,(class)), "XX" ){ CLIO_CLASS_NAMESPACE("b"); }
+CLIO_TEMPLATE_CLASS_EX( a::Y, (1,(class)), "YY" ){ CLIO_CLASS_NAMESPACE("b"); }
+CLIO_TEMPLATE_CLASS_EX( a::Z, (1,(class)), "ZZ" ){ CLIO_CLASS_NAMESPACE("b"); }
+CLIO_TEMPLATE_CLASS_EX( NONAME, (1,(class)), "NN" ){}
+CLIO_TEMPLATE_CLASS_MASTER( NONAME, (1,(class)),(1,(clio::IoObjectPointer)) );
+CLIO_TEMPLATE_CLASS_MASTER( a::X, (1,(class)),(1,(clio::IoObjectPointer)) );
+CLIO_TEMPLATE_CLASS_NOMASTER( a::Y, (1,(class)), blurb::NoMaster2 );
+CLIO_TEMPLATE_CLASS_NOMASTER( a::Z, (1,(class)), blurb::NoMaster3 );
+CLIO_INSTANTIATE_TEMPLATE( NONAME,(1,(int)),"NN_int");
+CLIO_INSTANTIATE_TEMPLATE( a::X,(1,(int)),"X_int");
+CLIO_INSTANTIATE_TEMPLATE( a::Y,(1,(int)),"Y_int");
+
void Test()
{
// clio::ClassInfo< TemplateTestBase< std::string, std::string, 2 > >::Get();
Modified: private/z-man/clio/tests/templates.test/test.io
===================================================================
--- private/z-man/clio/tests/templates.test/test.io 2008-02-22 15:44:23 UTC (rev 8054)
+++ private/z-man/clio/tests/templates.test/test.io 2008-02-22 17:46:12 UTC (rev 8055)
@@ -1,3 +1,26 @@
+# testing whether template masters were correctly handled
+B XX With(Clio Int) clone type println
+B YY With(Clio Int) clone type println
+NN With(Clio Int) clone type println
+B X_int type println
+B Y_int type println
+
+# expecting errors on the next command block
+A Y
+A YY
+A Z
+A ZZ
+B ZZ
+TemplateTestBase
+
+# some typename tests
+B XX type println
+B YY type println
+Clio Ref type println
+Base TemplateTestBase_Sequence_Object_3 type println
+TemplateTestBase_Sequence_Object_3 type println
+
+
testObject := TemplateTest With( Number ) clone
testObject2 := TemplateTest With( Sequence ) clone
testObject3 := TemplateTest clone
@@ -2,2 +25,3 @@
testObject4 := Base TemplateTestBase clone
+testObject4 type println
writeln("Expecting error")
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|