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-id.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 "oct-lvalue.h"
30 #include "pager.h"
31 #include "pt-bp.h"
32 #include "pt-const.h"
33 #include "pt-eval.h"
34 #include "pt-id.h"
35 #include "pt-walk.h"
36 #include "symtab.h"
37 #include "utils.h"
38 #include "variables.h"
39 
40 // Symbols from the symbol table.
41 
42 void
44 {
45  int l = line ();
46  int c = column ();
47 
49 
50  if (l == -1 && c == -1)
51  error_with_id ("Octave:undefined-function",
52  "'%s' undefined", name ().c_str ());
53  else
54  error_with_id ("Octave:undefined-function",
55  "'%s' undefined near line %d column %d",
56  name ().c_str (), l, c);
57 }
58 
61  const std::list<octave_lvalue> *lvalue_list)
62 {
64 
65  octave_value val = sym->find ();
66 
67  if (val.is_defined ())
68  {
69  // GAGME -- this would be cleaner if we required
70  // parens to indicate function calls.
71  //
72  // If this identifier refers to a function, we need to know
73  // whether it is indexed so that we can do the same thing
74  // for 'f' and 'f()'. If the index is present and the function
75  // object declares it can handle it, return the function object
76  // and let tree_index_expression::rvalue handle indexing.
77  // Otherwise, arrange to call the function here, so that we don't
78  // return the function definition as a value.
79 
80  octave_function *fcn = 0;
81 
82  if (val.is_function ())
83  fcn = val.function_value (true);
84 
85  if (fcn && ! (is_postfix_indexed ()
87  {
88  octave_value_list tmp_args;
89 
90  retval = (lvalue_list
91  ? val.do_multi_index_op (nargout, tmp_args, lvalue_list)
92  : val.do_multi_index_op (nargout, tmp_args));
93  }
94  else
95  {
96  if (print_result () && nargout == 0
99 
100  retval = val;
101  }
102  }
103  else if (sym->is_added_static ())
105  else
107 
108  return retval;
109 }
110 
113 {
115 
116  octave_value_list tmp = rvalue (nargout);
117 
118  if (! tmp.empty ())
119  retval = tmp(0);
120 
121  return retval;
122 }
123 
126 {
127  if (sym->is_added_static ())
129 
130  return octave_lvalue (sym);
131 }
132 
136 {
137  // The new tree_identifier object contains a symbol_record
138  // entry from the duplicated scope.
139 
140  // FIXME: is this the best way?
142  = symbol_table::find_symbol (name (), sc);
143 
144  tree_identifier *new_id
145  = new tree_identifier (new_sym, line (), column ());
146 
147  new_id->copy_base (*this);
148 
149  return new_id;
150 }
151 
152 void
154 {
155  tw.visit_identifier (*this);
156 }
octave_lvalue lvalue(void)
Definition: pt-id.cc:125
For example cd octave end example noindent changes the current working directory to an error message is printed and the working directory is not changed sc
Definition: dirfns.cc:120
symbol_table::symbol_reference sym
Definition: pt-id.h:139
virtual bool is_postfix_index_handled(char type) const
Definition: ov-fcn.h:181
bool is_function(void) const
Definition: ov.h:711
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
bool is_defined(void) const
Definition: ov.h:536
octave_value find(const octave_value_list &args=octave_value_list()) const
Definition: symtab.cc:128
nd deftypefn *void maybe_missing_function_hook(const std::string &name)
Definition: variables.cc:2268
static bool statement_printing_enabled(void)
Definition: pt-eval.cc:131
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:131
bool is_added_static(void) const
Definition: symtab.h:610
octave_function * fcn
Definition: ov-class.cc:1743
tree_identifier * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-id.cc:134
bool is_postfix_indexed(void) const
Definition: pt-exp.h:92
static symbol_record find_symbol(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1278
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov.cc:1527
bool print_result(void) const
Definition: pt-exp.h:99
void accept(tree_walker &tw)
Definition: pt-id.cc:153
octave_value_list rvalue(int nargout)
Definition: pt-id.h:109
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
void static_workspace_error(void)
Definition: pt-id.h:121
void error_with_id(const char *id, const char *fmt,...)
Definition: error.cc:615
std::string name(void) const
Definition: pt-id.h:67
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
tree_identifier(int l=-1, int c=-1)
Definition: pt-id.h:51
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 int line(void) const
Definition: pt.h:49
void eval_undefined_error(void)
Definition: pt-id.cc:43
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1705
octave_value rvalue1(int nargout=1)
Definition: pt-id.cc:112
bool empty(void) const
Definition: ovl.h:98
virtual void visit_identifier(tree_identifier &)=0
#define octave_stdout
Definition: pager.h:146
void print_with_name(std::ostream &os, const std::string &name) const
Definition: ov.h:1225
char postfix_index(void) const
Definition: pt-exp.h:94
virtual int column(void) const
Definition: pt.h:51