Skip to content

Commit 6981150

Browse files
committed
Harness option parser is a namespace
not a class: its methods are not static and we do not inherit from it. Also change the linter script to allow namespaces in the first place.
1 parent 72285b3 commit 6981150

7 files changed

+53
-69
lines changed

scripts/cpplint.py

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,26 +2479,26 @@ def CheckEnd(self, filename, clean_lines, linenum, error):
24792479
# Besides these, we don't accept anything else, otherwise we might
24802480
# get false negatives when existing comment is a substring of the
24812481
# expected namespace.
2482-
# if self.name:
2483-
# # Named namespace
2484-
# if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' +
2485-
# re.escape(self.name) + r'[\*/\.\\\s]*$'),
2486-
# line):
2487-
# error(filename, linenum, 'readability/namespace', 5,
2488-
# 'Namespace should be terminated with "// namespace %s"' %
2489-
# self.name)
2490-
# else:
2491-
# # Anonymous namespace
2492-
# if not Match(r'^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line):
2493-
# # If "// namespace anonymous" or "// anonymous namespace (more text)",
2494-
# # mention "// anonymous namespace" as an acceptable form
2495-
# if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line):
2496-
# error(filename, linenum, 'readability/namespace', 5,
2497-
# 'Anonymous namespace should be terminated with "// namespace"'
2498-
# ' or "// anonymous namespace"')
2499-
# else:
2500-
# error(filename, linenum, 'readability/namespace', 5,
2501-
# 'Anonymous namespace should be terminated with "// namespace"')
2482+
if self.name:
2483+
# Named namespace
2484+
if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' +
2485+
re.escape(self.name) + r'[\*/\.\\\s]*$'),
2486+
line):
2487+
error(filename, linenum, 'readability/namespace', 5,
2488+
'Namespace should be terminated with "// namespace %s"' %
2489+
self.name)
2490+
else:
2491+
# Anonymous namespace
2492+
if not Match(r'^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line):
2493+
# If "// namespace anonymous" or "// anonymous namespace (more text)",
2494+
# mention "// anonymous namespace" as an acceptable form
2495+
if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line):
2496+
error(filename, linenum, 'readability/namespace', 5,
2497+
'Anonymous namespace should be terminated with "// namespace"'
2498+
' or "// anonymous namespace"')
2499+
else:
2500+
error(filename, linenum, 'readability/namespace', 5,
2501+
'Anonymous namespace should be terminated with "// namespace"')
25022502

25032503

25042504
class _PreprocessorInfo(object):
@@ -6296,25 +6296,6 @@ def CheckItemIndentationInNamespace(filename, raw_lines_no_comments, linenum,
62966296
error(filename, linenum, 'runtime/indentation_namespace', 4,
62976297
'Do not indent within a namespace')
62986298

6299-
def CheckNamespaceOrUsing(filename, clean_lines, linenum, error):
6300-
line = clean_lines.elided[linenum]
6301-
if Match(r'^\s*namespace(\s+.*)?$', line):
6302-
num_lines=len(clean_lines.elided)
6303-
current_linenum=linenum
6304-
while current_linenum<num_lines:
6305-
current_line=clean_lines.elided[current_linenum]
6306-
if current_linenum==linenum:
6307-
is_named=Match(r'^\s*namespace\s+[^\s{]+.*$', current_line)
6308-
else:
6309-
is_named=Match(r'^\s*[^\s{]+.*$', current_line)
6310-
if is_named:
6311-
error(filename, linenum, 'readability/namespace', 4,
6312-
'Do not use namespaces')
6313-
break
6314-
if '{' in current_line:
6315-
break
6316-
current_linenum+=1
6317-
63186299
def CheckForEndl(filename, clean_lines, linenum, error):
63196300
"""Check that the line does not contain std::endl."""
63206301
line = clean_lines.elided[linenum]
@@ -6362,7 +6343,6 @@ def ProcessLine(filename, file_extension, clean_lines, line,
63626343
CheckMakePairUsesDeduction(filename, clean_lines, line, error)
63636344
CheckRedundantVirtual(filename, clean_lines, line, error)
63646345
CheckCatchTestHasTags(filename, clean_lines, line, error)
6365-
CheckNamespaceOrUsing(filename, clean_lines, line, error)
63666346
CheckForEndl(filename, clean_lines, line, error)
63676347
for check_fn in extra_check_functions:
63686348
check_fn(filename, clean_lines, line, error)

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void function_call_harness_generatort::handle_option(
9191
const std::list<std::string> &values)
9292
{
9393
auto &require_exactly_one_value =
94-
harness_options_parsert::require_exactly_one_value;
94+
harness_options_parser::require_exactly_one_value;
9595

9696
if(p_impl->recursive_initialization_config.handle_option(option, values))
9797
{

src/goto-harness/goto_harness_generator.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Author: Diffblue Ltd.
1515
#include <util/invariant.h>
1616
#include <util/string2int.h>
1717

18-
std::string harness_options_parsert::require_exactly_one_value(
18+
namespace harness_options_parser
19+
{
20+
std::string require_exactly_one_value(
1921
const std::string &option,
2022
const std::list<std::string> &values)
2123
{
@@ -28,14 +30,14 @@ std::string harness_options_parsert::require_exactly_one_value(
2830
return values.front();
2931
}
3032

31-
void harness_options_parsert::assert_no_values(
33+
void assert_no_values(
3234
const std::string &option,
3335
const std::list<std::string> &values)
3436
{
3537
PRECONDITION_WITH_DIAGNOSTICS(values.empty(), option);
3638
}
3739

38-
std::size_t harness_options_parsert::require_one_size_value(
40+
std::size_t require_one_size_value(
3941
const std::string &option,
4042
const std::list<std::string> &values)
4143
{
@@ -51,3 +53,4 @@ std::size_t harness_options_parsert::require_one_size_value(
5153
"failed to parse `" + string_value + "' as integer", "--" + option};
5254
}
5355
}
56+
} // namespace harness_options_parser

src/goto-harness/goto_harness_generator.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,25 @@ Author: Diffblue Ltd.
1616

1717
class goto_modelt;
1818

19-
class harness_options_parsert
19+
namespace harness_options_parser
2020
{
21-
public:
22-
/// Returns the only value of a single element list,
23-
/// throws an exception if not passed a single element list
24-
static std::string require_exactly_one_value(
25-
const std::string &option,
26-
const std::list<std::string> &values);
27-
28-
/// Asserts that the list of values to an option passed is empty
29-
static void assert_no_values(
30-
const std::string &option,
31-
const std::list<std::string> &values);
32-
33-
/// Returns the only Nat value of a single element list,
34-
/// throws an exception if not passed a single element list (or not Nat)
35-
static std::size_t require_one_size_value(
36-
const std::string &option,
37-
const std::list<std::string> &values);
38-
};
21+
/// Returns the only value of a single element list,
22+
/// throws an exception if not passed a single element list
23+
std::string require_exactly_one_value(
24+
const std::string &option,
25+
const std::list<std::string> &values);
26+
27+
/// Asserts that the list of values to an option passed is empty
28+
void assert_no_values(
29+
const std::string &option,
30+
const std::list<std::string> &values);
31+
32+
/// Returns the only Nat value of a single element list,
33+
/// throws an exception if not passed a single element list (or not Nat)
34+
std::size_t require_one_size_value(
35+
const std::string &option,
36+
const std::list<std::string> &values);
37+
} // namespace harness_options_parser
3938

4039
class goto_harness_generatort
4140
{

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void memory_snapshot_harness_generatort::handle_option(
3333
const std::list<std::string> &values)
3434
{
3535
auto &require_exactly_one_value =
36-
harness_options_parsert::require_exactly_one_value;
36+
harness_options_parser::require_exactly_one_value;
3737
if(recursive_initialization_config.handle_option(option, values))
3838
{
3939
// the option belongs to recursive initialization

src/goto-harness/recursive_initialization.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ bool recursive_initialization_configt::handle_option(
2626
{
2727
if(option == COMMON_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT)
2828
{
29-
auto const value = require_exactly_one_value(option, values);
29+
auto const value =
30+
harness_options_parser::require_exactly_one_value(option, values);
3031
auto const user_min_null_tree_depth =
3132
string2optional<std::size_t>(value, 10);
3233
if(user_min_null_tree_depth.has_value())
@@ -43,7 +44,8 @@ bool recursive_initialization_configt::handle_option(
4344
}
4445
else if(option == COMMON_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT)
4546
{
46-
auto const value = require_exactly_one_value(option, values);
47+
auto const value =
48+
harness_options_parser::require_exactly_one_value(option, values);
4749
auto const user_max_nondet_tree_depth =
4850
string2optional<std::size_t>(value, 10);
4951
if(user_max_nondet_tree_depth.has_value())
@@ -60,13 +62,13 @@ bool recursive_initialization_configt::handle_option(
6062
}
6163
else if(option == COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT)
6264
{
63-
max_dynamic_array_size = require_one_size_value(
65+
max_dynamic_array_size = harness_options_parser::require_one_size_value(
6466
COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT, values);
6567
return true;
6668
}
6769
else if(option == COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT)
6870
{
69-
min_dynamic_array_size = require_one_size_value(
71+
min_dynamic_array_size = harness_options_parser::require_one_size_value(
7072
COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT, values);
7173
return true;
7274
}

src/goto-harness/recursive_initialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Author: Diffblue Ltd.
2121
#include "function_harness_generator_options.h"
2222
#include "goto_harness_generator.h"
2323

24-
struct recursive_initialization_configt : harness_options_parsert
24+
struct recursive_initialization_configt
2525
{
2626
std::size_t min_null_tree_depth = 1;
2727
std::size_t max_nondet_tree_depth = 2;

0 commit comments

Comments
 (0)