History

prep for type dump functionality

Ge Wang committed 5 years ago

Commit 5f0f95d1 parent 438fb826 files · +77 −39Browse files

Unified · Split

6 files
  1. src/core/chuck_lang.cpp +11 −10
  2. src/core/chuck_lang.h +1 −1
  3. src/core/chuck_oo.cpp +9 −16
  4. src/core/chuck_oo.h +1 −1
  5. src/core/chuck_type.cpp +47 −9
  6. src/core/chuck_type.h +8 −2
src/core/chuck_lang.cpp+11−10
@@ -79,17 +79,17 @@ t_CKBOOL init_class_object( Chuck_Env * env, Chuck_Type * type ) · 78 unmodified lines
79 func = make_new_mfun( "string", "toString", object_toString );79 func = make_new_mfun( "string", "toString", object_toString );
80 func->doc = "get a textual description of this object.";80 func->doc = "get a textual description of this object.";
81 if( !type_engine_import_mfun( env, func ) ) goto error;81 if( !type_engine_import_mfun( env, func ) ) goto error;
82 82
83 // add dump()83 // add help()
84 // func = make_new_mfun( "void", "dump", object_dump );84 func = make_new_sfun( "void", "help", object_help );
85 // func->doc = "output current state of the object as text.";
86 // if( !type_engine_import_mfun( env, func ) ) goto error;
87
88 // add api()
89 func = make_new_sfun( "void", "help", object_apropos );
90 func->doc = "generate and output helpful information about a class or object.";85 func->doc = "generate and output helpful information about a class or object.";
91 if( !type_engine_import_sfun( env, func ) ) goto error;86 if( !type_engine_import_sfun( env, func ) ) goto error;
92 87
88// // add dump()
89// func = make_new_mfun( "void", "dump", object_dump );
90// func->doc = "output current state of the object.";
91// if( !type_engine_import_mfun( env, func ) ) goto error;
92
93 // end the class import93 // end the class import
94 type_engine_import_class_end( env );94 type_engine_import_class_end( env );
95 95
@@ -1071,8 +1071,8 @@ CK_DLL_MFUN( object_dump ) · 975 unmodified lines
1071 me->dump();1071 me->dump();
1072}1072}
1073 1073
1074// apropos1074// help
1075CK_DLL_SFUN( object_apropos )1075CK_DLL_SFUN( object_help )
1076{1076{
1077 TYPE->apropos();1077 TYPE->apropos();
1078 // get object1078 // get object
@@ -1083,6 +1083,7 @@ CK_DLL_SFUN( object_apropos ) · 4 unmodified lines
1083 1083
1084 1084
1085 1085
1086
1086// ctor1087// ctor
1087CK_DLL_CTOR( ugen_ctor )1088CK_DLL_CTOR( ugen_ctor )
1088{1089{
src/core/chuck_lang.h+1−1
@@ -73,7 +73,7 @@ CK_DLL_MFUN( object_getType ); · 72 unmodified lines
73CK_DLL_MFUN( object_hashCode );73CK_DLL_MFUN( object_hashCode );
74CK_DLL_MFUN( object_toString );74CK_DLL_MFUN( object_toString );
75CK_DLL_MFUN( object_dump );75CK_DLL_MFUN( object_dump );
76CK_DLL_SFUN( object_apropos );76CK_DLL_SFUN( object_help );
77 77
78 78
79//-----------------------------------------------------------------------------79//-----------------------------------------------------------------------------
src/core/chuck_oo.cpp+9−16
@@ -347,34 +347,27 @@ Chuck_Object::~Chuck_Object() · 346 unmodified lines
347// name: dump()347// name: dump()
348// desc: output current state (can be overridden)348// desc: output current state (can be overridden)
349//-----------------------------------------------------------------------------349//-----------------------------------------------------------------------------
350void Chuck_Object::dump() // 1.4.1.0350void Chuck_Object::dump() // 1.4.1.1 (ge)
351{351{
352 // TODO: implement!352 // need type info
353 Chuck_Type * type = this->type_ref;
354
355 // output state with type info
356 type->dump( this );
353}357}
354 358
355 359
356 360
357 361
358//-----------------------------------------------------------------------------362//-----------------------------------------------------------------------------
359// name: apropos()363// name: help()
360// desc: output interface (can be overriden; but probably shouldn't be)364// desc: output type info (can be overriden; but probably shouldn't be)
361//-----------------------------------------------------------------------------365//-----------------------------------------------------------------------------
362void Chuck_Object::apropos() // 1.4.1.0366void Chuck_Object::help() // 1.4.1.0 (ge)
363{367{
364 // type to unpack368 // type to unpack
365 Chuck_Type * type = this->type_ref;369 Chuck_Type * type = this->type_ref;
366 370
367 // if type is generic "@array"
368 if( type->xid == te_array )
369 {
370 // get more specific
371 Chuck_Array * arr = (Chuck_Array *)this;
372 // however, a number of chuck array allocations still do not
373 // set the m_array_type member; update to this only if it exists
374 if( arr->m_array_type != NULL )
375 type = arr->m_array_type;
376 }
377
378 // unpack type and output its info371 // unpack type and output its info
379 type->apropos();372 type->apropos();
380}373}
src/core/chuck_oo.h+1−1
@@ -180,7 +180,7 @@ public: · 179 unmodified lines
180 180
181public:181public:
182 // output type info (can be overriden; but probably shouldn't be)182 // output type info (can be overriden; but probably shouldn't be)
183 virtual void apropos();183 virtual void help();
184 184
185public:185public:
186 // virtual table186 // virtual table
src/core/chuck_type.cpp+47−9
@@ -6681,7 +6681,7 @@ const char * Chuck_Type::c_name() · 6680 unmodified lines
6681 6681
6682//-----------------------------------------------------------------------------6682//-----------------------------------------------------------------------------
6683// name: apropos()6683// name: apropos()
6684// desc: dump info to string; added 1.4.1.0 (ge)6684// desc: generate info; output to console | added 1.4.1.0 (ge)
6685// portions of this adapted from ckdoc -- thanks be to Spencer Salazar6685// portions of this adapted from ckdoc -- thanks be to Spencer Salazar
6686//-----------------------------------------------------------------------------6686//-----------------------------------------------------------------------------
6687void Chuck_Type::apropos( std::string & output )6687void Chuck_Type::apropos( std::string & output )
@@ -6754,7 +6754,7 @@ void Chuck_Type::apropos( std::string & output ) · 66 unmodified lines
6754 6754
6755//-----------------------------------------------------------------------------6755//-----------------------------------------------------------------------------
6756// name: apropos()6756// name: apropos()
6757// desc: dump info to console6757// desc: generate info; output to console | added 1.4.1.0 (ge)
6758//-----------------------------------------------------------------------------6758//-----------------------------------------------------------------------------
6759void Chuck_Type::apropos()6759void Chuck_Type::apropos()
6760{6760{
@@ -6769,11 +6769,15 @@ void Chuck_Type::apropos() · 8 unmodified lines
6769 6769
6770 6770
6771 6771
6772//-----------------------------------------------------------------------------
6772// comparer6773// comparer
6774//-----------------------------------------------------------------------------
6773static bool comp_func( Chuck_Func * a, Chuck_Func * b )6775static bool comp_func( Chuck_Func * a, Chuck_Func * b )
6774{ return a->name < b->name; }6776{ return a->name < b->name; }
6775 6777
6778//-----------------------------------------------------------------------------
6776// comparer6779// comparer
6780//-----------------------------------------------------------------------------
6777static bool comp_value( Chuck_Value * a, Chuck_Value * b )6781static bool comp_value( Chuck_Value * a, Chuck_Value * b )
6778{6782{
6779 string lowerA = a->name;;6783 string lowerA = a->name;;
@@ -6788,7 +6792,9 @@ static bool comp_value( Chuck_Value * a, Chuck_Value * b ) · 8 unmodified lines
6788 else return a->name > b->name;6792 else return a->name > b->name;
6789}6793}
6790 6794
6795//-----------------------------------------------------------------------------
6791// capitalize first character6796// capitalize first character
6797//-----------------------------------------------------------------------------
6792static string capitalize( const string & s )6798static string capitalize( const string & s )
6793{6799{
6794 // copy6800 // copy
@@ -6805,7 +6811,7 @@ static string capitalize( const string & s ) · 10 unmodified lines
6805 6811
6806//-----------------------------------------------------------------------------6812//-----------------------------------------------------------------------------
6807// name: apropos_top()6813// name: apropos_top()
6808// desc: dump top level info; added 1.4.1.0 (ge)6814// desc: output top level info; added 1.4.1.0 (ge)
6809//-----------------------------------------------------------------------------6815//-----------------------------------------------------------------------------
6810void Chuck_Type::apropos_top( std::string & output, const std::string & PREFIX )6816void Chuck_Type::apropos_top( std::string & output, const std::string & PREFIX )
6811{6817{
@@ -6899,7 +6905,8 @@ void apropos_func_arg( std::ostringstream & sout, a_Arg_List arg ) · 87 unmodified lines
6899// name: apropos_func()6905// name: apropos_func()
6900// desc: helper function for outputing function6906// desc: helper function for outputing function
6901//-----------------------------------------------------------------------------6907//-----------------------------------------------------------------------------
6902void apropos_func( std::ostringstream & sout, Chuck_Func * func, const std::string & PREFIX )6908void apropos_func( std::ostringstream & sout, Chuck_Func * func,
6909 const std::string & PREFIX )
6903{6910{
6904 // print line prefix, if any6911 // print line prefix, if any
6905 sout << PREFIX;6912 sout << PREFIX;
@@ -6940,9 +6947,10 @@ void apropos_func( std::ostringstream & sout, Chuck_Func * func, const std::stri · 34 unmodified lines
6940 6947
6941//-----------------------------------------------------------------------------6948//-----------------------------------------------------------------------------
6942// name: apropos_funcs()6949// name: apropos_funcs()
6943// desc: dump info about funcs; added 1.4.1.0 (ge)6950// desc: output info about funcs; added 1.4.1.0 (ge)
6944//-----------------------------------------------------------------------------6951//-----------------------------------------------------------------------------
6945void Chuck_Type::apropos_funcs( std::string & output, const std::string & PREFIX, t_CKBOOL inherited )6952void Chuck_Type::apropos_funcs( std::string & output,
6953 const std::string & PREFIX, t_CKBOOL inherited )
6946{6954{
6947 // make a string output stream6955 // make a string output stream
6948 ostringstream sout;6956 ostringstream sout;
@@ -7047,7 +7055,8 @@ void Chuck_Type::apropos_funcs( std::string & output, const std::string & PREFIX · 98 unmodified lines
7047// name: apropos_var()7055// name: apropos_var()
7048// desc: helper function for outputing variable7056// desc: helper function for outputing variable
7049//-----------------------------------------------------------------------------7057//-----------------------------------------------------------------------------
7050void apropos_var( std::ostringstream & sout, Chuck_Value * var, const std::string & PREFIX )7058void apropos_var( std::ostringstream & sout, Chuck_Value * var,
7059 const std::string & PREFIX )
7051{7060{
7052 // print line prefix, if any7061 // print line prefix, if any
7053 sout << PREFIX;7062 sout << PREFIX;
@@ -7072,9 +7081,10 @@ void apropos_var( std::ostringstream & sout, Chuck_Value * var, const std::strin · 18 unmodified lines
7072 7081
7073//-----------------------------------------------------------------------------7082//-----------------------------------------------------------------------------
7074// name: apropos_vars()7083// name: apropos_vars()
7075// desc: dump info about vars; added 1.4.1.0 (ge)7084// desc: output info about vars; added 1.4.1.0 (ge)
7076//-----------------------------------------------------------------------------7085//-----------------------------------------------------------------------------
7077void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX, t_CKBOOL inherited )7086void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX,
7087 t_CKBOOL inherited )
7078{7088{
7079 // make a string output stream7089 // make a string output stream
7080 ostringstream sout;7090 ostringstream sout;
@@ -7166,3 +7176,31 @@ void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX, · 85 unmodified lines
7166 // output to string7176 // output to string
7167 output = sout.str();7177 output = sout.str();
7168}7178}
7179
7180
7181
7182
7183//-----------------------------------------------------------------------------
7184// name: dump()
7185// desc: generate object state; output to console | 1.4.1.1 (ge)
7186//-----------------------------------------------------------------------------
7187void Chuck_Type::dump( Chuck_Object * obj )
7188{
7189 // the info
7190 string output;
7191 // get it
7192 this->dump( obj, output );
7193 // print it
7194 CK_STDCERR << output << CK_STDENDL;
7195}
7196
7197
7198
7199
7200//-----------------------------------------------------------------------------
7201// name: dump()
7202// desc: generate object state; output to string | 1.4.1.1 (ge)
7203//-----------------------------------------------------------------------------
7204void Chuck_Type::dump( Chuck_Object * obj, std::string & output )
7205{
7206}
src/core/chuck_type.h+8−2
@@ -656,11 +656,17 @@ protected: · 655 unmodified lines
656 std::string ret;656 std::string ret;
657 657
658public: // apropos | 1.4.1.0 (ge)658public: // apropos | 1.4.1.0 (ge)
659 // dump info to console659 // generate info; output to console
660 void apropos();660 void apropos();
661 // dump info to string661 // generate info; output to string
662 void apropos( std::string & output );662 void apropos( std::string & output );
663 663
664public: // dump | 1.4.1.1 (ge)
665 // generate object state; output to console
666 void dump( Chuck_Object * obj );
667 // generate object state; output to string
668 void dump( Chuck_Object * obj, std::string & output );
669
664protected: // apropos-related helper function670protected: // apropos-related helper function
665 // dump top level info671 // dump top level info
666 void apropos_top( std::string & output, const std::string & prefix );672 void apropos_top( std::string & output, const std::string & prefix );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t