Mercurial > hg > octave-lyh
annotate src/pt-binop.h @ 11298:cb94bdc74670
defaults.cc (FEXEC_PATH): only call set_exec_path if nargin is greater than zero
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 26 Nov 2010 02:44:24 -0500 |
parents | 5677f3f7b5fa |
children | fd0a3ac60b0e |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2006, 2007, |
4 2008, 2009 John W. Eaton | |
2980 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2980 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2980 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_tree_binop_h) | |
25 #define octave_tree_binop_h 1 | |
26 | |
27 #include <string> | |
28 | |
29 class tree_walker; | |
30 | |
31 class octave_value; | |
32 class octave_value_list; | |
33 class octave_lvalue; | |
34 | |
35 #include "ov.h" | |
36 #include "pt-exp.h" | |
7336 | 37 #include "symtab.h" |
2980 | 38 |
39 // Binary expressions. | |
40 | |
41 class | |
42 tree_binary_expression : public tree_expression | |
43 { | |
44 public: | |
45 | |
46 tree_binary_expression (int l = -1, int c = -1, | |
10313 | 47 octave_value::binary_op t |
48 = octave_value::unknown_binary_op) | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
49 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t), |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
50 eligible_for_braindead_shortcircuit (false) { } |
2980 | 51 |
52 tree_binary_expression (tree_expression *a, tree_expression *b, | |
10313 | 53 int l = -1, int c = -1, |
54 octave_value::binary_op t | |
55 = octave_value::unknown_binary_op) | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
56 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t), |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
57 eligible_for_braindead_shortcircuit (false) { } |
2980 | 58 |
59 ~tree_binary_expression (void) | |
60 { | |
61 delete op_lhs; | |
62 delete op_rhs; | |
63 } | |
64 | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
65 void mark_braindead_shortcircuit (const std::string& file) |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
66 { |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
67 if (etype == octave_value::op_el_and |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
68 || etype == octave_value::op_el_or) |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
69 { |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
70 if (file.empty ()) |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
71 warning_with_id ("Octave:possible-matlab-short-circuit-operator", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
72 "possible Matlab-style short-circuit operator at line %d, column %d", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
73 line (), column ()); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
74 else |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
75 warning_with_id ("Octave:possible-matlab-short-circuit-operator", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
76 "%s: possible Matlab-style short-circuit operator at line %d, column %d", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
77 file.c_str (), line (), column ()); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
78 |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
79 eligible_for_braindead_shortcircuit = true; |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
80 |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
81 op_lhs->mark_braindead_shortcircuit (file); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
82 op_rhs->mark_braindead_shortcircuit (file); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
83 } |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
84 } |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
85 |
4267 | 86 bool has_magic_end (void) const |
87 { | |
88 return ((op_lhs && op_lhs->has_magic_end ()) | |
10313 | 89 || (op_rhs && op_rhs->has_magic_end ())); |
4267 | 90 } |
91 | |
4023 | 92 bool is_binary_expression (void) const { return true; } |
93 | |
3933 | 94 bool rvalue_ok (void) const { return true; } |
2980 | 95 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
96 octave_value rvalue1 (int nargout = 1); |
2980 | 97 |
3010 | 98 octave_value_list rvalue (int nargout); |
2980 | 99 |
3523 | 100 std::string oper (void) const; |
2980 | 101 |
4023 | 102 octave_value::binary_op op_type (void) const { return etype; } |
103 | |
2980 | 104 tree_expression *lhs (void) { return op_lhs; } |
105 tree_expression *rhs (void) { return op_rhs; } | |
106 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
107 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 108 symbol_table::context_id context) const; |
5861 | 109 |
2980 | 110 void accept (tree_walker& tw); |
111 | |
112 protected: | |
113 | |
114 // The operands for the expression. | |
115 tree_expression *op_lhs; | |
116 tree_expression *op_rhs; | |
117 | |
118 private: | |
119 | |
120 // The type of the expression. | |
121 octave_value::binary_op etype; | |
2988 | 122 |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
123 // TRUE if this is an | or & expression in the condition of an IF |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
124 // or WHILE statement. |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
125 bool eligible_for_braindead_shortcircuit; |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
126 |
2988 | 127 // No copying! |
128 | |
129 tree_binary_expression (const tree_binary_expression&); | |
130 | |
131 tree_binary_expression& operator = (const tree_binary_expression&); | |
2980 | 132 }; |
133 | |
134 // Boolean expressions. | |
135 | |
136 class | |
137 tree_boolean_expression : public tree_binary_expression | |
138 { | |
139 public: | |
140 | |
141 enum type | |
142 { | |
143 unknown, | |
144 bool_and, | |
145 bool_or | |
146 }; | |
147 | |
148 tree_boolean_expression (int l = -1, int c = -1, type t = unknown) | |
149 : tree_binary_expression (l, c), etype (t) { } | |
150 | |
151 tree_boolean_expression (tree_expression *a, tree_expression *b, | |
10313 | 152 int l = -1, int c = -1, type t = unknown) |
2980 | 153 : tree_binary_expression (a, b, l, c), etype (t) { } |
154 | |
155 ~tree_boolean_expression (void) { } | |
156 | |
4023 | 157 bool is_boolean_expression (void) const { return true; } |
158 | |
3933 | 159 bool rvalue_ok (void) const { return true; } |
2980 | 160 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
161 octave_value rvalue1 (int nargout = 1); |
2980 | 162 |
163 octave_value_list rvalue (int nargout); | |
164 | |
3523 | 165 std::string oper (void) const; |
2980 | 166 |
4023 | 167 type op_type (void) const { return etype; } |
168 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
169 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 170 symbol_table::context_id context) const; |
5861 | 171 |
2980 | 172 private: |
173 | |
174 // The type of the expression. | |
175 type etype; | |
2988 | 176 |
177 // No copying! | |
178 | |
179 tree_boolean_expression (const tree_boolean_expression&); | |
180 | |
181 tree_boolean_expression& operator = (const tree_boolean_expression&); | |
2980 | 182 }; |
183 | |
184 #endif |