GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-id.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "error.h"
31#include "interpreter-private.h"
32#include "oct-lvalue.h"
33#include "pt-const.h"
34#include "pt-id.h"
35#include "symscope.h"
36#include "utils.h"
37#include "variables.h"
38
40
41// Symbols from the symbol table.
42
43void
45{
46 int l = line ();
47 int c = column ();
48
49 std::string msg = "'" + name () + "' undefined";
50
51 if (l > 0)
52 {
53 msg += " near line " + std::to_string (l);
54
55 if (c > 0)
56 msg += ", column " + std::to_string (c);
57 }
58
59 std::string missing_msg = maybe_missing_function_hook (name ());
60
61 if (! missing_msg.empty ())
62 msg += "\n\n" + missing_msg;
63
64 error_with_id ("Octave:undefined-function", "%s", msg.c_str ());
65}
66
75
78{
79 // The new tree_identifier object contains a symbol_record
80 // entry from the duplicated scope.
81
82 symbol_record new_sym = scope.find_symbol (name ());
83
84 tree_identifier *new_id = new tree_identifier (new_sym, m_token);
85
86 new_id->copy_base (*this);
87
88 return new_id;
89}
90
93{
94 octave_value_list retval;
95
96 octave_value val = tw.varval (m_sym);
97
98 if (val.is_undefined ())
99 {
100 interpreter& interp = tw.get_interpreter ();
101
102 symbol_table& symtab = interp.get_symbol_table ();
103
104 val = symtab.find_function (m_sym.name ());
105 }
106
107 if (val.is_defined ())
108 {
109 // GAGME -- this would be cleaner if we required
110 // parens to indicate function calls.
111 //
112 // If this identifier refers to a function, we need to know
113 // whether it is indexed so that we can do the same thing
114 // for 'f' and 'f()'. If the index is present and the function
115 // object declares it can handle it, return the function object
116 // and let tree_index_expression::rvalue handle indexing.
117 // Otherwise, arrange to call the function here, so that we don't
118 // return the function definition as a value.
119
120 octave_function *fcn = nullptr;
121
122 if (val.is_function ())
123 fcn = val.function_value (true);
124
125 if (fcn && ! (is_postfix_indexed ()
127 {
128 retval = fcn->call (tw, nargout);
129 }
130 else
131 {
132 if (print_result () && nargout == 0
134 {
135 octave_value_list args = ovl (val);
137
138 interpreter& interp = tw.get_interpreter ();
139
140 interp.feval ("display", args);
141 }
142
143 retval = ovl (val);
144 }
145 }
146 else if (m_sym.is_added_static ())
148 else
150
151 return retval;
152}
153
156{
158
159 retval.mark_black_hole ();
160
161 return retval;
162}
163
164OCTAVE_END_NAMESPACE(octave)
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
symbol_table & get_symbol_table()
virtual bool accepts_postfix_index(char type) const
Definition ov-fcn.h:227
virtual octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition ov-fcn.cc:67
void mark_black_hole()
Definition oct-lvalue.h:53
void stash_name_tags(const string_vector &nm)
Definition ovl.h:163
bool is_undefined() const
Definition ov.h:595
octave_function * function_value(bool silent=false) const
bool is_defined() const
Definition ov.h:592
bool is_function() const
Definition ov.h:777
std::string name() const
Definition symrec.h:218
bool is_added_static() const
Definition symrec.h:224
symbol_record find_symbol(const std::string &name)
Definition symscope.h:489
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope::invalid())
Definition symtab.cc:254
octave_lvalue lvalue(tree_evaluator &tw)
Definition pt-id.cc:155
interpreter & get_interpreter()
Definition pt-eval.h:422
std::shared_ptr< stack_frame > get_current_stack_frame() const
Definition pt-eval.h:445
octave_value varval(const symbol_record &sym) const
Definition pt-eval.cc:1957
bool statement_printing_enabled()
Definition pt-eval.cc:1377
char postfix_index() const
Definition pt-exp.h:102
bool is_postfix_indexed() const
Definition pt-exp.h:99
bool print_result() const
Definition pt-exp.h:107
virtual void copy_base(const tree_expression &e)
Definition pt-exp.h:137
token m_token
Definition pt-id.h:137
std::string name() const
Definition pt-id.h:71
octave_lvalue lvalue(tree_evaluator &tw)
Definition pt-id.cc:68
octave_value_list evaluate_n(tree_evaluator &tw, int nargout=1)
Definition pt-id.cc:92
tree_identifier * dup(symbol_scope &scope) const
Definition pt-id.cc:77
void static_workspace_error()
Definition pt-id.h:91
symbol_record m_sym
Definition pt-id.h:130
void eval_undefined_error()
Definition pt-id.cc:44
virtual int line() const
Definition pt.cc:45
virtual int column() const
Definition pt.cc:51
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error_with_id(const char *id, const char *fmt,...)
Definition error.cc:1048
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition ovl.h:217
std::string maybe_missing_function_hook(const std::string &name)