Mercurial > octave
annotate libinterp/parse-tree/pt.h @ 26376:00f796120a6d stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 02 Jan 2019 16:32:43 -0500 |
parents | 8a15f3bace49 |
children | fff643eb3514 |
rev | line source |
---|---|
2987 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26113
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2987 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
10 (at your option) any later version. |
2987 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22737
diff
changeset
|
15 GNU General Public License for more details. |
2987 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2987 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_pt_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 #define octave_pt_h 1 |
2987 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21157
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21157
diff
changeset
|
27 |
2991 | 28 #include <string> |
29 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
30 #include <iosfwd> |
2991 | 31 |
4748 | 32 class octave_function; |
2987 | 33 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
34 namespace octave |
2987 | 35 { |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
36 class tree_evaluator; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
37 class tree_walker; |
2987 | 38 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
39 // Base class for the parse tree. |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
40 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
41 class tree |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
42 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
43 public: |
2987 | 44 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
45 tree (int l = -1, int c = -1) |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
46 : m_line_num (l), m_column_num (c), m_bp_cond (nullptr) |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
47 { } |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
48 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
49 // No copying! |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
50 |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
51 tree (const tree&) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
52 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
53 tree& operator = (const tree&) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
54 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
55 virtual ~tree (void) = default; |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
56 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
57 virtual int line (void) const { return m_line_num; } |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
58 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
59 virtual int column (void) const { return m_column_num; } |
2987 | 60 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
61 void line (int l) { m_line_num = l; } |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7818
diff
changeset
|
62 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
63 void column (int c) { m_column_num = c; } |
2987 | 64 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
65 void set_location (int l, int c) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
66 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
67 m_line_num = l; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
68 m_column_num = c; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
69 } |
2987 | 70 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
71 virtual void set_breakpoint (const std::string& condition) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
72 { |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
73 if (m_bp_cond) |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
74 *m_bp_cond = condition; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
75 else |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
76 m_bp_cond = new std::string (condition); |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
77 } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
78 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
79 virtual void delete_breakpoint (void) |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
80 { |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
81 if (m_bp_cond) |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
82 { |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
83 delete m_bp_cond; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
84 |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
85 m_bp_cond = nullptr; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
86 } |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
87 } |
2991 | 88 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
89 bool meets_bp_condition (tree_evaluator& tw) const; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
90 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
91 bool is_breakpoint (void) const |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
92 { |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
93 return m_bp_cond; |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
94 } |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
95 |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
96 bool is_active_breakpoint (tree_evaluator& tw) const |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
97 { |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
98 return m_bp_cond && meets_bp_condition (tw); |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
99 } |
3772 | 100 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
101 // breakpoint condition, or "0" (i.e., "false") if no breakpoint. |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
102 // To distinguish "0" from a disabled breakpoint, test "is_breakpoint" too. |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
103 const std::string bp_cond (void) const |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
104 { |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
105 return m_bp_cond ? *m_bp_cond : "0"; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
106 } |
2987 | 107 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
108 std::string str_print_code (void); |
2987 | 109 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
110 virtual void accept (tree_walker& tw) = 0; |
2991 | 111 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
112 private: |
2987 | 113 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
114 // The input line and column where we found the text that was |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
115 // eventually converted to this tree node. |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
116 int m_line_num; |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
117 int m_column_num; |
2987 | 118 |
24846
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
119 // NULL if no breakpoint, or a breakpoint condition if there is one. |
7620f1f5290d
use m_ prefix for member variables in parse tree classes
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
120 std::string *m_bp_cond; |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
121 }; |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
122 } |
2987 | 123 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
124 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
125 |
23615
be7b884ac589
use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
126 OCTAVE_DEPRECATED (4.4, "use 'octave::tree' instead") |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
127 typedef octave::tree tree; |
2987 | 128 |
129 #endif | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
130 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23073
diff
changeset
|
131 #endif |