comparison libinterp/octave-value/ov-classdef.cc @ 19065:1f36981ab323

allow debugging messages in classdef code to be disabled * ov-classdef.cc (DEBUG_TRACE): New macro. Use DEBUG_TRACE to allow debugging messages to be disabled. Use std::cerr instead of printf for debugging messages.
author John W. Eaton <jwe@octave.org>
date Tue, 19 Aug 2014 12:02:15 -0400
parents fe0e34be5576
children 56bc1464ec59
comparison
equal deleted inserted replaced
19064:9ef10e6a5987 19065:1f36981ab323
42 #include "singleton-cleanup.h" 42 #include "singleton-cleanup.h"
43 #include "symtab.h" 43 #include "symtab.h"
44 #include "toplev.h" 44 #include "toplev.h"
45 45
46 #include "Array.cc" 46 #include "Array.cc"
47
48 // Define to 1 to enable debugging statements.
49 #define DEBUG_TRACE 0
47 50
48 static void 51 static void
49 gripe_method_access (const std::string& from, const cdef_method& meth) 52 gripe_method_access (const std::string& from, const cdef_method& meth)
50 { 53 {
51 octave_value acc = meth.get ("Access"); 54 octave_value acc = meth.get ("Access");
1854 return true; 1857 return true;
1855 } 1858 }
1856 1859
1857 handle_cdef_object::~handle_cdef_object (void) 1860 handle_cdef_object::~handle_cdef_object (void)
1858 { 1861 {
1859 gnulib::printf ("deleting %s object (handle)\n", 1862 #if DEBUG_TRACE
1860 get_class ().get_name ().c_str ()); 1863 std::cerr << "deleting " << get_class ().get_name ()
1864 << " object (handle)" << std::endl;
1865 #endif
1861 } 1866 }
1862 1867
1863 value_cdef_object::~value_cdef_object (void) 1868 value_cdef_object::~value_cdef_object (void)
1864 { 1869 {
1865 gnulib::printf ("deleting %s object (value)\n", 1870 #if DEBUG_TRACE
1866 get_class ().get_name ().c_str ()); 1871 std::cerr << "deleting " << get_class ().get_name ()
1872 << " object (value)" << std::endl;
1873 #endif
1867 } 1874 }
1868 1875
1869 cdef_class::cdef_class_rep::cdef_class_rep (const std::list<cdef_class>& superclasses) 1876 cdef_class::cdef_class_rep::cdef_class_rep (const std::list<cdef_class>& superclasses)
1870 : cdef_meta_object_rep (), member_count (0), handle_class (false), 1877 : cdef_meta_object_rep (), member_count (0), handle_class (false),
1871 object_count (0), meta (false) 1878 object_count (0), meta (false)
2065 = a.get_constructor_list (); 2072 = a.get_constructor_list ();
2066 2073
2067 for (std::list<cdef_class>::const_iterator it = explicit_ctor_list.begin (); 2074 for (std::list<cdef_class>::const_iterator it = explicit_ctor_list.begin ();
2068 ! error_state && it != explicit_ctor_list.end (); ++it) 2075 ! error_state && it != explicit_ctor_list.end (); ++it)
2069 { 2076 {
2070 gnulib::printf ("explicit superclass constructor: %s\n", 2077 #if DEBUG_TRACE
2071 it->get_name ().c_str ()); 2078 std::cerr << "explicit superclass constructor: "
2079 << it->get_name () << std::endl;
2080 #endif
2081
2072 implicit_ctor_list.remove (*it); 2082 implicit_ctor_list.remove (*it);
2073 } 2083 }
2074 } 2084 }
2075 } 2085 }
2076 else 2086 else
2382 2392
2383 switch (type[0]) 2393 switch (type[0])
2384 { 2394 {
2385 case '(': 2395 case '(':
2386 // Constructor call 2396 // Constructor call
2387 gnulib::printf ("constructor\n"); 2397
2398 #if DEBUG_TRACE
2399 std::cerr << "constructor" << std::endl;
2400 #endif
2401
2388 retval(0) = construct (idx.front ()); 2402 retval(0) = construct (idx.front ());
2389 break; 2403 break;
2390 2404
2391 case '.': 2405 case '.':
2392 // Static method, constant (or property?) 2406 // Static method, constant (or property?)
2393 gnulib::printf ("static method/property\n"); 2407
2408 #if DEBUG_TRACE
2409 std::cerr << "static method/property" << std::endl;
2410 #endif
2411
2394 if (idx.front ().length () == 1) 2412 if (idx.front ().length () == 1)
2395 { 2413 {
2396 std::string nm = idx.front ()(0).string_value (); 2414 std::string nm = idx.front ()(0).string_value ();
2397 2415
2398 if (! error_state) 2416 if (! error_state)
2683 // Class creation 2701 // Class creation
2684 2702
2685 class_name = full_class_name = t->ident ()->name (); 2703 class_name = full_class_name = t->ident ()->name ();
2686 if (! t->package_name ().empty ()) 2704 if (! t->package_name ().empty ())
2687 full_class_name = t->package_name () + "." + full_class_name; 2705 full_class_name = t->package_name () + "." + full_class_name;
2688 gnulib::printf ("class: %s\n", full_class_name.c_str ()); 2706
2707 #if DEBUG_TRACE
2708 std::cerr << "class: " << full_class_name << std::endl;
2709 #endif
2689 2710
2690 std::list<cdef_class> slist; 2711 std::list<cdef_class> slist;
2691 2712
2692 if (t->superclass_list ()) 2713 if (t->superclass_list ())
2693 { 2714 {
2694 for (tree_classdef_superclass_list::iterator it = t->superclass_list ()->begin (); 2715 for (tree_classdef_superclass_list::iterator it = t->superclass_list ()->begin ();
2695 ! error_state && it != t->superclass_list ()->end (); ++it) 2716 ! error_state && it != t->superclass_list ()->end (); ++it)
2696 { 2717 {
2697 std::string sclass_name = (*it)->class_name (); 2718 std::string sclass_name = (*it)->class_name ();
2698 2719
2699 gnulib::printf ("superclass: %s\n", sclass_name.c_str ()); 2720 #if DEBUG_TRACE
2721 std::cerr << "superclass: " << sclass_name << std::endl;
2722 #endif
2700 2723
2701 cdef_class sclass = lookup_class (sclass_name); 2724 cdef_class sclass = lookup_class (sclass_name);
2702 2725
2703 if (! error_state) 2726 if (! error_state)
2704 { 2727 {
2740 it != t->attribute_list ()->end (); ++it) 2763 it != t->attribute_list ()->end (); ++it)
2741 { 2764 {
2742 std::string aname = (*it)->ident ()->name (); 2765 std::string aname = (*it)->ident ()->name ();
2743 octave_value avalue = compute_attribute_value (*it); 2766 octave_value avalue = compute_attribute_value (*it);
2744 2767
2745 gnulib::printf ("class attribute: %s = %s\n", aname.c_str (), 2768 #if DEBUG_TRACE
2746 attribute_value_to_string (*it, avalue).c_str ()); 2769 std::cerr << "class attribute: " << aname << " = "
2770 << attribute_value_to_string (*it, avalue) << std::endl;
2771 #endif
2772
2747 retval.put (aname, avalue); 2773 retval.put (aname, avalue);
2748 } 2774 }
2749 } 2775 }
2750 2776
2751 tree_classdef_body* b = t->body (); 2777 tree_classdef_body* b = t->body ();
2764 2790
2765 for (tree_classdef_body::methods_list_iterator it = mb_list.begin (); 2791 for (tree_classdef_body::methods_list_iterator it = mb_list.begin ();
2766 it != mb_list.end (); ++it) 2792 it != mb_list.end (); ++it)
2767 { 2793 {
2768 std::map<std::string, octave_value> amap; 2794 std::map<std::string, octave_value> amap;
2769 gnulib::printf ("method block\n"); 2795
2796 #if DEBUG_TRACE
2797 std::cerr << "method block" << std::endl;
2798 #endif
2770 2799
2771 // Method attributes 2800 // Method attributes
2772 2801
2773 if ((*it)->attribute_list ()) 2802 if ((*it)->attribute_list ())
2774 { 2803 {
2776 ait != (*it)->attribute_list ()->end (); ++ait) 2805 ait != (*it)->attribute_list ()->end (); ++ait)
2777 { 2806 {
2778 std::string aname = (*ait)->ident ()->name (); 2807 std::string aname = (*ait)->ident ()->name ();
2779 octave_value avalue = compute_attribute_value (*ait); 2808 octave_value avalue = compute_attribute_value (*ait);
2780 2809
2781 gnulib::printf ("method attribute: %s = %s\n", aname.c_str (), 2810 #if DEBUG_TRACE
2782 attribute_value_to_string (*ait, avalue).c_str ()); 2811 std::cerr << "method attribute: " << aname << " = "
2812 << attribute_value_to_string (*ait, avalue)
2813 << std::endl;
2814 #endif
2815
2783 amap[aname] = avalue; 2816 amap[aname] = avalue;
2784 } 2817 }
2785 } 2818 }
2786 2819
2787 // Methods 2820 // Methods
2802 make_fcn_handle (*mit, full_class_name + ">" + mname); 2835 make_fcn_handle (*mit, full_class_name + ">" + mname);
2803 else 2836 else
2804 { 2837 {
2805 cdef_method meth = make_method (retval, mname, *mit); 2838 cdef_method meth = make_method (retval, mname, *mit);
2806 2839
2807 gnulib::printf ("%s: %s\n", (mname == class_name ? "constructor" : "method"), 2840 #if DEBUG_TRACE
2808 mname.c_str ()); 2841 std::cerr << (mname == class_name ? "constructor" : "method")
2842 << ": " << mname << std::endl;
2843 #endif
2844
2809 for (std::map<std::string, octave_value>::iterator ait = amap.begin (); 2845 for (std::map<std::string, octave_value>::iterator ait = amap.begin ();
2810 ait != amap.end (); ++ait) 2846 ait != amap.end (); ++ait)
2811 meth.put (ait->first, ait->second); 2847 meth.put (ait->first, ait->second);
2812 2848
2813 retval.install_method (meth); 2849 retval.install_method (meth);
2864 2900
2865 for (tree_classdef_body::properties_list_iterator it = pb_list.begin (); 2901 for (tree_classdef_body::properties_list_iterator it = pb_list.begin ();
2866 it != pb_list.end (); ++it) 2902 it != pb_list.end (); ++it)
2867 { 2903 {
2868 std::map<std::string, octave_value> amap; 2904 std::map<std::string, octave_value> amap;
2869 gnulib::printf ("property block\n"); 2905
2906 #if DEBUG_TRACE
2907 std::cerr << "property block" << std::endl;
2908 #endif
2870 2909
2871 // Property attributes 2910 // Property attributes
2872 2911
2873 if ((*it)->attribute_list ()) 2912 if ((*it)->attribute_list ())
2874 { 2913 {
2876 ait != (*it)->attribute_list ()->end (); ++ait) 2915 ait != (*it)->attribute_list ()->end (); ++ait)
2877 { 2916 {
2878 std::string aname = (*ait)->ident ()->name (); 2917 std::string aname = (*ait)->ident ()->name ();
2879 octave_value avalue = compute_attribute_value (*ait); 2918 octave_value avalue = compute_attribute_value (*ait);
2880 2919
2881 gnulib::printf ("property attribute: %s = %s\n", aname.c_str (), 2920 #if DEBUG_TRACE
2882 attribute_value_to_string (*ait, avalue).c_str ()); 2921 std::cerr << "property attribute: " << aname << " = "
2922 << attribute_value_to_string (*ait, avalue)
2923 << std::endl;
2924 #endif
2925
2883 if (aname == "Access") 2926 if (aname == "Access")
2884 { 2927 {
2885 amap["GetAccess"] = avalue; 2928 amap["GetAccess"] = avalue;
2886 amap["SetAccess"] = avalue; 2929 amap["SetAccess"] = avalue;
2887 } 2930 }
2899 { 2942 {
2900 std::string prop_name = (*pit)->ident ()->name (); 2943 std::string prop_name = (*pit)->ident ()->name ();
2901 2944
2902 cdef_property prop = ::make_property (retval, prop_name); 2945 cdef_property prop = ::make_property (retval, prop_name);
2903 2946
2904 gnulib::printf ("property: %s\n", (*pit)->ident ()->name ().c_str ()); 2947 #if DEBUG_TRACE
2948 std::cerr << "property: " << (*pit)->ident ()->name ()
2949 << std::endl;
2950 #endif
2951
2905 if ((*pit)->expression ()) 2952 if ((*pit)->expression ())
2906 { 2953 {
2907 octave_value pvalue = (*pit)->expression ()->rvalue1 (); 2954 octave_value pvalue = (*pit)->expression ()->rvalue1 ();
2908 2955
2909 gnulib::printf ("property default: %s\n", 2956 #if DEBUG_TRACE
2910 attribute_value_to_string (*pit, pvalue).c_str ()); 2957 std::cerr << "property default: "
2958 << attribute_value_to_string (*pit, pvalue)
2959 << std::endl;
2960 #endif
2961
2911 prop.put ("DefaultValue", pvalue); 2962 prop.put ("DefaultValue", pvalue);
2912 } 2963 }
2913 2964
2914 // Install property attributes. This is done before assigning the 2965 // Install property attributes. This is done before assigning the
2915 // property accessors so we can do validationby using cdef_property 2966 // property accessors so we can do validationby using cdef_property
3442 { 3493 {
3443 std::string nm = idx.front ()(0).string_value (); 3494 std::string nm = idx.front ()(0).string_value ();
3444 3495
3445 if (! error_state) 3496 if (! error_state)
3446 { 3497 {
3447 gnulib::printf ("meta.package query: %s\n", nm.c_str ()); 3498 #if DEBUG_TRACE
3499 std::cerr << "meta.package query: " << nm << std::endl;
3500 #endif
3448 3501
3449 octave_value o = find (nm); 3502 octave_value o = find (nm);
3450 3503
3451 if (o.is_defined ()) 3504 if (o.is_defined ())
3452 { 3505 {
3859 Undocumented internal function.\n\ 3912 Undocumented internal function.\n\
3860 @end deftypefn") 3913 @end deftypefn")
3861 { 3914 {
3862 octave_value retval; 3915 octave_value retval;
3863 3916
3917 #if DEBUG_TRACE
3864 std::cerr << "__meta_class_query__ (" 3918 std::cerr << "__meta_class_query__ ("
3865 << args(0).string_value () << ")" 3919 << args(0).string_value () << ")"
3866 << std::endl; 3920 << std::endl;
3921 #endif
3867 3922
3868 if (args.length () == 1) 3923 if (args.length () == 1)
3869 { 3924 {
3870 std::string cls = args(0).string_value (); 3925 std::string cls = args(0).string_value ();
3871 3926