Skip to content

Commit 14715d9

Browse files
committed
Remove parsert::clear and all of its overrides
Re-use of parsers should no longer be necessary now that they aren't objects of static lifetime anymore. Consequently, there is no need to "clear," and instead only a subset of the instructions is required in constructors.
1 parent 1fd7011 commit 14715d9

File tree

10 files changed

+8
-78
lines changed

10 files changed

+8
-78
lines changed

src/ansi-c/ansi_c_parser.h

-18
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ class ansi_c_parsert:public parsert
4343

4444
bool parse() override;
4545

46-
void clear() override
47-
{
48-
parsert::clear();
49-
parse_tree.clear();
50-
51-
// scanner state
52-
tag_following=false;
53-
asm_block_following=false;
54-
parenthesis_counter=0;
55-
string_literal.clear();
56-
pragma_pack.clear();
57-
pragma_cprover_stack.clear();
58-
59-
// set up global scope
60-
scopes.clear();
61-
scopes.push_back(scopet());
62-
}
63-
6446
// internal state of the scanner
6547
bool tag_following;
6648
bool asm_block_following;

src/assembler/assembler_parser.h

-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ class assembler_parsert:public parsert
4242
}
4343

4444
bool parse() override;
45-
46-
void clear() override
47-
{
48-
parsert::clear();
49-
instructions.clear();
50-
}
5145
};
5246

5347
#endif // CPROVER_ASSEMBLER_ASSEMBLER_PARSER_H

src/cpp/cpp_language.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ bool cpp_languaget::parse(
112112
// save result
113113
cpp_parse_tree.swap(cpp_parser.parse_tree);
114114

115-
// save some memory
116-
cpp_parser.clear();
117-
118115
return result;
119116
}
120117

@@ -260,9 +257,6 @@ bool cpp_languaget::to_expr(
260257
result = cpp_typecheck(expr, message_handler, ns);
261258
}
262259

263-
// save some memory
264-
cpp_parser.clear();
265-
266260
return result;
267261
}
268262

src/cpp/cpp_parser.h

-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ class cpp_parsert:public parsert
2828

2929
virtual bool parse() override;
3030

31-
virtual void clear() override
32-
{
33-
parsert::clear();
34-
parse_tree.clear();
35-
token_buffer.clear();
36-
asm_block_following=false;
37-
}
38-
3931
explicit cpp_parsert(message_handlert &message_handler)
4032
: parsert(message_handler),
4133
mode(configt::ansi_ct::flavourt::ANSI),

src/json/json_parser.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ bool parse_json(
4141
if(json_parser.stack.size()==1)
4242
dest.swap(json_parser.stack.top());
4343

44-
// save some memory
45-
json_parser.clear();
46-
4744
return result;
4845
}
4946

src/json/json_parser.h

-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ class json_parsert:public parsert
4141
dest.swap(stack.top());
4242
stack.pop();
4343
}
44-
45-
virtual void clear() override
46-
{
47-
stack=stackt();
48-
}
4944
};
5045

5146
// 'do it all' functions

src/statement-list/statement_list_parser.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,6 @@ bool statement_list_parsert::parse()
352352
return parse_fail;
353353
}
354354

355-
void statement_list_parsert::clear()
356-
{
357-
parsert::clear();
358-
parse_tree.clear();
359-
}
360-
361355
void statement_list_parsert::print_tree(std::ostream &out) const
362356
{
363357
output_parse_tree(out, parse_tree);

src/statement-list/statement_list_parser.h

-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ class statement_list_parsert : public parsert
7474
/// \param other: Parse tree which should be used in the swap operation.
7575
void swap_tree(statement_list_parse_treet &other);
7676

77-
/// Removes all functions and function blocks from the parse tree and
78-
/// clears the internal state of the parser.
79-
void clear() override;
80-
8177
private:
8278
/// Tree that is being filled by the parsing process.
8379
statement_list_parse_treet parse_tree;

src/util/parser.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,20 @@ class parsert
3030

3131
std::vector<exprt> stack;
3232

33-
virtual void clear()
33+
DEPRECATED(SINCE(2023, 12, 20, "use parsert(message_handler) instead"))
34+
parsert() : in(nullptr), line_no(0), previous_line_no(0), column(1)
3435
{
35-
line_no=0;
36-
previous_line_no=0;
37-
column=1;
38-
stack.clear();
39-
source_location.clear();
40-
last_line.clear();
4136
}
4237

43-
DEPRECATED(SINCE(2023, 12, 20, "use parsert(message_handler) instead"))
44-
parsert():in(nullptr) { clear(); }
4538
explicit parsert(message_handlert &message_handler)
46-
: in(nullptr), log(message_handler)
39+
: in(nullptr),
40+
log(message_handler),
41+
line_no(0),
42+
previous_line_no(0),
43+
column(1)
4744
{
48-
clear();
4945
}
46+
5047
virtual ~parsert() { }
5148

5249
// The following are for the benefit of the scanner

src/xmllang/xml_parser.h

-11
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ class xml_parsert:public parsert
5050
stack.push_back(&current().elements.back());
5151
}
5252

53-
/// Clears the parser state. May be removed in future as there should not be a
54-
/// need to re-use an existing parser object.
55-
void clear() override
56-
{
57-
parse_tree.clear();
58-
// set up stack
59-
stack.clear();
60-
stack.push_back(&parse_tree.element);
61-
parsert::clear();
62-
}
63-
6453
protected:
6554
static int instance_count;
6655
};

0 commit comments

Comments
 (0)