Mercurial > octave
diff libinterp/parse-tree/pt-decl.h @ 23469:2699c5974844
handle global and persistent in tree_decl_command, not as separate classes
* pt-decl.h, pt-decl.cc (tree_decl_command::mark_as_global,
tree_decl_command::mark_as_persistent, tree_decl_command::dup):
New functions.
(tree_global_command, tree_persistent_command): Delete classes.
(tree_decl_elt::decl_type): New enum. Store command type in each
initializer list element.
(tree_decl_elt::mark_as_global, tree_decl_elt::is_global,
tree_decl_elt::mark_as_persistent, tree_decl_elt::is_persistent):
New functions.
(tree_decl_init_list::mark_as_global, tree_decl_init_list::is_global,
tree_decl_init_list::mark_as_persistent, tree_decl_init_list::is_persistent):
New functions.
* pt-walk.h (tree_walker::visit_decl_command): New function.
(tree_walker::visit_global_command,
tree_walker::visit_persistent_command): Delete.
Update all derived classes.
* oct-parse.in.yy (base_parser::make_decl_command): Tag initialization
lists as global or persistent here.
* pt-eval.cc (tree_evaluator::visit_decl_command): New function.
Visit initialization list instead of looping here.
(tree_evaluator::visit_decl_init_list): Loop and visit elements here.
(tree_evaluator::visit_decl_elt): Handle evaluation of elements here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 04 May 2017 15:02:46 -0400 |
parents | 21baad6b35c4 |
children | a41fdb801db6 |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-decl.h Thu May 04 10:29:51 2017 -0400 +++ b/libinterp/parse-tree/pt-decl.h Thu May 04 15:02:46 2017 -0400 @@ -46,8 +46,15 @@ { public: + enum decl_type + { + unknown, + global, + persistent + }; + tree_decl_elt (tree_identifier *i = nullptr, tree_expression *e = nullptr) - : id (i), expr (e) { } + : type (unknown), id (i), expr (e) { } // No copying! @@ -74,6 +81,12 @@ return id ? id->lvalue (tw) : octave_lvalue (); } + void mark_as_global (void) { type = global; } + bool is_global (void) const { return type == global; } + + void mark_as_persistent (void) { type = persistent; } + bool is_persistent (void) const { return type == persistent; } + tree_identifier * ident (void) { return id; } std::string name (void) { return id ? id->name () : ""; } @@ -90,6 +103,8 @@ private: + decl_type type; + // An identifier to tag with the declared property. tree_identifier *id; @@ -121,6 +136,18 @@ } } + void mark_as_global (void) + { + for (tree_decl_elt *elt : *this) + elt->mark_as_global (); + } + + void mark_as_persistent (void) + { + for (tree_decl_elt *elt : *this) + elt->mark_as_persistent (); + } + tree_decl_init_list * dup (symbol_table::scope_id scope, symbol_table::context_id context) const; @@ -140,8 +167,7 @@ : tree_command (l, c), cmd_name (n), init_list (0) { } tree_decl_command (const std::string& n, tree_decl_init_list *t, - int l = -1, int c = -1) - : tree_command (l, c), cmd_name (n), init_list (t) { } + int l = -1, int c = -1); // No copying! @@ -151,11 +177,31 @@ ~tree_decl_command (void); + void mark_as_global (void) + { + if (init_list) + init_list->mark_as_global (); + } + + void mark_as_persistent (void) + { + if (init_list) + init_list->mark_as_persistent (); + } + tree_decl_init_list * initializer_list (void) { return init_list; } - std::string name (void) { return cmd_name; } + std::string name (void) const { return cmd_name; } + + tree_command *dup (symbol_table::scope_id scope, + symbol_table::context_id context) const; - protected: + void accept (tree_walker& tw) + { + tw.visit_decl_command (*this); + } + + private: // The name of this command -- global, static, etc. std::string cmd_name; @@ -163,72 +209,6 @@ // The list of variables or initializers in this declaration command. tree_decl_init_list *init_list; }; - - // Global. - - class tree_global_command : public tree_decl_command - { - public: - - tree_global_command (int l = -1, int c = -1) - : tree_decl_command ("global", l, c) { } - - tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) - : tree_decl_command ("global", t, l, c) { } - - // No copying! - - tree_global_command (const tree_global_command&) = delete; - - tree_global_command& operator = (const tree_global_command&) = delete; - - ~tree_global_command (void) = default; - - tree_command * dup (symbol_table::scope_id scope, - symbol_table::context_id context) const; - - void accept (tree_walker& tw) - { - tw.visit_global_command (*this); - } - - private: - - static void do_init (tree_decl_elt& elt); - }; - - // Persistent. - - class tree_persistent_command : public tree_decl_command - { - public: - - tree_persistent_command (int l = -1, int c = -1) - : tree_decl_command ("persistent", l, c) { } - - tree_persistent_command (tree_decl_init_list *t, int l = -1, int c = -1) - : tree_decl_command ("persistent", t, l, c) { } - - // No copying! - - tree_persistent_command (const tree_persistent_command&) = delete; - - tree_persistent_command& operator = (const tree_persistent_command&) = delete; - - ~tree_persistent_command (void) = default; - - tree_command * dup (symbol_table::scope_id scope, - symbol_table::context_id context) const; - - void accept (tree_walker& tw) - { - tw.visit_persistent_command (*this); - } - - private: - - static void do_init (tree_decl_elt& elt); - }; } #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) @@ -241,12 +221,6 @@ OCTAVE_DEPRECATED ("use 'octave::tree_decl_command' instead") typedef octave::tree_decl_command tree_decl_command; -OCTAVE_DEPRECATED ("use 'octave::tree_global_command' instead") -typedef octave::tree_global_command tree_global_command; - -OCTAVE_DEPRECATED ("use 'octave::tree_persistent_command' instead") -typedef octave::tree_persistent_command tree_persistent_command; - #endif #endif