comparison libinterp/parse-tree/pt-binop.h @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/parse-tree/pt-binop.h@46b19589b593
children
comparison
equal deleted inserted replaced
15194:0f0b795044c3 15195:2fc554ffbc28
1 /*
2
3 Copyright (C) 1996-2012 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_tree_binop_h)
24 #define octave_tree_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
41 tree_binary_expression : public tree_expression
42 {
43 public:
44
45 tree_binary_expression (int l = -1, int c = -1,
46 octave_value::binary_op t
47 = octave_value::unknown_binary_op)
48 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t),
49 eligible_for_braindead_shortcircuit (false) { }
50
51 tree_binary_expression (tree_expression *a, tree_expression *b,
52 int l = -1, int c = -1,
53 octave_value::binary_op t
54 = octave_value::unknown_binary_op)
55 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t),
56 eligible_for_braindead_shortcircuit (false) { }
57
58 ~tree_binary_expression (void)
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
67 || etype == octave_value::op_el_or)
68 {
69 if (file.empty ())
70 warning_with_id ("Octave:possible-matlab-short-circuit-operator",
71 "possible Matlab-style short-circuit operator at line %d, column %d",
72 line (), column ());
73 else
74 warning_with_id ("Octave:possible-matlab-short-circuit-operator",
75 "%s: possible Matlab-style short-circuit operator at line %d, column %d",
76 file.c_str (), line (), column ());
77
78 eligible_for_braindead_shortcircuit = true;
79
80 op_lhs->mark_braindead_shortcircuit (file);
81 op_rhs->mark_braindead_shortcircuit (file);
82 }
83 }
84
85 bool has_magic_end (void) const
86 {
87 return ((op_lhs && op_lhs->has_magic_end ())
88 || (op_rhs && op_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 octave_value rvalue1 (int nargout = 1);
96
97 octave_value_list rvalue (int nargout);
98
99 std::string oper (void) const;
100
101 octave_value::binary_op op_type (void) const { return etype; }
102
103 tree_expression *lhs (void) { return op_lhs; }
104 tree_expression *rhs (void) { return op_rhs; }
105
106 tree_expression *dup (symbol_table::scope_id scope,
107 symbol_table::context_id context) const;
108
109 void accept (tree_walker& tw);
110
111 protected:
112
113 // The operands for the expression.
114 tree_expression *op_lhs;
115 tree_expression *op_rhs;
116
117 private:
118
119 // The type of the expression.
120 octave_value::binary_op etype;
121
122 // TRUE if this is an | or & expression in the condition of an IF
123 // or WHILE statement.
124 bool eligible_for_braindead_shortcircuit;
125
126 // No copying!
127
128 tree_binary_expression (const tree_binary_expression&);
129
130 tree_binary_expression& operator = (const tree_binary_expression&);
131 };
132
133 // Boolean expressions.
134
135 class
136 tree_boolean_expression : public tree_binary_expression
137 {
138 public:
139
140 enum type
141 {
142 unknown,
143 bool_and,
144 bool_or
145 };
146
147 tree_boolean_expression (int l = -1, int c = -1, type t = unknown)
148 : tree_binary_expression (l, c), etype (t) { }
149
150 tree_boolean_expression (tree_expression *a, tree_expression *b,
151 int l = -1, int c = -1, type t = unknown)
152 : tree_binary_expression (a, b, l, c), etype (t) { }
153
154 ~tree_boolean_expression (void) { }
155
156 bool is_boolean_expression (void) const { return true; }
157
158 bool rvalue_ok (void) const { return true; }
159
160 octave_value rvalue1 (int nargout = 1);
161
162 octave_value_list rvalue (int nargout);
163
164 std::string oper (void) const;
165
166 type op_type (void) const { return etype; }
167
168 tree_expression *dup (symbol_table::scope_id scope,
169 symbol_table::context_id context) const;
170
171 private:
172
173 // The type of the expression.
174 type etype;
175
176 // No copying!
177
178 tree_boolean_expression (const tree_boolean_expression&);
179
180 tree_boolean_expression& operator = (const tree_boolean_expression&);
181 };
182
183 #endif