GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-exp.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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_pt_exp_h)
24 #define octave_pt_exp_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 #include <list>
30 
31 class octave_value;
32 class octave_lvalue;
33 
34 #include "pt.h"
35 #include "symtab.h"
36 
37 // A base class for expressions.
38 
39 class
40 tree_expression : public tree
41 {
42 public:
43 
44  tree_expression (int l = -1, int c = -1)
45  : tree (l, c), num_parens (0), postfix_index_type ('\0'),
46  for_cmd_expr (false), print_flag (false) { }
47 
48  virtual ~tree_expression (void) { }
49 
50  virtual bool has_magic_end (void) const = 0;
51 
54 
55  virtual bool is_constant (void) const { return false; }
56 
57  virtual bool is_matrix (void) const { return false; }
58 
59  virtual bool is_cell (void) const { return false; }
60 
61  virtual bool is_identifier (void) const { return false; }
62 
63  virtual bool is_index_expression (void) const { return false; }
64 
65  virtual bool is_assignment_expression (void) const { return false; }
66 
67  virtual bool is_prefix_expression (void) const { return false; }
68 
69  virtual bool is_unary_expression (void) const { return false; }
70 
71  virtual bool is_binary_expression (void) const { return false; }
72 
73  virtual bool is_boolean_expression (void) const { return false; }
74 
75  virtual bool is_logically_true (const char *);
76 
77  virtual bool lvalue_ok (void) const { return false; }
78 
79  virtual bool rvalue_ok (void) const { return false; }
80 
81  virtual octave_value rvalue1 (int nargout = 1);
82 
83  virtual octave_value_list rvalue (int nargout);
84 
85  virtual octave_value_list
86  rvalue (int nargout, const std::list<octave_lvalue> *lvalue_list);
87 
88  virtual octave_lvalue lvalue (void);
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  // octave::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  {
121  postfix_index_type = type;
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  {
133  num_parens = e.num_parens;
134  postfix_index_type = e.postfix_index_type;
135  print_flag = e.print_flag;
136  }
137 
138 protected:
139 
140  // A count of the number of times this expression appears directly
141  // inside a set of parentheses.
142  //
143  // (((e1)) + e2) ==> 2 for expression e1
144  // ==> 1 for expression ((e1)) + e2
145  // ==> 0 for expression e2
147 
148  // The first index type associated with this expression. This field
149  // is 0 (character '\0') if the expression has no associated index.
150  // See the code in tree_identifier::rvalue for the rationale.
152 
153  // TRUE if this expression is the EXPR in for loop:
154  // FOR i = EXPR ... END
156 
157  // Print result of rvalue for this expression?
159 
160 private:
161 
162  // No copying!
163 
165 
167 };
168 
169 #endif
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:77
int paren_count(void) const
Definition: pt-exp.h:90
virtual bool is_constant(void) const
Definition: pt-exp.h:55
virtual bool is_binary_expression(void) const
Definition: pt-exp.h:71
virtual bool is_cell(void) const
Definition: pt-exp.h:59
tree_expression(int l=-1, int c=-1)
Definition: pt-exp.h:44
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:125
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:131
i e
Definition: data.cc:2724
virtual bool is_prefix_expression(void) const
Definition: pt-exp.h:67
bool is_for_cmd_expr(void) const
Definition: pt-exp.h:111
bool is_postfix_indexed(void) const
Definition: pt-exp.h:92
virtual bool rvalue_ok(void) const
Definition: pt-exp.h:79
tree_expression * mark_in_parens(void)
Definition: pt-exp.h:113
bool print_result(void) const
Definition: pt-exp.h:99
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
bool print_flag
Definition: pt-exp.h:158
bool for_cmd_expr
Definition: pt-exp.h:155
virtual bool is_index_expression(void) const
Definition: pt-exp.h:63
is false
Definition: cellfun.cc:398
idx type
Definition: ov.cc:3129
virtual ~tree_expression(void)
Definition: pt-exp.h:48
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
virtual std::string oper(void) const
Definition: pt-exp.h:101
virtual std::string name(void) const
Definition: pt-exp.h:103
virtual void mark_braindead_shortcircuit(void)
Definition: pt-exp.h:107
virtual bool is_matrix(void) const
Definition: pt-exp.h:57
virtual bool is_unary_expression(void) const
Definition: pt-exp.h:69
void mark_as_for_cmd_expr(void)
Definition: pt-exp.h:109
int num_parens
Definition: pt-exp.h:146
Definition: pt.h:39
tree_expression * set_postfix_index(char type)
Definition: pt-exp.h:119
virtual bool is_assignment_expression(void) const
Definition: pt-exp.h:65
char postfix_index_type
Definition: pt-exp.h:151
char postfix_index(void) const
Definition: pt-exp.h:94
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
virtual bool is_identifier(void) const
Definition: pt-exp.h:61
octave_lvalue & operator=(const octave_lvalue &vr)
Definition: oct-lvalue.h:51
virtual bool is_boolean_expression(void) const
Definition: pt-exp.h:73