GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-check.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 "input.h"
32#include "ov-usr-fcn.h"
33#include "pt-all.h"
34
36
37void
39{
40 auto p = lst.begin ();
41
42 while (p != lst.end ())
43 {
44 tree_expression *elt = *p++;
45
46 if (elt)
47 {
48 if (m_do_lvalue_check && ! elt->lvalue_ok ())
49 errmsg ("invalid lvalue in multiple assignment", elt->line ());
50 }
51 }
52}
53
54void
56{
57 tree_expression *lhs = cmd.left_hand_side ();
58
59 if (lhs)
60 {
61 if (! lhs->lvalue_ok ())
62 errmsg ("invalid lvalue in for command", cmd.line ());
63 }
64
65 tree_expression *expr = cmd.control_expr ();
66
67 if (expr)
68 expr->accept (*this);
69
70 tree_expression *maxproc = cmd.maxproc_expr ();
71
72 if (maxproc)
73 maxproc->accept (*this);
74
75 tree_statement_list *list = cmd.body ();
76
77 if (list)
78 list->accept (*this);
79}
80
81void
83{
85
86 if (lhs)
87 {
88 int len = lhs->size ();
89
90 if (len == 0 || len > 2)
91 errmsg ("invalid number of output arguments in for command",
92 cmd.line ());
93
94 m_do_lvalue_check = true;
95
96 lhs->accept (*this);
97
98 m_do_lvalue_check = false;
99 }
100
101 tree_expression *expr = cmd.control_expr ();
102
103 if (expr)
104 expr->accept (*this);
105
106 tree_statement_list *list = cmd.body ();
107
108 if (list)
109 list->accept (*this);
110}
111
112void
114{
115 tree_argument_list *lhs = expr.left_hand_side ();
116
117 if (lhs)
118 {
119 m_do_lvalue_check = true;
120
121 lhs->accept (*this);
122
123 m_do_lvalue_check = false;
124 }
125
126 tree_expression *rhs = expr.right_hand_side ();
127
128 if (rhs)
129 rhs->accept (*this);
130}
131
132void
134{
135 tree_expression *lhs = expr.left_hand_side ();
136
137 if (lhs)
138 {
139 if (! lhs->lvalue_ok ())
140 errmsg ("invalid lvalue in assignment", expr.line ());
141 }
142
143 tree_expression *rhs = expr.right_hand_side ();
144
145 if (rhs)
146 rhs->accept (*this);
147}
148
149void
151{
152 tree_statement_list *try_code = cmd.body ();
153
154 tree_identifier *expr_id = cmd.identifier ();
155
156 if (expr_id)
157 {
158 if (! expr_id->lvalue_ok ())
159 errmsg ("invalid lvalue used for identifier in try-catch command",
160 cmd.line ());
161 }
162
163 if (try_code)
164 try_code->accept (*this);
165
166 tree_statement_list *catch_code = cmd.cleanup ();
167
168 if (catch_code)
169 catch_code->accept (*this);
170}
171
172void
173tree_checker::errmsg (const std::string& msg, int line)
174{
175 if (m_file_name.empty ())
176 error ("%s", msg.c_str ());
177 else
178 error ("%s: %d: %s", m_file_name.c_str (), line, msg.c_str ());
179}
180
181OCTAVE_END_NAMESPACE(octave)
void accept(tree_walker &tw)
void visit_complex_for_command(tree_complex_for_command &)
Definition pt-check.cc:82
void visit_simple_for_command(tree_simple_for_command &)
Definition pt-check.cc:55
void visit_simple_assignment(tree_simple_assignment &)
Definition pt-check.cc:133
void visit_multi_assignment(tree_multi_assignment &)
Definition pt-check.cc:113
void visit_argument_list(tree_argument_list &)
Definition pt-check.cc:38
void visit_try_catch_command(tree_try_catch_command &)
Definition pt-check.cc:150
tree_argument_list * left_hand_side()
Definition pt-loop.h:204
tree_statement_list * body()
Definition pt-loop.h:208
tree_expression * control_expr()
Definition pt-loop.h:206
virtual bool lvalue_ok() const
Definition pt-exp.h:84
bool lvalue_ok() const
Definition pt-id.h:85
tree_expression * right_hand_side()
Definition pt-assign.h:143
tree_argument_list * left_hand_side()
Definition pt-assign.h:141
tree_expression * right_hand_side()
Definition pt-assign.h:75
tree_expression * left_hand_side()
Definition pt-assign.h:73
tree_expression * maxproc_expr()
Definition pt-loop.h:148
tree_expression * left_hand_side()
Definition pt-loop.h:144
tree_expression * control_expr()
Definition pt-loop.h:146
tree_statement_list * body()
Definition pt-loop.h:150
void accept(tree_walker &tw)
Definition pt-stmt.h:213
tree_identifier * identifier()
Definition pt-except.h:57
tree_statement_list * cleanup()
Definition pt-except.h:61
tree_statement_list * body()
Definition pt-except.h:59
virtual int line() const
Definition pt.cc:45
virtual void accept(tree_walker &tw)=0
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
F77_RET_T len
Definition xerbla.cc:61