GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-cell.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1999-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 "Cell.h"
31 #include "ovl.h"
32 #include "pt-arg-list.h"
33 #include "pt-eval.h"
34 #include "pt-exp.h"
35 #include "pt-cell.h"
36 #include "pt-walk.h"
37 #include "ov.h"
38 
39 namespace octave
40 {
41  tree_expression *
43  {
44  tree_cell *new_cell = new tree_cell (nullptr, line (), column ());
45 
46  new_cell->copy_base (*this, scope);
47 
48  return new_cell;
49  }
50 
53  {
54  unwind_action act ([&tw] (const std::list<octave_lvalue> *lvl)
55  {
56  tw.set_lvalue_list (lvl);
57  }, tw.lvalue_list ());
58  tw.set_lvalue_list (nullptr);
59 
60  octave_idx_type nr = length ();
61  octave_idx_type nc = -1;
62 
63  Cell val;
64 
65  octave_idx_type i = 0;
66 
67  for (tree_argument_list *elt : *this)
68  {
70 
71  if (nr == 1)
72  // Optimize the single row case.
73  val = row.cell_value ();
74  else if (nc < 0)
75  {
76  nc = row.length ();
77 
78  val = Cell (nr, nc);
79  }
80  else
81  {
82  octave_idx_type this_nc = row.length ();
83 
84  if (this_nc != nc)
85  {
86  if (this_nc == 0)
87  continue; // blank line
88  else
89  error ("number of columns must match");
90  }
91  }
92 
93  for (octave_idx_type j = 0; j < nc; j++)
94  val(i,j) = row(j);
95 
96  i++;
97  }
98 
99  if (i < nr)
100  val.resize (dim_vector (i, nc)); // there were blank rows
101 
102  return octave_value (val);
103  }
104 }
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1011
Definition: Cell.h:43
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
void copy_base(const tree_array_list &array_list)
tree_expression * dup(symbol_scope &scope) const
Definition: pt-cell.cc:42
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-cell.cc:52
tree_cell(tree_argument_list *row=nullptr, int l=-1, int c=-1)
Definition: pt-cell.h:50
void set_lvalue_list(const std::list< octave_lvalue > *lst)
Definition: pt-eval.h:678
const std::list< octave_lvalue > * lvalue_list(void) const
Definition: pt-eval.h:673
octave_value_list convert_to_const_vector(tree_argument_list *arg_list)
Definition: pt-eval.cc:1685
virtual int column(void) const
Definition: pt.h:62
Cell cell_value(void) const
Definition: ovl.h:105
octave_idx_type length(void) const
Definition: ovl.h:113
void error(const char *fmt,...)
Definition: error.cc:968
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))