comparison src/parse-private.h @ 14333:6dd710b73150

maint: add yet another file omitted from earlier commit
author John W. Eaton <jwe@octave.org>
date Sun, 05 Feb 2012 15:41:42 -0500
parents
children
comparison
equal deleted inserted replaced
14332:affda9a8f7d0 14333:6dd710b73150
1 /*
2
3 Copyright (C) 2012 John W. Eaton
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #if !defined (octave_parse_private_h)
24 #define octave_parse_private_h 1
25
26 #include <stack>
27
28 #include "symtab.h"
29
30 // Keep track of symbol table information when parsing functions.
31 class symtab_context
32 {
33 private:
34
35 class frame
36 {
37 public:
38 frame (symbol_table::scope_id s, symbol_table::scope_id c)
39 : m_scope (s), m_context (c) { }
40
41 frame (const frame& f) : m_scope (f.m_scope), m_context (f.m_context) { }
42
43 frame& operator = (const frame& f)
44 {
45 if (&f != this)
46 {
47 m_scope = f.m_scope;
48 m_context = f.m_context;
49 }
50
51 return *this;
52 }
53
54 ~frame (void) { }
55
56 symbol_table::scope_id scope (void) const { return m_scope; }
57 symbol_table::scope_id context (void) const { return m_context; }
58
59 private:
60
61 symbol_table::scope_id m_scope;
62 symbol_table::scope_id m_context;
63 };
64
65 std::stack<frame> frame_stack;
66
67 public:
68 symtab_context (void) : frame_stack () { }
69
70 void clear (void)
71 {
72 while (! frame_stack.empty ())
73 frame_stack.pop ();
74 }
75
76 bool empty (void) const { return frame_stack.empty (); }
77
78 void pop (void)
79 {
80 frame tmp = frame_stack.top ();
81
82 symbol_table::set_scope_and_context (tmp.scope (), tmp.context ());
83
84 frame_stack.pop ();
85 }
86
87 void push (void)
88 {
89 frame_stack.push (frame (symbol_table::current_scope (),
90 symbol_table::current_context ()));
91 }
92 };
93
94 extern symtab_context parser_symtab_context;
95
96 #endif