GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-arg-list.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 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 (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <string>
31 
32 #include "str-vec.h"
33 
34 #include "ovl.h"
35 #include "ov.h"
36 #include "pt-arg-list.h"
37 #include "pt-exp.h"
38 #include "pt-id.h"
39 #include "pt-idx.h"
40 #include "pt-pr-code.h"
41 
42 namespace octave
43 {
44  // Argument lists.
45 
47  {
48  while (! empty ())
49  {
50  auto p = begin ();
51  delete *p;
52  erase (p);
53  }
54  }
55 
56  void
58  {
60 
61  if (! m_list_includes_magic_tilde && s && s->is_identifier ())
62  {
63  tree_identifier *id = dynamic_cast<tree_identifier *> (s);
64  m_list_includes_magic_tilde = id && id->is_black_hole ();
65  }
66  }
67 
68  bool
70  {
71  for (const tree_expression *elt : *this)
72  {
73  if (! elt->is_constant ())
74  return false;
75  }
76 
77  return true;
78  }
79 
80  bool
82  {
83  bool retval = true;
84 
85  for (const tree_expression *elt : *this)
86  {
87  // There is no need for a separate check for the magic "~" because it
88  // is represented by tree_black_hole, and that is derived from
89  // tree_identifier.
90  if (! (elt->is_identifier () || elt->is_index_expression ()))
91  {
92  retval = false;
93  break;
94  }
95  }
96 
97  return retval;
98  }
99 
102  {
103  int len = length ();
104 
106 
107  int k = 0;
108 
109  for (tree_expression *elt : *this)
110  retval(k++) = elt->str_print_code ();
111 
112  return retval;
113  }
114 
115  std::list<std::string>
117  {
118  std::list<std::string> retval;
119 
120  for (tree_expression *elt : *this)
121  {
122  if (elt->is_identifier ())
123  {
124  tree_identifier *id = dynamic_cast<tree_identifier *> (elt);
125 
126  retval.push_back (id->name ());
127  }
128  else if (elt->is_index_expression ())
129  {
130  tree_index_expression *idx_expr
131  = dynamic_cast<tree_index_expression *> (elt);
132 
133  retval.push_back (idx_expr->name ());
134  }
135  }
136 
137  return retval;
138  }
139 
142  {
143  tree_argument_list *new_list = new tree_argument_list ();
144 
146 
147  for (const tree_expression *elt : *this)
148  new_list->append (elt ? elt->dup (scope) : nullptr);
149 
150  return new_list;
151  }
152 }
void append(const elt_type &s)
Definition: base-list.h:92
iterator erase(iterator pos)
Definition: base-list.h:55
string_vector get_arg_names(void) const
Definition: pt-arg-list.cc:101
void append(const element_type &s)
Definition: pt-arg-list.cc:57
tree_argument_list * dup(symbol_scope &scope) const
Definition: pt-arg-list.cc:141
std::list< std::string > variable_names(void) const
Definition: pt-arg-list.cc:116
bool is_valid_lvalue_list(void) const
Definition: pt-arg-list.cc:81
bool all_elements_are_constant(void) const
Definition: pt-arg-list.cc:69
virtual bool is_identifier(void) const
Definition: pt-exp.h:70
virtual bool is_index_expression(void) const
Definition: pt-exp.h:72
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual bool is_constant(void) const
Definition: pt-exp.h:64
std::string name(void) const
Definition: pt-id.h:73
std::string name(void) const
Definition: pt-idx.cc:133
std::string str_print_code(void)
Definition: pt.cc:46
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
F77_RET_T len
Definition: xerbla.cc:61