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
|
////////////////////////////////////////////////////////////////////////
//
// 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 (octave_tree_classdef_h)
#define octave_tree_classdef_h 1
#include "octave-config.h"
class octave_value;
#include "comment-list.h"
#include "pt-cmd.h"
#include "pt-exp.h"
#include "pt-walk.h"
#include "pt-id.h"
#include "base-list.h"
#include <list>
namespace octave
{
class interpreter;
class tree_superclass_ref : public tree_expression
{
public:
tree_superclass_ref (void) = delete;
tree_superclass_ref (const std::string& meth, const std::string& cls,
int l = -1, int c = -1)
: tree_expression (l, c), m_method_name (meth), m_class_name (cls)
{ }
// No copying!
tree_superclass_ref (const tree_superclass_ref&) = delete;
tree_superclass_ref& operator = (const tree_superclass_ref&) = delete;
std::string method_name (void) const
{
return m_method_name;
}
std::string class_name (void) const { return m_class_name; }
tree_superclass_ref * dup (symbol_scope& scope) const;
octave_value evaluate (tree_evaluator& tw, int nargout = 1)
{
octave_value_list retval = evaluate_n (tw, nargout);
return retval.length () > 0 ? retval(0) : octave_value ();
}
octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1);
void accept (tree_walker& tw)
{
tw.visit_superclass_ref (*this);
}
private:
// The name of the method to call. This is the text before the
// "@" and may be of the form "object.method".
std::string m_method_name;
// The name of the superclass. This is the text after the "@"
// and may be of the form "object.method".
std::string m_class_name;
};
class tree_metaclass_query : public tree_expression
{
public:
tree_metaclass_query (void) = delete;
tree_metaclass_query (const std::string& cls, int l = -1, int c = -1)
: tree_expression (l, c), m_class_name (cls)
{ }
// No copying!
tree_metaclass_query (const tree_metaclass_query&) = delete;
tree_metaclass_query& operator = (const tree_metaclass_query&) = delete;
std::string class_name (void) const { return m_class_name; }
tree_metaclass_query * dup (symbol_scope& scope) const;
octave_value evaluate (tree_evaluator&, int nargout = 1);
octave_value_list evaluate_n (tree_evaluator& tw, int nargout = 1)
{
return ovl (evaluate (tw, nargout));
}
void accept (tree_walker& tw)
{
tw.visit_metaclass_query (*this);
}
private:
std::string m_class_name;
};
class tree_classdef_attribute
{
public:
tree_classdef_attribute (tree_identifier *i = nullptr,
tree_expression *e = nullptr)
: m_id (i), m_expr (e), m_neg (false)
{ }
tree_classdef_attribute (tree_identifier *i, bool b)
: m_id (i), m_expr (nullptr), m_neg (b)
{ }
// No copying!
tree_classdef_attribute (const tree_classdef_attribute&) = delete;
tree_classdef_attribute& operator = (const tree_classdef_attribute&) = delete;
~tree_classdef_attribute (void)
{
delete m_id;
delete m_expr;
}
tree_identifier * ident (void) { return m_id; }
tree_expression * expression (void) { return m_expr; }
bool negate (void) { return m_neg; }
void accept (tree_walker& tw)
{
tw.visit_classdef_attribute (*this);
}
private:
tree_identifier *m_id;
tree_expression *m_expr;
bool m_neg;
};
class tree_classdef_attribute_list : public base_list<tree_classdef_attribute *>
{
public:
tree_classdef_attribute_list (void) { }
tree_classdef_attribute_list (tree_classdef_attribute *a) { append (a); }
tree_classdef_attribute_list (const base_list<tree_classdef_attribute *>& a)
: base_list<tree_classdef_attribute *> (a)
{ }
// No copying!
tree_classdef_attribute_list (const tree_classdef_attribute_list&) = delete;
tree_classdef_attribute_list&
operator = (const tree_classdef_attribute_list&) = delete;
~tree_classdef_attribute_list (void);
void accept (tree_walker& tw)
{
tw.visit_classdef_attribute_list (*this);
}
};
class tree_classdef_superclass
{
public:
tree_classdef_superclass (const std::string& cname)
: m_cls_name (cname)
{ }
// No copying!
tree_classdef_superclass (const tree_classdef_superclass&) = delete;
tree_classdef_superclass&
operator = (const tree_classdef_superclass&) = delete;
~tree_classdef_superclass (void) = default;
std::string class_name (void) { return m_cls_name; }
void accept (tree_walker& tw)
{
tw.visit_classdef_superclass (*this);
}
private:
std::string m_cls_name;
};
class tree_classdef_superclass_list
: public base_list<tree_classdef_superclass *>
{
public:
tree_classdef_superclass_list (void) { }
tree_classdef_superclass_list (tree_classdef_superclass *sc)
{
append (sc);
}
tree_classdef_superclass_list (const base_list<tree_classdef_superclass *>& a)
: base_list<tree_classdef_superclass *> (a)
{ }
// No copying!
tree_classdef_superclass_list (const tree_classdef_superclass_list&) = delete;
tree_classdef_superclass_list&
operator = (const tree_classdef_superclass_list&) = delete;
~tree_classdef_superclass_list (void);
void accept (tree_walker& tw)
{
tw.visit_classdef_superclass_list (*this);
}
};
template <typename T>
class tree_classdef_element : public tree
{
public:
tree_classdef_element (tree_classdef_attribute_list *a,
base_list<T> *elist, comment_list *lc,
comment_list *tc, int l = -1, int c = -1)
: tree (l, c), m_attr_list (a), m_elt_list (elist),
m_lead_comm (lc), m_trail_comm (tc)
{ }
// No copying!
tree_classdef_element (const tree_classdef_element&) = delete;
tree_classdef_element& operator = (const tree_classdef_element&) = delete;
~tree_classdef_element (void)
{
delete m_attr_list;
delete m_elt_list;
delete m_lead_comm;
delete m_trail_comm;
}
tree_classdef_attribute_list * attribute_list (void) { return m_attr_list; }
base_list<T> * element_list (void) { return m_elt_list; }
comment_list * leading_comment (void) { return m_lead_comm; }
comment_list * trailing_comment (void) { return m_trail_comm; }
void accept (tree_walker&) { }
private:
// List of attributes that apply to this class.
tree_classdef_attribute_list *m_attr_list;
// The list of objects contained in this block.
base_list<T> *m_elt_list;
// Comments preceding the token marking the beginning of the block.
comment_list *m_lead_comm;
// Comments preceding the END token marking the end of the block.
comment_list *m_trail_comm;
};
class tree_classdef_property
{
public:
tree_classdef_property (tree_identifier *i,
comment_list *comments = nullptr);
tree_classdef_property (tree_identifier *i, tree_expression *e,
comment_list *comments = nullptr);
// No copying!
tree_classdef_property (const tree_classdef_property&) = delete;
tree_classdef_property& operator = (const tree_classdef_property&) = delete;
~tree_classdef_property (void)
{
delete m_id;
delete m_expr;
}
tree_identifier * ident (void) { return m_id; }
tree_expression * expression (void) { return m_expr; }
comment_list * comments (void) const { return m_comments; }
void doc_string (const std::string& txt) { m_doc_string = txt; }
std::string doc_string (void) const { return m_doc_string; }
bool have_doc_string (void) const { return ! m_doc_string.empty (); }
void accept (tree_walker& tw)
{
tw.visit_classdef_property (*this);
}
private:
tree_identifier *m_id;
tree_expression *m_expr;
comment_list *m_comments;
std::string m_doc_string;
};
class tree_classdef_property_list : public base_list<tree_classdef_property *>
{
public:
tree_classdef_property_list (void) { }
tree_classdef_property_list (tree_classdef_property *p) { append (p); }
tree_classdef_property_list (const base_list<tree_classdef_property *>& a)
: base_list<tree_classdef_property *> (a) { }
// No copying!
tree_classdef_property_list (const tree_classdef_property_list&) = delete;
tree_classdef_property_list&
operator = (const tree_classdef_property_list&) = delete;
~tree_classdef_property_list (void);
void accept (tree_walker& tw)
{
tw.visit_classdef_property_list (*this);
}
};
class tree_classdef_properties_block
: public tree_classdef_element<tree_classdef_property *>
{
public:
tree_classdef_properties_block (tree_classdef_attribute_list *a,
tree_classdef_property_list *plist,
comment_list *lc, comment_list *tc,
int l = -1, int c = -1)
: tree_classdef_element<tree_classdef_property *> (a, plist, lc, tc, l, c)
{ }
// No copying!
tree_classdef_properties_block (const tree_classdef_properties_block&) = delete;
tree_classdef_properties_block&
operator = (const tree_classdef_properties_block&) = delete;
~tree_classdef_properties_block (void) = default;
void accept (tree_walker& tw)
{
tw.visit_classdef_properties_block (*this);
}
};
class tree_classdef_methods_list : public base_list<octave_value>
{
public:
tree_classdef_methods_list (void) { }
tree_classdef_methods_list (const octave_value& f) { append (f); }
tree_classdef_methods_list (const base_list<octave_value>& a)
: base_list<octave_value> (a) { }
// No copying!
tree_classdef_methods_list (const tree_classdef_methods_list&) = delete;
tree_classdef_methods_list&
operator = (const tree_classdef_methods_list&) = delete;
~tree_classdef_methods_list (void) = default;
void accept (tree_walker& tw)
{
tw.visit_classdef_methods_list (*this);
}
};
class tree_classdef_methods_block : public tree_classdef_element<octave_value>
{
public:
tree_classdef_methods_block (tree_classdef_attribute_list *a,
tree_classdef_methods_list *mlist,
comment_list *lc, comment_list *tc,
int l = -1, int c = -1)
: tree_classdef_element<octave_value> (a, mlist, lc, tc, l, c)
{ }
// No copying!
tree_classdef_methods_block (const tree_classdef_methods_block&) = delete;
tree_classdef_methods_block&
operator = (const tree_classdef_methods_block&) = delete;
~tree_classdef_methods_block (void) = default;
void accept (tree_walker& tw)
{
tw.visit_classdef_methods_block (*this);
}
};
class tree_classdef_event
{
public:
tree_classdef_event (tree_identifier *i = nullptr,
comment_list *comments = nullptr);
// No copying!
tree_classdef_event (const tree_classdef_event&) = delete;
tree_classdef_event& operator = (const tree_classdef_event&) = delete;
~tree_classdef_event (void)
{
delete m_id;
}
tree_identifier * ident (void) { return m_id; }
comment_list * comments (void) const { return m_comments; }
void doc_string (const std::string& txt) { m_doc_string = txt; }
std::string doc_string (void) const { return m_doc_string; }
bool have_doc_string (void) const { return ! m_doc_string.empty (); }
void accept (tree_walker& tw)
{
tw.visit_classdef_event (*this);
}
private:
tree_identifier *m_id;
comment_list *m_comments;
std::string m_doc_string;
};
class tree_classdef_events_list : public base_list<tree_classdef_event *>
{
public:
tree_classdef_events_list (void) { }
tree_classdef_events_list (tree_classdef_event *e) { append (e); }
tree_classdef_events_list (const base_list<tree_classdef_event *>& a)
: base_list<tree_classdef_event *> (a)
{ }
// No copying!
tree_classdef_events_list (const tree_classdef_events_list&) = delete;
tree_classdef_events_list&
operator = (const tree_classdef_events_list&) = delete;
~tree_classdef_events_list (void);
void accept (tree_walker& tw)
{
tw.visit_classdef_events_list (*this);
}
};
class tree_classdef_events_block
: public tree_classdef_element<tree_classdef_event *>
{
public:
tree_classdef_events_block (tree_classdef_attribute_list *a,
tree_classdef_events_list *elist,
comment_list *lc, comment_list *tc,
int l = -1, int c = -1)
: tree_classdef_element<tree_classdef_event *> (a, elist, lc, tc, l, c)
{ }
// No copying!
tree_classdef_events_block (const tree_classdef_events_block&) = delete;
tree_classdef_events_block&
operator = (const tree_classdef_events_block&) = delete;
~tree_classdef_events_block (void) = default;
void accept (tree_walker& tw)
{
tw.visit_classdef_events_block (*this);
}
};
class tree_classdef_enum
{
public:
tree_classdef_enum (tree_identifier *i, tree_expression *e,
comment_list *comments);
// No copying!
tree_classdef_enum (const tree_classdef_enum&) = delete;
tree_classdef_enum& operator = (const tree_classdef_enum&) = delete;
~tree_classdef_enum (void)
{
delete m_id;
delete m_expr;
}
tree_identifier * ident (void) { return m_id; }
tree_expression * expression (void) { return m_expr; }
comment_list * comments (void) const { return m_comments; }
void doc_string (const std::string& txt) { m_doc_string = txt; }
std::string doc_string (void) const { return m_doc_string; }
bool have_doc_string (void) const { return ! m_doc_string.empty (); }
void accept (tree_walker& tw)
{
tw.visit_classdef_enum (*this);
}
private:
tree_identifier *m_id;
tree_expression *m_expr;
comment_list *m_comments;
std::string m_doc_string;
};
class tree_classdef_enum_list : public base_list<tree_classdef_enum *>
{
public:
tree_classdef_enum_list (void) { }
tree_classdef_enum_list (tree_classdef_enum *e) { append (e); }
tree_classdef_enum_list (const base_list<tree_classdef_enum *>& a)
: base_list<tree_classdef_enum *> (a)
{ }
// No copying!
tree_classdef_enum_list (const tree_classdef_enum_list&) = delete;
tree_classdef_enum_list& operator = (const tree_classdef_enum_list&) = delete;
~tree_classdef_enum_list (void);
void accept (tree_walker& tw)
{
tw.visit_classdef_enum_list (*this);
}
};
class tree_classdef_enum_block
: public tree_classdef_element<tree_classdef_enum *>
{
public:
tree_classdef_enum_block (tree_classdef_attribute_list *a,
tree_classdef_enum_list *elist,
comment_list *lc, comment_list *tc,
int l = -1, int c = -1)
: tree_classdef_element<tree_classdef_enum *> (a, elist, lc, tc, l, c)
{ }
// No copying!
tree_classdef_enum_block (const tree_classdef_enum_block&) = delete;
tree_classdef_enum_block&
operator = (const tree_classdef_enum_block&) = delete;
~tree_classdef_enum_block (void) = default;
void accept (tree_walker& tw)
{
tw.visit_classdef_enum_block (*this);
}
};
class tree_classdef_body
{
public:
typedef std::list<tree_classdef_properties_block *>::iterator
properties_list_iterator;
typedef std::list<tree_classdef_properties_block *>::const_iterator
properties_list_const_iterator;
typedef std::list<tree_classdef_methods_block *>::iterator
methods_list_iterator;
typedef std::list<tree_classdef_methods_block *>::const_iterator
methods_list_const_iterator;
typedef std::list<tree_classdef_events_block *>::iterator events_list_iterator;
typedef std::list<tree_classdef_events_block *>::const_iterator
events_list_const_iterator;
typedef std::list<tree_classdef_enum_block *>::iterator enum_list_iterator;
typedef std::list<tree_classdef_enum_block *>::const_iterator
enum_list_const_iterator;
tree_classdef_body (void);
tree_classdef_body (tree_classdef_properties_block *pb);
tree_classdef_body (tree_classdef_methods_block *mb);
tree_classdef_body (tree_classdef_events_block *evb);
tree_classdef_body (tree_classdef_enum_block *enb);
// No copying!
tree_classdef_body (const tree_classdef_body&) = delete;
tree_classdef_body& operator = (const tree_classdef_body&) = delete;
~tree_classdef_body (void);
void append (tree_classdef_properties_block *pb)
{
m_properties_lst.push_back (pb);
}
void append (tree_classdef_methods_block *mb)
{
m_methods_lst.push_back (mb);
}
void append (tree_classdef_events_block *evb)
{
m_events_lst.push_back (evb);
}
void append (tree_classdef_enum_block *enb)
{
m_enum_lst.push_back (enb);
}
std::list<tree_classdef_properties_block *> properties_list (void)
{
return m_properties_lst;
}
std::list<tree_classdef_methods_block *> methods_list (void)
{
return m_methods_lst;
}
std::list<tree_classdef_events_block *> events_list (void)
{
return m_events_lst;
}
std::list<tree_classdef_enum_block *> enum_list (void)
{
return m_enum_lst;
}
void doc_string (const std::string& txt) { m_doc_string = txt; }
std::string doc_string (void) const { return m_doc_string; }
bool have_doc_string (void) const { return ! m_doc_string.empty (); }
void accept (tree_walker& tw)
{
tw.visit_classdef_body (*this);
}
private:
std::string get_doc_string (comment_list *comment) const;
std::list<tree_classdef_properties_block *> m_properties_lst;
std::list<tree_classdef_methods_block *> m_methods_lst;
std::list<tree_classdef_events_block *> m_events_lst;
std::list<tree_classdef_enum_block *> m_enum_lst;
std::string m_doc_string;
};
// Classdef definition.
class tree_classdef : public tree_command
{
public:
tree_classdef (const octave::symbol_scope& scope,
tree_classdef_attribute_list *a, tree_identifier *i,
tree_classdef_superclass_list *sc,
tree_classdef_body *b, comment_list *lc,
comment_list *tc, const std::string& pn = "",
int l = -1, int c = -1)
: tree_command (l, c), m_scope (scope), m_attr_list (a), m_id (i),
m_supclass_list (sc), m_element_list (b), m_lead_comm (lc),
m_trail_comm (tc), m_pack_name (pn)
{ }
// No copying!
tree_classdef (const tree_classdef&) = delete;
tree_classdef& operator = (const tree_classdef&) = delete;
~tree_classdef (void)
{
delete m_attr_list;
delete m_id;
delete m_supclass_list;
delete m_element_list;
delete m_lead_comm;
delete m_trail_comm;
}
octave::symbol_scope scope (void) { return m_scope; }
tree_classdef_attribute_list *
attribute_list (void) { return m_attr_list; }
tree_identifier * ident (void) { return m_id; }
tree_classdef_superclass_list *
superclass_list (void) { return m_supclass_list; }
tree_classdef_body * body (void) { return m_element_list; }
comment_list * leading_comment (void) { return m_lead_comm; }
comment_list * trailing_comment (void) { return m_trail_comm; }
std::string package_name (void) const { return m_pack_name; }
octave_value make_meta_class (interpreter& interp,
bool is_at_folder = false);
std::string doc_string (void) const
{
return m_element_list ? m_element_list->doc_string () : "";
}
void accept (tree_walker& tw)
{
tw.visit_classdef (*this);
}
private:
// The scope that was used when parsing the classdef object and that
// corresponds to any identifiers that were found in attribute lists
// (for example). Used again when computing the meta class object.
octave::symbol_scope m_scope;
tree_classdef_attribute_list *m_attr_list;
tree_identifier *m_id;
tree_classdef_superclass_list *m_supclass_list;
tree_classdef_body *m_element_list;
comment_list *m_lead_comm;
comment_list *m_trail_comm;
std::string m_pack_name;
};
}
#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
// Hmm, a lot of these are templates, so not sure how to typedef them.
#endif
#endif
|