view libinterp/parse-tree/pt-select.h @ 31837:febd82d1a8de

use new macros to consistently delete copy and move member functions Use new OCTAVE_DISABLE_COPY_MOVE macro to consistently disable copy and move constructors and assignment operators. Consistently declare deleted functions in public class sections. Affected files: dw-main-window.h, gui-preferences.h, gui-settings.h, qt-application.h, qt-interpreter-events.h, variable-editor-model.cc, variable-editor-model.h, variable-editor.h, base-text-renderer.h, c-file-ptr-stream.h, dynamic-ld.h, error.h, event-manager.h, event-queue.h, fcn-info.h, ft-text-renderer.cc, gl-render.cc, gl-render.h, graphics.cc, graphics.in.h, gzfstream.h, interpreter.cc, interpreter.h, load-path.h, load-save.h, mex.cc, mxarray.h, oct-fstrm.h, oct-hist.h, oct-iostrm.h, oct-prcstrm.h, oct-procbuf.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h, pager.h, settings.h, stack-frame.cc, symscope.h, symtab.h, text-renderer.h, url-handle-manager.h, __init_fltk__.cc, gzip.cc, cdef-class.cc, cdef-manager.h, ov-builtin.h, ov-class.cc, ov-classdef.h, ov-dld-fcn.h, ov-fcn.h, ov-mex-fcn.h, ov-typeinfo.h, ov-usr-fcn.h, octave.h, anon-fcn-validator.h, lex.h, oct-parse.yy, parse.h, profiler.h, pt-anon-scopes.h, pt-arg-list.h, pt-args-block.h, pt-array-list.h, pt-assign.h, pt-binop.h, pt-bp.h, pt-cbinop.h, pt-cell.h, pt-check.h, pt-classdef.h, pt-cmd.h, pt-colon.h, pt-const.h, pt-decl.h, pt-eval.h, pt-except.h, pt-exp.h, pt-fcn-handle.h, pt-id.h, pt-idx.h, pt-jump.h, pt-loop.h, pt-mat.h, pt-misc.h, pt-pr-code.h, pt-select.h, pt-spmd.h, pt-stmt.h, pt-tm-const.h, pt-unop.h, pt-walk.h, pt.h, token.h, Array-base.cc, idx-vector.h, oct-fftw.h, sparse-chol.cc, sparse-qr.cc, oct-env.h, action-container.h, cmd-edit.cc, cmd-edit.h, cmd-hist.h, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-sort.h, oct-string.h, singleton-cleanup.h, unwind-prot.h, url-transfer.cc, and url-transfer.h.
author John W. Eaton <jwe@octave.org>
date Thu, 16 Feb 2023 14:43:18 -0500
parents 21f9b34eb893
children 2e484f9f1f18
line wrap: on
line source

////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 1996-2023 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// 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
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if ! defined (octave_pt_select_h)
#define octave_pt_select_h 1

#include "octave-config.h"

#include "base-list.h"
#include "comment-list.h"
#include "pt-cmd.h"
#include "pt-walk.h"

OCTAVE_BEGIN_NAMESPACE(octave)

class tree_expression;
class tree_statement_list;

// If.

class tree_if_clause : public tree
{
public:

  tree_if_clause (int l = -1, int c = -1)
    : tree (l, c), m_expr (nullptr), m_list (nullptr), m_lead_comm (nullptr)
  { }

  tree_if_clause (tree_statement_list *sl, comment_list *lc = nullptr,
                  int l = -1, int c = -1)
    : tree (l, c), m_expr (nullptr), m_list (sl), m_lead_comm (lc) { }

  tree_if_clause (tree_expression *e, tree_statement_list *sl,
                  comment_list *lc = nullptr,
                  int l = -1, int c = -1)
    : tree (l, c), m_expr (e), m_list (sl), m_lead_comm (lc) { }

  OCTAVE_DISABLE_COPY_MOVE (tree_if_clause)

  ~tree_if_clause ();

  bool is_else_clause () { return ! m_expr; }

  tree_expression * condition () { return m_expr; }

  tree_statement_list * commands () { return m_list; }

  comment_list * leading_comment () { return m_lead_comm; }

  void accept (tree_walker& tw)
  {
    tw.visit_if_clause (*this);
  }

private:

  // The condition to test.
  tree_expression *m_expr;

  // The list of statements to evaluate if expr is true.
  tree_statement_list *m_list;

  // Comment preceding ELSE or ELSEIF token.
  comment_list *m_lead_comm;
};

class tree_if_command_list : public base_list<tree_if_clause *>
{
public:

  tree_if_command_list () { }

  tree_if_command_list (tree_if_clause *t) { append (t); }

  OCTAVE_DISABLE_COPY_MOVE (tree_if_command_list)

  ~tree_if_command_list ()
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  void accept (tree_walker& tw)
  {
    tw.visit_if_command_list (*this);
  }
};

class tree_if_command : public tree_command
{
public:

  tree_if_command (int l = -1, int c = -1)
    : tree_command (l, c), m_list (nullptr),
      m_lead_comm (nullptr), m_trail_comm (nullptr)
  { }

  tree_if_command (tree_if_command_list *lst, comment_list *lc,
                   comment_list *tc, int l = -1, int c = -1)
    : tree_command (l, c), m_list (lst), m_lead_comm (lc), m_trail_comm (tc)
  { }

  OCTAVE_DISABLE_COPY_MOVE (tree_if_command)

  ~tree_if_command ();

  tree_if_command_list * cmd_list () { return m_list; }

  comment_list * leading_comment () { return m_lead_comm; }

  comment_list * trailing_comment () { return m_trail_comm; }

  void accept (tree_walker& tw)
  {
    tw.visit_if_command (*this);
  }

private:

  // List of if commands (if, elseif, elseif, ... else, endif)
  tree_if_command_list *m_list;

  // Comment preceding IF token.
  comment_list *m_lead_comm;

  // Comment preceding ENDIF token.
  comment_list *m_trail_comm;
};

// Switch.

class tree_switch_case : public tree
{
public:

  tree_switch_case (int l = -1, int c = -1)
    : tree (l, c), m_label (nullptr), m_list (nullptr), m_lead_comm (nullptr)
  { }

  tree_switch_case (tree_statement_list *sl, comment_list *lc = nullptr,
                    int l = -1, int c = -1)
    : tree (l, c), m_label (nullptr), m_list (sl), m_lead_comm (lc) { }

  tree_switch_case (tree_expression *e, tree_statement_list *sl,
                    comment_list *lc = nullptr,
                    int l = -1, int c = -1)
    : tree (l, c), m_label (e), m_list (sl), m_lead_comm (lc) { }

  OCTAVE_DISABLE_COPY_MOVE (tree_switch_case)

  ~tree_switch_case ();

  bool is_default_case () { return ! m_label; }

  tree_expression * case_label () { return m_label; }

  tree_statement_list * commands () { return m_list; }

  comment_list * leading_comment () { return m_lead_comm; }

  void accept (tree_walker& tw)
  {
    tw.visit_switch_case (*this);
  }

private:

  // The case label.
  tree_expression *m_label;

  // The list of statements to evaluate if the label matches.
  tree_statement_list *m_list;

  // Comment preceding CASE or OTHERWISE token.
  comment_list *m_lead_comm;
};

class tree_switch_case_list : public base_list<tree_switch_case *>
{
public:

  tree_switch_case_list () { }

  tree_switch_case_list (tree_switch_case *t) { append (t); }

  OCTAVE_DISABLE_COPY_MOVE (tree_switch_case_list)

  ~tree_switch_case_list ()
  {
    while (! empty ())
      {
        auto p = begin ();
        delete *p;
        erase (p);
      }
  }

  void accept (tree_walker& tw)
  {
    tw.visit_switch_case_list (*this);
  }
};

class tree_switch_command : public tree_command
{
public:

  tree_switch_command (int l = -1, int c = -1)
    : tree_command (l, c), m_expr (nullptr), m_list (nullptr),
      m_lead_comm (nullptr), m_trail_comm (nullptr) { }

  tree_switch_command (tree_expression *e, tree_switch_case_list *lst,
                       comment_list *lc, comment_list *tc,
                       int l = -1, int c = -1)
    : tree_command (l, c), m_expr (e), m_list (lst), m_lead_comm (lc),
      m_trail_comm (tc) { }

  OCTAVE_DISABLE_COPY_MOVE (tree_switch_command)

  ~tree_switch_command ();

  tree_expression * switch_value () { return m_expr; }

  tree_switch_case_list * case_list () { return m_list; }

  comment_list * leading_comment () { return m_lead_comm; }

  comment_list * trailing_comment () { return m_trail_comm; }

  void accept (tree_walker& tw)
  {
    tw.visit_switch_command (*this);
  }

private:

  // Value on which to switch.
  tree_expression *m_expr;

  // List of cases (case 1, case 2, ..., default)
  tree_switch_case_list *m_list;

  // Comment preceding SWITCH token.
  comment_list *m_lead_comm;

  // Comment preceding ENDSWITCH token.
  comment_list *m_trail_comm;
};

OCTAVE_END_NAMESPACE(octave)

#endif