1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
|
////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2012-2021 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Octave is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file COPYING. If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include "cdef-manager.h"
#include "cdef-utils.h"
#include "interpreter.h"
#include "ov-classdef.h"
namespace octave
{
static octave_value
make_fcn_handle (octave_builtin::fcn ff, const std::string& nm)
{
octave_value fcn (new octave_builtin (ff, nm));
return octave_value (new octave_fcn_handle (fcn));
}
static octave_value_list
class_get_properties (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () == 1 && args(0).type_name () == "object")
{
cdef_class cls (to_cdef (args(0)));
retval(0) = cls.get_properties ();
}
return retval;
}
static octave_value_list
class_get_methods (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () == 1 && args(0).type_name () == "object")
{
cdef_class cls (to_cdef (args(0)));
retval(0) = cls.get_methods ();
}
return retval;
}
static octave_value_list
class_get_superclasses (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () == 1 && args(0).type_name () == "object"
&& args(0).class_name () == "meta.class")
{
cdef_class cls (to_cdef (args(0)));
Cell classes = cls.get ("SuperClasses").cell_value ();
retval(0) = to_ov (lookup_classes (classes));
}
return retval;
}
static octave_value_list
class_get_inferiorclasses (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () == 1 && args(0).type_name () == "object"
&& args(0).class_name () == "meta.class")
{
cdef_class cls (to_cdef (args(0)));
Cell classes = cls.get ("InferiorClasses").cell_value ();
retval(0) = to_ov (lookup_classes (classes));
}
return retval;
}
static octave_value_list
class_fromName (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () != 1)
error ("fromName: invalid number of parameters");
std::string name = args(0).xstring_value ("fromName: CLASS_NAME must be a string");
retval(0) = to_ov (lookup_class (name, false));
return retval;
}
static octave_value_list
class_fevalStatic (const octave_value_list& args, int nargout)
{
if (args.length () <= 1 || args(0).type_name () != "object")
error ("fevalStatic: first argument must be a meta.class object");
cdef_class cls (to_cdef (args(0)));
std::string meth_name = args(1).xstring_value ("fevalStatic: method name must be a string");
cdef_method meth = cls.find_method (meth_name);
if (! meth.ok ())
error ("fevalStatic: method not found: %s", meth_name.c_str ());
if (! meth.is_static ())
error ("fevalStatic: method '%s' is not static", meth_name.c_str ());
return meth.execute (args.splice (0, 2), nargout, true, "fevalStatic");
}
static octave_value_list
class_getConstant (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () != 2 || args(0).type_name () != "object"
|| args(0).class_name () != "meta.class")
error ("getConstant: first argument must be a meta.class object");
cdef_class cls = to_cdef (args(0));
std::string prop_name = args(1).xstring_value ("getConstant: property name must be a string");
cdef_property prop = cls.find_property (prop_name);
if (! prop.ok ())
error ("getConstant: property not found: %s",
prop_name.c_str ());
if (! prop.is_constant ())
error ("getConstant: property '%s' is not constant",
prop_name.c_str ());
retval(0) = prop.get_value (true, "getConstant");
return retval;
}
#define META_CLASS_CMP(OP, CLSA, CLSB, FUN) \
static octave_value_list \
class_ ## OP (const octave_value_list& args, int /* nargout */) \
{ \
octave_value_list retval; \
\
if (args.length () != 2 \
|| args(0).type_name () != "object" \
|| args(1).type_name () != "object" \
|| args(0).class_name () != "meta.class" \
|| args(1).class_name () != "meta.class") \
error (#OP ": invalid arguments"); \
\
cdef_class clsa = to_cdef (args(0)); \
\
cdef_class clsb = to_cdef (args(1)); \
\
retval(0) = FUN (CLSA, CLSB); \
\
return retval; \
}
META_CLASS_CMP (lt, clsb, clsa, is_strict_superclass)
META_CLASS_CMP (le, clsb, clsa, is_superclass)
META_CLASS_CMP (gt, clsa, clsb, is_strict_superclass)
META_CLASS_CMP (ge, clsa, clsb, is_superclass)
META_CLASS_CMP (eq, clsa, clsb, operator==)
META_CLASS_CMP (ne, clsa, clsb, operator!=)
static octave_value_list
property_get_defaultvalue (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () == 1 && args(0).type_name () == "object")
{
cdef_property prop (to_cdef (args(0)));
retval(0) = prop.get ("DefaultValue");
if (! retval(0).is_defined ())
error_with_id ("Octave:class:NoDefaultDefined",
"no default value for property '%s'",
prop.get_name ().c_str ());
}
return retval;
}
static octave_value_list
handle_delete (const octave_value_list& /* args */, int /* nargout */)
{
octave_value_list retval;
// FIXME: implement this. Wait, what is this supposed to do?
return retval;
}
static octave_value_list
package_get_classes (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval (1, Matrix ());
if (args.length () == 1 && args(0).type_name () == "object"
&& args(0).class_name () == "meta.package")
{
cdef_package pack (to_cdef (args(0)));
retval(0) = pack.get_classes ();
}
return retval;
}
static octave_value_list
package_get_functions (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval (1, Matrix ());
if (args.length () == 0 && args(0).type_name () == "object"
&& args(0).class_name () == "meta.package")
{
cdef_package pack (to_cdef (args(0)));
retval(0) = pack.get_functions ();
}
return retval;
}
static octave_value_list
package_get_packages (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval (1, Matrix ());
if (args.length () == 0 && args(0).type_name () == "object"
&& args(0).class_name () == "meta.package")
{
cdef_package pack (to_cdef (args(0)));
retval(0) = pack.get_packages ();
}
return retval;
}
static octave_value_list
package_getAllPackages (interpreter& interp,
const octave_value_list& /* args */, int /* nargout */)
{
std::map<std::string, cdef_package> toplevel_packages;
load_path& lp = interp.get_load_path ();
std::list<std::string> names = lp.get_all_package_names ();
cdef_manager& cdm = interp.get_cdef_manager ();
toplevel_packages["meta"] = cdm.find_package ("meta", false, false);
for (const auto& nm : names)
toplevel_packages[nm] = cdm.find_package (nm, false, true);
Cell c (toplevel_packages.size (), 1);
int i = 0;
for (const auto& nm_pkg : toplevel_packages)
c(i++,0) = to_ov (nm_pkg.second);
return octave_value_list (octave_value (c));
}
static octave_value_list
package_fromName (const octave_value_list& args, int /* nargout */)
{
octave_value_list retval;
if (args.length () != 1)
error ("fromName: invalid number of parameters");
std::string name = args(0).xstring_value ("fromName: PACKAGE_NAME must be a string");
retval(0) = to_ov (lookup_package (name, false));
return retval;
}
cdef_manager::cdef_manager (interpreter& interp)
: m_interpreter (interp), m_all_classes (), m_all_packages (),
m_meta_class (), m_meta_property (), m_meta_method (),
m_meta_package (), m_meta ()
{
type_info& ti = m_interpreter.get_type_info ();
octave_classdef::register_type (ti);
// bootstrap
cdef_class tmp_handle = make_class ("handle");
m_meta_class = make_meta_class ("meta.class", tmp_handle);
tmp_handle.set_class (m_meta_class);
m_meta_class.set_class (m_meta_class);
// meta classes
m_meta_property = make_meta_class ("meta.property", tmp_handle);
m_meta_method = make_meta_class ("meta.method", tmp_handle);
m_meta_package = make_meta_class ("meta.package", tmp_handle);
cdef_class tmp_meta_event
= make_meta_class ("meta.event", tmp_handle);
cdef_class tmp_meta_dynproperty
= make_meta_class ("meta.dynamicproperty", tmp_handle);
// meta.class properties
m_meta_class.install_property
(make_attribute (m_meta_class, "Abstract"));
m_meta_class.install_property
(make_attribute (m_meta_class, "ConstructOnLoad"));
m_meta_class.install_property
(make_property (m_meta_class, "ContainingPackage"));
m_meta_class.install_property
(make_property (m_meta_class, "Description"));
m_meta_class.install_property
(make_property (m_meta_class, "DetailedDescription"));
m_meta_class.install_property
(make_property (m_meta_class, "Events"));
m_meta_class.install_property
(make_attribute (m_meta_class, "HandleCompatible"));
m_meta_class.install_property
(make_attribute (m_meta_class, "Hidden"));
m_meta_class.install_property
(make_property (m_meta_class, "InferiorClasses",
make_fcn_handle (class_get_inferiorclasses,
"meta.class>get.InferiorClasses"),
"public", Matrix (), "private"));
m_meta_class.install_property
(make_property (m_meta_class, "Methods",
make_fcn_handle (class_get_methods,
"meta.class>get.Methods"),
"public", Matrix (), "private"));
m_meta_class.install_property
(make_property (m_meta_class, "MethodList",
make_fcn_handle (class_get_methods,
"meta.class>get.MethodList"),
"public", Matrix (), "private"));
m_meta_class.install_property (make_attribute (m_meta_class, "Name"));
m_meta_class.install_property
(make_property (m_meta_class, "Properties",
make_fcn_handle (class_get_properties,
"meta.class>get.Properties"),
"public", Matrix (), "private"));
m_meta_class.install_property
(make_property (m_meta_class, "PropertyList",
make_fcn_handle (class_get_properties,
"meta.class>get.PropertyList"),
"public", Matrix (), "private"));
m_meta_class.install_property (make_attribute (m_meta_class, "Sealed"));
m_meta_class.install_property
(make_property (m_meta_class, "SuperClasses",
make_fcn_handle (class_get_superclasses,
"meta.class>get.SuperClasses"),
"public", Matrix (), "private"));
m_meta_class.install_property
(make_property (m_meta_class, "SuperclassList",
make_fcn_handle (class_get_superclasses,
"meta.class>get.SuperclassList"),
"public", Matrix (), "private"));
// FIXME: Matlab supports this property under "SuperclassList".
// Octave, however, has supported this under "SuperClassList".
// Alias the property. Remove in Octave version 8.1.
m_meta_class.install_property
(make_property (m_meta_class, "SuperClassList",
make_fcn_handle (class_get_superclasses,
"meta.class>get.SuperclassList"),
"public", Matrix (), "private"));
// meta.class methods
m_meta_class.install_method
(make_method (m_meta_class, "fromName", class_fromName, "public", true));
m_meta_class.install_method
(make_method (m_meta_class, "fevalStatic", class_fevalStatic, "public",
false));
m_meta_class.install_method
(make_method (m_meta_class, "getConstant", class_getConstant, "public",
false));
m_meta_class.install_method (make_method (m_meta_class, "eq", class_eq));
m_meta_class.install_method (make_method (m_meta_class, "ne", class_ne));
m_meta_class.install_method (make_method (m_meta_class, "lt", class_lt));
m_meta_class.install_method (make_method (m_meta_class, "le", class_le));
m_meta_class.install_method (make_method (m_meta_class, "gt", class_gt));
m_meta_class.install_method (make_method (m_meta_class, "ge", class_ge));
// meta.method properties
m_meta_method.install_property
(make_attribute (m_meta_method, "Abstract"));
m_meta_method.install_property
(make_attribute (m_meta_method, "Access"));
m_meta_method.install_property
(make_attribute (m_meta_method, "DefiningClass"));
m_meta_method.install_property
(make_attribute (m_meta_method, "Description"));
m_meta_method.install_property
(make_attribute (m_meta_method, "DetailedDescription"));
m_meta_method.install_property
(make_attribute (m_meta_method, "Hidden"));
m_meta_method.install_property
(make_attribute (m_meta_method, "Name"));
m_meta_method.install_property
(make_attribute (m_meta_method, "Sealed"));
m_meta_method.install_property
(make_attribute (m_meta_method, "Static"));
// meta.property properties
m_meta_property.install_property
(make_attribute (m_meta_property, "Name"));
m_meta_property.install_property
(make_attribute (m_meta_property, "Description"));
m_meta_property.install_property
(make_attribute (m_meta_property, "DetailedDescription"));
m_meta_property.install_property
(make_attribute (m_meta_property, "Abstract"));
m_meta_property.install_property
(make_attribute (m_meta_property, "Constant"));
m_meta_property.install_property
(make_attribute (m_meta_property, "GetAccess"));
m_meta_property.install_property
(make_attribute (m_meta_property, "SetAccess"));
m_meta_property.install_property
(make_attribute (m_meta_property, "Dependent"));
m_meta_property.install_property
(make_attribute (m_meta_property, "Transient"));
m_meta_property.install_property
(make_attribute (m_meta_property, "Hidden"));
m_meta_property.install_property
(make_attribute (m_meta_property, "GetObservable"));
m_meta_property.install_property
(make_attribute (m_meta_property, "SetObservable"));
m_meta_property.install_property
(make_attribute (m_meta_property, "GetMethod"));
m_meta_property.install_property
(make_attribute (m_meta_property, "SetMethod"));
m_meta_property.install_property
(make_attribute (m_meta_property, "DefiningClass"));
m_meta_property.install_property
(make_property (m_meta_property, "DefaultValue",
make_fcn_handle (property_get_defaultvalue,
"meta.property>get.DefaultValue"),
"public", Matrix (), "private"));
m_meta_property.install_property
(make_attribute (m_meta_property, "HasDefault"));
// meta.property events
// FIXME: add events
// handle methods
tmp_handle.install_method
(make_method (tmp_handle, "delete", handle_delete));
// meta.package properties
m_meta_package.install_property
(make_attribute (m_meta_package, "Name"));
m_meta_package.install_property
(make_property (m_meta_package, "ContainingPackage"));
m_meta_package.install_property
(make_property (m_meta_package, "ClassList",
make_fcn_handle (package_get_classes,
"meta.package>get.ClassList"),
"public", Matrix (), "private"));
m_meta_package.install_property
(make_property (m_meta_package, "Classes",
make_fcn_handle (package_get_classes,
"meta.package>get.Classes"),
"public", Matrix (), "private"));
m_meta_package.install_property
(make_property (m_meta_package, "FunctionList",
make_fcn_handle (package_get_functions,
"meta.package>get.FunctionList"),
"public", Matrix (), "private"));
m_meta_package.install_property
(make_property (m_meta_package, "Functions",
make_fcn_handle (package_get_functions,
"meta.package>get.Functions"),
"public", Matrix (), "private"));
m_meta_package.install_property
(make_property (m_meta_package, "PackageList",
make_fcn_handle (package_get_packages,
"meta.package>get.PackageList"),
"public", Matrix (), "private"));
m_meta_package.install_property
(make_property (m_meta_package, "Packages",
make_fcn_handle (package_get_packages,
"meta.package>get.Packages"),
"public", Matrix (), "private"));
m_meta_package.install_method
(make_method (m_meta_package, "fromName", package_fromName,
"public", true));
m_meta_package.install_method
(make_method (m_meta_package, "getAllPackages", package_getAllPackages,
"public", true));
// create "meta" package
cdef_package package_meta
= m_meta
= make_package ("meta");
package_meta.install_class (m_meta_class, "class");
package_meta.install_class (m_meta_property, "property");
package_meta.install_class (m_meta_method, "method");
package_meta.install_class (m_meta_package, "package");
package_meta.install_class (tmp_meta_event, "event");
package_meta.install_class (tmp_meta_dynproperty, "dynproperty");
symbol_table& symtab = m_interpreter.get_symbol_table ();
// install built-in classes into the symbol table
symtab.install_built_in_function
("meta.class", m_meta_class.get_constructor_function ());
symtab.install_built_in_function
("meta.method", m_meta_method.get_constructor_function ());
symtab.install_built_in_function
("meta.property", m_meta_property.get_constructor_function ());
symtab.install_built_in_function
("meta.package", m_meta_package.get_constructor_function ());
// FIXME: meta.event and meta.dynproperty are not implemented
// and should not be installed into symbol table.
// symtab.install_built_in_function
// ("meta.event", tmp_meta_event.get_constructor_function ());
// symtab.install_built_in_function
// ("meta.dynproperty", tmp_meta_dynproperty.get_constructor_function ());
}
cdef_class
cdef_manager::find_class (const std::string& name, bool error_if_not_found,
bool load_if_not_found)
{
auto it = m_all_classes.find (name);
if (it == m_all_classes.end ())
{
if (load_if_not_found)
{
octave_value ov_cls;
size_t pos = name.rfind ('.');
if (pos == std::string::npos)
ov_cls = m_interpreter.find (name);
else
{
std::string pack_name = name.substr (0, pos);
cdef_package pack = find_package (pack_name, false, true);
if (pack.ok ())
ov_cls = pack.find (name.substr (pos+1));
}
if (ov_cls.is_defined ())
it = m_all_classes.find (name);
}
}
if (it == m_all_classes.end ())
{
if (error_if_not_found)
error ("class not found: %s", name.c_str ());
}
else
{
cdef_class cls = it->second;
if (! cls.is_builtin ())
cls = lookup_class (cls);
if (cls.ok ())
return cls;
else
m_all_classes.erase (it);
}
return cdef_class ();
}
octave_value
cdef_manager::find_method_symbol (const std::string& method_name,
const std::string& class_name)
{
cdef_class cls = find_class (class_name, false, false);
if (cls.ok ())
{
cdef_method meth = cls.find_method (method_name);
if (meth.ok ())
return octave_value (new octave_classdef_meta (meth));
}
return octave_value ();
}
cdef_package
cdef_manager::find_package (const std::string& name, bool error_if_not_found,
bool load_if_not_found)
{
cdef_package retval;
std::map<std::string, cdef_package>::const_iterator it
= m_all_packages.find (name);
if (it != m_all_packages.end ())
{
retval = it->second;
if (! retval.ok ())
error ("invalid package '%s'", name.c_str ());
}
else
{
load_path& lp = m_interpreter.get_load_path ();
if (load_if_not_found && lp.find_package (name))
{
size_t pos = name.rfind ('.');
if (pos == std::string::npos)
retval = make_package (name, "");
else
{
std::string parent_name = name.substr (0, pos);
retval = make_package (name, parent_name);
}
}
else if (error_if_not_found)
error ("unknown package '%s'", name.c_str ());
}
return retval;
}
octave_value
cdef_manager::find_package_symbol (const std::string& pack_name)
{
cdef_package pack = find_package (pack_name, false);
if (pack.ok ())
return octave_value (new octave_classdef_meta (pack));
return octave_value ();
}
cdef_class
cdef_manager::make_class (const std::string& name,
const std::list<cdef_class>& super_list)
{
cdef_class cls (name, super_list);
cls.set_class (meta_class ());
cls.put ("Abstract", false);
cls.put ("ConstructOnLoad", false);
cls.put ("ContainingPackage", Matrix ());
cls.put ("Description", "");
cls.put ("DetailedDescription", "");
cls.put ("Events", Cell ());
cls.put ("Hidden", false);
cls.put ("InferiorClasses", Cell ());
cls.put ("Methods", Cell ());
cls.put ("Properties", Cell ());
cls.put ("Sealed", false);
if (name == "handle")
{
cls.put ("HandleCompatible", true);
cls.mark_as_handle_class ();
}
else if (super_list.empty ())
{
cls.put ("HandleCompatible", false);
}
else
{
bool all_handle_compatible = true;
bool has_handle_class = false;
for (const auto& cl : super_list)
{
all_handle_compatible = all_handle_compatible
&& cl.get ("HandleCompatible").bool_value ();
has_handle_class = has_handle_class || cl.is_handle_class ();
}
if (has_handle_class && ! all_handle_compatible)
error ("%s: cannot mix handle and non-HandleCompatible classes",
name.c_str ());
cls.put ("HandleCompatible", all_handle_compatible);
if (has_handle_class)
cls.mark_as_handle_class ();
}
if (! name.empty ())
register_class (cls);
return cls;
}
cdef_class
cdef_manager::make_class (const std::string& name,
const cdef_class& super)
{
return make_class (name, std::list<cdef_class> (1, super));
}
cdef_class
cdef_manager::make_meta_class (const std::string& name,
const cdef_class& super)
{
cdef_class cls = make_class (name, super);
cls.put ("Sealed", true);
cls.mark_as_meta_class ();
return cls;
}
cdef_property
cdef_manager::make_property (const cdef_class& cls, const std::string& name,
const octave_value& get_method,
const std::string& get_access,
const octave_value& set_method,
const std::string& set_access)
{
cdef_property prop (name);
prop.set_class (meta_property ());
prop.put ("Description", "");
prop.put ("DetailedDescription", "");
prop.put ("Abstract", false);
prop.put ("Constant", false);
prop.put ("GetAccess", get_access);
prop.put ("SetAccess", set_access);
prop.put ("Dependent", false);
prop.put ("Transient", false);
prop.put ("Hidden", false);
prop.put ("GetObservable", false);
prop.put ("SetObservable", false);
prop.put ("GetMethod", get_method);
prop.put ("SetMethod", set_method);
prop.put ("DefiningClass", to_ov (cls));
prop.put ("DefaultValue", octave_value ());
prop.put ("HasDefault", false);
std::string class_name = cls.get_name ();
if (! get_method.isempty ())
make_function_of_class (class_name, get_method);
if (! set_method.isempty ())
make_function_of_class (class_name, set_method);
return prop;
}
cdef_property
cdef_manager::make_attribute (const cdef_class& cls, const std::string& name)
{
return make_property (cls, name, Matrix (), "public", Matrix (), "private");
}
cdef_method
cdef_manager::make_method (const cdef_class& cls, const std::string& name,
const octave_value& fcn,
const std::string& m_access, bool is_static)
{
cdef_method meth (name);
meth.set_class (meta_method ());
meth.put ("Abstract", false);
meth.put ("Access", m_access);
meth.put ("DefiningClass", to_ov (cls));
meth.put ("Description", "");
meth.put ("DetailedDescription", "");
meth.put ("Hidden", false);
meth.put ("Sealed", true);
meth.put ("Static", is_static);
if (fcn.is_defined ())
make_function_of_class (cls, fcn);
meth.set_function (fcn);
if (is_dummy_method (fcn))
meth.mark_as_external (cls.get_name ());
return meth;
}
cdef_method
cdef_manager::make_method (const cdef_class& cls, const std::string& name,
octave_builtin::fcn ff,
const std::string& m_access, bool is_static)
{
octave_value fcn (new octave_builtin (ff, name));
return make_method (cls, name, fcn, m_access, is_static);
}
cdef_method
cdef_manager::make_method (const cdef_class& cls, const std::string& name,
octave_builtin::meth mm,
const std::string& m_access, bool is_static)
{
octave_value fcn (new octave_builtin (mm, name));
return make_method (cls, name, fcn, m_access, is_static);
}
cdef_package
cdef_manager::make_package (const std::string& nm, const std::string& parent)
{
cdef_package pack (nm);
pack.set_class (meta_package ());
if (parent.empty ())
pack.put ("ContainingPackage", Matrix ());
else
pack.put ("ContainingPackage", to_ov (find_package (parent)));
if (! nm.empty ())
register_package (pack);
return pack;
}
octave_value
cdef_manager::find_method (const std::string& class_name,
const std::string& name) const
{
cdef_class cls = lookup_class (class_name);
return cls.get_method (name);
}
}
|