GNU Octave  4.0.0
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-2015 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 <string>
27 #include <list>
28 
29 class octave_value;
30 class octave_lvalue;
31 
32 #include "pt.h"
33 #include "symtab.h"
34 
35 // A base class for expressions.
36 
37 class
38 tree_expression : public tree
39 {
40 public:
41 
42  tree_expression (int l = -1, int c = -1)
43  : tree (l, c), num_parens (0), postfix_index_type ('\0'),
44  for_cmd_expr (false), print_flag (false) { }
45 
46  virtual ~tree_expression (void) { }
47 
48  virtual bool has_magic_end (void) const = 0;
49 
52 
53  virtual bool is_constant (void) const { return false; }
54 
55  virtual bool is_matrix (void) const { return false; }
56 
57  virtual bool is_cell (void) const { return false; }
58 
59  virtual bool is_identifier (void) const { return false; }
60 
61  virtual bool is_index_expression (void) const { return false; }
62 
63  virtual bool is_assignment_expression (void) const { return false; }
64 
65  virtual bool is_prefix_expression (void) const { return false; }
66 
67  virtual bool is_unary_expression (void) const { return false; }
68 
69  virtual bool is_binary_expression (void) const { return false; }
70 
71  virtual bool is_boolean_expression (void) const { return false; }
72 
73  virtual bool is_logically_true (const char *);
74 
75  virtual bool lvalue_ok (void) const { return false; }
76 
77  virtual bool rvalue_ok (void) const { return false; }
78 
79  virtual octave_value rvalue1 (int nargout = 1);
80 
81  virtual octave_value_list rvalue (int nargout);
82 
83  virtual octave_value_list
84  rvalue (int nargout, const std::list<octave_lvalue> *lvalue_list);
85 
86  virtual octave_lvalue lvalue (void);
87 
88  int paren_count (void) const { return num_parens; }
89 
90  bool is_postfix_indexed (void) const { return (postfix_index_type != '\0'); }
91 
92  char postfix_index (void) const { return postfix_index_type; }
93 
94  // Check if the result of the expression should be printed.
95  // Should normally be used in conjunction with
96  // tree_evaluator::statement_printing_enabled.
97  bool print_result (void) const { return print_flag; }
98 
99  virtual std::string oper (void) const { return "<unknown>"; }
100 
101  virtual std::string name (void) const { return "<unknown>"; }
102 
103  virtual std::string original_text (void) const;
104 
105  virtual void mark_braindead_shortcircuit (void) { }
106 
107  void mark_as_for_cmd_expr (void) { for_cmd_expr = true; }
108 
109  bool is_for_cmd_expr (void) const { return for_cmd_expr; }
110 
112  {
113  num_parens++;
114  return this;
115  }
116 
118  {
119  postfix_index_type = type;
120  return this;
121  }
122 
124  {
125  print_flag = print;
126  return this;
127  }
128 
129  virtual void copy_base (const tree_expression& e)
130  {
131  num_parens = e.num_parens;
132  postfix_index_type = e.postfix_index_type;
133  print_flag = e.print_flag;
134  }
135 
136 protected:
137 
138  // A count of the number of times this expression appears directly
139  // inside a set of parentheses.
140  //
141  // (((e1)) + e2) ==> 2 for expression e1
142  // ==> 1 for expression ((e1)) + e2
143  // ==> 0 for expression e2
145 
146  // The first index type associated with this expression. This field
147  // is 0 (character '\0') if the expression has no associated index.
148  // See the code in tree_identifier::rvalue for the rationale.
150 
151  // TRUE if this expression is the EXPR in for loop:
152  // FOR i = EXPR ... END
154 
155  // Print result of rvalue for this expression?
157 
158 private:
159 
160  // No copying!
161 
163 
165 };
166 
167 #endif
virtual bool lvalue_ok(void) const
Definition: pt-exp.h:75
int paren_count(void) const
Definition: pt-exp.h:88
virtual bool is_constant(void) const
Definition: pt-exp.h:53
virtual bool is_binary_expression(void) const
Definition: pt-exp.h:69
virtual bool is_cell(void) const
Definition: pt-exp.h:57
tree_expression(int l=-1, int c=-1)
Definition: pt-exp.h:42
tree_expression * set_print_flag(bool print)
Definition: pt-exp.h:123
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:129
virtual bool is_prefix_expression(void) const
Definition: pt-exp.h:65
bool is_for_cmd_expr(void) const
Definition: pt-exp.h:109
bool is_postfix_indexed(void) const
Definition: pt-exp.h:90
virtual bool rvalue_ok(void) const
Definition: pt-exp.h:77
tree_expression * mark_in_parens(void)
Definition: pt-exp.h:111
bool print_result(void) const
Definition: pt-exp.h:97
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
bool print_flag
Definition: pt-exp.h:156
bool for_cmd_expr
Definition: pt-exp.h:153
virtual bool is_index_expression(void) const
Definition: pt-exp.h:61
virtual ~tree_expression(void)
Definition: pt-exp.h:46
virtual std::string oper(void) const
Definition: pt-exp.h:99
virtual std::string name(void) const
Definition: pt-exp.h:101
virtual void mark_braindead_shortcircuit(void)
Definition: pt-exp.h:105
virtual bool is_matrix(void) const
Definition: pt-exp.h:55
virtual bool is_unary_expression(void) const
Definition: pt-exp.h:67
void mark_as_for_cmd_expr(void)
Definition: pt-exp.h:107
int num_parens
Definition: pt-exp.h:144
Definition: pt.h:35
tree_expression * set_postfix_index(char type)
Definition: pt-exp.h:117
virtual bool is_assignment_expression(void) const
Definition: pt-exp.h:63
char postfix_index_type
Definition: pt-exp.h:149
size_t context_id
Definition: symtab.h:51
char postfix_index(void) const
Definition: pt-exp.h:92
virtual bool is_identifier(void) const
Definition: pt-exp.h:59
octave_lvalue & operator=(const octave_lvalue &vr)
Definition: oct-lvalue.h:49
virtual bool is_boolean_expression(void) const
Definition: pt-exp.h:71