GNU Octave  8.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-2023 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 
57  { }
58 
61  {
62  append (t);
63  }
64 
67  {
68  append (new tree_decl_elt (id));
69  }
70 
71  // No copying!
72 
74 
76 
77  ~tree_parameter_list (void);
78 
79  void mark_as_formal_parameters (void);
80 
81  void mark_varargs (void) { m_marked_for_varargs = 1; }
82 
84 
85  bool takes_varargs (void) const { return m_marked_for_varargs != 0; }
86 
87  bool varargs_only (void) { return (m_marked_for_varargs < 0); }
88 
89  bool is_input_list (void) const { return m_in_or_out == in; }
90 
91  bool is_output_list (void) const { return m_in_or_out == out; }
92 
93  std::list<std::string> variable_names (void) const;
94 
95  std::string varargs_symbol_name (void) const
96  {
97  return m_in_or_out == in ? "varargin" : "varargout";
98  }
99 
100  tree_parameter_list * dup (symbol_scope& scope) const;
101 
102  void accept (tree_walker& tw)
103  {
104  tw.visit_parameter_list (*this);
105  }
106 
107 private:
108 
110 
111  // 1: takes varargs
112  // -1: takes varargs only
113  // 0: does not take varargs.
115 };
116 
118 
119 #endif
OCTAVE_END_NAMESPACE(octave)
void append(const tree_decl_elt * &s)
Definition: base-list.h:92
std::list< std::string > variable_names(void) const
Definition: pt-misc.cc:55
void mark_varargs_only(void)
Definition: pt-misc.h:83
int m_marked_for_varargs
Definition: pt-misc.h:114
void mark_varargs(void)
Definition: pt-misc.h:81
bool varargs_only(void)
Definition: pt-misc.h:87
void accept(tree_walker &tw)
Definition: pt-misc.h:102
tree_parameter_list & operator=(const tree_parameter_list &)=delete
in_or_out m_in_or_out
Definition: pt-misc.h:109
tree_parameter_list(in_or_out io)
Definition: pt-misc.h:55
tree_parameter_list(in_or_out io, tree_identifier *id)
Definition: pt-misc.h:65
tree_parameter_list(const tree_parameter_list &)=delete
tree_parameter_list * dup(symbol_scope &scope) const
Definition: pt-misc.cc:69
bool is_input_list(void) const
Definition: pt-misc.h:89
bool is_output_list(void) const
Definition: pt-misc.h:91
~tree_parameter_list(void)
Definition: pt-misc.cc:37
std::string varargs_symbol_name(void) const
Definition: pt-misc.h:95
bool takes_varargs(void) const
Definition: pt-misc.h:85
tree_parameter_list(in_or_out io, tree_decl_elt *t)
Definition: pt-misc.h:59
void mark_as_formal_parameters(void)
Definition: pt-misc.cc:48
virtual void visit_parameter_list(tree_parameter_list &)
Definition: pt-walk.cc:478
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn