Mercurial > octave
annotate libinterp/parse-tree/pt-id.cc @ 23599:5cb3a2bb5e1e
don't use singleton for symbol_table
This is the first of a series of changes to make the symbol table a
part of the interpreter instead of a global object. These changes
also aim to simplify the implementation of symbol table so that it is
easier to understand and modify.
* Functions now own their scope (workspace) data.
* The list of subfunctions is contained in the scope rather than a
global list.
* symtab.h, symtab.cc (class symbol_table): Don't use singleton
pattern.
* interpreter.h, interpreter.cc (interpreter::m_symbol_table): New
data member.
(interpreter::~interpreter): Don't set instance to 0.
* interpreter-private.h, interpreter-private.cc
(__get_symbol_table__): New function.
Change all uses of call_stack to access call_stack object from the
interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Jun 2017 02:21:28 -0400 |
parents | c452180ab672 |
children | 214cb58ccc1c |
rev | line source |
---|---|
2887 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 John W. Eaton |
2887 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
2887 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2887 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2887 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2887 | 25 #endif |
26 | |
27 #include "error.h" | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
28 #include "interpreter-private.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
29 #include "ovl.h" |
2979 | 30 #include "oct-lvalue.h" |
2900 | 31 #include "pager.h" |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
32 #include "parse.h" |
3770 | 33 #include "pt-bp.h" |
2887 | 34 #include "pt-const.h" |
15606
fb9dffe5fbfb
The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents:
15467
diff
changeset
|
35 #include "pt-eval.h" |
2887 | 36 #include "pt-id.h" |
37 #include "pt-walk.h" | |
2900 | 38 #include "symtab.h" |
2887 | 39 #include "utils.h" |
2956 | 40 #include "variables.h" |
2887 | 41 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
42 namespace octave |
2887 | 43 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
44 // Symbols from the symbol table. |
2887 | 45 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
46 void |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
47 tree_identifier::eval_undefined_error (void) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
48 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
49 int l = line (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
50 int c = column (); |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
51 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
52 maybe_missing_function_hook (name ()); |
2887 | 53 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
54 if (l == -1 && c == -1) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
55 error_with_id ("Octave:undefined-function", |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
56 "'%s' undefined", name ().c_str ()); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
57 else |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
58 error_with_id ("Octave:undefined-function", |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
59 "'%s' undefined near line %d column %d", |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
60 name ().c_str (), l, c); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
61 } |
2887 | 62 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
63 octave_lvalue |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23332
diff
changeset
|
64 tree_identifier::lvalue (tree_evaluator *) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
65 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
66 if (sym->is_added_static ()) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
67 static_workspace_error (); |
15236
44d6ffdf9479
Disallow new variables in nested functions (bug #36271)
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
68 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
69 return octave_lvalue (sym); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
70 } |
2971 | 71 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
72 tree_identifier * |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
73 tree_identifier::dup (symbol_table::scope_id sc, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
74 symbol_table::context_id) const |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
75 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
76 // The new tree_identifier object contains a symbol_record |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
77 // entry from the duplicated scope. |
5861 | 78 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
79 symbol_table& symtab = octave::__get_symbol_table__ ("tree_identifier::dup"); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
80 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
81 // FIXME: is this the best way? |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
82 symbol_table::symbol_record new_sym = symtab.find_symbol (name (), sc); |
7336 | 83 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
84 tree_identifier *new_id |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
85 = new tree_identifier (new_sym, line (), column ()); |
5861 | 86 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
87 new_id->copy_base (*this); |
5861 | 88 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
89 return new_id; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
90 } |
2887 | 91 } |