GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-exp.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_pt_exp_h)
27 #define octave_pt_exp_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 #include <list>
33 
34 class octave_value;
35 
36 #include "pt.h"
37 #include "pt-eval.h"
38 
39 namespace octave
40 {
41  class symbol_scope;
42  class octave_lvalue;
43 
44  // A base class for expressions.
45 
46  class tree_expression : public tree
47  {
48  public:
49 
50  tree_expression (int l = -1, int c = -1)
51  : tree (l, c), num_parens (0), postfix_index_type ('\0'),
52  for_cmd_expr (false), print_flag (false) { }
53 
54  // No copying!
55 
56  tree_expression (const tree_expression&) = delete;
57 
59 
60  virtual ~tree_expression (void) = default;
61 
62  virtual tree_expression * dup (symbol_scope& scope) const = 0;
63 
64  virtual bool is_constant (void) const { return false; }
65 
66  virtual bool is_matrix (void) const { return false; }
67 
68  virtual bool iscell (void) const { return false; }
69 
70  virtual bool is_identifier (void) const { return false; }
71 
72  virtual bool is_index_expression (void) const { return false; }
73 
74  virtual bool is_assignment_expression (void) const { return false; }
75 
76  virtual bool is_prefix_expression (void) const { return false; }
77 
78  virtual bool is_unary_expression (void) const { return false; }
79 
80  virtual bool is_binary_expression (void) const { return false; }
81 
82  virtual bool is_boolean_expression (void) const { return false; }
83 
84  virtual bool lvalue_ok (void) const { return false; }
85 
86  virtual bool rvalue_ok (void) const { return false; }
87 
89 
90  int paren_count (void) const { return num_parens; }
91 
92  bool is_postfix_indexed (void) const { return (postfix_index_type != '\0'); }
93 
94  char postfix_index (void) const { return postfix_index_type; }
95 
96  // Check if the result of the expression should be printed.
97  // Should normally be used in conjunction with
98  // tree_evaluator::statement_printing_enabled.
99  bool print_result (void) const { return print_flag; }
100 
101  virtual std::string oper (void) const { return "<unknown>"; }
102 
103  virtual std::string name (void) const { return "<unknown>"; }
104 
105  virtual std::string original_text (void) const;
106 
107  virtual void mark_braindead_shortcircuit (void) { }
108 
109  void mark_as_for_cmd_expr (void) { for_cmd_expr = true; }
110 
111  bool is_for_cmd_expr (void) const { return for_cmd_expr; }
112 
114  {
115  num_parens++;
116  return this;
117  }
118 
120  {
122  return this;
123  }
124 
126  {
127  print_flag = print;
128  return this;
129  }
130 
131  virtual void copy_base (const tree_expression& e)
132  {
136  }
137 
138  virtual octave_value evaluate (tree_evaluator& tw, int nargout = 1) = 0;
139 
140  virtual octave_value_list
141  evaluate_n (tree_evaluator& tw, int nargout = 1) = 0;
142 
143  protected:
144 
145  // A count of the number of times this expression appears directly
146  // inside a set of parentheses.
147  //
148  // (((e1)) + e2) ==> 2 for expression e1
149  // ==> 1 for expression ((e1)) + e2
150  // ==> 0 for expression e2
152 
153  // The first index type associated with this expression. This field
154  // is 0 (character '\0') if the expression has no associated index.
155  // See the code in tree_identifier::rvalue for the rationale.
157 
158  // TRUE if this expression is the EXPR in for loop:
159  // FOR i = EXPR ... END
161 
162  // Print result of rvalue for this expression?
164  };
165 }
166 
167 #endif
virtual bool is_binary_expression(void) const
Definition: pt-exp.h:80
virtual ~tree_expression(void)=default
virtual bool is_identifier(void) const
Definition: pt-exp.h:70
virtual bool is_index_expression(void) const
Definition: pt-exp.h:72
virtual std::string original_text(void) const
Definition: pt-exp.cc:49
virtual void mark_braindead_shortcircuit(void)
Definition: pt-exp.h:107
void mark_as_for_cmd_expr(void)
Definition: pt-exp.h:109
virtual std::string oper(void) const
Definition: pt-exp.h:101
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:131
char postfix_index(void) const
Definition: pt-exp.h:94
tree_expression * mark_in_parens(void)
Definition: pt-exp.h:113
bool is_for_cmd_expr(void) const
Definition: pt-exp.h:111
tree_expression(const tree_expression &)=delete
virtual tree_expression * dup(symbol_scope &scope) const =0
virtual bool iscell(void) const
Definition: pt-exp.h:68
virtual bool is_boolean_expression(void) const
Definition: pt-exp.h:82
virtual bool is_matrix(void) const
Definition: pt-exp.h:66
tree_expression * set_postfix_index(char type)
Definition: pt-exp.h:119
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:84
tree_expression(int l=-1, int c=-1)
Definition: pt-exp.h:50
virtual octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)=0
virtual octave_lvalue lvalue(tree_evaluator &)
Definition: pt-exp.cc:43
virtual bool rvalue_ok(void) const
Definition: pt-exp.h:86
virtual std::string name(void) const
Definition: pt-exp.h:103
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
int paren_count(void) const
Definition: pt-exp.h:90
virtual bool is_unary_expression(void) const
Definition: pt-exp.h:78
virtual bool is_assignment_expression(void) const
Definition: pt-exp.h:74
bool is_postfix_indexed(void) const
Definition: pt-exp.h:92
virtual bool is_prefix_expression(void) const
Definition: pt-exp.h:76
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:125
bool print_result(void) const
Definition: pt-exp.h:99
virtual bool is_constant(void) const
Definition: pt-exp.h:64
tree_expression & operator=(const tree_expression &)=delete