GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-misc.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1994-2025 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 <list>
32
33#include "pt-decl.h"
34#include "pt-walk.h"
35
37
38class symbol_scope;
39class tree_identifier;
41
42// Parameter lists. Used to hold the list of input and output
43// parameters in a function definition. Elements are identifiers
44// only.
45
46class tree_parameter_list : public std::list<tree_decl_elt *>
47{
48public:
49
51 {
52 in = 1,
53 out = 2
54 };
55
57 : m_in_or_out (io), m_marked_for_varargs (0)
58 { }
59
61 : m_in_or_out (io), m_marked_for_varargs (0)
62 {
63 push_back (t);
64 }
65
67 : m_in_or_out (io), m_marked_for_varargs (0)
68 {
69 push_back (new tree_decl_elt (id));
70 }
71
72 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tree_parameter_list)
73
75
76 tree_parameter_list * mark_in_delims (const token& open_delim, const token& close_delim)
77 {
78 m_open_delim = open_delim;
79 m_close_delim = close_delim;
80
81 return this;
82 }
83
84 filepos beg_pos () const { return m_open_delim.beg_pos (); }
85 filepos end_pos () const { return m_close_delim.end_pos (); }
86
88
89 void mark_varargs () { m_marked_for_varargs = 1; }
90
91 void mark_varargs_only () { m_marked_for_varargs = -1; }
92
93 bool takes_varargs () const { return m_marked_for_varargs != 0; }
94
95 bool varargs_only () { return (m_marked_for_varargs < 0); }
96
97 bool is_input_list () const { return m_in_or_out == in; }
98
99 bool is_output_list () const { return m_in_or_out == out; }
100
101 std::list<std::string> variable_names () const;
102
103 std::string varargs_symbol_name () const
104 {
105 return m_in_or_out == in ? "varargin" : "varargout";
106 }
107
108 tree_parameter_list * dup (symbol_scope& scope) const;
109
111 {
112 tw.visit_parameter_list (*this);
113 }
114
115private:
116
117 in_or_out m_in_or_out;
118
119 // 1: takes varargs
120 // -1: takes varargs only
121 // 0: does not take varargs.
122 int m_marked_for_varargs;
123
124 token m_open_delim;
125 token m_close_delim;
126};
127
128OCTAVE_END_NAMESPACE(octave)
129
130#endif
Definition token.h:42
filepos end_pos() const
Definition token.h:129
filepos beg_pos() const
Definition token.h:128
bool is_output_list() const
Definition pt-misc.h:99
void accept(tree_walker &tw)
Definition pt-misc.h:110
void mark_varargs_only()
Definition pt-misc.h:91
bool takes_varargs() const
Definition pt-misc.h:93
bool is_input_list() const
Definition pt-misc.h:97
filepos beg_pos() const
Definition pt-misc.h:84
tree_parameter_list(in_or_out io)
Definition pt-misc.h:56
void mark_varargs()
Definition pt-misc.h:89
tree_parameter_list(in_or_out io, tree_identifier *id)
Definition pt-misc.h:66
tree_parameter_list * dup(symbol_scope &scope) const
Definition pt-misc.cc:69
filepos end_pos() const
Definition pt-misc.h:85
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 * mark_in_delims(const token &open_delim, const token &close_delim)
Definition pt-misc.h:76
tree_parameter_list(in_or_out io, tree_decl_elt *t)
Definition pt-misc.h:60
std::string varargs_symbol_name() const
Definition pt-misc.h:103
bool varargs_only()
Definition pt-misc.h:95
virtual void visit_parameter_list(tree_parameter_list &)
Definition pt-walk.cc:515
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn