GNU Octave  9.1.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-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 (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 
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 
105  string_vector retval (len);
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 
145  new_list->m_simple_assign_lhs = m_simple_assign_lhs;
146 
147  for (const tree_expression *elt : *this)
148  new_list->append (elt ? elt->dup (scope) : nullptr);
149 
150  return new_list;
151 }
152 
153 OCTAVE_END_NAMESPACE(octave)
std::size_t length() const
Definition: base-list.h:53
void append(const elt_type &s)
Definition: base-list.h:92
std::list< std::string > variable_names() const
Definition: pt-arg-list.cc:116
bool all_elements_are_constant() const
Definition: pt-arg-list.cc:69
tree_argument_list * dup(symbol_scope &scope) const
Definition: pt-arg-list.cc:141
bool is_valid_lvalue_list() const
Definition: pt-arg-list.cc:81
void append(const element_type &s)
Definition: pt-arg-list.cc:57
string_vector get_arg_names() const
Definition: pt-arg-list.cc:101
virtual bool is_identifier() const
Definition: pt-exp.h:66
virtual bool is_constant() const
Definition: pt-exp.h:60
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual bool is_index_expression() const
Definition: pt-exp.h:68
std::string name() const
Definition: pt-id.h:69
std::string name() const
Definition: pt-idx.cc:139
std::string str_print_code()
Definition: pt.cc:46
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T len
Definition: xerbla.cc:61