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
7979 func = make_new_mfun( "string", "toString", object_toString );
8080 func->doc = "get a textual description of this object.";
8181 if( !type_engine_import_mfun( env, func ) ) goto error;
82−
83− // add dump()
84− // func = make_new_mfun( "void", "dump", object_dump );
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 );
82+
83+ // add help()
84+ func = make_new_sfun( "void", "help", object_help );
9085 func->doc = "generate and output helpful information about a class or object.";
9186 if( !type_engine_import_sfun( env, func ) ) goto error;
9287
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+
9393 // end the class import
9494 type_engine_import_class_end( env );
9595
@@ -1071,8 +1071,8 @@ CK_DLL_MFUN( object_dump ) · 975 unmodified lines
10711071 me->dump();
10721072 }
10731073
1074−// apropos
1075−CK_DLL_SFUN( object_apropos )
1074+// help
1075+CK_DLL_SFUN( object_help )
10761076 {
10771077 TYPE->apropos();
10781078 // get object
@@ -1083,6 +1083,7 @@ CK_DLL_SFUN( object_apropos ) · 4 unmodified lines
10831083
10841084
10851085
1086+
10861087 // ctor
10871088 CK_DLL_CTOR( ugen_ctor )
10881089 {
src/core/chuck_lang.h+1−1
@@ -73,7 +73,7 @@ CK_DLL_MFUN( object_getType ); · 72 unmodified lines
7373 CK_DLL_MFUN( object_hashCode );
7474 CK_DLL_MFUN( object_toString );
7575 CK_DLL_MFUN( object_dump );
76−CK_DLL_SFUN( object_apropos );
76+CK_DLL_SFUN( object_help );
7777
7878
7979 //-----------------------------------------------------------------------------
src/core/chuck_oo.cpp+9−16
@@ -347,34 +347,27 @@ Chuck_Object::~Chuck_Object() · 346 unmodified lines
347347 // name: dump()
348348 // desc: output current state (can be overridden)
349349 //-----------------------------------------------------------------------------
350−void Chuck_Object::dump() // 1.4.1.0
350+void Chuck_Object::dump() // 1.4.1.1 (ge)
351351 {
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 );
353357 }
354358
355359
356360
357361
358362 //-----------------------------------------------------------------------------
359−// name: apropos()
360−// desc: output interface (can be overriden; but probably shouldn't be)
363+// name: help()
364+// desc: output type info (can be overriden; but probably shouldn't be)
361365 //-----------------------------------------------------------------------------
362−void Chuck_Object::apropos() // 1.4.1.0
366+void Chuck_Object::help() // 1.4.1.0 (ge)
363367 {
364368 // type to unpack
365369 Chuck_Type * type = this->type_ref;
366370
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−
378371 // unpack type and output its info
379372 type->apropos();
380373 }
src/core/chuck_oo.h+1−1
@@ -180,7 +180,7 @@ public: · 179 unmodified lines
180180
181181 public:
182182 // output type info (can be overriden; but probably shouldn't be)
183− virtual void apropos();
183+ virtual void help();
184184
185185 public:
186186 // virtual table
src/core/chuck_type.cpp+47−9
@@ -6681,7 +6681,7 @@ const char * Chuck_Type::c_name() · 6680 unmodified lines
66816681
66826682 //-----------------------------------------------------------------------------
66836683 // 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)
66856685 // portions of this adapted from ckdoc -- thanks be to Spencer Salazar
66866686 //-----------------------------------------------------------------------------
66876687 void Chuck_Type::apropos( std::string & output )
@@ -6754,7 +6754,7 @@ void Chuck_Type::apropos( std::string & output ) · 66 unmodified lines
67546754
67556755 //-----------------------------------------------------------------------------
67566756 // name: apropos()
6757−// desc: dump info to console
6757+// desc: generate info; output to console | added 1.4.1.0 (ge)
67586758 //-----------------------------------------------------------------------------
67596759 void Chuck_Type::apropos()
67606760 {
@@ -6769,11 +6769,15 @@ void Chuck_Type::apropos() · 8 unmodified lines
67696769
67706770
67716771
6772+//-----------------------------------------------------------------------------
67726773 // comparer
6774+//-----------------------------------------------------------------------------
67736775 static bool comp_func( Chuck_Func * a, Chuck_Func * b )
67746776 { return a->name < b->name; }
67756777
6778+//-----------------------------------------------------------------------------
67766779 // comparer
6780+//-----------------------------------------------------------------------------
67776781 static bool comp_value( Chuck_Value * a, Chuck_Value * b )
67786782 {
67796783 string lowerA = a->name;;
@@ -6788,7 +6792,9 @@ static bool comp_value( Chuck_Value * a, Chuck_Value * b ) · 8 unmodified lines
67886792 else return a->name > b->name;
67896793 }
67906794
6795+//-----------------------------------------------------------------------------
67916796 // capitalize first character
6797+//-----------------------------------------------------------------------------
67926798 static string capitalize( const string & s )
67936799 {
67946800 // copy
@@ -6805,7 +6811,7 @@ static string capitalize( const string & s ) · 10 unmodified lines
68056811
68066812 //-----------------------------------------------------------------------------
68076813 // 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)
68096815 //-----------------------------------------------------------------------------
68106816 void Chuck_Type::apropos_top( std::string & output, const std::string & PREFIX )
68116817 {
@@ -6899,7 +6905,8 @@ void apropos_func_arg( std::ostringstream & sout, a_Arg_List arg ) · 87 unmodified lines
68996905 // name: apropos_func()
69006906 // desc: helper function for outputing function
69016907 //-----------------------------------------------------------------------------
6902−void apropos_func( std::ostringstream & sout, Chuck_Func * func, const std::string & PREFIX )
6908+void apropos_func( std::ostringstream & sout, Chuck_Func * func,
6909+ const std::string & PREFIX )
69036910 {
69046911 // print line prefix, if any
69056912 sout << PREFIX;
@@ -6940,9 +6947,10 @@ void apropos_func( std::ostringstream & sout, Chuck_Func * func, const std::stri · 34 unmodified lines
69406947
69416948 //-----------------------------------------------------------------------------
69426949 // 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)
69446951 //-----------------------------------------------------------------------------
6945−void Chuck_Type::apropos_funcs( std::string & output, const std::string & PREFIX, t_CKBOOL inherited )
6952+void Chuck_Type::apropos_funcs( std::string & output,
6953+ const std::string & PREFIX, t_CKBOOL inherited )
69466954 {
69476955 // make a string output stream
69486956 ostringstream sout;
@@ -7047,7 +7055,8 @@ void Chuck_Type::apropos_funcs( std::string & output, const std::string & PREFIX · 98 unmodified lines
70477055 // name: apropos_var()
70487056 // desc: helper function for outputing variable
70497057 //-----------------------------------------------------------------------------
7050−void apropos_var( std::ostringstream & sout, Chuck_Value * var, const std::string & PREFIX )
7058+void apropos_var( std::ostringstream & sout, Chuck_Value * var,
7059+ const std::string & PREFIX )
70517060 {
70527061 // print line prefix, if any
70537062 sout << PREFIX;
@@ -7072,9 +7081,10 @@ void apropos_var( std::ostringstream & sout, Chuck_Value * var, const std::strin · 18 unmodified lines
70727081
70737082 //-----------------------------------------------------------------------------
70747083 // 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)
70767085 //-----------------------------------------------------------------------------
7077−void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX, t_CKBOOL inherited )
7086+void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX,
7087+ t_CKBOOL inherited )
70787088 {
70797089 // make a string output stream
70807090 ostringstream sout;
@@ -7166,3 +7176,31 @@ void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX, · 85 unmodified lines
71667176 // output to string
71677177 output = sout.str();
71687178 }
7179+
7180+
7181+
7182+
7183+//-----------------------------------------------------------------------------
7184+// name: dump()
7185+// desc: generate object state; output to console | 1.4.1.1 (ge)
7186+//-----------------------------------------------------------------------------
7187+void 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+//-----------------------------------------------------------------------------
7204+void 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
656656 std::string ret;
657657
658658 public: // apropos | 1.4.1.0 (ge)
659− // dump info to console
659+ // generate info; output to console
660660 void apropos();
661− // dump info to string
661+ // generate info; output to string
662662 void apropos( std::string & output );
663663
664+public: // 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+
664670 protected: // apropos-related helper function
665671 // dump top level info
666672 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