GNU Octave 7.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-2022 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
45namespace octave
46{
49 {
50 tm_const tmp (*this, tw);
51
52 return tmp.concat (tw.string_fill_char ());
53 }
54
55 std::string
56 get_concat_class (const std::string& c1, const std::string& c2)
57 {
58 std::string retval = octave_base_value::static_class_name ();
59
60 if (c1 == c2)
61 retval = c1;
62 else if (c1.empty ())
63 retval = c2;
64 else if (c2.empty ())
65 retval = c1;
66 else if (c1 == "class" || c2 == "class")
67 retval = "class";
68 else
69 {
70 bool c1_is_int = (c1 == "int8" || c1 == "uint8"
71 || c1 == "int16" || c1 == "uint16"
72 || c1 == "int32" || c1 == "uint32"
73 || c1 == "int64" || c1 == "uint64");
74 bool c2_is_int = (c2 == "int8" || c2 == "uint8"
75 || c2 == "int16" || c2 == "uint16"
76 || c2 == "int32" || c2 == "uint32"
77 || c2 == "int64" || c2 == "uint64");
78
79 bool c1_is_char = (c1 == "char");
80 bool c2_is_char = (c2 == "char");
81
82 bool c1_is_double = (c1 == "double");
83 bool c2_is_double = (c2 == "double");
84
85 bool c1_is_single = (c1 == "single");
86 bool c2_is_single = (c2 == "single");
87
88 bool c1_is_logical = (c1 == "logical");
89 bool c2_is_logical = (c2 == "logical");
90
91 bool c1_is_built_in_type
92 = (c1_is_int || c1_is_char || c1_is_double || c1_is_single
93 || c1_is_logical);
94
95 bool c2_is_built_in_type
96 = (c2_is_int || c2_is_char || c2_is_double || c2_is_single
97 || c2_is_logical);
98
99 // Order is important here...
100
101 if (c1 == "cell" || c2 == "cell")
102 retval = "cell";
103 else if (c1_is_char && c2_is_built_in_type)
104 retval = c1;
105 else if (c2_is_char && c1_is_built_in_type)
106 retval = c2;
107 else if (c1_is_int && c2_is_built_in_type)
108 retval = c1;
109 else if (c2_is_int && c1_is_built_in_type)
110 retval = c2;
111 else if (c1_is_single && c2_is_built_in_type)
112 retval = c1;
113 else if (c2_is_single && c1_is_built_in_type)
114 retval = c2;
115 else if (c1_is_double && c2_is_built_in_type)
116 retval = c1;
117 else if (c2_is_double && c1_is_built_in_type)
118 retval = c2;
119 else if (c1_is_logical && c2_is_logical)
120 retval = c1;
121 }
122
123 return retval;
124 }
125
126 void
127 maybe_warn_string_concat (bool all_dq_strings_p, bool all_sq_strings_p)
128 {
129 if (! (all_dq_strings_p || all_sq_strings_p))
130 warning_with_id ("Octave:mixed-string-concat",
131 "concatenation of different character string types may have unintended consequences");
132 }
133
134 tree_expression *
136 {
137 tree_matrix *new_matrix = new tree_matrix (nullptr, line (), column ());
138
139 new_matrix->copy_base (*this, scope);
140
141 return new_matrix;
142 }
143}
octave_value concat(char string_fill_char) const
Definition: pt-tm-const.cc:217
void copy_base(const tree_array_list &array_list)
tree_matrix(tree_argument_list *row=nullptr, int l=-1, int c=-1)
Definition: pt-mat.h:53
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition: pt-mat.cc:48
tree_expression * dup(symbol_scope &scope) const
Definition: pt-mat.cc:135
virtual int column(void) const
Definition: pt.h:62
virtual int line(void) const
Definition: pt.h:60
static std::string static_class_name(void)
Definition: ov-base.h:922
char string_fill_char(void) const
Definition: pt-eval.h:643
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:1070
std::string get_concat_class(const std::string &c1, const std::string &c2)
Definition: pt-mat.cc:56
void maybe_warn_string_concat(bool all_dq_strings_p, bool all_sq_strings_p)
Definition: pt-mat.cc:127