mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fix various compiler/linter warnings in script_opt/CPP code
This commit is contained in:
parent
e200016200
commit
3e85375010
15 changed files with 43 additions and 41 deletions
|
@ -322,7 +322,7 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft,
|
|||
auto n = bs.size();
|
||||
ASSERT(n == priorities.size());
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
{
|
||||
Body b;
|
||||
b.stmts = std::move(bs[i]);
|
||||
|
|
|
@ -86,9 +86,8 @@ void CPPCompile::GenAttrs(const AttributesPtr& attrs)
|
|||
|
||||
AddInit(attrs);
|
||||
|
||||
for ( auto i = 0; i < avec.size(); ++i )
|
||||
for ( const auto& attr : avec )
|
||||
{
|
||||
const auto& attr = avec[i];
|
||||
const auto& e = attr->GetExpr();
|
||||
|
||||
if ( ! e )
|
||||
|
@ -171,7 +170,7 @@ const char* CPPCompile::AttrName(const AttrPtr& attr)
|
|||
case ATTR_IS_ASSIGNED: return "ATTR_IS_ASSIGNED";
|
||||
case ATTR_IS_USED: return "ATTR_IS_USED";
|
||||
|
||||
case NUM_ATTRS: return "<busted>";
|
||||
default: return "<busted>";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
%%{ // C segment
|
||||
|
||||
#include <cinttypes>
|
||||
#
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/script_opt/ScriptOpt.h"
|
||||
#include "zeek/script_opt/CPP/Func.h"
|
||||
|
@ -22,7 +24,7 @@ function load_CPP%(h: count%): bool
|
|||
|
||||
if ( cb == detail::standalone_callbacks.end() )
|
||||
{
|
||||
reporter->Error("load of non-existing C++ code (%llu)", h);
|
||||
reporter->Error("load of non-existing C++ code (%" PRIu64 ")", h);
|
||||
return zeek::val_mgr->False();
|
||||
}
|
||||
|
||||
|
|
|
@ -233,14 +233,14 @@ void CPPCompile::AddRecordConstant(const ValPtr& v, string& const_name)
|
|||
auto r = cast_intrusive<RecordVal>(v);
|
||||
auto n = r->NumFields();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
{
|
||||
const auto& r_i = r->GetField(i);
|
||||
|
||||
if ( r_i )
|
||||
{
|
||||
auto r_i_c = BuildConstant(v, r_i);
|
||||
AddInit(v, const_name + "->Assign(" + Fmt(i) +
|
||||
AddInit(v, const_name + "->Assign(" + Fmt(static_cast<int>(i)) +
|
||||
", " + r_i_c + ");");
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ void CPPCompile::AddVectorConstant(const ValPtr& v, string& const_name)
|
|||
auto vv = cast_intrusive<VectorVal>(v);
|
||||
auto n = vv->Size();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
{
|
||||
const auto& v_i = vv->ValAt(i);
|
||||
auto v_i_c = BuildConstant(v, v_i);
|
||||
|
|
|
@ -19,7 +19,7 @@ void CPPCompile::DeclareFunc(const FuncInfo& func)
|
|||
auto fname = Canonicalize(BodyName(func).c_str()) + "_zf";
|
||||
auto pf = func.Profile();
|
||||
auto f = func.Func();
|
||||
auto body = func.Body();
|
||||
const auto& body = func.Body();
|
||||
auto priority = func.Priority();
|
||||
|
||||
DeclareSubclass(f->GetType(), pf, fname, body, priority, nullptr,
|
||||
|
@ -133,7 +133,7 @@ void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf,
|
|||
body_hashes[fname] = h;
|
||||
body_priorities[fname] = priority;
|
||||
body_names.emplace(body.get(), fname);
|
||||
names_to_bodies.emplace(move(fname), body.get());
|
||||
names_to_bodies.emplace(fname, body.get());
|
||||
|
||||
total_hash = merge_p_hashes(total_hash, h);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,9 @@ void CPPCompile::Compile()
|
|||
// as a way to identify this compilation. Only germane when doing
|
||||
// incremental compilation (particularly of the test suite).
|
||||
char buf[8192];
|
||||
getcwd(buf, sizeof buf);
|
||||
if ( ! getcwd(buf, sizeof buf) )
|
||||
reporter->FatalError("getcwd failed: %s", strerror(errno));
|
||||
|
||||
working_dir = buf;
|
||||
|
||||
if ( update && addl_tag > 0 && CheckForCollisions() )
|
||||
|
@ -212,7 +214,7 @@ void CPPCompile::RegisterCompiledBody(const string& f)
|
|||
// Build up an initializer of the events relevant to the function.
|
||||
string events;
|
||||
if ( body_events.count(f) > 0 )
|
||||
for ( auto e : body_events[f] )
|
||||
for ( const auto& e : body_events[f] )
|
||||
{
|
||||
if ( events.size() > 0 )
|
||||
events += ", ";
|
||||
|
|
|
@ -638,7 +638,7 @@ string CPPCompile::GenSetConstructorExpr(const Expr* e)
|
|||
{
|
||||
auto sc = static_cast<const SetConstructorExpr*>(e);
|
||||
const auto& t = sc->GetType();
|
||||
auto attrs = sc->GetAttrs();
|
||||
const auto& attrs = sc->GetAttrs();
|
||||
|
||||
string attr_tags;
|
||||
string attr_vals;
|
||||
|
@ -654,7 +654,7 @@ string CPPCompile::GenTableConstructorExpr(const Expr* e)
|
|||
{
|
||||
auto tc = static_cast<const TableConstructorExpr*>(e);
|
||||
const auto& t = tc->GetType();
|
||||
auto attrs = tc->GetAttrs();
|
||||
const auto& attrs = tc->GetAttrs();
|
||||
|
||||
string attr_tags;
|
||||
string attr_vals;
|
||||
|
@ -1126,7 +1126,7 @@ string CPPCompile::GenIntVector(const vector<int>& vec)
|
|||
{
|
||||
string res("{ ");
|
||||
|
||||
for ( auto i = 0; i < vec.size(); ++i )
|
||||
for ( auto i = 0u; i < vec.size(); ++i )
|
||||
{
|
||||
res += Fmt(vec[i]);
|
||||
|
||||
|
|
|
@ -36,9 +36,8 @@ broker::expected<broker::data> CPPLambdaFunc::SerializeClosure() const
|
|||
|
||||
broker::vector body;
|
||||
|
||||
for ( int i = 0; i < vals.size(); ++i )
|
||||
for ( const auto& val : vals )
|
||||
{
|
||||
const auto& val = vals[i];
|
||||
auto expected = Broker::detail::val_to_data(val.get());
|
||||
if ( ! expected )
|
||||
return broker::ec::invalid_data;
|
||||
|
|
|
@ -19,7 +19,7 @@ void CPPCompile::CompileFunc(const FuncInfo& func)
|
|||
auto fname = Canonicalize(BodyName(func).c_str()) + "_zf";
|
||||
auto pf = func.Profile();
|
||||
auto f = func.Func();
|
||||
auto body = func.Body();
|
||||
const auto& body = func.Body();
|
||||
|
||||
DefineBody(f->GetType(), pf, fname, body, nullptr, f->Flavor());
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ string CPPCompile::BodyName(const FuncInfo& func)
|
|||
|
||||
// Make the name distinct-per-body.
|
||||
|
||||
int i;
|
||||
size_t i;
|
||||
for ( i = 0; i < bodies.size(); ++i )
|
||||
if ( bodies[i].stmts == body )
|
||||
break;
|
||||
|
@ -231,7 +231,7 @@ string CPPCompile::BodyName(const FuncInfo& func)
|
|||
if ( i >= bodies.size() )
|
||||
reporter->InternalError("can't find body in CPPCompile::BodyName");
|
||||
|
||||
return fname + "__" + Fmt(i);
|
||||
return fname + "__" + Fmt(static_cast<int>(i));
|
||||
}
|
||||
|
||||
string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e)
|
||||
|
@ -258,7 +258,7 @@ string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e)
|
|||
if ( ! param_any && arg_any )
|
||||
expr_gen = GenericValPtrToGT(expr_gen, param_t, GEN_NATIVE);
|
||||
|
||||
gen = gen + expr_gen;
|
||||
gen += expr_gen;
|
||||
if ( i < n - 1 )
|
||||
gen += ", ";
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ void CPPCompile::GenFuncVarInits()
|
|||
|
||||
string hashes = "{";
|
||||
|
||||
for ( auto b : bodies )
|
||||
for ( const auto& b : bodies )
|
||||
{
|
||||
auto body = b.stmts.get();
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ ListValPtr index_val__CPP(vector<ValPtr> indices)
|
|||
|
||||
// In the future, we could provide N versions of this that
|
||||
// unroll the loop.
|
||||
for ( auto i : indices )
|
||||
for ( const auto& i : indices )
|
||||
ind_v->Append(i);
|
||||
|
||||
return ind_v;
|
||||
|
@ -61,7 +61,7 @@ ValPtr index_string__CPP(const StringValPtr& svp, vector<ValPtr> indices)
|
|||
|
||||
ValPtr set_event__CPP(IDPtr g, ValPtr v, EventHandlerPtr& gh)
|
||||
{
|
||||
g->SetVal(move(v));
|
||||
g->SetVal(v);
|
||||
gh = event_registry->Register(g->Name());
|
||||
return v;
|
||||
}
|
||||
|
@ -116,15 +116,15 @@ ValPtr assign_to_index__CPP(T v1, ValPtr v2, ValPtr v3)
|
|||
|
||||
ValPtr assign_to_index__CPP(TableValPtr v1, ValPtr v2, ValPtr v3)
|
||||
{
|
||||
return assign_to_index__CPP<TableValPtr>(v1, v2, v3);
|
||||
return assign_to_index__CPP<TableValPtr>(std::move(v1), std::move(v2), std::move(v3));
|
||||
}
|
||||
ValPtr assign_to_index__CPP(VectorValPtr v1, ValPtr v2, ValPtr v3)
|
||||
{
|
||||
return assign_to_index__CPP<VectorValPtr>(v1, v2, v3);
|
||||
return assign_to_index__CPP<VectorValPtr>(std::move(v1), std::move(v2), std::move(v3));
|
||||
}
|
||||
ValPtr assign_to_index__CPP(StringValPtr v1, ValPtr v2, ValPtr v3)
|
||||
{
|
||||
return assign_to_index__CPP<StringValPtr>(v1, v2, v3);
|
||||
return assign_to_index__CPP<StringValPtr>(std::move(v1), std::move(v2), std::move(v3));
|
||||
}
|
||||
|
||||
void add_element__CPP(TableValPtr aggr, ListValPtr indices)
|
||||
|
@ -172,7 +172,7 @@ TableValPtr set_constructor__CPP(vector<ValPtr> elements, TableTypePtr t,
|
|||
auto attrs = build_attrs__CPP(move(attr_tags), move(attr_vals));
|
||||
auto aggr = make_intrusive<TableVal>(move(t), move(attrs));
|
||||
|
||||
for ( const auto& elem : elements )
|
||||
for ( auto& elem : elements )
|
||||
aggr->Assign(move(elem), nullptr);
|
||||
|
||||
return aggr;
|
||||
|
@ -188,7 +188,7 @@ TableValPtr table_constructor__CPP(vector<ValPtr> indices, vector<ValPtr> vals,
|
|||
auto attrs = build_attrs__CPP(move(attr_tags), move(attr_vals));
|
||||
auto aggr = make_intrusive<TableVal>(move(t), move(attrs));
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
{
|
||||
auto v = check_and_promote(vals[i], yt, true);
|
||||
if ( v )
|
||||
|
@ -205,7 +205,7 @@ RecordValPtr record_constructor__CPP(vector<ValPtr> vals, RecordTypePtr t)
|
|||
|
||||
rv->Reserve(n);
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
rv->Assign(i, vals[i]);
|
||||
|
||||
return rv;
|
||||
|
@ -216,7 +216,7 @@ VectorValPtr vector_constructor__CPP(vector<ValPtr> vals, VectorTypePtr t)
|
|||
auto vv = make_intrusive<VectorVal>(move(t));
|
||||
auto n = vals.size();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
vv->Assign(i, vals[i]);
|
||||
|
||||
return vv;
|
||||
|
|
|
@ -140,10 +140,10 @@ void CPPCompile::ExpandTypeVar(const TypePtr& t)
|
|||
|
||||
void CPPCompile::ExpandListTypeVar(const TypePtr& t, string& tn)
|
||||
{
|
||||
auto tl = t->AsTypeList()->GetTypes();
|
||||
const auto& tl = t->AsTypeList()->GetTypes();
|
||||
auto t_name = tn + "->AsTypeList()";
|
||||
|
||||
for ( auto i = 0; i < tl.size(); ++i )
|
||||
for ( auto i = 0u; i < tl.size(); ++i )
|
||||
AddInit(t, t_name + "->Append(" +
|
||||
GenTypeName(tl[i]) + ");");
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ void CPPCompile::ExpandFuncTypeVar(const TypePtr& t, string& tn)
|
|||
auto f = t->AsFuncType();
|
||||
|
||||
auto args_type_accessor = GenTypeName(f->Params());
|
||||
auto yt = f->Yield();
|
||||
const auto& yt = f->Yield();
|
||||
|
||||
string yield_type_accessor;
|
||||
|
||||
|
@ -447,9 +447,9 @@ void CPPCompile::RegisterType(const TypePtr& tp)
|
|||
|
||||
void CPPCompile::RegisterListType(const TypePtr& t)
|
||||
{
|
||||
auto tl = t->AsTypeList()->GetTypes();
|
||||
const auto& tl = t->AsTypeList()->GetTypes();
|
||||
|
||||
for ( auto i = 0; i < tl.size(); ++i )
|
||||
for ( auto i = 0u; i < tl.size(); ++i )
|
||||
{
|
||||
NoteNonRecordInitDependency(t, tl[i]);
|
||||
RegisterType(tl[i]);
|
||||
|
|
|
@ -241,7 +241,7 @@ string CPPCompile::Canonicalize(const char* name) const
|
|||
if ( c == ':' || c == '-' )
|
||||
c = '_';
|
||||
|
||||
cname = cname + c;
|
||||
cname += c;
|
||||
}
|
||||
|
||||
// Add a trailing '_' to avoid conflicts with C++ keywords.
|
||||
|
|
|
@ -483,7 +483,7 @@ void ProfileFuncs::MergeInProfile(ProfileFunc* pf)
|
|||
(void) HashType(t->AsTypeType()->GetType());
|
||||
|
||||
auto& init_exprs = g->GetInitExprs();
|
||||
for ( auto i_e : init_exprs )
|
||||
for ( const auto& i_e : init_exprs )
|
||||
if ( i_e )
|
||||
{
|
||||
pending_exprs.push_back(i_e.get());
|
||||
|
@ -550,7 +550,7 @@ void ProfileFuncs::TraverseValue(const ValPtr& v)
|
|||
auto r = cast_intrusive<RecordVal>(v);
|
||||
auto n = r->NumFields();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
TraverseValue(r->GetField(i));
|
||||
}
|
||||
break;
|
||||
|
@ -583,7 +583,7 @@ void ProfileFuncs::TraverseValue(const ValPtr& v)
|
|||
auto vv = cast_intrusive<VectorVal>(v);
|
||||
auto n = vv->Size();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
for ( auto i = 0u; i < n; ++i )
|
||||
TraverseValue(vv->ValAt(i));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -334,7 +334,7 @@ void analyze_scripts()
|
|||
|
||||
printf("\nAdditional C++ script bodies available:\n");
|
||||
int addl = 0;
|
||||
for ( auto s : compiled_scripts )
|
||||
for ( const auto& s : compiled_scripts )
|
||||
if ( already_reported.count(s.first) == 0 )
|
||||
{
|
||||
printf("%s body (hash %llu)\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue