GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-misc.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_pt_misc_h)
27 #define octave_pt_misc_h 1
28 
29 #include "octave-config.h"
30 
31 #include "base-list.h"
32 #include "pt-decl.h"
33 #include "pt-walk.h"
34 
36 
37 class symbol_scope;
38 class tree_identifier;
40 
41 // Parameter lists. Used to hold the list of input and output
42 // parameters in a function definition. Elements are identifiers
43 // only.
44 
45 class tree_parameter_list : public base_list<tree_decl_elt *>
46 {
47 public:
48 
49  enum in_or_out
50  {
51  in = 1,
52  out = 2
53  };
54 
56  : m_in_or_out (io), m_marked_for_varargs (0)
57  { }
58 
60  : m_in_or_out (io), m_marked_for_varargs (0)
61  {
62  append (t);
63  }
64 
66  : m_in_or_out (io), m_marked_for_varargs (0)
67  {
68  append (new tree_decl_elt (id));
69  }
70 
71  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_parameter_list)
72 
74 
76 
77  void mark_varargs () { m_marked_for_varargs = 1; }
78 
79  void mark_varargs_only () { m_marked_for_varargs = -1; }
80 
81  bool takes_varargs () const { return m_marked_for_varargs != 0; }
82 
83  bool varargs_only () { return (m_marked_for_varargs < 0); }
84 
85  bool is_input_list () const { return m_in_or_out == in; }
86 
87  bool is_output_list () const { return m_in_or_out == out; }
88 
89  std::list<std::string> variable_names () const;
90 
91  std::string varargs_symbol_name () const
92  {
93  return m_in_or_out == in ? "varargin" : "varargout";
94  }
95 
96  tree_parameter_list * dup (symbol_scope& scope) const;
97 
98  void accept (tree_walker& tw)
99  {
100  tw.visit_parameter_list (*this);
101  }
102 
103 private:
104 
105  in_or_out m_in_or_out;
106 
107  // 1: takes varargs
108  // -1: takes varargs only
109  // 0: does not take varargs.
110  int m_marked_for_varargs;
111 };
112 
113 OCTAVE_END_NAMESPACE(octave)
114 
115 #endif
void append(const tree_decl_elt * &s)
Definition: base-list.h:92
bool is_output_list() const
Definition: pt-misc.h:87
void accept(tree_walker &tw)
Definition: pt-misc.h:98
void mark_varargs_only()
Definition: pt-misc.h:79
bool takes_varargs() const
Definition: pt-misc.h:81
bool is_input_list() const
Definition: pt-misc.h:85
tree_parameter_list(in_or_out io)
Definition: pt-misc.h:55
void mark_varargs()
Definition: pt-misc.h:77
tree_parameter_list(in_or_out io, tree_identifier *id)
Definition: pt-misc.h:65
tree_parameter_list * dup(symbol_scope &scope) const
Definition: pt-misc.cc:69
std::list< std::string > variable_names() const
Definition: pt-misc.cc:55
void mark_as_formal_parameters()
Definition: pt-misc.cc:48
tree_parameter_list(in_or_out io, tree_decl_elt *t)
Definition: pt-misc.h:59
std::string varargs_symbol_name() const
Definition: pt-misc.h:91
bool varargs_only()
Definition: pt-misc.h:83
virtual void visit_parameter_list(tree_parameter_list &)
Definition: pt-walk.cc:515
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn