annotate libinterp/parse-tree/pt-check.h @ 16203:127cccb037bf

move more global parser and lexer variables to classes * pt-check.h, pt-check.cc (tree_checker::file_name): New data member. (tree_checker::gripe): Use it instead of curr_fcn_file_name. * input.h, input.cc, octave.cc (input_from_command_line_file): Delete global variable and all uses. * parse.h, oct-parse.in.yy (input_from_startup_file): Delete global variable and all uses. * input.h, input.cc, lex.h, lex.ll (curr_fcn_file_name, curr_fcn_file_full_name): Declare as members of lexical_feedback class. Rename to fcn_file_name and fcn_file_full_name. Change all uses. * oct-parse.in.yy (parse_fcn_file): New arg, file. Set curr_lexer->fcn_file_name and curr_lexer->fcn_file_full_name here. (load_fcn_from_file): Pass short file name to parse_fcn_file. * octave.cc (execute_command_line_file): Not here. * lex.h, lex.ll (lexical_feedback::force_script): New data member. * oct-parse.in.yy (parse_fcn_file): Set it here. * lex.h, lex.ll (lexical_feedback::input_from_terminal, lexical_feedback::input_from_file): New functions. * lex.ll (octave_lexer::handle_keyword): Set reading_fcn_file, reading_classdef_file, and reading_script_file. * lex.h, lex.ll (lexical_feedback::token_count): New variable. (COUNT_TOK_AND_RETURN): Increment it here. Don't count '\n' as a token. * lex.h, lex.ll (lexical_feedback::help_text): New variable. * parse.h, parse.in.yy (help_buf): Delete global variable and all uses. (octave_parser::frob_function, octave_parser::make_script): Use help_text. * lex.ll (octave_lexer::process_comment): Cache doc string directly in help_text variable. (looks_like_copyright): Move here from parse.in.yy. * lex.h, lex.ll (octave_lexer::prep_for_file): New function. (octave_lexer::prep_for_function_file, octave_lexer::prep_for_script_file): Delete. * parse.in.yy (INPUT_FILE_BEGIN): New start state. Delete SCRIPT_FILE_BEGIN and FCN_FILE_BEGIN. Tentatively set curr_lexer->reading_script_file to true. (parse_fcn_file): Call curr_lexer->prep_for_file. Don't call gobble_leading_whitespace. Don't attempt to determine function script, or classdef file status here. * parse.in.yy (INPUT_FILE): New token. (SCRIPT_FILE, FUNCTION_FILE): Delete. * lex.ll (octave_lexer::display_token): Update. * parse.in.yy (nl, opt_nl): New non-terminals. (function_file): Delete rule. (file): Rename from script_file. Allow opt_nl before opt_list. Don't make script if reading fcn file. * parse.in.yy (text_getc, class stdio_stream_reader, skip_white_space, looking_at_classdef_keyword, gobble_leading_white_space, looking_at_function_keyword): Delete. (get_help_from_file): Parse file to get help instead of calling gobble_leading_white_space
author John W. Eaton <jwe@octave.org>
date Wed, 06 Mar 2013 14:36:19 -0500
parents 2fc554ffbc28
children a8f9eb92fa6e d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
1 /*
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
3 Copyright (C) 1996-2012 John W. Eaton
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
4
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
6
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
10 option) any later version.
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
11
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
15 for more details.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
16
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
19 <http://www.gnu.org/licenses/>.
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
20
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
21 */
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
22
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
23 #if !defined (octave_tree_checker_h)
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
24 #define octave_tree_checker_h 1
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
25
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
26 #include "pt-walk.h"
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
27
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
28 class tree_decl_command;
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
29
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
30 // How to check the semantics of the code that the parse trees represent.
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
31
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
32 class
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
33 tree_checker : public tree_walker
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
34 {
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
35 public:
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
36
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
37 tree_checker (void)
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
38 : do_lvalue_check (false), file_name () { }
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
39
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
40 ~tree_checker (void) { }
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
41
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
42 void visit_argument_list (tree_argument_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
43
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
44 void visit_binary_expression (tree_binary_expression&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
45
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
46 void visit_break_command (tree_break_command&);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
47
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
48 void visit_colon_expression (tree_colon_expression&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
49
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
50 void visit_continue_command(tree_continue_command&);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
51
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
52 void visit_global_command (tree_global_command&);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
53
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
54 void visit_persistent_command (tree_persistent_command&);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
55
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
56 void visit_decl_elt (tree_decl_elt&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
57
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
58 void visit_decl_init_list (tree_decl_init_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
59
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
60 void visit_simple_for_command (tree_simple_for_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
61
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
62 void visit_complex_for_command (tree_complex_for_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
63
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
64 void visit_octave_user_script (octave_user_script&);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
65
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
66 void visit_octave_user_function (octave_user_function&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
67
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
68 void visit_function_def (tree_function_def&);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
69
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
70 void visit_identifier (tree_identifier&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
71
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
72 void visit_if_clause (tree_if_clause&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
73
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
74 void visit_if_command (tree_if_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
75
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
76 void visit_if_command_list (tree_if_command_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
77
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
78 void visit_index_expression (tree_index_expression&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
79
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
80 void visit_matrix (tree_matrix&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
81
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4207
diff changeset
82 void visit_cell (tree_cell&);
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4207
diff changeset
83
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
84 void visit_multi_assignment (tree_multi_assignment&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
85
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
86 void visit_no_op_command (tree_no_op_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
87
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5307
diff changeset
88 void visit_anon_fcn_handle (tree_anon_fcn_handle&);
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5307
diff changeset
89
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
90 void visit_constant (tree_constant&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
91
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4229
diff changeset
92 void visit_fcn_handle (tree_fcn_handle&);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4229
diff changeset
93
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
94 void visit_parameter_list (tree_parameter_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
95
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
96 void visit_postfix_expression (tree_postfix_expression&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
97
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
98 void visit_prefix_expression (tree_prefix_expression&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
99
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
100 void visit_return_command (tree_return_command&);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
101
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
102 void visit_return_list (tree_return_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
103
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
104 void visit_simple_assignment (tree_simple_assignment&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
105
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
106 void visit_statement (tree_statement&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
107
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
108 void visit_statement_list (tree_statement_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
109
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
110 void visit_switch_case (tree_switch_case&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
111
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
112 void visit_switch_case_list (tree_switch_case_list&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
113
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
114 void visit_switch_command (tree_switch_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
115
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
116 void visit_try_catch_command (tree_try_catch_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
117
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
118 void visit_unwind_protect_command (tree_unwind_protect_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
119
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
120 void visit_while_command (tree_while_command&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
121
4229
40153a2affd6 [project @ 2002-12-18 20:37:32 by jwe]
jwe
parents: 4219
diff changeset
122 void visit_do_until_command (tree_do_until_command&);
40153a2affd6 [project @ 2002-12-18 20:37:32 by jwe]
jwe
parents: 4219
diff changeset
123
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
124 private:
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
125
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
126 bool do_lvalue_check;
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
127
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
128 std::string file_name;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
129
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
130 void do_decl_command (tree_decl_command&);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
131
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3011
diff changeset
132 void gripe (const std::string& msg, int line);
3011
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
133
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
134 // No copying!
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
135
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
136 tree_checker (const tree_checker&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
137
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
138 tree_checker& operator = (const tree_checker&);
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
139 };
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
140
2ad9af85b89b [project @ 1997-06-01 19:34:20 by jwe]
jwe
parents:
diff changeset
141 #endif