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-id.cc
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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "error.h"
28 #include "oct-obj.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  if (error_state)
50  return;
51 
52  if (l == -1 && c == -1)
53  ::error_with_id ("Octave:undefined-function",
54  "'%s' undefined", name ().c_str ());
55  else
56  ::error_with_id ("Octave:undefined-function",
57  "'%s' undefined near line %d column %d",
58  name ().c_str (), l, c);
59 }
60 
63  const std::list<octave_lvalue> *lvalue_list)
64 {
65  octave_value_list retval;
66 
67  if (error_state)
68  return retval;
69 
70  octave_value val = sym->find ();
71 
72  if (val.is_defined ())
73  {
74  // GAGME -- this would be cleaner if we required
75  // parens to indicate function calls.
76  //
77  // If this identifier refers to a function, we need to know
78  // whether it is indexed so that we can do the same thing
79  // for 'f' and 'f()'. If the index is present and the function
80  // object declares it can handle it, return the function object
81  // and let tree_index_expression::rvalue handle indexing.
82  // Otherwise, arrange to call the function here, so that we don't
83  // return the function definition as a value.
84 
85  octave_function *fcn = 0;
86 
87  if (val.is_function ())
88  fcn = val.function_value (true);
89 
90  if (fcn && ! (is_postfix_indexed ()
92  {
93  octave_value_list tmp_args;
94 
95  retval = (lvalue_list
96  ? val.do_multi_index_op (nargout, tmp_args, lvalue_list)
97  : val.do_multi_index_op (nargout, tmp_args));
98  }
99  else
100  {
101  if (print_result () && nargout == 0
104 
105  retval = val;
106  }
107  }
108  else if (sym->is_added_static ())
110  else
112 
113  return retval;
114 }
115 
118 {
119  octave_value retval;
120 
121  octave_value_list tmp = rvalue (nargout);
122 
123  if (! tmp.empty ())
124  retval = tmp(0);
125 
126  return retval;
127 }
128 
131 {
132  if (sym->is_added_static ())
134 
135  return octave_lvalue (sym);
136 }
137 
141 {
142  // The new tree_identifier object contains a symbol_record
143  // entry from the duplicated scope.
144 
145  // FIXME: is this the best way?
147  = symbol_table::find_symbol (name (), sc);
148 
149  tree_identifier *new_id
150  = new tree_identifier (new_sym, line (), column ());
151 
152  new_id->copy_base (*this);
153 
154  return new_id;
155 }
156 
157 void
159 {
160  tw.visit_identifier (*this);
161 }
octave_lvalue lvalue(void)
Definition: pt-id.cc:130
static bool statement_printing_enabled(void)
Definition: pt-eval.cc:138
symbol_table::symbol_reference sym
Definition: pt-id.h:137
virtual bool is_postfix_index_handled(char type) const
Definition: ov-fcn.h:179
bool is_function(void) const
Definition: ov.h:695
bool is_defined(void) const
Definition: ov.h:520
octave_value find(const octave_value_list &args=octave_value_list()) const
Definition: symtab.cc:125
virtual void copy_base(const tree_expression &e)
Definition: pt-exp.h:129
bool is_added_static(void) const
Definition: symtab.h:614
tree_identifier * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-id.cc:139
bool is_postfix_indexed(void) const
Definition: pt-exp.h:90
static symbol_record find_symbol(const std::string &name, scope_id scope=xcurrent_scope)
Definition: symtab.h:1281
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov.cc:1382
bool print_result(void) const
Definition: pt-exp.h:97
void accept(tree_walker &tw)
Definition: pt-id.cc:158
octave_value_list rvalue(int nargout)
Definition: pt-id.h:107
void static_workspace_error(void)
Definition: pt-id.h:119
void error_with_id(const char *id, const char *fmt,...)
Definition: error.cc:506
std::string name(void) const
Definition: pt-id.h:65
int error_state
Definition: error.cc:101
tree_identifier(int l=-1, int c=-1)
Definition: pt-id.h:49
void maybe_missing_function_hook(const std::string &name)
Definition: variables.cc:2683
virtual int line(void) const
Definition: pt.h:45
void eval_undefined_error(void)
Definition: pt-id.cc:43
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1597
octave_value rvalue1(int nargout=1)
Definition: pt-id.cc:117
bool empty(void) const
Definition: oct-obj.h:91
virtual void visit_identifier(tree_identifier &)=0
#define octave_stdout
Definition: pager.h:144
void print_with_name(std::ostream &os, const std::string &name) const
Definition: ov.h:1040
char postfix_index(void) const
Definition: pt-exp.h:92
virtual int column(void) const
Definition: pt.h:47