Reformat the world

This commit is contained in:
Tim Wojtulewicz 2021-09-16 15:35:39 -07:00
parent 194cb24547
commit b2f171ec69
714 changed files with 35149 additions and 35203 deletions

View file

@ -1,25 +1,25 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include "zeek/zeek-config.h"
#include "zeek/Var.h"
#include <memory>
#include "zeek/Val.h"
#include "zeek/EventRegistry.h"
#include "zeek/Expr.h"
#include "zeek/Func.h"
#include "zeek/IntrusivePtr.h"
#include "zeek/Stmt.h"
#include "zeek/Scope.h"
#include "zeek/Reporter.h"
#include "zeek/EventRegistry.h"
#include "zeek/Traverse.h"
#include "zeek/module_util.h"
#include "zeek/ID.h"
#include "zeek/IntrusivePtr.h"
#include "zeek/Reporter.h"
#include "zeek/Scope.h"
#include "zeek/Stmt.h"
#include "zeek/Traverse.h"
#include "zeek/Val.h"
#include "zeek/module_util.h"
#include "zeek/script_opt/ScriptOpt.h"
#include "zeek/zeek-config.h"
namespace zeek::detail {
namespace zeek::detail
{
static ValPtr init_val(Expr* init, const Type* t, ValPtr aggr)
{
@ -83,7 +83,11 @@ static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs,
if ( alt_args->FieldDecl(i)->attrs )
{
alt_ft->Error(util::fmt("alternate function prototype arguments may not have attributes: arg '%s'", field), canon_ft);
alt_ft->Error(
util::fmt(
"alternate function prototype arguments may not have attributes: arg '%s'",
field),
canon_ft);
return false;
}
@ -91,7 +95,10 @@ static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs,
if ( o < 0 )
{
alt_ft->Error(util::fmt("alternate function prototype arg '%s' not found in canonical prototype", field), canon_ft);
alt_ft->Error(
util::fmt("alternate function prototype arg '%s' not found in canonical prototype",
field),
canon_ft);
return false;
}
@ -121,14 +128,13 @@ static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs,
}
static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
std::unique_ptr<std::vector<AttrPtr>> attr, DeclType dt,
bool do_init)
std::unique_ptr<std::vector<AttrPtr>> attr, DeclType dt, bool do_init)
{
if ( id->GetType() )
{
if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->GetType()->Tag())) )
{
Obj* redef_obj = init ? (Obj*) init.get() : (Obj*) t.get();
Obj* redef_obj = init ? (Obj*)init.get() : (Obj*)t.get();
if ( dt != VAR_REDEF )
id->Warn("redefinition requires \"redef\"", redef_obj, true);
}
@ -158,8 +164,7 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR )
{
if ( dt != VAR_REDEF &&
(! init || ! do_init || (! t && ! (t = init_type(init.get())))) )
if ( dt != VAR_REDEF && (! init || ! do_init || (! t && ! (t = init_type(init.get())))) )
{
id->Error("already defined", init.get());
return;
@ -209,42 +214,44 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
id->SetType(t);
if ( attr )
id->AddAttrs(make_intrusive<Attributes>(std::move(*attr), t, false, id->IsGlobal()), dt == VAR_REDEF);
id->AddAttrs(make_intrusive<Attributes>(std::move(*attr), t, false, id->IsGlobal()),
dt == VAR_REDEF);
if ( init )
{
switch ( init->Tag() ) {
case EXPR_TABLE_CONSTRUCTOR:
switch ( init->Tag() )
{
auto* ctor = static_cast<TableConstructorExpr*>(init.get());
if ( ctor->GetAttrs() )
id->AddAttrs(ctor->GetAttrs());
}
break;
case EXPR_TABLE_CONSTRUCTOR:
{
auto* ctor = static_cast<TableConstructorExpr*>(init.get());
if ( ctor->GetAttrs() )
id->AddAttrs(ctor->GetAttrs());
}
break;
case EXPR_SET_CONSTRUCTOR:
{
auto* ctor = static_cast<SetConstructorExpr*>(init.get());
if ( ctor->GetAttrs() )
id->AddAttrs(ctor->GetAttrs());
}
break;
case EXPR_SET_CONSTRUCTOR:
{
auto* ctor = static_cast<SetConstructorExpr*>(init.get());
if ( ctor->GetAttrs() )
id->AddAttrs(ctor->GetAttrs());
}
break;
default:
break;
}
default:
break;
}
}
if ( do_init )
{
if ( c == INIT_NONE && dt == VAR_REDEF && t->IsTable() &&
init && init->Tag() == EXPR_ASSIGN )
if ( c == INIT_NONE && dt == VAR_REDEF && t->IsTable() && init &&
init->Tag() == EXPR_ASSIGN )
// e.g. 'redef foo["x"] = 1' is missing an init class, but the
// intention clearly isn't to overwrite entire existing table val.
c = INIT_EXTRA;
if ( init && ((c == INIT_EXTRA && id->GetAttr(ATTR_ADD_FUNC)) ||
(c == INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC)) ))
(c == INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC))) )
// Just apply the function.
id->SetVal(init, c);
@ -267,13 +274,11 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
if ( init && t )
// Have an initialization and type is not deduced.
init = make_intrusive<RecordCoerceExpr>(
std::move(init),
IntrusivePtr{NewRef{}, t->AsRecordType()});
std::move(init), IntrusivePtr{NewRef{}, t->AsRecordType()});
}
else if ( t->Tag() == TYPE_TABLE )
aggr = make_intrusive<TableVal>(cast_intrusive<TableType>(t),
id->GetAttrs());
aggr = make_intrusive<TableVal>(cast_intrusive<TableType>(t), id->GetAttrs());
else if ( t->Tag() == TYPE_VECTOR )
aggr = make_intrusive<VectorVal>(cast_intrusive<VectorType>(t));
@ -343,12 +348,10 @@ StmtPtr add_local(IDPtr id, TypePtr t, InitClass c, ExprPtr init,
id->Error("can't use += / -= for initializations of local variables");
// copy Location to the stack, because AssignExpr may free "init"
const Location location = init->GetLocationInfo() ?
*init->GetLocationInfo() : no_location;
const Location location = init->GetLocationInfo() ? *init->GetLocationInfo() : no_location;
auto name_expr = make_intrusive<NameExpr>(id, dt == VAR_CONST);
auto assign_expr = make_intrusive<AssignExpr>(std::move(name_expr),
std::move(init), 0,
auto assign_expr = make_intrusive<AssignExpr>(std::move(name_expr), std::move(init), 0,
nullptr, id->GetAttrs());
auto stmt = make_intrusive<ExprStmt>(std::move(assign_expr));
stmt->SetLocationInfo(&location);
@ -366,8 +369,7 @@ extern ExprPtr add_and_assign_local(IDPtr id, ExprPtr init, ValPtr val)
{
make_var(id, nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false);
auto name_expr = make_intrusive<NameExpr>(std::move(id));
return make_intrusive<AssignExpr>(std::move(name_expr), std::move(init),
false, std::move(val));
return make_intrusive<AssignExpr>(std::move(name_expr), std::move(init), false, std::move(val));
}
void add_type(ID* id, TypePtr t, std::unique_ptr<std::vector<AttrPtr>> attr)
@ -376,8 +378,7 @@ void add_type(ID* id, TypePtr t, std::unique_ptr<std::vector<AttrPtr>> attr)
std::string old_type_name = t->GetName();
TypePtr tnew;
if ( (t->Tag() == TYPE_RECORD || t->Tag() == TYPE_ENUM) &&
old_type_name.empty() )
if ( (t->Tag() == TYPE_RECORD || t->Tag() == TYPE_ENUM) && old_type_name.empty() )
// An extensible type (record/enum) being declared for first time.
tnew = std::move(t);
else
@ -413,8 +414,7 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv)
if ( ! recv_i->attrs )
{
std::vector<AttrPtr> a{def};
recv_i->attrs = make_intrusive<Attributes>(std::move(a), recv_i->type,
true, false);
recv_i->attrs = make_intrusive<Attributes>(std::move(a), recv_i->type, true, false);
}
else if ( ! recv_i->attrs->Find(ATTR_DEFAULT) )
@ -422,8 +422,7 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv)
}
}
static Attr* find_attr(const std::vector<AttrPtr>* al,
AttrTag tag)
static Attr* find_attr(const std::vector<AttrPtr>* al, AttrTag tag)
{
if ( ! al )
return nullptr;
@ -435,7 +434,8 @@ static Attr* find_attr(const std::vector<AttrPtr>* al,
return nullptr;
}
static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl, const FuncType* impl)
static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
const FuncType* impl)
{
if ( decl->Flavor() != impl->Flavor() )
{
@ -461,13 +461,13 @@ static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
auto msg = ad->DeprecationMessage();
if ( msg.empty() )
impl->Warn(util::fmt("use of deprecated parameter '%s'",
rval->args->FieldName(i)),
decl, true);
impl->Warn(
util::fmt("use of deprecated parameter '%s'", rval->args->FieldName(i)),
decl, true);
else
impl->Warn(util::fmt("use of deprecated parameter '%s': %s",
rval->args->FieldName(i), msg.data()),
decl, true);
decl, true);
}
return rval;
@ -519,8 +519,8 @@ static auto get_prototype(IDPtr id, FuncTypePtr t)
{
reporter->PushLocation(args->GetLocationInfo());
reporter->Warning(
"&default on parameter '%s' has no effect (not a %s declaration)",
args->FieldName(i), t->FlavorString().data());
"&default on parameter '%s' has no effect (not a %s declaration)",
args->FieldName(i), t->FlavorString().data());
reporter->PopLocation();
}
}
@ -530,11 +530,11 @@ static auto get_prototype(IDPtr id, FuncTypePtr t)
{
if ( prototype->deprecation_msg.empty() )
t->Warn(util::fmt("use of deprecated '%s' prototype", id->Name()),
prototype->args.get(), true);
prototype->args.get(), true);
else
t->Warn(util::fmt("use of deprecated '%s' prototype: %s",
id->Name(), prototype->deprecation_msg.data()),
prototype->args.get(), true);
t->Warn(util::fmt("use of deprecated '%s' prototype: %s", id->Name(),
prototype->deprecation_msg.data()),
prototype->args.get(), true);
}
}
@ -552,9 +552,8 @@ static auto get_prototype(IDPtr id, FuncTypePtr t)
}
static bool check_params(int i, std::optional<FuncType::Prototype> prototype,
const RecordTypePtr& args,
const RecordTypePtr& canon_args,
const char* module_name)
const RecordTypePtr& args, const RecordTypePtr& canon_args,
const char* module_name)
{
TypeDecl* arg_i;
bool hide = false;
@ -601,10 +600,8 @@ static bool check_params(int i, std::optional<FuncType::Prototype> prototype,
return true;
}
void begin_func(IDPtr id, const char* module_name,
FunctionFlavor flavor, bool is_redef,
FuncTypePtr t,
std::unique_ptr<std::vector<AttrPtr>> attrs)
void begin_func(IDPtr id, const char* module_name, FunctionFlavor flavor, bool is_redef,
FuncTypePtr t, std::unique_ptr<std::vector<AttrPtr>> attrs)
{
if ( flavor == FUNC_FLAVOR_EVENT )
{
@ -631,31 +628,31 @@ void begin_func(IDPtr id, const char* module_name,
if ( id_flavor != flavor )
id->Error("inconsistent function flavor", t.get());
switch ( id_flavor ) {
switch ( id_flavor )
{
case FUNC_FLAVOR_EVENT:
case FUNC_FLAVOR_HOOK:
if ( is_redef )
// Clear out value so it will be replaced.
id->SetVal(nullptr);
break;
case FUNC_FLAVOR_EVENT:
case FUNC_FLAVOR_HOOK:
if ( is_redef )
// Clear out value so it will be replaced.
id->SetVal(nullptr);
break;
case FUNC_FLAVOR_FUNCTION:
if ( ! id->IsRedefinable() )
id->Error("already defined", t.get());
break;
case FUNC_FLAVOR_FUNCTION:
if ( ! id->IsRedefinable() )
id->Error("already defined", t.get());
break;
default:
reporter->InternalError("invalid function flavor");
break;
}
default:
reporter->InternalError("invalid function flavor");
break;
}
}
else
id->SetType(t);
if ( IsErrorType(id->GetType()->Tag()) )
reporter->FatalError("invalid definition of '%s' (see previous errors)",
id->Name());
reporter->FatalError("invalid definition of '%s' (see previous errors)", id->Name());
const auto& args = t->Params();
const auto& canon_args = id->GetType()->AsFuncType()->Params();
@ -670,19 +667,17 @@ void begin_func(IDPtr id, const char* module_name,
current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr());
}
class OuterIDBindingFinder : public TraversalCallback {
class OuterIDBindingFinder : public TraversalCallback
{
public:
OuterIDBindingFinder(ScopePtr s)
{
scopes.emplace_back(s);
}
OuterIDBindingFinder(ScopePtr s) { scopes.emplace_back(s); }
TraversalCode PreExpr(const Expr*) override;
TraversalCode PostExpr(const Expr*) override;
std::vector<ScopePtr> scopes;
std::unordered_set<ID*> outer_id_references;
};
};
TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
{
@ -737,18 +732,11 @@ void end_func(StmtPtr body)
if ( ingredients->id->HasVal() )
ingredients->id->GetVal()->AsFunc()->AddBody(
ingredients->body,
ingredients->inits,
ingredients->frame_size,
ingredients->priority);
ingredients->body, ingredients->inits, ingredients->frame_size, ingredients->priority);
else
{
auto f = make_intrusive<ScriptFunc>(
ingredients->id,
ingredients->body,
ingredients->inits,
ingredients->frame_size,
ingredients->priority);
auto f = make_intrusive<ScriptFunc>(ingredients->id, ingredients->body, ingredients->inits,
ingredients->frame_size, ingredients->priority);
ingredients->id->SetVal(make_intrusive<FuncVal>(std::move(f)));
ingredients->id->SetConst();
@ -779,4 +767,4 @@ IDPList gather_outer_ids(ScopePtr scope, StmtPtr body)
return idl;
}
} // namespace zeek::detail
} // namespace zeek::detail