GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-binop.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_pt_binop_h)
24 #define octave_pt_binop_h 1
25 
26 #include <string>
27 
28 class tree_walker;
29 
30 class octave_value;
31 class octave_value_list;
32 class octave_lvalue;
33 
34 #include "ov.h"
35 #include "pt-exp.h"
36 #include "symtab.h"
37 
38 // Binary expressions.
39 
40 class
42 {
43 public:
44 
45  tree_binary_expression (int l = -1, int c = -1,
48  : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t),
49  eligible_for_braindead_shortcircuit (false) { }
50 
52  int l = -1, int c = -1,
55  : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t),
56  eligible_for_braindead_shortcircuit (false) { }
57 
59  {
60  delete op_lhs;
61  delete op_rhs;
62  }
63 
64  void mark_braindead_shortcircuit (const std::string& file)
65  {
66  if (etype == octave_value::op_el_and || etype == octave_value::op_el_or)
67  {
68  if (file.empty ())
69  warning_with_id ("Octave:possible-matlab-short-circuit-operator",
70  "possible Matlab-style short-circuit operator at line %d, column %d",
71  line (), column ());
72  else
73  warning_with_id ("Octave:possible-matlab-short-circuit-operator",
74  "%s: possible Matlab-style short-circuit operator at line %d, column %d",
75  file.c_str (), line (), column ());
76 
77  eligible_for_braindead_shortcircuit = true;
78 
79  op_lhs->mark_braindead_shortcircuit (file);
80  op_rhs->mark_braindead_shortcircuit (file);
81  }
82  }
83 
84  bool has_magic_end (void) const
85  {
86  return ((op_lhs && op_lhs->has_magic_end ())
87  || (op_rhs && op_rhs->has_magic_end ()));
88  }
89 
90  bool is_binary_expression (void) const { return true; }
91 
92  bool rvalue_ok (void) const { return true; }
93 
94  octave_value rvalue1 (int nargout = 1);
95 
96  octave_value_list rvalue (int nargout);
97 
98  std::string oper (void) const;
99 
100  octave_value::binary_op op_type (void) const { return etype; }
101 
102  tree_expression *lhs (void) { return op_lhs; }
103  tree_expression *rhs (void) { return op_rhs; }
104 
107 
108  void accept (tree_walker& tw);
109 
110 protected:
111 
112  // The operands for the expression.
115 
116 private:
117 
118  // The type of the expression.
120 
121  // TRUE if this is an | or & expression in the condition of an IF
122  // or WHILE statement.
124 
125  // No copying!
126 
128 
130 };
131 
132 // Boolean expressions.
133 
134 class
136 {
137 public:
138 
139  enum type
140  {
143  bool_or
144  };
145 
146  tree_boolean_expression (int l = -1, int c = -1, type t = unknown)
147  : tree_binary_expression (l, c), etype (t) { }
148 
150  int l = -1, int c = -1, type t = unknown)
151  : tree_binary_expression (a, b, l, c), etype (t) { }
152 
154 
155  bool is_boolean_expression (void) const { return true; }
156 
157  bool rvalue_ok (void) const { return true; }
158 
159  octave_value rvalue1 (int nargout = 1);
160 
161  octave_value_list rvalue (int nargout);
162 
163  std::string oper (void) const;
164 
165  type op_type (void) const { return etype; }
166 
169 
170 private:
171 
172  // The type of the expression.
174 
175  // No copying!
176 
178 
180 };
181 
182 #endif