pt-exp.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_tree_expr_h)
00024 #define octave_tree_expr_h 1
00025 
00026 #include <string>
00027 #include <list>
00028 
00029 class octave_value;
00030 class octave_lvalue;
00031 
00032 #include "pt.h"
00033 #include "symtab.h"
00034 
00035 // A base class for expressions.
00036 
00037 class
00038 tree_expression : public tree
00039 {
00040 public:
00041 
00042   tree_expression (int l = -1, int c = -1)
00043     : tree (l, c), num_parens (0), postfix_indexed (false),
00044       print_flag (false) { }
00045 
00046   virtual ~tree_expression (void) { }
00047 
00048   virtual bool has_magic_end (void) const = 0;
00049 
00050   virtual tree_expression *dup (symbol_table::scope_id,
00051                                 symbol_table::context_id context) const = 0;
00052 
00053   virtual bool is_constant (void) const { return false; }
00054 
00055   virtual bool is_matrix_constant (void) const { return false; }
00056 
00057   virtual bool is_identifier (void) const { return false; }
00058 
00059   virtual bool is_index_expression (void) const { return false; }
00060 
00061   virtual bool is_assignment_expression (void) const { return false; }
00062 
00063   virtual bool is_prefix_expression (void) const { return false; }
00064 
00065   virtual bool is_unary_expression (void) const { return false; }
00066 
00067   virtual bool is_binary_expression (void) const { return false; }
00068 
00069   virtual bool is_boolean_expression (void) const { return false; }
00070 
00071   virtual bool is_logically_true (const char *);
00072 
00073   virtual bool lvalue_ok (void) const { return false; }
00074 
00075   virtual bool rvalue_ok (void) const { return false; }
00076 
00077   virtual octave_value rvalue1 (int nargout = 1);
00078 
00079   virtual octave_value_list rvalue (int nargout);
00080 
00081   virtual octave_value_list rvalue (int nargout,
00082                                     const std::list<octave_lvalue> *lvalue_list);
00083 
00084   virtual octave_lvalue lvalue (void);
00085 
00086   int paren_count (void) const { return num_parens; }
00087 
00088   bool is_postfix_indexed (void) const { return postfix_indexed; }
00089 
00090   bool print_result (void) const { return print_flag; }
00091 
00092   virtual std::string oper (void) const { return "<unknown>"; }
00093 
00094   virtual std::string name (void) const { return "<unknown>"; }
00095 
00096   virtual std::string original_text (void) const;
00097 
00098   virtual void mark_braindead_shortcircuit (const std::string&) { }
00099 
00100   tree_expression *mark_in_parens (void)
00101     {
00102       num_parens++;
00103       return this;
00104     }
00105 
00106   tree_expression *mark_postfix_indexed (void)
00107     {
00108       postfix_indexed = true;
00109       return this;
00110     }
00111 
00112   tree_expression *set_print_flag (bool print)
00113     {
00114       print_flag = print;
00115       return this;
00116     }
00117 
00118   virtual void copy_base (const tree_expression& e)
00119     {
00120       num_parens = e.num_parens;
00121       postfix_indexed = e.postfix_indexed;
00122       print_flag = e.print_flag;
00123     }
00124 
00125 protected:
00126 
00127   // A count of the number of times this expression appears directly
00128   // inside a set of parentheses.
00129   //
00130   //   (((e1)) + e2)  ==> 2 for expression e1
00131   //                  ==> 1 for expression ((e1)) + e2
00132   //                  ==> 0 for expression e2
00133   int num_parens;
00134 
00135   // A flag that says whether this expression has an index associated
00136   // with it.  See the code in tree_identifier::rvalue for the rationale.
00137   bool postfix_indexed;
00138 
00139   // Print result of rvalue for this expression?
00140   bool print_flag;
00141 
00142 private:
00143 
00144   // No copying!
00145 
00146   tree_expression (const tree_expression&);
00147 
00148   tree_expression& operator = (const tree_expression&);
00149 };
00150 
00151 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines