diff --git a/src/Expr.h b/src/Expr.h index 08301de0d8..524cd1440d 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -22,8 +22,6 @@ namespace zeek { template class IntrusivePtr; -using ObjPtr = IntrusivePtr; - namespace detail { class Frame; @@ -1794,28 +1792,8 @@ inline bool is_vector(const ExprPtr& e) { return is_vector(e.get()); } // True if the given Expr* has a list type inline bool is_list(Expr* e) { return e->GetType()->Tag() == TYPE_LIST; } + inline bool is_list(const ExprPtr& e) { return is_list(e.get()); } -// Helper functions for setting the location of an expression (usually newly -// created) to match that of the associated object, returning the expression -// for convenience. -inline ExprPtr with_location_of(ExprPtr e, const Obj* o) { - e->SetLocationInfo(o->GetLocationInfo()); - return e; -} - -inline ExprPtr with_location_of(ExprPtr e, const ObjPtr& o) { return with_location_of(e, o.get()); } - -// Versions that preserve the expression as a ListExpr. -inline ListExprPtr with_location_of(ListExprPtr e, const ObjPtr& o) { - (void)with_location_of(e, o.get()); - return e; -} - -inline ListExprPtr with_location_of(ListExprPtr e, const Obj* o) { - e->SetLocationInfo(o->GetLocationInfo()); - return e; -} - } // namespace detail } // namespace zeek diff --git a/src/Obj.h b/src/Obj.h index fda839d6f0..492679cf3e 100644 --- a/src/Obj.h +++ b/src/Obj.h @@ -49,6 +49,13 @@ inline void set_location(const Location start, const Location end) { end_location = end; } +// Helper for updating e's location to the one used by o, returning e. +template +T with_location_of(T e, const U& o) { + e->SetLocationInfo(o->GetLocationInfo()); + return e; +} + } // namespace detail class Obj { diff --git a/src/Stmt.h b/src/Stmt.h index caf93f59e3..054bf263eb 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -780,25 +780,4 @@ protected: int expected_len; }; -// Helper functions for setting the location of a statement (usually newly -// created) to match that of the associated object, returning the statement -// for convenience. -inline StmtPtr with_location_of(StmtPtr s, const Obj* o) { - s->SetLocationInfo(o->GetLocationInfo()); - return s; -} - -inline StmtPtr with_location_of(StmtPtr s, const ObjPtr& o) { return with_location_of(s, o.get()); } - -// Versions that preserve the statement as a StmtList. -inline IntrusivePtr with_location_of(IntrusivePtr s, const ObjPtr& o) { - (void)with_location_of(s, o.get()); - return s; -} - -inline IntrusivePtr with_location_of(IntrusivePtr s, const Obj* o) { - s->SetLocationInfo(o->GetLocationInfo()); - return s; -} - } // namespace zeek::detail