comparison libinterp/parse-tree/lex.h @ 16101:8d19626b38ae

provide copy contructor and operator = for lexical_feedback class. * lex.h, lex.ll (lexical_feedback::lexical_feedback): Provide copy constructor. Correctly initialize looking_at_anon_fcn_args to false. (lexical_feedback::operator=): New function. (lexical_feedback::init): Simplify. (reset_parser): Assign new lexical_feedback object to global lexer_flags instead of calling init on existing object.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Feb 2013 20:06:44 -0500
parents 6b26e18d1dcb
children 679a54d274d9
comparison
equal deleted inserted replaced
16100:6b26e18d1dcb 16101:8d19626b38ae
22 22
23 #if !defined (octave_lex_h) 23 #if !defined (octave_lex_h)
24 #define octave_lex_h 1 24 #define octave_lex_h 1
25 25
26 #include <list> 26 #include <list>
27 #include <set>
27 #include <stack> 28 #include <stack>
28 29
29 // FIXME -- these input buffer things should be members of a 30 // FIXME -- these input buffer things should be members of a
30 // parser input stream class. 31 // parser input stream class.
31 32
61 public: 62 public:
62 63
63 lexical_feedback (void) 64 lexical_feedback (void)
64 : convert_spaces_to_comma (true), do_comma_insert (false), 65 : convert_spaces_to_comma (true), do_comma_insert (false),
65 at_beginning_of_statement (true), 66 at_beginning_of_statement (true),
66 looking_at_anon_fcn_args (true), looking_at_return_list (false), 67 looking_at_anon_fcn_args (false), looking_at_return_list (false),
67 looking_at_parameter_list (false), looking_at_decl_list (false), 68 looking_at_parameter_list (false), looking_at_decl_list (false),
68 looking_at_initializer_expression (false), 69 looking_at_initializer_expression (false),
69 looking_at_matrix_or_assign_lhs (false), 70 looking_at_matrix_or_assign_lhs (false),
70 looking_for_object_index (false), 71 looking_for_object_index (false),
71 looking_at_indirect_ref (false), parsing_class_method (false), 72 looking_at_indirect_ref (false), parsing_class_method (false),
72 maybe_classdef_get_set_method (false), parsing_classdef (false), 73 maybe_classdef_get_set_method (false), parsing_classdef (false),
73 quote_is_transpose (false), bracketflag (0), braceflag (0), 74 quote_is_transpose (false), bracketflag (0), braceflag (0),
74 looping (0), defining_func (0), looking_at_function_handle (0), 75 looping (0), defining_func (0), looking_at_function_handle (0),
75 looking_at_object_index (), parsed_function_name (), 76 looking_at_object_index (), parsed_function_name (),
76 pending_local_variables () 77 pending_local_variables ()
77 { 78 {
78 init (); 79 init ();
79 } 80 }
81
82 lexical_feedback (const lexical_feedback& lf)
83 : convert_spaces_to_comma (lf.convert_spaces_to_comma),
84 do_comma_insert (lf.do_comma_insert),
85 at_beginning_of_statement (lf.at_beginning_of_statement),
86 looking_at_anon_fcn_args (lf.looking_at_anon_fcn_args),
87 looking_at_return_list (lf.looking_at_return_list),
88 looking_at_parameter_list (lf.looking_at_parameter_list),
89 looking_at_decl_list (lf.looking_at_decl_list),
90 looking_at_initializer_expression (lf.looking_at_initializer_expression),
91 looking_at_matrix_or_assign_lhs (lf.looking_at_matrix_or_assign_lhs),
92 looking_for_object_index (lf.looking_for_object_index),
93 looking_at_indirect_ref (lf.looking_at_indirect_ref),
94 parsing_class_method (lf.parsing_class_method),
95 maybe_classdef_get_set_method (lf.maybe_classdef_get_set_method),
96 parsing_classdef (lf.parsing_classdef),
97 quote_is_transpose (lf.quote_is_transpose),
98 bracketflag (lf.bracketflag),
99 braceflag (lf.braceflag),
100 looping (lf.looping),
101 defining_func (lf.defining_func),
102 looking_at_function_handle (lf.looking_at_function_handle),
103 looking_at_object_index (lf.looking_at_object_index),
104 parsed_function_name (lf.parsed_function_name),
105 pending_local_variables (lf.pending_local_variables)
106 { }
107
108 lexical_feedback& operator = (const lexical_feedback& lf)
109 {
110 if (&lf != this)
111 {
112 convert_spaces_to_comma = lf.convert_spaces_to_comma;
113 do_comma_insert = lf.do_comma_insert;
114 at_beginning_of_statement = lf.at_beginning_of_statement;
115 looking_at_anon_fcn_args = lf.looking_at_anon_fcn_args;
116 looking_at_return_list = lf.looking_at_return_list;
117 looking_at_parameter_list = lf.looking_at_parameter_list;
118 looking_at_decl_list = lf.looking_at_decl_list;
119 looking_at_initializer_expression = lf.looking_at_initializer_expression;
120 looking_at_matrix_or_assign_lhs = lf.looking_at_matrix_or_assign_lhs;
121 looking_for_object_index = lf.looking_for_object_index;
122 looking_at_indirect_ref = lf.looking_at_indirect_ref;
123 parsing_class_method = lf.parsing_class_method;
124 maybe_classdef_get_set_method = lf.maybe_classdef_get_set_method;
125 parsing_classdef = lf.parsing_classdef;
126 quote_is_transpose = lf.quote_is_transpose;
127 bracketflag = lf.bracketflag;
128 braceflag = lf.braceflag;
129 looping = lf.looping;
130 defining_func = lf.defining_func;
131 looking_at_function_handle = lf.looking_at_function_handle;
132 looking_at_object_index = lf.looking_at_object_index;
133 parsed_function_name = lf.parsed_function_name;
134 pending_local_variables = lf.pending_local_variables;
135 }
136
137 return *this;
138 }
80 139
81 ~lexical_feedback (void) { } 140 ~lexical_feedback (void) { }
82 141
83 void init (void); 142 void init (void)
143 {
144 // The closest paren, brace, or bracket nesting is not an object
145 // index.
146 looking_at_object_index.push_front (false);
147 }
84 148
85 // TRUE means that we should convert spaces to a comma inside a 149 // TRUE means that we should convert spaces to a comma inside a
86 // matrix definition. 150 // matrix definition.
87 bool convert_spaces_to_comma; 151 bool convert_spaces_to_comma;
88 152
159 // current_function_level > 0 223 // current_function_level > 0
160 std::stack<bool> parsed_function_name; 224 std::stack<bool> parsed_function_name;
161 225
162 // Set of identifiers that might be local variable names. 226 // Set of identifiers that might be local variable names.
163 std::set<std::string> pending_local_variables; 227 std::set<std::string> pending_local_variables;
164
165 private:
166
167 lexical_feedback (const lexical_feedback&);
168
169 lexical_feedback& operator = (const lexical_feedback&);
170 }; 228 };
171 229
172 class 230 class
173 stream_reader 231 stream_reader
174 { 232 {