changeset 15035:a820a990968e classdef

new tree_funcall class * pt-funcall.h, pt-funcall.cc: New files. Define tree_funcall class. * pt-all.h: Also include pt-funcall.h. * pt-bp.h, pt-bp.cc (tree_breakpoint::visit_funcall): New function. * pt-check.h, pt-check.cc (tree_checker::visit_funcall): New function. * pt-eval.h, pt-eval.cc (tree_evaluator::visit_funcall): New function. * pt-pr-code.h, pt-pr-code.cc (tree_print_code::visit_funcall): New function. * pt-walk.h (tree_walker::visit_funcall): New pure virtual function. * src/Makefile.am (PT_INCLUDES): Add pt-funcall.h to the list.* (PT_SRC): Add pt-funcall.cc to the list.
author John W. Eaton <jwe@octave.org>
date Fri, 27 Jul 2012 15:44:11 -0400
parents 1116864ee270
children aa1f9e479c6e
files src/Makefile.am src/pt-all.h src/pt-bp.cc src/pt-bp.h src/pt-check.cc src/pt-check.h src/pt-eval.cc src/pt-eval.h src/pt-funcall.cc src/pt-funcall.h src/pt-pr-code.cc src/pt-pr-code.h src/pt-walk.h
diffstat 13 files changed, 228 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/Makefile.am	Fri Jul 27 15:44:11 2012 -0400
@@ -218,6 +218,7 @@
   pt-except.h \
   pt-exp.h \
   pt-fcn-handle.h \
+  pt-funcall.h \
   pt-id.h \
   pt-idx.h \
   pt-jump.h \
@@ -397,6 +398,7 @@
   pt-except.cc \
   pt-exp.cc \
   pt-fcn-handle.cc \
+  pt-funcall.cc \
   pt-id.cc \
   pt-idx.cc \
   pt-jump.cc \
--- a/src/pt-all.h	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-all.h	Fri Jul 27 15:44:11 2012 -0400
@@ -37,6 +37,7 @@
 #include "pt-except.h"
 #include "pt-exp.h"
 #include "pt-fcn-handle.h"
+#include "pt-funcall.h"
 #include "pt-id.h"
 #include "pt-idx.h"
 #include "pt-jump.h"
--- a/src/pt-bp.cc	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-bp.cc	Fri Jul 27 15:44:11 2012 -0400
@@ -299,6 +299,12 @@
 }
 
 void
+tree_breakpoint::visit_funcall (tree_funcall&)
+{
+  panic_impossible ();
+}
+
+void
 tree_breakpoint::visit_parameter_list (tree_parameter_list&)
 {
   panic_impossible ();
--- a/src/pt-bp.h	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-bp.h	Fri Jul 27 15:44:11 2012 -0400
@@ -106,6 +106,8 @@
 
   void visit_fcn_handle (tree_fcn_handle&);
 
+  void visit_funcall (tree_funcall&);
+
   void visit_parameter_list (tree_parameter_list&);
 
   void visit_postfix_expression (tree_postfix_expression&);
--- a/src/pt-check.cc	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-check.cc	Fri Jul 27 15:44:11 2012 -0400
@@ -357,6 +357,11 @@
 }
 
 void
+tree_checker::visit_funcall (tree_funcall& /* fc */)
+{
+}
+
+void
 tree_checker::visit_parameter_list (tree_parameter_list& lst)
 {
   tree_parameter_list::iterator p = lst.begin ();
--- a/src/pt-check.h	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-check.h	Fri Jul 27 15:44:11 2012 -0400
@@ -91,6 +91,8 @@
 
   void visit_fcn_handle (tree_fcn_handle&);
 
+  void visit_funcall (tree_funcall&);
+
   void visit_parameter_list (tree_parameter_list&);
 
   void visit_postfix_expression (tree_postfix_expression&);
--- a/src/pt-eval.cc	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-eval.cc	Fri Jul 27 15:44:11 2012 -0400
@@ -633,6 +633,12 @@
 }
 
 void
+tree_evaluator::visit_funcall (tree_funcall&)
+{
+  panic_impossible ();
+}
+
+void
 tree_evaluator::visit_parameter_list (tree_parameter_list&)
 {
   panic_impossible ();
--- a/src/pt-eval.h	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-eval.h	Fri Jul 27 15:44:11 2012 -0400
@@ -102,6 +102,8 @@
 
   void visit_fcn_handle (tree_fcn_handle&);
 
+  void visit_funcall (tree_funcall&);
+
   void visit_parameter_list (tree_parameter_list&);
 
   void visit_postfix_expression (tree_postfix_expression&);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pt-funcall.cc	Fri Jul 27 15:44:11 2012 -0400
@@ -0,0 +1,83 @@
+/*
+
+Copyright (C) 2012 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "ov-fcn.h"
+#include "pt-funcall.h"
+#include "pt-walk.h"
+
+// Function call objects.
+
+void
+tree_funcall::print (std::ostream& os, bool pr_as_read_syntax,
+                     bool pr_orig_text)
+{
+  print_raw (os, pr_as_read_syntax, pr_orig_text);
+}
+
+void
+tree_funcall::print_raw (std::ostream& os, bool pr_as_read_syntax,
+                         bool pr_orig_text)
+{
+  if (pr_orig_text)
+    {
+      os << original_text ();
+    }
+  else
+    {
+      octave_function *fp = fcn.function_value ();
+      std::string nm = fp ? fp->name () : std::string ("<invalid-function>");
+
+      os << nm << " (";
+
+      octave_idx_type len = args.length ();
+      for (octave_idx_type i = 0; i < len; i++)
+        {
+          args(i).print_raw (os, pr_as_read_syntax);
+
+          if (i < len - 1)
+            os << ", ";
+        }
+
+      os << ")";
+    }
+}
+
+tree_funcall *
+tree_funcall::dup (symbol_table::scope_id,
+                  symbol_table::context_id context) const
+{
+  tree_funcall *new_fc = new tree_funcall (fcn, args, line (), column ());
+
+  new_fc->copy_base (*new_fc);
+
+  return new_fc;
+}
+
+void
+tree_funcall::accept (tree_walker& tw)
+{
+  tw.visit_funcall (*this);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pt-funcall.h	Fri Jul 27 15:44:11 2012 -0400
@@ -0,0 +1,101 @@
+/*
+
+Copyright (C) 2012 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if !defined (octave_tree_funcall_h)
+#define octave_tree_funcall_h 1
+
+#include "ov.h"
+#include "oct-obj.h"
+#include "parse.h"
+#include "pt-exp.h"
+
+// Function call.  This class only represents function calls that have
+// known functions (most useful for calls to built-in functions that
+// are generated by the parser) and fixed argument lists, known at
+// compile time.
+
+class
+tree_funcall : public tree_expression
+{
+public:
+
+  tree_funcall (const octave_value& f, const octave_value_list& a,
+                int l = -1, int c = -1)
+    : tree_expression (l, c), fcn (f), args (a)
+  {
+    if (! fcn.is_function ())
+      error ("tree_funcall: invalid function");
+  }
+
+  ~tree_funcall (void) { }
+
+  bool has_magic_end (void) const { return false; }
+
+  void print (std::ostream& os, bool pr_as_read_syntax = false,
+              bool pr_orig_txt = true);
+
+  void print_raw (std::ostream& os, bool pr_as_read_syntax = false,
+                  bool pr_orig_txt = true);
+
+  tree_funcall *dup (symbol_table::scope_id,
+                     symbol_table::context_id context) const;
+
+  octave_value rvalue1 (int nargout)
+  {
+    octave_value retval;
+
+    const octave_value_list tmp = rvalue (nargout);
+
+    if (! tmp.empty ())
+      retval = tmp(0);
+
+    return retval;
+  }
+
+  octave_value_list rvalue (int nargout)
+  {
+    return feval (fcn.function_value (), args, nargout);
+  }
+
+  octave_value function (void) const { return fcn; }
+
+  octave_value_list arguments (void) const { return args; }
+
+  void accept (tree_walker& tw);
+
+private:
+
+  // Function to call.  Error if not a valid function at time of
+  // construction.
+  octave_value fcn;
+
+  // Argument list.
+  octave_value_list args;
+
+  // No copying!
+
+  tree_funcall (const tree_funcall&);
+
+  tree_funcall& operator = (const tree_funcall&);
+};
+
+#endif
--- a/src/pt-pr-code.cc	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-pr-code.cc	Fri Jul 27 15:44:11 2012 -0400
@@ -749,6 +749,18 @@
 }
 
 void
+tree_print_code::visit_funcall (tree_funcall& fc)
+{
+  indent ();
+
+  print_parens (fc, "(");
+
+  fc.print_raw (os, true, print_original_text);
+
+  print_parens (fc, ")");
+}
+
+void
 tree_print_code::visit_parameter_list (tree_parameter_list& lst)
 {
   tree_parameter_list::iterator p = lst.begin ();
--- a/src/pt-pr-code.h	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-pr-code.h	Fri Jul 27 15:44:11 2012 -0400
@@ -109,6 +109,8 @@
 
   void visit_fcn_handle (tree_fcn_handle&);
 
+  void visit_funcall (tree_funcall&);
+
   void visit_parameter_list (tree_parameter_list&);
 
   void visit_postfix_expression (tree_postfix_expression&);
--- a/src/pt-walk.h	Fri Jul 27 09:11:49 2012 -0700
+++ b/src/pt-walk.h	Fri Jul 27 15:44:11 2012 -0400
@@ -52,6 +52,7 @@
 class tree_no_op_command;
 class tree_constant;
 class tree_fcn_handle;
+class tree_funcall;
 class tree_parameter_list;
 class tree_postfix_expression;
 class tree_prefix_expression;
@@ -158,6 +159,9 @@
   visit_fcn_handle (tree_fcn_handle&) = 0;
 
   virtual void
+  visit_funcall (tree_funcall&) = 0;
+
+  virtual void
   visit_parameter_list (tree_parameter_list&) = 0;
 
   virtual void