clang-format: Set IndentCaseBlocks to false

This commit is contained in:
Tim Wojtulewicz 2021-09-24 15:40:37 -07:00
parent 02206f3215
commit 4423574d26
58 changed files with 4729 additions and 4766 deletions

View file

@ -129,49 +129,49 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s)
break;
case STMT_FOR:
{
auto sf = s->AsForStmt();
auto loop_vars = sf->LoopVars();
auto value_var = sf->ValueVar();
{
auto sf = s->AsForStmt();
auto loop_vars = sf->LoopVars();
auto value_var = sf->ValueVar();
for ( auto id : *loop_vars )
locals.insert(id);
for ( auto id : *loop_vars )
locals.insert(id);
if ( value_var )
locals.insert(value_var.get());
}
if ( value_var )
locals.insert(value_var.get());
}
break;
case STMT_SWITCH:
{
// If this is a type-case switch statement, then find the
// identifiers created so we can add them to our list of
// locals. Ideally this wouldn't be necessary since *surely*
// if one bothers to define such an identifier then it'll be
// subsequently used, and we'll pick up the local that way ...
// but if for some reason it's not, then we would have an
// incomplete list of locals that need to be tracked.
auto sw = s->AsSwitchStmt();
bool is_type_switch = false;
for ( auto& c : *sw->Cases() )
{
// If this is a type-case switch statement, then find the
// identifiers created so we can add them to our list of
// locals. Ideally this wouldn't be necessary since *surely*
// if one bothers to define such an identifier then it'll be
// subsequently used, and we'll pick up the local that way ...
// but if for some reason it's not, then we would have an
// incomplete list of locals that need to be tracked.
auto sw = s->AsSwitchStmt();
bool is_type_switch = false;
for ( auto& c : *sw->Cases() )
auto idl = c->TypeCases();
if ( idl )
{
auto idl = c->TypeCases();
if ( idl )
{
for ( auto id : *idl )
locals.insert(id);
for ( auto id : *idl )
locals.insert(id);
is_type_switch = true;
}
is_type_switch = true;
}
if ( is_type_switch )
type_switches.insert(sw);
else
expr_switches.insert(sw);
}
if ( is_type_switch )
type_switches.insert(sw);
else
expr_switches.insert(sw);
}
break;
default:
@ -194,46 +194,46 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e)
break;
case EXPR_NAME:
{
auto n = e->AsNameExpr();
auto id = n->Id();
if ( id->IsGlobal() )
{
auto n = e->AsNameExpr();
auto id = n->Id();
globals.insert(id);
all_globals.insert(id);
if ( id->IsGlobal() )
{
globals.insert(id);
all_globals.insert(id);
const auto& t = id->GetType();
if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT )
events.insert(id->Name());
}
else
{
// This is a tad ugly. Unfortunately due to the
// weird way that Zeek function *declarations* work,
// there's no reliable way to get the list of
// parameters for a function *definition*, since
// they can have different names than what's present
// in the declaration. So we identify them directly,
// by knowing that they come at the beginning of the
// frame ... and being careful to avoid misconfusing
// a lambda capture with a low frame offset as a
// parameter.
if ( captures.count(id) == 0 && id->Offset() < num_params )
params.insert(id);
locals.insert(id);
}
// Turns out that NameExpr's can be constructed using a
// different Type* than that of the identifier itself,
// so be sure we track the latter too.
TrackType(id->GetType());
break;
const auto& t = id->GetType();
if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT )
events.insert(id->Name());
}
else
{
// This is a tad ugly. Unfortunately due to the
// weird way that Zeek function *declarations* work,
// there's no reliable way to get the list of
// parameters for a function *definition*, since
// they can have different names than what's present
// in the declaration. So we identify them directly,
// by knowing that they come at the beginning of the
// frame ... and being careful to avoid misconfusing
// a lambda capture with a low frame offset as a
// parameter.
if ( captures.count(id) == 0 && id->Offset() < num_params )
params.insert(id);
locals.insert(id);
}
// Turns out that NameExpr's can be constructed using a
// different Type* than that of the identifier itself,
// so be sure we track the latter too.
TrackType(id->GetType());
break;
}
case EXPR_FIELD:
if ( abs_rec_fields )
{
@ -265,130 +265,130 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e)
case EXPR_ADD_TO:
case EXPR_REMOVE_FROM:
case EXPR_ASSIGN:
{
if ( e->GetOp1()->Tag() == EXPR_REF )
{
if ( e->GetOp1()->Tag() == EXPR_REF )
{
auto lhs = e->GetOp1()->GetOp1();
if ( lhs->Tag() == EXPR_NAME )
TrackAssignment(lhs->AsNameExpr()->Id());
}
// else this isn't a direct assignment.
break;
auto lhs = e->GetOp1()->GetOp1();
if ( lhs->Tag() == EXPR_NAME )
TrackAssignment(lhs->AsNameExpr()->Id());
}
// else this isn't a direct assignment.
break;
}
case EXPR_CALL:
{
auto c = e->AsCallExpr();
auto f = c->Func();
if ( f->Tag() != EXPR_NAME )
{
auto c = e->AsCallExpr();
auto f = c->Func();
does_indirect_calls = true;
return TC_CONTINUE;
}
if ( f->Tag() != EXPR_NAME )
auto n = f->AsNameExpr();
auto func = n->Id();
if ( ! func->IsGlobal() )
{
does_indirect_calls = true;
return TC_CONTINUE;
}
all_globals.insert(func);
auto func_v = func->GetVal();
if ( func_v )
{
auto func_vf = func_v->AsFunc();
if ( func_vf->GetKind() == Func::SCRIPT_FUNC )
{
does_indirect_calls = true;
return TC_CONTINUE;
}
auto bf = static_cast<ScriptFunc*>(func_vf);
script_calls.insert(bf);
auto n = f->AsNameExpr();
auto func = n->Id();
if ( ! func->IsGlobal() )
{
does_indirect_calls = true;
return TC_CONTINUE;
}
all_globals.insert(func);
auto func_v = func->GetVal();
if ( func_v )
{
auto func_vf = func_v->AsFunc();
if ( func_vf->GetKind() == Func::SCRIPT_FUNC )
{
auto bf = static_cast<ScriptFunc*>(func_vf);
script_calls.insert(bf);
if ( in_when )
when_calls.insert(bf);
}
else
BiF_globals.insert(func);
if ( in_when )
when_calls.insert(bf);
}
else
{
// We could complain, but for now we don't, because
// if we're invoked prior to full Zeek initialization,
// the value might indeed not there yet.
// printf("no function value for global %s\n", func->Name());
}
// Recurse into the arguments.
auto args = c->Args();
args->Traverse(this);
// Do the following explicitly, since we won't be recursing
// into the LHS global.
// Note that the type of the expression and the type of the
// function can actually be *different* due to the NameExpr
// being constructed based on a forward reference and then
// the global getting a different (constructed) type when
// the function is actually declared. Geez. So hedge our
// bets.
TrackType(n->GetType());
TrackType(func->GetType());
TrackID(func);
return TC_ABORTSTMT;
BiF_globals.insert(func);
}
else
{
// We could complain, but for now we don't, because
// if we're invoked prior to full Zeek initialization,
// the value might indeed not there yet.
// printf("no function value for global %s\n", func->Name());
}
// Recurse into the arguments.
auto args = c->Args();
args->Traverse(this);
// Do the following explicitly, since we won't be recursing
// into the LHS global.
// Note that the type of the expression and the type of the
// function can actually be *different* due to the NameExpr
// being constructed based on a forward reference and then
// the global getting a different (constructed) type when
// the function is actually declared. Geez. So hedge our
// bets.
TrackType(n->GetType());
TrackType(func->GetType());
TrackID(func);
return TC_ABORTSTMT;
}
case EXPR_EVENT:
{
auto ev = e->AsEventExpr()->Name();
events.insert(ev);
addl_hashes.push_back(p_hash(ev));
}
{
auto ev = e->AsEventExpr()->Name();
events.insert(ev);
addl_hashes.push_back(p_hash(ev));
}
break;
case EXPR_LAMBDA:
{
auto l = e->AsLambdaExpr();
lambdas.push_back(l);
for ( const auto& i : l->OuterIDs() )
{
auto l = e->AsLambdaExpr();
lambdas.push_back(l);
locals.insert(i);
TrackID(i);
for ( const auto& i : l->OuterIDs() )
{
locals.insert(i);
TrackID(i);
// See above re EXPR_NAME regarding the following
// logic.
if ( captures.count(i) == 0 && i->Offset() < num_params )
params.insert(i);
}
// Avoid recursing into the body.
return TC_ABORTSTMT;
// See above re EXPR_NAME regarding the following
// logic.
if ( captures.count(i) == 0 && i->Offset() < num_params )
params.insert(i);
}
// Avoid recursing into the body.
return TC_ABORTSTMT;
}
case EXPR_SET_CONSTRUCTOR:
{
auto sc = static_cast<const SetConstructorExpr*>(e);
const auto& attrs = sc->GetAttrs();
{
auto sc = static_cast<const SetConstructorExpr*>(e);
const auto& attrs = sc->GetAttrs();
if ( attrs )
constructor_attrs.insert(attrs.get());
}
if ( attrs )
constructor_attrs.insert(attrs.get());
}
break;
case EXPR_TABLE_CONSTRUCTOR:
{
auto tc = static_cast<const TableConstructorExpr*>(e);
const auto& attrs = tc->GetAttrs();
{
auto tc = static_cast<const TableConstructorExpr*>(e);
const auto& attrs = tc->GetAttrs();
if ( attrs )
constructor_attrs.insert(attrs.get());
}
if ( attrs )
constructor_attrs.insert(attrs.get());
}
break;
default:
@ -560,46 +560,46 @@ void ProfileFuncs::TraverseValue(const ValPtr& v)
break;
case TYPE_RECORD:
{
auto r = cast_intrusive<RecordVal>(v);
auto n = r->NumFields();
{
auto r = cast_intrusive<RecordVal>(v);
auto n = r->NumFields();
for ( auto i = 0u; i < n; ++i )
TraverseValue(r->GetField(i));
}
for ( auto i = 0u; i < n; ++i )
TraverseValue(r->GetField(i));
}
break;
case TYPE_TABLE:
{
auto tv = cast_intrusive<TableVal>(v);
auto tv_map = tv->ToMap();
{
auto tv = cast_intrusive<TableVal>(v);
auto tv_map = tv->ToMap();
for ( auto& tv_i : tv_map )
{
TraverseValue(tv_i.first);
TraverseValue(tv_i.second);
}
for ( auto& tv_i : tv_map )
{
TraverseValue(tv_i.first);
TraverseValue(tv_i.second);
}
}
break;
case TYPE_LIST:
{
auto lv = cast_intrusive<ListVal>(v);
auto n = lv->Length();
{
auto lv = cast_intrusive<ListVal>(v);
auto n = lv->Length();
for ( auto i = 0; i < n; ++i )
TraverseValue(lv->Idx(i));
}
for ( auto i = 0; i < n; ++i )
TraverseValue(lv->Idx(i));
}
break;
case TYPE_VECTOR:
{
auto vv = cast_intrusive<VectorVal>(v);
auto n = vv->Size();
{
auto vv = cast_intrusive<VectorVal>(v);
auto n = vv->Size();
for ( auto i = 0u; i < n; ++i )
TraverseValue(vv->ValAt(i));
}
for ( auto i = 0u; i < n; ++i )
TraverseValue(vv->ValAt(i));
}
break;
case TYPE_TYPE:
@ -759,82 +759,82 @@ p_hash_type ProfileFuncs::HashType(const Type* t)
break;
case TYPE_RECORD:
{
const auto& ft = t->AsRecordType();
auto n = ft->NumFields();
auto orig_n = ft->NumOrigFields();
h = merge_p_hashes(h, p_hash("record"));
if ( full_record_hashes )
h = merge_p_hashes(h, p_hash(n));
else
h = merge_p_hashes(h, p_hash(orig_n));
for ( auto i = 0; i < n; ++i )
{
const auto& ft = t->AsRecordType();
auto n = ft->NumFields();
auto orig_n = ft->NumOrigFields();
bool do_hash = full_record_hashes;
if ( ! do_hash )
do_hash = (i < orig_n);
h = merge_p_hashes(h, p_hash("record"));
const auto& f = ft->FieldDecl(i);
auto type_h = HashType(f->type);
if ( full_record_hashes )
h = merge_p_hashes(h, p_hash(n));
else
h = merge_p_hashes(h, p_hash(orig_n));
for ( auto i = 0; i < n; ++i )
if ( do_hash )
{
bool do_hash = full_record_hashes;
if ( ! do_hash )
do_hash = (i < orig_n);
const auto& f = ft->FieldDecl(i);
auto type_h = HashType(f->type);
if ( do_hash )
{
h = merge_p_hashes(h, p_hash(f->id));
h = merge_p_hashes(h, type_h);
}
h = merge_p_hashes(h, p_hash(f->id));
h = merge_p_hashes(h, HashType(f->type));
h = merge_p_hashes(h, type_h);
}
// We don't hash the field name, as in some contexts
// those are ignored.
h = merge_p_hashes(h, p_hash(f->id));
h = merge_p_hashes(h, HashType(f->type));
if ( f->attrs )
{
if ( do_hash )
h = merge_p_hashes(h, HashAttrs(f->attrs));
AnalyzeAttrs(f->attrs.get());
}
// We don't hash the field name, as in some contexts
// those are ignored.
if ( f->attrs )
{
if ( do_hash )
h = merge_p_hashes(h, HashAttrs(f->attrs));
AnalyzeAttrs(f->attrs.get());
}
}
}
break;
case TYPE_TABLE:
{
auto tbl = t->AsTableType();
h = merge_p_hashes(h, p_hash("table"));
h = merge_p_hashes(h, p_hash("indices"));
h = merge_p_hashes(h, HashType(tbl->GetIndices()));
h = merge_p_hashes(h, p_hash("tbl-yield"));
h = merge_p_hashes(h, HashType(tbl->Yield()));
}
{
auto tbl = t->AsTableType();
h = merge_p_hashes(h, p_hash("table"));
h = merge_p_hashes(h, p_hash("indices"));
h = merge_p_hashes(h, HashType(tbl->GetIndices()));
h = merge_p_hashes(h, p_hash("tbl-yield"));
h = merge_p_hashes(h, HashType(tbl->Yield()));
}
break;
case TYPE_FUNC:
{
auto ft = t->AsFuncType();
auto flv = ft->FlavorString();
h = merge_p_hashes(h, p_hash(flv));
h = merge_p_hashes(h, p_hash("params"));
h = merge_p_hashes(h, HashType(ft->Params()));
h = merge_p_hashes(h, p_hash("func-yield"));
h = merge_p_hashes(h, HashType(ft->Yield()));
}
{
auto ft = t->AsFuncType();
auto flv = ft->FlavorString();
h = merge_p_hashes(h, p_hash(flv));
h = merge_p_hashes(h, p_hash("params"));
h = merge_p_hashes(h, HashType(ft->Params()));
h = merge_p_hashes(h, p_hash("func-yield"));
h = merge_p_hashes(h, HashType(ft->Yield()));
}
break;
case TYPE_LIST:
{
auto& tl = t->AsTypeList()->GetTypes();
{
auto& tl = t->AsTypeList()->GetTypes();
h = merge_p_hashes(h, p_hash("list"));
h = merge_p_hashes(h, p_hash(tl.size()));
h = merge_p_hashes(h, p_hash("list"));
h = merge_p_hashes(h, p_hash(tl.size()));
for ( const auto& tl_i : tl )
h = merge_p_hashes(h, HashType(tl_i));
}
for ( const auto& tl_i : tl )
h = merge_p_hashes(h, HashType(tl_i));
}
break;
case TYPE_VECTOR: