Add is_atomic_type() overloads for IntrusivePtr

This commit is contained in:
Jon Siwek 2020-05-21 22:53:10 -07:00
parent 6a1c312451
commit 457c08f531
4 changed files with 10 additions and 6 deletions

View file

@ -606,10 +606,10 @@ SwitchStmt::SwitchStmt(IntrusivePtr<Expr> index, case_list* arg_cases)
{ {
have_exprs = true; have_exprs = true;
if ( ! is_atomic_type(e->GetType().get()) ) if ( ! is_atomic_type(e->GetType()) )
e->Error("switch expression must be of an atomic type when cases are expressions"); e->Error("switch expression must be of an atomic type when cases are expressions");
if ( ! le->GetType()->AsTypeList()->AllMatch(e->GetType().get(), false) ) if ( ! le->GetType()->AsTypeList()->AllMatch(e->GetType(), false) )
{ {
le->Error("case expression type differs from switch type", e.get()); le->Error("case expression type differs from switch type", e.get());
continue; continue;

View file

@ -2082,9 +2082,9 @@ IntrusivePtr<BroType> init_type(Expr* init)
nullptr); nullptr);
} }
bool is_atomic_type(const BroType* t) bool is_atomic_type(const BroType& t)
{ {
switch ( t->InternalType() ) { switch ( t.InternalType() ) {
case TYPE_INTERNAL_INT: case TYPE_INTERNAL_INT:
case TYPE_INTERNAL_UNSIGNED: case TYPE_INTERNAL_UNSIGNED:
case TYPE_INTERNAL_DOUBLE: case TYPE_INTERNAL_DOUBLE:

View file

@ -860,7 +860,11 @@ IntrusivePtr<BroType> merge_type_list(ListExpr* elements);
IntrusivePtr<BroType> init_type(Expr* init); IntrusivePtr<BroType> init_type(Expr* init);
// Returns true if argument is an atomic type. // Returns true if argument is an atomic type.
bool is_atomic_type(const BroType* t); bool is_atomic_type(const BroType& t);
inline bool is_atomic_type(const BroType* t)
{ return is_atomic_type(*t); }
inline bool is_atomic_type(const IntrusivePtr<BroType>& t)
{ return is_atomic_type(*t); }
// True if the given type tag corresponds to type that can be assigned to. // True if the given type tag corresponds to type that can be assigned to.
extern bool is_assignable(BroType* t); extern bool is_assignable(BroType* t);

View file

@ -3305,7 +3305,7 @@ bool same_val(const Val* /* v1 */, const Val* /* v2 */)
bool is_atomic_val(const Val* v) bool is_atomic_val(const Val* v)
{ {
return is_atomic_type(v->GetType().get()); return is_atomic_type(v->GetType());
} }
bool same_atomic_val(const Val* v1, const Val* v2) bool same_atomic_val(const Val* v1, const Val* v2)