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-colon.cc
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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "error.h"
28 #include "ovl.h"
29 #include "pager.h"
30 #include "ov.h"
31 #include "pt-bp.h"
32 #include "pt-colon.h"
33 #include "pt-walk.h"
34 
35 // Colon expressions.
36 
39 {
41 
42  if (! op_base)
43  error ("invalid colon expression");
44 
45  if (op_limit)
46  {
47  if (op_increment)
48  error ("invalid colon expression");
49 
50  // Stupid syntax:
51  //
52  // base : limit
53  // base : increment : limit
54 
56  op_limit = t;
57  }
58  else
59  op_limit = t;
60 
61  retval = this;
62 
63  return retval;
64 }
65 
68 {
69  if (nargout > 1)
70  error ("invalid number of output arguments for colon expression");
71 
72  return rvalue1 (nargout);
73 }
74 
77 {
79 
80  if (! op_base || ! op_limit)
81  return retval;
82 
83  octave_value ov_base = op_base->rvalue1 ();
84 
85  octave_value ov_limit = op_limit->rvalue1 ();
86 
87  if (ov_base.is_object () || ov_limit.is_object ())
88  {
89  octave_value_list tmp1;
90 
91  if (op_increment)
92  {
93  octave_value ov_increment = op_increment->rvalue1 ();
94 
95  tmp1(2) = ov_limit;
96  tmp1(1) = ov_increment;
97  tmp1(0) = ov_base;
98  }
99  else
100  {
101  tmp1(1) = ov_limit;
102  tmp1(0) = ov_base;
103  }
104 
105  octave_value fcn = symbol_table::find_function ("colon", tmp1);
106 
107  if (! fcn.is_defined ())
108  error ("can not find overloaded colon function");
109 
110  octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1);
111 
112  retval = tmp2 (0);
113  }
114  else
115  {
116  octave_value ov_increment = 1.0;
117 
118  if (op_increment)
119  ov_increment = op_increment->rvalue1 ();
120 
121  retval = do_colon_op (ov_base, ov_increment, ov_limit,
122  is_for_cmd_expr ());
123  }
124 
125  return retval;
126 }
127 
128 void
130 {
131  error ("%s", s.c_str ());
132 }
133 
134 int
136 {
137  return (op_base ? op_base->line ()
139  : (op_limit ? op_limit->line ()
140  : -1)));
141 }
142 
143 int
145 {
146  return (op_base ? op_base->column ()
148  : (op_limit ? op_limit->column ()
149  : -1)));
150 }
151 
155 {
156  tree_colon_expression *new_ce = new
157  tree_colon_expression (op_base ? op_base->dup (scope, context) : 0,
158  op_limit ? op_limit->dup (scope, context) : 0,
159  op_increment ? op_increment->dup (scope, context)
160  : 0,
161  line (), column ());
162 
163  new_ce->copy_base (*new_ce);
164 
165  return new_ce;
166 }
167 
168 void
170 {
171  tw.visit_colon_expression (*this);
172 }
bool is_object(void) const
Definition: ov.h:593
octave_value rvalue1(int nargout=1)
Definition: pt-colon.cc:76
bool is_defined(void) const
Definition: ov.h:536
virtual tree_expression * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
void error(const char *fmt,...)
Definition: error.cc:570
int line(void) const
Definition: pt-colon.cc:135
void eval_error(const std::string &s) const
Definition: pt-colon.cc:129
tree_expression * op_increment
Definition: pt-colon.h:106
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:131
int column(void) const
Definition: pt-colon.cc:144
s
Definition: file-io.cc:2682
static octave_value find_function(const std::string &name, const octave_value_list &args=octave_value_list(), bool local_funcs=true)
Definition: symtab.cc:1276
tree_colon_expression * append(tree_expression *t)
Definition: pt-colon.cc:38
octave_function * fcn
Definition: ov-class.cc:1743
bool is_for_cmd_expr(void) const
Definition: pt-exp.h:111
void accept(tree_walker &tw)
Definition: pt-colon.cc:169
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov.cc:1527
virtual void visit_colon_expression(tree_colon_expression &)=0
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
tree_colon_expression(int l=-1, int c=-1)
Definition: pt-colon.h:46
octave_value retval
Definition: data.cc:6294
virtual int line(void) const
Definition: pt.h:49
tree_expression * op_limit
Definition: pt-colon.h:105
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:54
octave_value_list rvalue(int nargout)
Definition: pt-colon.cc:67
virtual int column(void) const
Definition: pt.h:51
octave_value do_colon_op(const octave_value &base, const octave_value &increment, const octave_value &limit, bool is_for_cmd_expr)
Definition: ov.cc:2524
tree_expression * op_base
Definition: pt-colon.h:104
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
tree_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-colon.cc:153