Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove curly brace CPP Lint checks #2109

Merged
merged 4 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CODING_STANDARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Formatting is enforced using clang-format. For more information about this, see
- Nested function calls do not need to be broken up into separate lines
even if the outer function call does.
- If a method is bigger than 50 lines, break it into parts.
- Put matching `{ }` into the same column.
- Put matching `{ }` into the same column, except for lambdas, where you should
place `{` directly after the closing `)`. This rule also doesn't apply to
initializer lists.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment on the rationale of this (convenience rule due to deficiencies of clang-format)? We should revert the rule once the clang-format bug is fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule also doesn't apply to initializer lists. sounds a bit strange to me. I'd remove the also - is it the rule (Put matching...) or the exception (except...) that doesn't apply... a bit confusing. Please reword.

- Spaces around binary operators (`=`, `+`, `==` ...)
- Space after comma (parameter lists, argument lists, ...)
- Space after colon inside `for`
Expand Down
8 changes: 0 additions & 8 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3972,14 +3972,6 @@ def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error):
error(filename, linenum, 'whitespace/braces', 5,
'Missing space before {')

# Make sure '} else {' has spaces.
# if Search(r'}else', line):
# error(filename, linenum, 'whitespace/braces', 5,
# 'Missing space before else')
if (Search(r'^.*[^\s].*}$', line) or Search(r'^.*[^\s].*{$', line)) and not(Search(r'{[^}]*}', line)):
error(filename, linenum, 'whitespace/braces', 5,
'Put braces on a separate next line')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this also remove the check for all compound statements such as loops, non-lambda function bodies, if/else? How about, instead of completely removing it, adding a not(Search(r'\]\s*\(.*\)\s*{', line))?

Copy link
Contributor Author

@LAJW LAJW Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work in the case of lambda with a return type:

[] (T& t) -> optionalt<std::string> { ...

Or with a lambda with omitted arguments (used in named scopes):

auto value = [&] {
  if (this)
    return 1;
  if (that)
    return 2;
  return 3;
}();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't be very hard to add expressions for those, but I do worry about the various line breaks that could be used.

# You shouldn't have a space before a semicolon at the end of the line.
# There's a special case for "for" since the style guide allows space before
# the semicolon there.
Expand Down
6 changes: 2 additions & 4 deletions src/goto-programs/goto_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,10 +1823,8 @@ void goto_convertt::generate_ifthenelse(
// Note this depends on the fact that `instructions` is a std::list
// and so goto-program-destructive-append preserves iterator validity.
if(is_guarded_goto)
guarded_gotos.push_back({ // NOLINT(whitespace/braces)
tmp_v.instructions.begin(),
tmp_w.instructions.begin(),
guard});
guarded_gotos.push_back(
{tmp_v.instructions.begin(), tmp_w.instructions.begin(), guard});

dest.destructive_append(tmp_v);
dest.destructive_append(tmp_w);
Expand Down
6 changes: 3 additions & 3 deletions src/goto-programs/lazy_goto_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class lazy_goto_modelt : public abstract_goto_modelt
message_handlert &message_handler)
{
return lazy_goto_modelt(
[&handler, &options]
(goto_model_functiont &fun, const abstract_goto_modelt &model) { // NOLINT(*)
[&handler,
&options](goto_model_functiont &fun, const abstract_goto_modelt &model) {
handler.process_goto_function(fun, model, options);
},
[&handler, &options] (goto_modelt &goto_model) -> bool { // NOLINT(*)
[&handler, &options](goto_modelt &goto_model) -> bool {
return handler.process_goto_functions(goto_model, options);
},
message_handler);
Expand Down
4 changes: 2 additions & 2 deletions src/goto-symex/symex_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ void goto_symext::symex_threaded_step(
static goto_symext::get_goto_functiont get_function_from_goto_functions(
const goto_functionst &goto_functions)
{
return [&goto_functions](const irep_idt &key) ->
const goto_functionst::goto_functiont & { // NOLINT(*)
return [&goto_functions](
const irep_idt &key) -> const goto_functionst::goto_functiont & {
return goto_functions.function_map.at(key);
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/java_bytecode/expr2java.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::string floating_point_to_java_string(float_type value)
return class_name + ".POSITIVE_INFINITY";
if(std::isinf(value) && value <= 0.)
return class_name + ".NEGATIVE_INFINITY";
const std::string decimal = [&]() -> std::string { // NOLINT
const std::string decimal = [&]() -> std::string {
// Using ostringstream instead of to_string to get string without
// trailing zeros
std::ostringstream raw_stream;
Expand All @@ -76,7 +76,7 @@ std::string floating_point_to_java_string(float_type value)
return raw_decimal + ".0";
return raw_decimal;
}();
const bool is_lossless = [&] { // NOLINT
const bool is_lossless = [&] {
if(value == std::numeric_limits<float_type>::min())
return true;
try
Expand All @@ -88,7 +88,7 @@ std::string floating_point_to_java_string(float_type value)
return false;
}
}();
const std::string lossless = [&]() -> std::string { // NOLINT
const std::string lossless = [&]() -> std::string {
if(is_lossless)
return decimal;
std::ostringstream stream;
Expand Down
6 changes: 2 additions & 4 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,8 @@ static void gather_symbol_live_ranges(
if(e.id()==ID_symbol)
{
const auto &symexpr=to_symbol_expr(e);
auto findit=
result.insert({ // NOLINT(whitespace/braces)
symexpr.get_identifier(),
java_bytecode_convert_methodt::variablet()});
auto findit = result.insert(
{symexpr.get_identifier(), java_bytecode_convert_methodt::variablet()});
auto &var=findit.first->second;
if(findit.second)
{
Expand Down
2 changes: 1 addition & 1 deletion src/java_bytecode/java_bytecode_instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class java_bytecode_instrumentt:public messaget
optionalt<codet> instrument_expr(const exprt &expr);
};

const std::vector<std::string> exception_needed_classes = { // NOLINT
const std::vector<std::string> exception_needed_classes = {
"java.lang.ArithmeticException",
"java.lang.ArrayIndexOutOfBoundsException",
"java.lang.ClassCastException",
Expand Down
2 changes: 1 addition & 1 deletion src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool java_bytecode_languaget::parse(
{
string_preprocess.initialize_known_type_table();

auto get_string_base_classes = [this](const irep_idt &id) { // NOLINT (*)
auto get_string_base_classes = [this](const irep_idt &id) {
return string_preprocess.get_string_type_base_classes(id);
};

Expand Down
2 changes: 1 addition & 1 deletion src/java_bytecode/remove_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void remove_exceptions(
std::map<irep_idt, std::set<irep_idt>> exceptions_map;
uncaught_exceptions(goto_functions, ns, exceptions_map);
remove_exceptionst::function_may_throwt function_may_throw =
[&exceptions_map](const irep_idt &id) { // NOLINT(whitespace/braces)
[&exceptions_map](const irep_idt &id) {
return !exceptions_map[id].empty();
};
remove_exceptionst remove_exceptions(
Expand Down
4 changes: 1 addition & 3 deletions src/java_bytecode/remove_instanceof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ std::size_t remove_instanceoft::lower_instanceof(
// Sort alphabetically to make order of generated disjuncts
// independent of class loading order
std::sort(
children.begin(),
children.end(),
[](const irep_idt &a, const irep_idt &b) { // NOLINT
children.begin(), children.end(), [](const irep_idt &a, const irep_idt &b) {
return a.compare(b) < 0;
});

Expand Down
4 changes: 1 addition & 3 deletions src/java_bytecode/replace_java_nondet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ static goto_programt::targett check_and_replace_target(
"goto_program missing END_FUNCTION instruction");

std::for_each(
target,
after_matching_assignment,
[](goto_programt::instructiont &instr) { // NOLINT (*)
target, after_matching_assignment, [](goto_programt::instructiont &instr) {
instr.make_skip();
});

Expand Down
25 changes: 12 additions & 13 deletions src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@ int jbmc_parse_optionst::doit()
std::function<void(bmct &, const symbol_tablet &)> configure_bmc = nullptr;
if(options.get_bool_option("java-unwind-enum-static"))
{
configure_bmc = [](
bmct &bmc, const symbol_tablet &symbol_table) { // NOLINT (*)
bmc.add_loop_unwind_handler([&symbol_table](
const irep_idt &function_id,
unsigned loop_number,
unsigned unwind,
unsigned &max_unwind) { // NOLINT (*)
configure_bmc = [](bmct &bmc, const symbol_tablet &symbol_table) {
bmc.add_loop_unwind_handler(
[&symbol_table](
const irep_idt &function_id,
unsigned loop_number,
unsigned unwind,
unsigned &max_unwind) {
return java_enum_static_init_unwind_handler(
function_id,
loop_number,
Expand Down Expand Up @@ -564,7 +564,7 @@ int jbmc_parse_optionst::doit()
// executes. If --paths is active, these dump routines run after every
// paths iteration. Its return value indicates that if we ran any dump
// function, then we should skip the actual solver phase.
auto callback_after_symex = [this, &lazy_goto_model]() { // NOLINT (*)
auto callback_after_symex = [this, &lazy_goto_model]() {
return show_loaded_functions(lazy_goto_model);
};

Expand Down Expand Up @@ -729,11 +729,10 @@ void jbmc_parse_optionst::process_goto_function(
remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
}

auto function_is_stub =
[&symbol_table, &model](const irep_idt &id) { // NOLINT(*)
return symbol_table.lookup_ref(id).value.is_nil() &&
!model.can_produce_function(id);
};
auto function_is_stub = [&symbol_table, &model](const irep_idt &id) {
return symbol_table.lookup_ref(id).value.is_nil() &&
!model.can_produce_function(id);
};

remove_returns(function, function_is_stub);

Expand Down
46 changes: 14 additions & 32 deletions src/jsil/jsil_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,38 @@ Author: Daiva Naudziuniene, [email protected]

typet jsil_any_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
jsil_empty_type(),
jsil_reference_type(),
jsil_value_type()
});
return jsil_union_typet(
{jsil_empty_type(), jsil_reference_type(), jsil_value_type()});
}

typet jsil_value_or_empty_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
jsil_value_type(),
jsil_empty_type()
});
return jsil_union_typet({jsil_value_type(), jsil_empty_type()});
}

typet jsil_value_or_reference_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
jsil_value_type(),
jsil_reference_type()
});
return jsil_union_typet({jsil_value_type(), jsil_reference_type()});
}

typet jsil_value_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
jsil_undefined_type(),
jsil_null_type(),
jsil_prim_type(),
jsil_object_type()
});
return jsil_union_typet(
{jsil_undefined_type(),
jsil_null_type(),
jsil_prim_type(),
jsil_object_type()});
}

typet jsil_prim_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
floatbv_typet(),
string_typet(),
bool_typet()
});
return jsil_union_typet({floatbv_typet(), string_typet(), bool_typet()});
}

typet jsil_reference_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
jsil_member_reference_type(),
jsil_variable_reference_type()
});
return jsil_union_typet(
{jsil_member_reference_type(), jsil_variable_reference_type()});
}

typet jsil_member_reference_type()
Expand All @@ -77,10 +61,8 @@ typet jsil_variable_reference_type()

typet jsil_object_type()
{
return jsil_union_typet({ // NOLINT(whitespace/braces)
jsil_user_object_type(),
jsil_builtin_object_type()
});
return jsil_union_typet(
{jsil_user_object_type(), jsil_builtin_object_type()});
}

typet jsil_user_object_type()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ exprt string_constraint_generatort::add_axioms_for_substring(
lemmas.push_back(equal_exprt(res.length(), minus_exprt(end1, start1)));

// Axiom 2.
constraints.push_back([&] { // NOLINT
constraints.push_back([&] {
const symbol_exprt idx = fresh_univ_index("QA_index_substring", index_type);
return string_constraintt(
idx, res.length(), equal_exprt(res[idx], str[plus_exprt(start1, idx)]));
Expand Down Expand Up @@ -197,7 +197,7 @@ exprt string_constraint_generatort::add_axioms_for_trim(
constraints.push_back(a6);

// Axiom 7.
constraints.push_back([&] { // NOLINT
constraints.push_back([&] {
const symbol_exprt n2 = fresh_univ_index("QA_index_trim2", index_type);
const minus_exprt bound(minus_exprt(str.length(), idx), res.length());
const binary_relation_exprt eqn2(
Expand Down Expand Up @@ -473,7 +473,7 @@ exprt string_constraint_generatort::add_axioms_for_replace(
char_array_of_pointer(f.arguments()[1], f.arguments()[0]);
if(
const auto maybe_chars =
to_char_pair(f.arguments()[3], f.arguments()[4], [this](const exprt &e) { // NOLINT
to_char_pair(f.arguments()[3], f.arguments()[4], [this](const exprt &e) {
return get_string_expr(e);
}))
{
Expand Down
8 changes: 4 additions & 4 deletions src/solvers/refinement/string_refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
constraints.begin(),
constraints.end(),
std::back_inserter(axioms.universal),
[&](string_constraintt constraint) { // NOLINT
[&](string_constraintt constraint) {
symbol_resolve.replace_expr(constraint);
DATA_INVARIANT(
is_valid_string_constraint(error(), ns, constraint),
Expand All @@ -707,14 +707,14 @@ decision_proceduret::resultt string_refinementt::dec_solve()
not_contains_constraints.begin(),
not_contains_constraints.end(),
std::back_inserter(axioms.not_contains),
[&](string_not_contains_constraintt axiom) { // NOLINT
[&](string_not_contains_constraintt axiom) {
symbol_resolve.replace_expr(axiom);
return axiom;
});

for(const auto &nc_axiom : axioms.not_contains)
{
const auto &witness_type = [&] { // NOLINT
const auto &witness_type = [&] {
const auto &rtype = to_array_type(nc_axiom.s0().type());
const typet &index_type = rtype.size().type();
return array_typet(index_type, infinity_exprt(index_type));
Expand Down Expand Up @@ -1920,7 +1920,7 @@ static void update_index_set(
static optionalt<exprt>
find_index(const exprt &expr, const exprt &str, const symbol_exprt &qvar)
{
auto index_str_containing_qvar = [&](const exprt &e) { // NOLINT
auto index_str_containing_qvar = [&](const exprt &e) {
if(auto index_expr = expr_try_dynamic_cast<index_exprt>(e))
{
const auto &arr = index_expr->array();
Expand Down
11 changes: 5 additions & 6 deletions src/util/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void get_reachable(
{
auto n = stack.back();
stack.pop_back();
for_each_successor(n, [&](const nodet &node) { // NOLINT
for_each_successor(n, [&](const nodet &node) {
if(set.insert(node).second)
stack.push_back(node);
});
Expand Down Expand Up @@ -749,8 +749,8 @@ void output_dot_generic(
&for_each_succ,
const std::function<std::string(const node_index_type &)> node_to_string)
{
for_each_node([&](const node_index_type &i) { // NOLINT
for_each_succ(i, [&](const node_index_type &n) { // NOLINT
for_each_node([&](const node_index_type &i) {
for_each_succ(i, [&](const node_index_type &n) {
out << node_to_string(i) << " -> " << node_to_string(n) << '\n';
});
});
Expand Down Expand Up @@ -784,14 +784,13 @@ template <class N>
void grapht<N>::output_dot(std::ostream &out) const
{
const auto for_each_node =
[&](const std::function<void(const node_indext &)> &f) { // NOLINT
[&](const std::function<void(const node_indext &)> &f) {
for(node_indext i = 0; i < nodes.size(); ++i)
f(i);
};

const auto for_each_succ = [&](
const node_indext &i,
const std::function<void(const node_indext &)> &f) { // NOLINT
const node_indext &i, const std::function<void(const node_indext &)> &f) {
for_each_successor(i, f);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
/// \return true if a suitable symbol_exprt is found
static bool contains_symbol_reference(const exprt &expr, const irep_idt &id)
{
return
std::any_of(
expr.depth_begin(),
expr.depth_end(),
[id](const exprt &e) { // NOLINT (*)
return e.id() == ID_symbol && to_symbol_expr(e).get_identifier() == id;
});
return std::any_of(
expr.depth_begin(), expr.depth_end(), [id](const exprt &e) {
return e.id() == ID_symbol && to_symbol_expr(e).get_identifier() == id;
});
}

SCENARIO(
Expand Down
Loading