529
|
1 // tree-const.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
296
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
455
|
28 #if defined (__GNUG__) |
|
29 #pragma implementation |
|
30 #endif |
|
31 |
581
|
32 #include <iostream.h> |
|
33 |
493
|
34 #include "tree-const.h" |
1
|
35 #include "error.h" |
|
36 #include "gripes.h" |
529
|
37 #include "user-prefs.h" |
1
|
38 |
|
39 tree_constant::~tree_constant (void) |
|
40 { |
|
41 #if defined (MDEBUG) |
|
42 cerr << "~tree_constant: rep: " << rep |
|
43 << " rep->count: " << rep->count << "\n"; |
|
44 #endif |
|
45 |
|
46 if (--rep->count <= 0) |
|
47 { |
|
48 delete rep; |
531
|
49 rep = 0; |
1
|
50 } |
|
51 } |
|
52 |
|
53 #if defined (MDEBUG) |
|
54 void * |
|
55 tree_constant::operator new (size_t size) |
|
56 { |
|
57 tree_constant *p = ::new tree_constant; |
|
58 cerr << "tree_constant::new(): " << p << "\n"; |
|
59 return p; |
|
60 } |
|
61 |
|
62 void |
|
63 tree_constant::operator delete (void *p, size_t size) |
|
64 { |
|
65 cerr << "tree_constant::delete(): " << p << "\n"; |
|
66 ::delete p; |
|
67 } |
|
68 #endif |
|
69 |
581
|
70 // Construct return vector of empty matrices. Return empty matrices |
|
71 // and/or gripe when appropriate. |
|
72 |
500
|
73 Octave_object |
164
|
74 vector_of_empties (int nargout, const char *fcn_name) |
96
|
75 { |
500
|
76 Octave_object retval; |
96
|
77 |
|
78 // Got an empty argument, check if should gripe/return empty values. |
|
79 |
|
80 int flag = user_pref.propagate_empty_matrices; |
|
81 if (flag != 0) |
|
82 { |
|
83 if (flag < 0) |
|
84 gripe_empty_arg (fcn_name, 0); |
|
85 |
|
86 Matrix m; |
500
|
87 retval.resize (nargout ? nargout : 1); |
96
|
88 for (int i = 0; i < nargout; i++) |
529
|
89 retval(i) = m; |
96
|
90 } |
|
91 else |
|
92 gripe_empty_arg (fcn_name, 1); |
|
93 |
|
94 return retval; |
|
95 } |
|
96 |
581
|
97 void |
|
98 tree_constant::print_code (ostream& os) |
|
99 { |
|
100 print_code_indent (os); |
|
101 |
|
102 if (in_parens) |
|
103 os << "("; |
|
104 |
|
105 if (rep) |
|
106 rep->print_code (os); |
|
107 |
|
108 if (in_parens) |
|
109 os << ")"; |
|
110 } |
|
111 |
620
|
112 void |
|
113 gripe_wrong_type_arg (const char *name, const tree_constant& tc) |
|
114 { |
|
115 error ("%s: wrong type argument `%s'", name, tc.type_as_string ()); |
|
116 } |
|
117 |
96
|
118 /* |
1
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; page-delimiter: "^/\\*" *** |
|
122 ;;; End: *** |
|
123 */ |