comparison libinterp/octave-value/ov-classdef.cc @ 20615:729a85dafba8

use new string_value method to handle value extraction errors * ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov.cc, pt-idx.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 17:55:57 -0400
parents c1a6c31ac29a
children
comparison
equal deleted inserted replaced
20614:10ec79b47808 20615:729a85dafba8
526 { 526 {
527 octave_value_list retval; 527 octave_value_list retval;
528 528
529 if (args.length () == 1) 529 if (args.length () == 1)
530 { 530 {
531 std::string name = args(0).string_value (); 531 std::string name = args(0).string_value ("fromName: invalid class name, expected a string value");
532 532
533 if (! error_state) 533 retval(0) = to_ov (lookup_class (name));
534 retval(0) = to_ov (lookup_class (name));
535 else
536 error ("fromName: invalid class name, expected a string value");
537 } 534 }
538 else 535 else
539 error ("fromName: invalid number of parameters"); 536 error ("fromName: invalid number of parameters");
540 537
541 return retval; 538 return retval;
550 { 547 {
551 cdef_class cls (to_cdef (args(0))); 548 cdef_class cls (to_cdef (args(0)));
552 549
553 if (! error_state) 550 if (! error_state)
554 { 551 {
555 std::string meth_name = args(1).string_value (); 552 std::string meth_name = args(1).string_value ("fevalStatic: invalid method name, expected a string value");
556 553
557 if (! error_state) 554 cdef_method meth = cls.find_method (meth_name);
555
556 if (meth.ok ())
558 { 557 {
559 cdef_method meth = cls.find_method (meth_name); 558 if (meth.is_static ())
560 559 retval = meth.execute (args.splice (0, 2), nargout,
561 if (meth.ok ()) 560 true, "fevalStatic");
562 {
563 if (meth.is_static ())
564 retval = meth.execute (args.splice (0, 2), nargout,
565 true, "fevalStatic");
566 else
567 error ("fevalStatic: method `%s' is not static",
568 meth_name.c_str ());
569 }
570 else 561 else
571 error ("fevalStatic: method not found: %s", meth_name.c_str ()); 562 error ("fevalStatic: method `%s' is not static",
563 meth_name.c_str ());
572 } 564 }
573 else 565 else
574 error ("fevalStatic: invalid method name, expected a string value"); 566 error ("fevalStatic: method not found: %s", meth_name.c_str ());
575 } 567 }
576 else 568 else
577 error ("fevalStatic: invalid object, expected a meta.class object"); 569 error ("fevalStatic: invalid object, expected a meta.class object");
578 } 570 }
579 else 571 else
592 { 584 {
593 cdef_class cls = to_cdef (args(0)); 585 cdef_class cls = to_cdef (args(0));
594 586
595 if (! error_state) 587 if (! error_state)
596 { 588 {
597 std::string prop_name = args(1).string_value (); 589 std::string prop_name = args(1).string_value ("getConstant: invalid property name, expected a string value");
598 590
599 if (! error_state) 591 cdef_property prop = cls.find_property (prop_name);
592
593 if (prop.ok ())
600 { 594 {
601 cdef_property prop = cls.find_property (prop_name); 595 if (prop.is_constant ())
602 596 retval(0) = prop.get_value (true, "getConstant");
603 if (prop.ok ())
604 {
605 if (prop.is_constant ())
606 retval(0) = prop.get_value (true, "getConstant");
607 else
608 error ("getConstant: property `%s' is not constant",
609 prop_name.c_str ());
610 }
611 else 597 else
612 error ("getConstant: property not found: %s", 598 error ("getConstant: property `%s' is not constant",
613 prop_name.c_str ()); 599 prop_name.c_str ());
614 } 600 }
615 else 601 else
616 error ("getConstant: invalid property name, expected a string value"); 602 error ("getConstant: property not found: %s",
603 prop_name.c_str ());
617 } 604 }
618 else 605 else
619 error ("getConstant: invalid object, expected a meta.class object"); 606 error ("getConstant: invalid object, expected a meta.class object");
620 } 607 }
621 else 608 else
2411 std::cerr << "static method/property" << std::endl; 2398 std::cerr << "static method/property" << std::endl;
2412 #endif 2399 #endif
2413 2400
2414 if (idx.front ().length () == 1) 2401 if (idx.front ().length () == 1)
2415 { 2402 {
2416 std::string nm = idx.front ()(0).string_value (); 2403 std::string nm = idx.front ()(0).string_value ("invalid meta.class indexing, expected a method or property name");
2417 2404
2418 if (! error_state) 2405 cdef_method meth = find_method (nm);
2406
2407 if (meth.ok ())
2419 { 2408 {
2420 cdef_method meth = find_method (nm); 2409 if (meth.is_static ())
2421
2422 if (meth.ok ())
2423 { 2410 {
2424 if (meth.is_static ()) 2411 octave_value_list args;
2412
2413 if (type.length () > 1 && idx.size () > 1
2414 && type[1] == '(')
2425 { 2415 {
2426 octave_value_list args; 2416 args = *(++(idx.begin ()));
2427 2417 skip++;
2428 if (type.length () > 1 && idx.size () > 1
2429 && type[1] == '(')
2430 {
2431 args = *(++(idx.begin ()));
2432 skip++;
2433 }
2434
2435 retval = meth.execute (args, (type.length () > skip
2436 ? 1 : nargout), true,
2437 "meta.class");
2438 } 2418 }
2439 else 2419
2440 error ("method `%s' is not static", nm.c_str ()); 2420 retval = meth.execute (args, (type.length () > skip
2421 ? 1 : nargout), true,
2422 "meta.class");
2441 } 2423 }
2442 else 2424 else
2443 { 2425 error ("method `%s' is not static", nm.c_str ());
2444 cdef_property prop = find_property (nm);
2445
2446 if (prop.ok ())
2447 {
2448 if (prop.is_constant ())
2449 retval(0) = prop.get_value (true, "meta.class");
2450 else
2451 error ("property `%s' is not constant", nm.c_str ());
2452 }
2453 else
2454 error ("no such method or property `%s'", nm.c_str ());
2455 }
2456 } 2426 }
2457 else 2427 else
2458 error ("invalid meta.class indexing, expected a method or property name"); 2428 {
2429 cdef_property prop = find_property (nm);
2430
2431 if (prop.ok ())
2432 {
2433 if (prop.is_constant ())
2434 retval(0) = prop.get_value (true, "meta.class");
2435 else
2436 error ("property `%s' is not constant", nm.c_str ());
2437 }
2438 else
2439 error ("no such method or property `%s'", nm.c_str ());
2440 }
2459 } 2441 }
2460 else 2442 else
2461 error ("invalid meta.class indexing"); 2443 error ("invalid meta.class indexing");
2462 break; 2444 break;
2463 2445
3303 { 3285 {
3304 octave_value_list retval; 3286 octave_value_list retval;
3305 3287
3306 if (args.length () == 1) 3288 if (args.length () == 1)
3307 { 3289 {
3308 std::string name = args(0).string_value (); 3290 std::string name = args(0).string_value ("fromName: invalid package name, expected a string value");
3309 3291
3310 if (! error_state) 3292 retval(0) = to_ov (lookup_package (name));
3311 retval(0) = to_ov (lookup_package (name));
3312 else
3313 error ("fromName: invalid package name, expected a string value");
3314 } 3293 }
3315 else 3294 else
3316 error ("fromName: invalid number of parameters"); 3295 error ("fromName: invalid number of parameters");
3317 3296
3318 return retval; 3297 return retval;
3463 switch (type[0]) 3442 switch (type[0])
3464 { 3443 {
3465 case '.': 3444 case '.':
3466 if (idx.front ().length () == 1) 3445 if (idx.front ().length () == 1)
3467 { 3446 {
3468 std::string nm = idx.front ()(0).string_value (); 3447 std::string nm = idx.front ()(0).string_value ("invalid meta.package indexing, expected a symbol name");
3469 3448
3470 if (! error_state) 3449 #if DEBUG_TRACE
3450 std::cerr << "meta.package query: " << nm << std::endl;
3451 #endif
3452
3453 octave_value o = find (nm);
3454
3455 if (o.is_defined ())
3471 { 3456 {
3472 #if DEBUG_TRACE 3457 if (o.is_function ())
3473 std::cerr << "meta.package query: " << nm << std::endl;
3474 #endif
3475
3476 octave_value o = find (nm);
3477
3478 if (o.is_defined ())
3479 { 3458 {
3480 if (o.is_function ()) 3459 octave_function* fcn = o.function_value ();
3460
3461 // NOTE: the case where the package query is the last
3462 // part of this subsref index is handled in the parse
3463 // tree, because there is some logic to handle magic
3464 // "end" that makes it impossible to execute the
3465 // function call at this stage.
3466
3467 if (type.size () > 1
3468 && ! fcn->is_postfix_index_handled (type[1]))
3481 { 3469 {
3482 octave_function* fcn = o.function_value (); 3470 octave_value_list tmp_args;
3483 3471
3484 // NOTE: the case where the package query is the last 3472 retval = o.do_multi_index_op (nargout,
3485 // part of this subsref index is handled in the parse 3473 tmp_args);
3486 // tree, because there is some logic to handle magic
3487 // "end" that makes it impossible to execute the
3488 // function call at this stage.
3489
3490 if (type.size () > 1
3491 && ! fcn->is_postfix_index_handled (type[1]))
3492 {
3493 octave_value_list tmp_args;
3494
3495 retval = o.do_multi_index_op (nargout,
3496 tmp_args);
3497 }
3498 else
3499 retval(0) = o;
3500
3501 if (type.size () > 1 && idx.size () > 1)
3502 retval = retval(0).next_subsref (nargout, type,
3503 idx, 1);
3504 } 3474 }
3505 else if (type.size () > 1 && idx.size () > 1)
3506 retval = o.next_subsref (nargout, type, idx, 1);
3507 else 3475 else
3508 retval(0) = o; 3476 retval(0) = o;
3477
3478 if (type.size () > 1 && idx.size () > 1)
3479 retval = retval(0).next_subsref (nargout, type,
3480 idx, 1);
3509 } 3481 }
3510 else if (! error_state) 3482 else if (type.size () > 1 && idx.size () > 1)
3511 error ("member `%s' in package `%s' does not exist", 3483 retval = o.next_subsref (nargout, type, idx, 1);
3512 nm.c_str (), get_name ().c_str ()); 3484 else
3485 retval(0) = o;
3513 } 3486 }
3514 else 3487 else if (! error_state)
3515 error ("invalid meta.package indexing, expected a symbol name"); 3488 error ("member `%s' in package `%s' does not exist",
3489 nm.c_str (), get_name ().c_str ());
3516 } 3490 }
3517 else 3491 else
3518 error ("invalid meta.package indexing"); 3492 error ("invalid meta.package indexing");
3519 break; 3493 break;
3520 3494
3853 { 3827 {
3854 octave_value retval; 3828 octave_value retval;
3855 3829
3856 if (args.length () == 1) 3830 if (args.length () == 1)
3857 { 3831 {
3858 std::string cname = args(0).string_value (); 3832 std::string cname = args(0).string_value ("invalid package name, expected a string value");
3859 3833
3860 if (! error_state) 3834 retval = to_ov (lookup_package (cname));
3861 retval = to_ov (lookup_package (cname));
3862 else
3863 error ("invalid package name, expected a string value");
3864 } 3835 }
3865 else 3836 else
3866 print_usage (); 3837 print_usage ();
3867 3838
3868 return retval; 3839 return retval;
3891 << std::endl; 3862 << std::endl;
3892 #endif 3863 #endif
3893 3864
3894 if (args.length () == 1) 3865 if (args.length () == 1)
3895 { 3866 {
3896 std::string cls = args(0).string_value (); 3867 std::string cls = args(0).string_value ("invalid class name, expected a string value");
3897 3868
3898 if (! error_state) 3869 retval = to_ov (lookup_class (cls));
3899 retval = to_ov (lookup_class (cls));
3900 else
3901 error ("invalid class name, expected a string value");
3902 } 3870 }
3903 else 3871 else
3904 print_usage (); 3872 print_usage ();
3905 3873
3906 return retval; 3874 return retval;