Mercurial > octave
annotate libinterp/parse-tree/pt-unop.h @ 26377:fff643eb3514
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 02 Jan 2019 16:45:58 -0500 |
parents | f23f27e78aa2 00f796120a6d |
children | fcaecdbc8d8a |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25149
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2980 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
2980 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2980 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2980 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_pt_unop_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 #define octave_pt_unop_h 1 |
2980 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
27 |
2980 | 28 #include <string> |
29 | |
30 class octave_value; | |
31 class octave_value_list; | |
32 | |
25149
dd774017866b
allow most headers to be included alone (bug #53505)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
33 #include "ov.h" |
2980 | 34 #include "pt-exp.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
35 #include "pt-walk.h" |
2980 | 36 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
37 namespace octave |
2980 | 38 { |
24362
3fc24b792a24
avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
39 class symbol_scope; |
3fc24b792a24
avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
40 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
41 // Unary expressions. |
2980 | 42 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
43 class tree_unary_expression : public tree_expression |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
44 { |
23423
50fc8edb007b
protect tree_unop and tree_array_list constructors
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
45 protected: |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
46 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
47 tree_unary_expression (int l = -1, int c = -1, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
48 octave_value::unary_op t |
10313 | 49 = octave_value::unknown_unary_op) |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
50 : tree_expression (l, c), m_op (nullptr), m_etype (t) { } |
2980 | 51 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
52 tree_unary_expression (tree_expression *e, int l = -1, int c = -1, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
53 octave_value::unary_op t |
10313 | 54 = octave_value::unknown_unary_op) |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
55 : tree_expression (l, c), m_op (e), m_etype (t) { } |
2980 | 56 |
23423
50fc8edb007b
protect tree_unop and tree_array_list constructors
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
57 public: |
50fc8edb007b
protect tree_unop and tree_array_list constructors
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
58 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
59 // No copying! |
2980 | 60 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
61 tree_unary_expression (const tree_unary_expression&) = delete; |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
62 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
63 tree_unary_expression& operator = (const tree_unary_expression&) = delete; |
4267 | 64 |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
65 ~tree_unary_expression (void) { delete m_op; } |
2980 | 66 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
67 bool is_unary_expression (void) const { return true; } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
68 |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
69 bool has_magic_end (void) const { return (m_op && m_op->has_magic_end ()); } |
3203 | 70 |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
71 tree_expression * operand (void) { return m_op; } |
2980 | 72 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
73 std::string oper (void) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
75 octave_value::unary_op op_type (void) const { return m_etype; } |
2988 | 76 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
77 protected: |
3203 | 78 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
79 // The operand for the expression. |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
80 tree_expression *m_op; |
3203 | 81 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
82 // The type of the expression. |
24848
2d68dc548561
use m_ prefix for member variables in unary op parser classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
83 octave_value::unary_op m_etype; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
84 }; |
2988 | 85 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
86 // Prefix expressions. |
2980 | 87 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
88 class tree_prefix_expression : public tree_unary_expression |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
89 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
90 public: |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
91 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
92 tree_prefix_expression (int l = -1, int c = -1) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
93 : tree_unary_expression (l, c, octave_value::unknown_unary_op) { } |
2980 | 94 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
95 tree_prefix_expression (tree_expression *e, int l = -1, int c = -1, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
96 octave_value::unary_op t |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
97 = octave_value::unknown_unary_op) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
98 : tree_unary_expression (e, l, c, t) { } |
2980 | 99 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
100 // No copying! |
2980 | 101 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
102 tree_prefix_expression (const tree_prefix_expression&) = delete; |
2980 | 103 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
104 tree_prefix_expression& operator = (const tree_prefix_expression&) = delete; |
2980 | 105 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
106 ~tree_prefix_expression (void) = default; |
2980 | 107 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
108 bool rvalue_ok (void) const { return true; } |
2980 | 109 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23795
diff
changeset
|
110 tree_expression * dup (symbol_scope& scope) const; |
5861 | 111 |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
112 void accept (tree_walker& tw) |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
113 { |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
114 tw.visit_prefix_expression (*this); |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
115 } |
19327
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17822
diff
changeset
|
116 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
117 std::string profiler_name (void) const { return "prefix " + oper (); } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
118 }; |
2980 | 119 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
120 // Postfix expressions. |
2988 | 121 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
122 class tree_postfix_expression : public tree_unary_expression |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
123 { |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
124 public: |
2980 | 125 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
126 tree_postfix_expression (int l = -1, int c = -1) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
127 : tree_unary_expression (l, c, octave_value::unknown_unary_op) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
128 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
129 tree_postfix_expression (tree_expression *e, int l = -1, int c = -1, |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
130 octave_value::unary_op t |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
131 = octave_value::unknown_unary_op) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
132 : tree_unary_expression (e, l, c, t) { } |
2980 | 133 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
134 // No copying! |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
135 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
136 tree_postfix_expression (const tree_postfix_expression&) = delete; |
2980 | 137 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
138 tree_postfix_expression& operator = (const tree_postfix_expression&) = delete; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
139 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
140 ~tree_postfix_expression (void) = default; |
2980 | 141 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
142 bool rvalue_ok (void) const { return true; } |
2980 | 143 |
24270
bc3819b7cca1
don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents:
23795
diff
changeset
|
144 tree_expression * dup (symbol_scope& scope) const; |
2980 | 145 |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
146 void accept (tree_walker& tw) |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
147 { |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
148 tw.visit_postfix_expression (*this); |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23423
diff
changeset
|
149 } |
5861 | 150 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
151 std::string profiler_name (void) const { return "postfix " + oper (); } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
152 }; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
153 } |
2980 | 154 |
155 #endif |