GNU Octave  4.2.1
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-2017 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 "octave-config.h"
27 
28 #include <string>
29 
30 class tree_walker;
31 
32 class octave_value;
33 class octave_value_list;
34 class octave_lvalue;
35 
36 #include "ov.h"
37 #include "pt-exp.h"
38 #include "symtab.h"
39 
40 // Binary expressions.
41 
42 class
44 {
45 public:
46 
47  tree_binary_expression (int l = -1, int c = -1,
50  : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t),
51  eligible_for_braindead_shortcircuit (false),
52  braindead_shortcircuit_warning_issued (false) { }
53 
55  int l = -1, int c = -1,
58  : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t),
59  eligible_for_braindead_shortcircuit (false),
60  braindead_shortcircuit_warning_issued (false) { }
61 
63  {
64  delete op_lhs;
65  delete op_rhs;
66  }
67 
69  {
70  if (etype == octave_value::op_el_and || etype == octave_value::op_el_or)
71  {
72  eligible_for_braindead_shortcircuit = true;
73 
74  op_lhs->mark_braindead_shortcircuit ();
75  op_rhs->mark_braindead_shortcircuit ();
76  }
77  }
78 
79  bool has_magic_end (void) const
80  {
81  return ((op_lhs && op_lhs->has_magic_end ())
82  || (op_rhs && op_rhs->has_magic_end ()));
83  }
84 
85  bool is_binary_expression (void) const { return true; }
86 
87  bool rvalue_ok (void) const { return true; }
88 
89  octave_value rvalue1 (int nargout = 1);
90 
91  octave_value_list rvalue (int nargout);
92 
93  std::string oper (void) const;
94 
95  octave_value::binary_op op_type (void) const { return etype; }
96 
97  tree_expression *lhs (void) { return op_lhs; }
98  tree_expression *rhs (void) { return op_rhs; }
99 
102 
103  void accept (tree_walker& tw);
104 
105  std::string profiler_name (void) const { return "binary " + oper (); }
106 
107 protected:
108 
109  // The operands for the expression.
112 
113 private:
114 
115  // The type of the expression.
117 
118  // TRUE if this is an | or & expression in the condition of an IF
119  // or WHILE statement.
121 
122  // TRUE if we have already issued a warning about short circuiting
123  // for this operator.
125 
126  void matlab_style_short_circuit_warning (const char *op);
127 
128  // No copying!
129 
131 
133 };
134 
135 // Boolean expressions.
136 
137 class
139 {
140 public:
141 
142  enum type
143  {
146  bool_or
147  };
148 
149  tree_boolean_expression (int l = -1, int c = -1, type t = unknown)
150  : tree_binary_expression (l, c), etype (t) { }
151 
153  int l = -1, int c = -1, type t = unknown)
154  : tree_binary_expression (a, b, l, c), etype (t) { }
155 
157 
158  bool is_boolean_expression (void) const { return true; }
159 
160  bool rvalue_ok (void) const { return true; }
161 
162  octave_value rvalue1 (int nargout = 1);
163 
164  octave_value_list rvalue (int nargout);
165 
166  std::string oper (void) const;
167 
168  type op_type (void) const { return etype; }
169 
172 
173 private:
174 
175  // The type of the expression.
177 
178  // No copying!
179 
181 
183 };
184 
185 #endif
bool rvalue_ok(void) const
Definition: pt-binop.h:160
~tree_boolean_expression(void)
Definition: pt-binop.h:156
octave_value::binary_op etype
Definition: pt-binop.h:116
type op_type(void) const
Definition: pt-binop.h:168
binary_op
Definition: ov.h:89
bool rvalue_ok(void) const
Definition: pt-binop.h:87
void mark_braindead_shortcircuit(void)
Definition: pt-binop.h:68
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
std::string profiler_name(void) const
Definition: pt-binop.h:105
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
bool eligible_for_braindead_shortcircuit
Definition: pt-binop.h:120
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
bool has_magic_end(void) const
Definition: pt-binop.h:79
is false
Definition: cellfun.cc:398
tree_expression * lhs(void)
Definition: pt-binop.h:97
bool braindead_shortcircuit_warning_issued
Definition: pt-binop.h:124
tree_expression * op_rhs
Definition: pt-binop.h:111
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
octave_value::binary_op op_type(void) const
Definition: pt-binop.h:95
tree_binary_expression(int l=-1, int c=-1, octave_value::binary_op t=octave_value::unknown_binary_op)
Definition: pt-binop.h:47
~tree_binary_expression(void)
Definition: pt-binop.h:62
tree_boolean_expression(tree_expression *a, tree_expression *b, int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:152
tree_expression * rhs(void)
Definition: pt-binop.h:98
tree_binary_expression(tree_expression *a, tree_expression *b, int l=-1, int c=-1, octave_value::binary_op t=octave_value::unknown_binary_op)
Definition: pt-binop.h:54
tree_expression * op_lhs
Definition: pt-binop.h:110
bool is_boolean_expression(void) const
Definition: pt-binop.h:158
b
Definition: cellfun.cc:398
bool is_binary_expression(void) const
Definition: pt-binop.h:85
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
tree_boolean_expression(int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:149
octave_lvalue & operator=(const octave_lvalue &vr)
Definition: oct-lvalue.h:51