GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-pr-code.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pt_pr_code_h)
24 #define octave_pt_pr_code_h 1
25 
26 #include "octave-config.h"
27 
28 #include <stack>
29 #include <string>
30 
31 #include "pt-walk.h"
32 
33 namespace octave
34 {
35  class comment_elt;
36  class comment_list;
37  class tree_decl_command;
38  class tree_expression;
39 
40  // How to print the code that the parse trees represent.
41 
43  {
44  public:
45 
46  tree_print_code (std::ostream& os_arg,
47  const std::string& pfx = "",
48  bool pr_orig_txt = true)
49  : m_os (os_arg), m_prefix (pfx), m_nesting (),
50  m_print_original_text (pr_orig_txt),
53  {
54  // For "none".
55  m_nesting.push ('n');
56  }
57 
58  // No copying!
59 
60  tree_print_code (const tree_print_code&) = delete;
61 
63 
64  ~tree_print_code (void) = default;
65 
67 
69 
71 
73 
75 
77 
79 
81 
83 
85 
87 
89 
91 
93 
95 
97 
99 
101 
103 
105 
107 
108  void visit_matrix (tree_matrix&);
109 
110  void visit_cell (tree_cell&);
111 
113 
115 
117 
119 
120  void visit_funcall (tree_funcall&);
121 
123 
125 
127 
129 
131 
133 
135 
137 
139 
141 
143 
145 
147 
149 
151 
153 
154  private:
155 
156  std::ostream& m_os;
157 
159 
160  std::stack<char> m_nesting;
161 
163 
164  // Current indentation.
166 
167  // TRUE means we are at the beginning of a line.
169 
170  // Nonzero means we are not printing newlines and indenting.
172 
174 
176 
178 
179  void newline (const char *alt_txt = ", ");
180 
181  void indent (void);
182 
183  void reset (void);
184 
185  void print_parens (const tree_expression& expr, const char *txt);
186 
188 
190 
192 
193  // Must create with an output stream!
194 
195  tree_print_code (void);
196  };
197 }
198 
199 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
200 
201 OCTAVE_DEPRECATED (4.4, "use 'octave::tree_print_code' instead")
202 typedef octave::tree_print_code tree_print_code;
203 
204 #endif
205 
206 #endif
void reset_indent_level(void)
Definition: pt-pr-code.h:173
void visit_return_list(tree_return_list &)
Definition: pt-pr-code.cc:818
void visit_break_command(tree_break_command &)
Definition: pt-pr-code.cc:102
void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-pr-code.cc:982
~tree_print_code(void)=default
void visit_switch_command(tree_switch_command &)
Definition: pt-pr-code.cc:948
void visit_return_command(tree_return_command &)
Definition: pt-pr-code.cc:810
void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-pr-code.cc:837
void visit_function_def(tree_function_def &)
Definition: pt-pr-code.cc:427
void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-pr-code.cc:733
void visit_octave_user_function_trailer(octave_user_function &)
Definition: pt-pr-code.cc:419
void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-pr-code.cc:776
void print_fcn_handle_body(tree_expression *)
Definition: pt-pr-code.cc:1155
void visit_constant(tree_constant &)
Definition: pt-pr-code.cc:721
void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-pr-code.cc:201
std::stack< char > m_nesting
Definition: pt-pr-code.h:160
void visit_if_command_list(tree_if_command_list &)
Definition: pt-pr-code.cc:496
void visit_do_until_command(tree_do_until_command &)
Definition: pt-pr-code.cc:1119
void visit_switch_case(tree_switch_case &)
Definition: pt-pr-code.cc:901
void print_indented_comment(comment_list *comment_list)
Definition: pt-pr-code.cc:1300
tree_print_code(std::ostream &os_arg, const std::string &pfx="", bool pr_orig_txt=true)
Definition: pt-pr-code.h:46
void visit_statement_list(tree_statement_list &)
Definition: pt-pr-code.cc:891
void visit_parameter_list(tree_parameter_list &)
Definition: pt-pr-code.cc:757
void visit_octave_user_function(octave_user_function &)
Definition: pt-pr-code.cc:308
void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-pr-code.cc:254
void visit_binary_expression(tree_binary_expression &)
Definition: pt-pr-code.cc:80
void visit_octave_user_script(octave_user_script &)
Definition: pt-pr-code.cc:297
void visit_if_command(tree_if_command &)
Definition: pt-pr-code.cc:475
void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-pr-code.cc:1037
void visit_while_command(tree_while_command &)
Definition: pt-pr-code.cc:1085
tree_print_code & operator=(const tree_print_code &)=delete
void increment_indent_level(void)
Definition: pt-pr-code.h:175
void visit_continue_command(tree_continue_command &)
Definition: pt-pr-code.cc:143
std::ostream & m_os
Definition: pt-pr-code.h:156
void visit_decl_command(tree_decl_command &)
Definition: pt-pr-code.cc:151
void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-pr-code.cc:793
void print_comment_list(comment_list *comment_list)
Definition: pt-pr-code.cc:1281
void visit_decl_elt(tree_decl_elt &)
Definition: pt-pr-code.cc:183
void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-pr-code.cc:934
void decrement_indent_level(void)
Definition: pt-pr-code.h:177
void visit_octave_user_function_header(octave_user_function &)
Definition: pt-pr-code.cc:329
void newline(const char *alt_txt=", ")
Definition: pt-pr-code.cc:1185
void visit_if_clause(tree_if_clause &)
Definition: pt-pr-code.cc:453
void visit_cell(tree_cell &)
Definition: pt-pr-code.cc:641
void print_comment_elt(const comment_elt &comment_elt)
Definition: pt-pr-code.cc:1221
void visit_colon_expression(tree_colon_expression &)
Definition: pt-pr-code.cc:110
void visit_argument_list(tree_argument_list &)
Definition: pt-pr-code.cc:61
void visit_identifier(tree_identifier &)
Definition: pt-pr-code.cc:440
void visit_matrix(tree_matrix &)
Definition: pt-pr-code.cc:610
void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-pr-code.cc:164
void visit_statement(tree_statement &)
Definition: pt-pr-code.cc:859
void visit_funcall(tree_funcall &)
Definition: pt-pr-code.cc:745
void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-pr-code.cc:672
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
void visit_index_expression(tree_index_expression &)
Definition: pt-pr-code.cc:528
void visit_no_op_command(tree_no_op_command &)
Definition: pt-pr-code.cc:710
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-pr-code.cc:40
void print_parens(const tree_expression &expr, const char *txt)
Definition: pt-pr-code.cc:1212