GNU Octave  4.0.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-2015 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  braindead_shortcircuit_warning_issued (false) { }
51 
53  int l = -1, int c = -1,
56  : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t),
57  eligible_for_braindead_shortcircuit (false),
58  braindead_shortcircuit_warning_issued (false) { }
59 
61  {
62  delete op_lhs;
63  delete op_rhs;
64  }
65 
67  {
68  if (etype == octave_value::op_el_and || etype == octave_value::op_el_or)
69  {
70  eligible_for_braindead_shortcircuit = true;
71 
72  op_lhs->mark_braindead_shortcircuit ();
73  op_rhs->mark_braindead_shortcircuit ();
74  }
75  }
76 
77  bool has_magic_end (void) const
78  {
79  return ((op_lhs && op_lhs->has_magic_end ())
80  || (op_rhs && op_rhs->has_magic_end ()));
81  }
82 
83  bool is_binary_expression (void) const { return true; }
84 
85  bool rvalue_ok (void) const { return true; }
86 
87  octave_value rvalue1 (int nargout = 1);
88 
89  octave_value_list rvalue (int nargout);
90 
91  std::string oper (void) const;
92 
93  octave_value::binary_op op_type (void) const { return etype; }
94 
95  tree_expression *lhs (void) { return op_lhs; }
96  tree_expression *rhs (void) { return op_rhs; }
97 
100 
101  void accept (tree_walker& tw);
102 
103  std::string profiler_name (void) const { return "binary " + oper (); }
104 
105 
106 protected:
107 
108  // The operands for the expression.
111 
112 private:
113 
114  // The type of the expression.
116 
117  // TRUE if this is an | or & expression in the condition of an IF
118  // or WHILE statement.
120 
121  // TRUE if we have already issued a warning about short circuiting
122  // for this operator.
124 
125  void matlab_style_short_circuit_warning (const char *op);
126 
127  // No copying!
128 
130 
132 };
133 
134 // Boolean expressions.
135 
136 class
138 {
139 public:
140 
141  enum type
142  {
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 
152  int l = -1, int c = -1, type t = unknown)
153  : tree_binary_expression (a, b, l, c), etype (t) { }
154 
156 
157  bool is_boolean_expression (void) const { return true; }
158 
159  bool rvalue_ok (void) const { return true; }
160 
161  octave_value rvalue1 (int nargout = 1);
162 
163  octave_value_list rvalue (int nargout);
164 
165  std::string oper (void) const;
166 
167  type op_type (void) const { return etype; }
168 
171 
172 private:
173 
174  // The type of the expression.
176 
177  // No copying!
178 
180 
182 };
183 
184 #endif
bool rvalue_ok(void) const
Definition: pt-binop.h:159
~tree_boolean_expression(void)
Definition: pt-binop.h:155
octave_value::binary_op etype
Definition: pt-binop.h:115
type op_type(void) const
Definition: pt-binop.h:167
binary_op
Definition: ov.h:87
bool rvalue_ok(void) const
Definition: pt-binop.h:85
void mark_braindead_shortcircuit(void)
Definition: pt-binop.h:66
std::string profiler_name(void) const
Definition: pt-binop.h:103
bool eligible_for_braindead_shortcircuit
Definition: pt-binop.h:119
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
bool has_magic_end(void) const
Definition: pt-binop.h:77
tree_expression * lhs(void)
Definition: pt-binop.h:95
bool braindead_shortcircuit_warning_issued
Definition: pt-binop.h:123
tree_expression * op_rhs
Definition: pt-binop.h:110
octave_value::binary_op op_type(void) const
Definition: pt-binop.h:93
tree_binary_expression(int l=-1, int c=-1, octave_value::binary_op t=octave_value::unknown_binary_op)
Definition: pt-binop.h:45
~tree_binary_expression(void)
Definition: pt-binop.h:60
tree_boolean_expression(tree_expression *a, tree_expression *b, int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:151
tree_expression * rhs(void)
Definition: pt-binop.h:96
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:52
tree_expression * op_lhs
Definition: pt-binop.h:109
bool is_boolean_expression(void) const
Definition: pt-binop.h:157
bool is_binary_expression(void) const
Definition: pt-binop.h:83
size_t context_id
Definition: symtab.h:51
tree_boolean_expression(int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:148
octave_lvalue & operator=(const octave_lvalue &vr)
Definition: oct-lvalue.h:49