Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-exp.h @ 18131:c7b68a11074b
maint: Periodic merge of gui-release to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 12 Dec 2013 00:24:02 -0500 |
parents | 97e49b588f5d d76f790b4eec |
children | b39cbe9f3bb0 |
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) |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
43 : tree (l, c), num_parens (0), postfix_index_type ('\0'), |
2980 | 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 |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
90 bool is_postfix_indexed (void) const { return (postfix_index_type != '\0'); } |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
91 |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
92 char postfix_index (void) const { return postfix_index_type; } |
2124 | 93 |
15606
fb9dffe5fbfb
The silent_functions flag no longer modifies the parse tree
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
94 // 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
|
95 // 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
|
96 // tree_evaluator::statement_printing_enabled. |
3933 | 97 bool print_result (void) const { return print_flag; } |
1739 | 98 |
3933 | 99 virtual std::string oper (void) const { return "<unknown>"; } |
1739 | 100 |
3933 | 101 virtual std::string name (void) const { return "<unknown>"; } |
2124 | 102 |
3523 | 103 virtual std::string original_text (void) const; |
1739 | 104 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
105 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
|
106 |
2980 | 107 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
|
108 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 num_parens++; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
110 return this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 } |
1739 | 112 |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
113 tree_expression *set_postfix_index (char type) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
114 { |
17856
97e49b588f5d
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
115 postfix_index_type = type; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 return this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
117 } |
2971 | 118 |
2980 | 119 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
|
120 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
121 print_flag = print; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
122 return this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
123 } |
2971 | 124 |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
125 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
|
126 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 num_parens = e.num_parens; |
17856
97e49b588f5d
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
128 postfix_index_type = e.postfix_index_type; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
129 print_flag = e.print_flag; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
130 } |
5861 | 131 |
2980 | 132 protected: |
2971 | 133 |
2980 | 134 // A count of the number of times this expression appears directly |
135 // inside a set of parentheses. | |
136 // | |
137 // (((e1)) + e2) ==> 2 for expression e1 | |
138 // ==> 1 for expression ((e1)) + e2 | |
139 // ==> 0 for expression e2 | |
140 int num_parens; | |
2971 | 141 |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
142 // The first index type associated with this expression. This field |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
143 // is 0 (character '\0') if the expression has no associated index. |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
144 // See the code in tree_identifier::rvalue for the rationale. |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15606
diff
changeset
|
145 char postfix_index_type; |
2971 | 146 |
2980 | 147 // Print result of rvalue for this expression? |
148 bool print_flag; | |
2988 | 149 |
150 private: | |
151 | |
152 // No copying! | |
153 | |
154 tree_expression (const tree_expression&); | |
155 | |
156 tree_expression& operator = (const tree_expression&); | |
2971 | 157 }; |
158 | |
1739 | 159 #endif |