Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-exp.h @ 19840:c5270263d466 gui-release
close gui-release branch
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Jan 2015 17:41:50 -0500 |
parents | d76f790b4eec |
children | c7b68a11074b |
rev | line source |
---|---|
1739 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16273
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
1739 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1739 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1739 | 20 |
21 */ | |
22 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
23 #if !defined (octave_pt_exp_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
24 #define octave_pt_exp_h 1 |
1739 | 25 |
2980 | 26 #include <string> |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
27 #include <list> |
2124 | 28 |
2879 | 29 class octave_value; |
2979 | 30 class octave_lvalue; |
2879 | 31 |
2988 | 32 #include "pt.h" |
7336 | 33 #include "symtab.h" |
2124 | 34 |
2980 | 35 // A base class for expressions. |
1739 | 36 |
37 class | |
2980 | 38 tree_expression : public tree |
2388 | 39 { |
40 public: | |
41 | |
2980 | 42 tree_expression (int l = -1, int c = -1) |
43 : tree (l, c), num_parens (0), postfix_indexed (false), | |
44 print_flag (false) { } | |
2388 | 45 |
2980 | 46 virtual ~tree_expression (void) { } |
2388 | 47 |
4267 | 48 virtual bool has_magic_end (void) const = 0; |
49 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
50 virtual tree_expression *dup (symbol_table::scope_id, |
10313 | 51 symbol_table::context_id context) const = 0; |
5861 | 52 |
3933 | 53 virtual bool is_constant (void) const { return false; } |
2388 | 54 |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
15606
diff
changeset
|
55 virtual bool is_matrix (void) const { return false; } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
15606
diff
changeset
|
56 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
15606
diff
changeset
|
57 virtual bool is_cell (void) const { return false; } |
2388 | 58 |
3933 | 59 virtual bool is_identifier (void) const { return false; } |
1739 | 60 |
3933 | 61 virtual bool is_index_expression (void) const { return false; } |
1739 | 62 |
3933 | 63 virtual bool is_assignment_expression (void) const { return false; } |
1739 | 64 |
3933 | 65 virtual bool is_prefix_expression (void) const { return false; } |
1739 | 66 |
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
|
67 virtual bool is_unary_expression (void) const { return false; } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
68 |
4023 | 69 virtual bool is_binary_expression (void) const { return false; } |
70 | |
71 virtual bool is_boolean_expression (void) const { return false; } | |
72 | |
2980 | 73 virtual bool is_logically_true (const char *); |
1739 | 74 |
3933 | 75 virtual bool lvalue_ok (void) const { return false; } |
1739 | 76 |
3933 | 77 virtual bool rvalue_ok (void) const { return false; } |
2124 | 78 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7800
diff
changeset
|
79 virtual octave_value rvalue1 (int nargout = 1); |
1739 | 80 |
2980 | 81 virtual octave_value_list rvalue (int nargout); |
2879 | 82 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
83 virtual octave_value_list |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 rvalue (int nargout, const std::list<octave_lvalue> *lvalue_list); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
85 |
2980 | 86 virtual octave_lvalue lvalue (void); |
2879 | 87 |
3933 | 88 int paren_count (void) const { return num_parens; } |
2124 | 89 |
3933 | 90 bool is_postfix_indexed (void) const { return postfix_indexed; } |
2124 | 91 |
15606
fb9dffe5fbfb
The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
92 // Check if the result of the expression should be printed. |
fb9dffe5fbfb
The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
93 // Should normally be used in conjunction with |
fb9dffe5fbfb
The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
94 // tree_evaluator::statement_printing_enabled. |
3933 | 95 bool print_result (void) const { return print_flag; } |
1739 | 96 |
3933 | 97 virtual std::string oper (void) const { return "<unknown>"; } |
1739 | 98 |
3933 | 99 virtual std::string name (void) const { return "<unknown>"; } |
2124 | 100 |
3523 | 101 virtual std::string original_text (void) const; |
1739 | 102 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
103 virtual void mark_braindead_shortcircuit (void) { } |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10832
diff
changeset
|
104 |
2980 | 105 tree_expression *mark_in_parens (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
106 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 num_parens++; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 return this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 } |
1739 | 110 |
2980 | 111 tree_expression *mark_postfix_indexed (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 postfix_indexed = true; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
114 return this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 } |
2971 | 116 |
2980 | 117 tree_expression *set_print_flag (bool print) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
118 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
119 print_flag = print; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
120 return this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
121 } |
2971 | 122 |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
123 virtual void copy_base (const tree_expression& e) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
124 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 num_parens = e.num_parens; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
126 postfix_indexed = e.postfix_indexed; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 print_flag = e.print_flag; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
128 } |
5861 | 129 |
2980 | 130 protected: |
2971 | 131 |
2980 | 132 // A count of the number of times this expression appears directly |
133 // inside a set of parentheses. | |
134 // | |
135 // (((e1)) + e2) ==> 2 for expression e1 | |
136 // ==> 1 for expression ((e1)) + e2 | |
137 // ==> 0 for expression e2 | |
138 int num_parens; | |
2971 | 139 |
2980 | 140 // A flag that says whether this expression has an index associated |
141 // with it. See the code in tree_identifier::rvalue for the rationale. | |
142 bool postfix_indexed; | |
2971 | 143 |
2980 | 144 // Print result of rvalue for this expression? |
145 bool print_flag; | |
2988 | 146 |
147 private: | |
148 | |
149 // No copying! | |
150 | |
151 tree_expression (const tree_expression&); | |
152 | |
153 tree_expression& operator = (const tree_expression&); | |
2971 | 154 }; |
155 | |
1739 | 156 #endif |