GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-binop.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 octave_value;
31 class octave_value_list;
32 
33 #include "ov.h"
34 #include "pt-exp.h"
35 #include "pt-walk.h"
36 
37 namespace octave
38 {
39  class symbol_scope;
40 
41  // Binary expressions.
42 
44  {
45  public:
46 
47  tree_binary_expression (int l = -1, int c = -1,
50  : tree_expression (l, c), m_lhs (nullptr), m_rhs (nullptr), m_etype (t),
53 
55  int l = -1, int c = -1,
58  : tree_expression (l, c), m_lhs (a), m_rhs (b), m_etype (t),
61 
62  // No copying!
63 
65 
67 
69  {
70  delete m_lhs;
71  delete m_rhs;
72  }
73 
75  {
77  {
79 
82  }
83  }
84 
85  bool has_magic_end (void) const
86  {
87  return ((m_lhs && m_lhs->has_magic_end ())
88  || (m_rhs && m_rhs->has_magic_end ()));
89  }
90 
91  bool is_binary_expression (void) const { return true; }
92 
93  bool rvalue_ok (void) const { return true; }
94 
95  std::string oper (void) const;
96 
97  octave_value::binary_op op_type (void) const { return m_etype; }
98 
99  tree_expression * lhs (void) { return m_lhs; }
100  tree_expression * rhs (void) { return m_rhs; }
101 
103  {
105  }
106 
107  tree_expression * dup (symbol_scope& scope) const;
108 
109  void accept (tree_walker& tw)
110  {
111  tw.visit_binary_expression (*this);
112  }
113 
114  std::string profiler_name (void) const { return "binary " + oper (); }
115 
116  void matlab_style_short_circuit_warning (const char *op);
117 
118  protected:
119 
120  // The operands for the expression.
123 
124  private:
125 
126  // The type of the expression.
128 
129  // TRUE if this is an | or & expression in the condition of an IF
130  // or WHILE statement.
132 
133  // TRUE if we have already issued a warning about short circuiting
134  // for this operator.
136  };
137 
138  // Boolean expressions.
139 
141  {
142  public:
143 
144  enum type
145  {
149  };
150 
151  tree_boolean_expression (int l = -1, int c = -1, type t = unknown)
152  : tree_binary_expression (l, c), m_etype (t) { }
153 
155  int l = -1, int c = -1, type t = unknown)
156  : tree_binary_expression (a, b, l, c), m_etype (t) { }
157 
158  // No copying!
159 
161 
163 
164  ~tree_boolean_expression (void) = default;
165 
166  bool is_boolean_expression (void) const { return true; }
167 
168  bool rvalue_ok (void) const { return true; }
169 
170  std::string oper (void) const;
171 
172  type op_type (void) const { return m_etype; }
173 
174  tree_expression * dup (symbol_scope& scope) const;
175 
176  void accept (tree_walker& tw)
177  {
178  tw.visit_boolean_expression (*this);
179  }
180 
181  private:
182 
183  // The type of the expression.
185  };
186 }
187 
188 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
189 
190 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_binary_expression' instead")
191 typedef octave::tree_binary_expression tree_binary_expression;
192 
193 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_boolean_expression' instead")
194 typedef octave::tree_boolean_expression tree_boolean_expression;
195 
196 #endif
197 
198 #endif
std::string profiler_name(void) const
Definition: pt-binop.h:114
tree_binary_expression & operator=(const tree_binary_expression &)=delete
void accept(tree_walker &tw)
Definition: pt-binop.h:176
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
type op_type(void) const
Definition: pt-binop.h:172
octave_value::binary_op op_type(void) const
Definition: pt-binop.h:97
virtual void mark_braindead_shortcircuit(void)
Definition: pt-exp.h:106
bool is_eligible_for_braindead_shortcircuit(void) const
Definition: pt-binop.h:102
std::string oper(void) const
Definition: pt-binop.cc:47
tree_expression * m_rhs
Definition: pt-binop.h:122
virtual bool has_magic_end(void) const =0
virtual void visit_boolean_expression(tree_boolean_expression &expr)
Definition: pt-walk.cc:34
tree_boolean_expression(int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:151
binary_op
Definition: ov.h:94
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:997
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
bool has_magic_end(void) const
Definition: pt-binop.h:85
void matlab_style_short_circuit_warning(const char *op)
Definition: pt-binop.cc:37
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:400
void accept(tree_walker &tw)
Definition: pt-binop.h:109
tree_expression * dup(symbol_scope &scope) const
Definition: pt-binop.cc:53
bool is_binary_expression(void) const
Definition: pt-binop.h:91
std::string oper(void) const
Definition: pt-binop.cc:68
is false
Definition: cellfun.cc:400
tree_boolean_expression & operator=(const tree_boolean_expression &)=delete
void mark_braindead_shortcircuit(void)
Definition: pt-binop.h:74
tree_boolean_expression(tree_expression *a, tree_expression *b, int l=-1, int c=-1, type t=unknown)
Definition: pt-binop.h:154
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_expression * dup(symbol_scope &scope) const
Definition: pt-binop.cc:90
octave_value::binary_op m_etype
Definition: pt-binop.h:127
bool rvalue_ok(void) const
Definition: pt-binop.h:168
tree_expression * rhs(void)
Definition: pt-binop.h:100
virtual void visit_binary_expression(tree_binary_expression &)=0
b
Definition: cellfun.cc:400
tree_expression * m_lhs
Definition: pt-binop.h:121
tree_expression * lhs(void)
Definition: pt-binop.h:99
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:888
bool is_boolean_expression(void) const
Definition: pt-binop.h:166
bool rvalue_ok(void) const
Definition: pt-binop.h:93
~tree_boolean_expression(void)=default