annotate libinterp/parse-tree/anon-fcn-validator.cc @ 33634:4a70f390c85e default tip @

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 28 May 2024 15:25:54 +0200
parents 2f24c41a14cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32589
diff changeset
3 // Copyright (C) 2019-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <string>
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "anon-fcn-validator.h"
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "ov.h"
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "pt-all.h"
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
36 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
37
33316
2f24c41a14cd use filepos instead of line and column in anonymous function validator
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
38 anon_fcn_validator::anon_fcn_validator (tree_parameter_list *, tree_expression *expr)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
39 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
40 expr->accept (*this);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
41 }
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
43 void
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
44 anon_fcn_validator::visit_postfix_expression (tree_postfix_expression& expr)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
45 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
46 octave_value::unary_op op = expr.op_type ();
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
48 if (op == octave_value::op_incr || op == octave_value::op_decr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
49 error (expr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
50 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
51 tree_walker::visit_postfix_expression (expr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
52 }
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
54 void
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
55 anon_fcn_validator::visit_prefix_expression (tree_prefix_expression& expr)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
56 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
57 octave_value::unary_op op = expr.op_type ();
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
59 if (op == octave_value::op_incr || op == octave_value::op_decr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
60 error (expr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
61 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
62 tree_walker::visit_prefix_expression (expr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
63 }
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
65 void
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
66 anon_fcn_validator::visit_multi_assignment (tree_multi_assignment& expr)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
67 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
68 error (expr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
69 }
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
71 void
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
72 anon_fcn_validator::visit_simple_assignment (tree_simple_assignment& expr)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
73 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
74 error (expr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
75 }
27728
5e92bff668d6 disallow lvalue references in anonymous functions (bug #57255)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
77 void
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 31706
diff changeset
78 anon_fcn_validator::error (tree_expression& expr)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
79 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
80 m_ok = false;
33316
2f24c41a14cd use filepos instead of line and column in anonymous function validator
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
81 m_beg_pos = expr.beg_pos ();
2f24c41a14cd use filepos instead of line and column in anonymous function validator
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
82 m_end_pos = expr.end_pos ();
2f24c41a14cd use filepos instead of line and column in anonymous function validator
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
83 m_message = "invalid use of operator " + expr.oper () + " in anonymous function";
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
84 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
85
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30564
diff changeset
86 OCTAVE_END_NAMESPACE(octave)