view libinterp/parse-tree/parse-private.h @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/parse-tree/parse-private.h@28f5f4a4a80a
children
line wrap: on
line source

/*

Copyright (C) 2012 John W. Eaton

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
<http://www.gnu.org/licenses/>.

*/

#if !defined (octave_parse_private_h)
#define octave_parse_private_h 1

#include <stack>

#include "symtab.h"

// Keep track of symbol table information when parsing functions.
class symtab_context
{
private:

  class frame
  {
  public:
    frame (symbol_table::scope_id s, symbol_table::scope_id c)
      : m_scope (s), m_context (c) { }

    frame (const frame& f) : m_scope (f.m_scope), m_context (f.m_context) { }

    frame& operator = (const frame& f)
    {
      if (&f != this)
        {
          m_scope = f.m_scope;
          m_context = f.m_context;
        }

      return *this;
    }

    ~frame (void) { }

    symbol_table::scope_id scope (void) const { return m_scope; }
    symbol_table::scope_id context (void) const { return m_context; }

  private:

    symbol_table::scope_id m_scope;
    symbol_table::scope_id m_context;
  };

  std::stack<frame> frame_stack;

public:
  symtab_context (void) : frame_stack () { }

  void clear (void)
  {
    while (! frame_stack.empty ())
      frame_stack.pop ();
  }

  bool empty (void) const { return frame_stack.empty (); }

  void pop (void)
  {
    frame tmp = frame_stack.top ();

    symbol_table::set_scope_and_context (tmp.scope (), tmp.context ());

    frame_stack.pop ();
  }

  void push (void)
  {
    frame_stack.push (frame (symbol_table::current_scope (),
                             symbol_table::current_context ()));
  }
};

extern symtab_context parser_symtab_context;

#endif