comparison src/pt-id.h @ 7752:40c428ea3408

initial implementation of dbup and dbdown
author John W. Eaton <jwe@octave.org>
date Sun, 04 May 2008 03:42:19 -0400
parents db02cc0ba8f2
children e76a4a6e3c47
comparison
equal deleted inserted replaced
7751:7c020c067a60 7752:40c428ea3408
45 friend class tree_index_expression; 45 friend class tree_index_expression;
46 46
47 public: 47 public:
48 48
49 tree_identifier (int l = -1, int c = -1) 49 tree_identifier (int l = -1, int c = -1)
50 : tree_expression (l, c), sym () { } 50 : tree_expression (l, c), sym (), scope (-1) { }
51 51
52 tree_identifier (const symbol_table::symbol_record& s, int l = -1, int c = -1) 52 tree_identifier (const symbol_table::symbol_record& s,
53 : tree_expression (l, c), sym (s) { } 53 int l = -1, int c = -1,
54 symbol_table::scope_id sc = symbol_table::current_scope ())
55 : tree_expression (l, c), sym (s), scope (sc)
56 {
57 symbol_table::scope_id curr_scope = symbol_table::current_scope ();
58 }
54 59
55 ~tree_identifier (void) { } 60 ~tree_identifier (void) { }
56 61
57 bool has_magic_end (void) const { return (name () == "__end__"); } 62 bool has_magic_end (void) const { return (name () == "__end__"); }
58 63
59 bool is_identifier (void) const { return true; } 64 bool is_identifier (void) const { return true; }
60 65
66 // The name doesn't change with scope, so use sym instead of
67 // accessing it through sym so that this function may remain const.
61 std::string name (void) const { return sym.name (); } 68 std::string name (void) const { return sym.name (); }
62 69
63 bool is_defined (void) { return sym.is_defined (); } 70 bool is_defined (void) { return xsym().is_defined (); }
64 71
65 bool is_variable (void) { return sym.is_variable (); } 72 bool is_variable (void) { return xsym().is_variable (); }
66 73
67 // Try to find a definition for an identifier. Here's how: 74 // Try to find a definition for an identifier. Here's how:
68 // 75 //
69 // * If the identifier is already defined and is a function defined 76 // * If the identifier is already defined and is a function defined
70 // in an function file that has been modified since the last time 77 // in an function file that has been modified since the last time
83 do_lookup (tree_argument_list *args, const string_vector& arg_names, 90 do_lookup (tree_argument_list *args, const string_vector& arg_names,
84 octave_value_list& evaluated_args, bool& args_evaluated) 91 octave_value_list& evaluated_args, bool& args_evaluated)
85 { 92 {
86 MAYBE_DO_BREAKPOINT; 93 MAYBE_DO_BREAKPOINT;
87 94
88 return sym.find (args, arg_names, evaluated_args, args_evaluated); 95 return xsym().find (args, arg_names, evaluated_args, args_evaluated);
89 } 96 }
90 97
91 void mark_global (void) { sym.mark_global (); } 98 void mark_global (void) { xsym().mark_global (); }
92 99
93 void mark_as_static (void) { sym.init_persistent (); } 100 void mark_as_static (void) { xsym().init_persistent (); }
94 101
95 void mark_as_formal_parameter (void) { sym.mark_formal (); } 102 void mark_as_formal_parameter (void) { xsym().mark_formal (); }
96 103
97 // We really need to know whether this symbol referst to a variable 104 // We really need to know whether this symbol referst to a variable
98 // or a function, but we may not know that yet. 105 // or a function, but we may not know that yet.
99 106
100 bool lvalue_ok (void) const { return true; } 107 bool lvalue_ok (void) const { return true; }
114 private: 121 private:
115 122
116 // The symbol record that this identifier references. 123 // The symbol record that this identifier references.
117 symbol_table::symbol_record sym; 124 symbol_table::symbol_record sym;
118 125
126 symbol_table::scope_id scope;
127
128 // A script may be executed in multiple scopes. If the last one was
129 // different from the one we are in now, update sym to be from the
130 // new scope.
131 symbol_table::symbol_record& xsym (void)
132 {
133 symbol_table::scope_id curr_scope = symbol_table::current_scope ();
134
135 if (scope != curr_scope)
136 {
137 scope = curr_scope;
138 sym = symbol_table::insert (sym.name ());
139 }
140
141 return sym;
142 }
143
119 // No copying! 144 // No copying!
120 145
121 tree_identifier (const tree_identifier&); 146 tree_identifier (const tree_identifier&);
122 147
123 tree_identifier& operator = (const tree_identifier&); 148 tree_identifier& operator = (const tree_identifier&);