GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-mat.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 "defun.h"
31 #include "ov.h"
32 #include "ovl.h"
33 #include "pt-arg-list.h"
34 #include "pt-eval.h"
35 #include "pt-exp.h"
36 #include "pt-mat.h"
37 #include "pt-tm-const.h"
38 #include "variables.h"
39 
40 #include "ov-cx-mat.h"
41 #include "ov-flt-cx-mat.h"
42 #include "ov-re-sparse.h"
43 #include "ov-cx-sparse.h"
44 
46 
49 {
50  unwind_action act ([&tw] (const std::list<octave_lvalue> *lvl)
51  {
52  tw.set_lvalue_list (lvl);
53  }, tw.lvalue_list ());
54 
55  tw.set_lvalue_list (nullptr);
56 
57  tm_const tmp (*this, tw);
58 
59  return tmp.concat (tw.string_fill_char ());
60 }
61 
62 std::string
63 get_concat_class (const std::string& c1, const std::string& c2)
64 {
65  std::string retval = octave_base_value::static_class_name ();
66 
67  if (c1 == c2)
68  retval = c1;
69  else if (c1.empty ())
70  retval = c2;
71  else if (c2.empty ())
72  retval = c1;
73  else if (c1 == "class" || c2 == "class")
74  retval = "class";
75  else
76  {
77  bool c1_is_int = (c1 == "int8" || c1 == "uint8"
78  || c1 == "int16" || c1 == "uint16"
79  || c1 == "int32" || c1 == "uint32"
80  || c1 == "int64" || c1 == "uint64");
81  bool c2_is_int = (c2 == "int8" || c2 == "uint8"
82  || c2 == "int16" || c2 == "uint16"
83  || c2 == "int32" || c2 == "uint32"
84  || c2 == "int64" || c2 == "uint64");
85 
86  bool c1_is_char = (c1 == "char");
87  bool c2_is_char = (c2 == "char");
88 
89  bool c1_is_double = (c1 == "double");
90  bool c2_is_double = (c2 == "double");
91 
92  bool c1_is_single = (c1 == "single");
93  bool c2_is_single = (c2 == "single");
94 
95  bool c1_is_logical = (c1 == "logical");
96  bool c2_is_logical = (c2 == "logical");
97 
98  bool c1_is_built_in_type
99  = (c1_is_int || c1_is_char || c1_is_double || c1_is_single
100  || c1_is_logical);
101 
102  bool c2_is_built_in_type
103  = (c2_is_int || c2_is_char || c2_is_double || c2_is_single
104  || c2_is_logical);
105 
106  // Order is important here...
107 
108  if (c1 == "cell" || c2 == "cell")
109  retval = "cell";
110  else if (c1_is_char && c2_is_built_in_type)
111  retval = c1;
112  else if (c2_is_char && c1_is_built_in_type)
113  retval = c2;
114  else if (c1_is_int && c2_is_built_in_type)
115  retval = c1;
116  else if (c2_is_int && c1_is_built_in_type)
117  retval = c2;
118  else if (c1_is_single && c2_is_built_in_type)
119  retval = c1;
120  else if (c2_is_single && c1_is_built_in_type)
121  retval = c2;
122  else if (c1_is_double && c2_is_built_in_type)
123  retval = c1;
124  else if (c2_is_double && c1_is_built_in_type)
125  retval = c2;
126  else if (c1_is_logical && c2_is_logical)
127  retval = c1;
128  }
129 
130  return retval;
131 }
132 
133 void
134 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p)
135 {
136  if (! (all_dq_strings_p || all_sq_strings_p))
137  warning_with_id ("Octave:mixed-string-concat",
138  "concatenation of different character string types may have unintended consequences");
139 }
140 
143 {
144  tree_matrix *new_matrix = new tree_matrix (nullptr, line (), column ());
145 
146  new_matrix->copy_base (*this, scope);
147 
148  return new_matrix;
149 }
150 
151 OCTAVE_END_NAMESPACE(octave)
static std::string static_class_name()
Definition: ov-base.h:954
octave_value concat(char string_fill_char) const
Definition: pt-tm-const.cc:228
void copy_base(const tree_array_list &array_list)
char string_fill_char() const
Definition: pt-eval.h:648
const std::list< octave_lvalue > * lvalue_list() const
Definition: pt-eval.h:756
void set_lvalue_list(const std::list< octave_lvalue > *lst)
Definition: pt-eval.h:761
tree_expression * dup(symbol_scope &scope) const
Definition: pt-mat.cc:142
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-mat.cc:48
tree_matrix(tree_argument_list *row=nullptr, int l=-1, int c=-1)
Definition: pt-mat.h:53
virtual int column() const
Definition: pt.h:58
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:1078
void maybe_warn_string_concat(bool all_dq_strings_p, bool all_sq_strings_p)
Definition: pt-mat.cc:134
std::string get_concat_class(const std::string &c1, const std::string &c2)
Definition: pt-mat.cc:63