Superficial changes to script-opt related code

* Rename overly generic ACCESSORS macro with ZEEK_ prefix
* A few places where whitespace was noticeably wrong/distracting
* Minor/obvious reference/move semantics improvements suggested by linter
* Remove unused detail::Scope::Remove(), no need for deprecation
This commit is contained in:
Jon Siwek 2020-12-13 10:33:28 -08:00
parent ff7d9e3d72
commit 481d989495
9 changed files with 23 additions and 46 deletions

View file

@ -179,19 +179,18 @@ public:
void MarkParen() { paren = true; }
bool IsParen() const { return paren; }
#undef ACCESSORS
#define ACCESSORS(ctype) \
#define ZEEK_EXPR_ACCESSOR_DECLS(ctype) \
const ctype* As ## ctype () const; \
ctype* As ## ctype (); \
IntrusivePtr<ctype> As ## ctype ## Ptr ();
ACCESSORS(ListExpr)
ACCESSORS(NameExpr)
ACCESSORS(ConstExpr)
ACCESSORS(CallExpr)
ACCESSORS(AssignExpr)
ACCESSORS(IndexExpr)
ACCESSORS(EventExpr)
ZEEK_EXPR_ACCESSOR_DECLS(ListExpr)
ZEEK_EXPR_ACCESSOR_DECLS(NameExpr)
ZEEK_EXPR_ACCESSOR_DECLS(ConstExpr)
ZEEK_EXPR_ACCESSOR_DECLS(CallExpr)
ZEEK_EXPR_ACCESSOR_DECLS(AssignExpr)
ZEEK_EXPR_ACCESSOR_DECLS(IndexExpr)
ZEEK_EXPR_ACCESSOR_DECLS(EventExpr)
void Describe(ODesc* d) const override final;
@ -770,7 +769,7 @@ public:
TableConstructorExpr(ListExprPtr constructor_list,
std::unique_ptr<std::vector<AttrPtr>> attrs,
TypePtr arg_type = nullptr,
AttributesPtr arg_attrs = nullptr);
AttributesPtr arg_attrs = nullptr);
[[deprecated("Remove in v4.1. Use GetAttrs().")]]
Attributes* Attrs() { return attrs.get(); }

View file

@ -105,7 +105,7 @@ public:
* @param incr Amount by which to increase the frame offset.
* Use a negative value to shrink the offset.
*/
void IncreaseOffset(int incr) { current_offset += incr; }
void IncreaseOffset(int incr) { current_offset += incr; }
/**
* Resets all of the indexes from [*startIdx, frame_size) in
@ -325,7 +325,8 @@ private:
/** Associates ID's offsets with values. */
std::unique_ptr<Element[]> frame;
/** The offset we're currently using for references into the frame.
/**
* The offset we're currently using for references into the frame.
* This is how we support inlined functions without having to
* alter the offsets associated with their local variables.
*/

View file

@ -63,17 +63,11 @@ public:
~Func() override;
zeek::detail::ScriptFunc* AsScriptFunc()
{
return GetKind() == SCRIPT_FUNC ?
(zeek::detail::ScriptFunc*) this : nullptr;
}
zeek::detail::ScriptFunc* AsScriptFunc()
{ return GetKind() == SCRIPT_FUNC ? (detail::ScriptFunc*) this : nullptr; }
const zeek::detail::ScriptFunc* AsScriptFunc() const
{
return GetKind() == SCRIPT_FUNC ?
(zeek::detail::ScriptFunc*) this : nullptr;
}
const zeek::detail::ScriptFunc* AsScriptFunc() const
{ return GetKind() == SCRIPT_FUNC ? (detail::ScriptFunc*) this : nullptr; }
virtual bool IsPure() const = 0;
FunctionFlavor Flavor() const { return GetType()->Flavor(); }

View file

@ -47,20 +47,6 @@ const IDPtr& Scope::Find(std::string_view name) const
return ID::nil;
}
IDPtr Scope::Remove(std::string_view name)
{
auto entry = local.find(name);
if ( entry != local.end() )
{
auto id = std::move(entry->second);
local.erase(entry);
return id;
}
return nullptr;
}
IDPtr Scope::GenerateTemporary(const char* name)
{
return make_intrusive<ID>(name, SCOPE_FUNCTION, false);

View file

@ -50,9 +50,6 @@ public:
ordered_vars.push_back(std::forward<I>(id));
}
IDPtr Remove(std::string_view name);
[[deprecated("Remove in v4.1 as an unused API call.")]]
[[deprecated("Remove in v4.1. Use GetID().")]]
ID* ScopeID() const { return scope_id.get(); }

View file

@ -171,7 +171,7 @@ ExprPtr Inliner::CheckForInlining(IntrusivePtr<CallExpr> c)
if ( ! func->IsGlobal() )
return std::move(c);
auto func_v = func->GetVal();
const auto& func_v = func->GetVal();
if ( ! func_v )
return std::move(c);

View file

@ -20,7 +20,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s)
if ( tag == STMT_INIT )
{
for ( auto id : s->AsInitStmt()->Inits() )
for ( const auto& id : s->AsInitStmt()->Inits() )
inits.insert(id.get());
// Don't recurse into these, as we don't want to consider

View file

@ -34,9 +34,9 @@ class FuncInfo {
public:
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body)
{
func = _func;
scope = _scope;
body = _body;
func = std::move(_func);
scope = std::move(_scope);
body = std::move(_body);
}
~FuncInfo();

View file

@ -159,8 +159,8 @@ StmtPtr ReturnStmt::Duplicate()
ReturnStmt::ReturnStmt(ExprPtr arg_e, bool ignored)
: ExprStmt(STMT_RETURN, std::move(arg_e))
{
}
{
}
StmtPtr StmtList::Duplicate()