fixed / removed out-of-date comments, tidied check_and_promote_args() interface

This commit is contained in:
Vern Paxson 2021-05-30 17:25:40 -07:00
parent efd03d41f8
commit a16a25efbd
4 changed files with 15 additions and 21 deletions

View file

@ -2954,7 +2954,7 @@ ValPtr IndexExpr::Fold(Val* v1, Val* v2) const
break; break;
case TYPE_TABLE: case TYPE_TABLE:
v = v1->AsTableVal()->FindOrDefault({NewRef{}, v2}); // Then, we jump into the TableVal here. v = v1->AsTableVal()->FindOrDefault({NewRef{}, v2});
break; break;
case TYPE_STRING: case TYPE_STRING:
@ -5286,7 +5286,7 @@ bool check_and_promote_exprs(ListExpr* const elements, TypeList* types)
return true; return true;
} }
bool check_and_promote_args(ListExpr* const args, RecordType* types) bool check_and_promote_args(ListExpr* const args, const RecordType* types)
{ {
ExprPList& el = args->Exprs(); ExprPList& el = args->Exprs();
int ntypes = types->NumFields(); int ntypes = types->NumFields();
@ -5303,7 +5303,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types)
// arguments using &default expressions. // arguments using &default expressions.
for ( int i = ntypes - 1; i >= el.length(); --i ) for ( int i = ntypes - 1; i >= el.length(); --i )
{ {
TypeDecl* td = types->FieldDecl(i); auto td = types->FieldDecl(i);
const auto& def_attr = td->attrs ? td->attrs->Find(ATTR_DEFAULT).get() : nullptr; const auto& def_attr = td->attrs ? td->attrs->Find(ATTR_DEFAULT).get() : nullptr;
if ( ! def_attr ) if ( ! def_attr )

View file

@ -1645,25 +1645,21 @@ ExprPtr get_assign_expr(
ExprPtr op1, ExprPtr op1,
ExprPtr op2, bool is_init); ExprPtr op2, bool is_init);
// Type-check the given expression(s) against the given type(s). Complain
// if the expression cannot match the given type, returning 0. If it can
// match, promote it as necessary (modifying the ref parameter accordingly)
// and return 1.
//
// The second, third, and fourth forms are for promoting a list of
// expressions (which is updated in place) to either match a list of
// types or a single type.
//
// Note, the type is not "const" because it can be ref'd.
/** /**
* Returns nullptr if the expression cannot match or a promoted * Type-check the given expression(s) against the given type(s). Complain
* expression. * if the expression cannot match the given type, returning nullptr;
* otherwise, returns an expression reflecting the promotion.
*
* The second, third, and fourth forms are for promoting a list of
* expressions (which is updated in place) to either match a list of
* types or a single type.
*
* Note, the type is not "const" because it can be ref'd.
*/ */
extern ExprPtr check_and_promote_expr(Expr* e, Type* t); extern ExprPtr check_and_promote_expr(Expr* e, Type* t);
extern bool check_and_promote_exprs(ListExpr* elements, TypeList* types); extern bool check_and_promote_exprs(ListExpr* elements, TypeList* types);
extern bool check_and_promote_args(ListExpr* args, RecordType* types); extern bool check_and_promote_args(ListExpr* args, const RecordType* types);
extern bool check_and_promote_exprs_to_type(ListExpr* elements, Type* type); extern bool check_and_promote_exprs_to_type(ListExpr* elements, Type* type);
// Returns a ListExpr simplified down to a list a values, or nil // Returns a ListExpr simplified down to a list a values, or nil

View file

@ -33,7 +33,7 @@ using ListExprPtr = IntrusivePtr<ListExpr>;
} // namespace detail } // namespace detail
// BRO types. // Zeek types.
enum TypeTag { enum TypeTag {
TYPE_VOID, // 0 TYPE_VOID, // 0
TYPE_BOOL, // 1 TYPE_BOOL, // 1
@ -171,7 +171,7 @@ public:
explicit Type(TypeTag tag, bool base_type = false); explicit Type(TypeTag tag, bool base_type = false);
// Performs a shallow clone operation of the Bro type. // Performs a shallow clone operation of the Zeek type.
// This especially means that especially for tables the types // This especially means that especially for tables the types
// are not recursively cloned; altering one type will in this case // are not recursively cloned; altering one type will in this case
// alter one of them. // alter one of them.

View file

@ -231,8 +231,6 @@ ValPtr Val::SizeVal() const
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {
case TYPE_INTERNAL_INT: case TYPE_INTERNAL_INT:
// Return abs value. However abs() only works on ints and llabs
// doesn't work on Mac OS X 10.5. So we do it by hand
if ( AsInt() < 0 ) if ( AsInt() < 0 )
return val_mgr->Count(-AsInt()); return val_mgr->Count(-AsInt());
else else