Completely remove all traces of the COUNTER type.

Relates to GH-1095
This commit is contained in:
Johanna Amann 2020-07-30 12:10:54 -07:00
parent 01fa5611ef
commit 417a6eb1e9
28 changed files with 79 additions and 140 deletions

View file

@ -782,7 +782,6 @@ const char* CompositeHash::RecoverOneVal(
switch ( tag ) {
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
*pval = zeek::val_mgr->Count(*kp);
break;

View file

@ -1685,12 +1685,9 @@ BitExpr::BitExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2)
if ( IsVector(bt2) )
bt2 = t2->AsVectorType()->Yield()->Tag();
if ( (bt1 == zeek::TYPE_COUNT || bt1 == zeek::TYPE_COUNTER) &&
(bt2 == zeek::TYPE_COUNT || bt2 == zeek::TYPE_COUNTER) )
if ( (bt1 == zeek::TYPE_COUNT) && (bt2 == zeek::TYPE_COUNT) )
{
if ( bt1 == zeek::TYPE_COUNTER && bt2 == zeek::TYPE_COUNTER )
ExprError("cannot apply a bitwise operator to two \"counter\" operands");
else if ( is_vector(op1) || is_vector(op2) )
if ( is_vector(op1) || is_vector(op2) )
SetType(zeek::make_intrusive<zeek::VectorType>(base_type(zeek::TYPE_COUNT)));
else
SetType(base_type(zeek::TYPE_COUNT));

View file

@ -34,28 +34,27 @@ const char* type_name(zeek::TypeTag t)
"bool", // 1
"int", // 2
"count", // 3
"counter", // 4
"double", // 5
"time", // 6
"interval", // 7
"string", // 8
"pattern", // 9
"enum", // 10
"timer", // 11
"port", // 12
"addr", // 13
"subnet", // 14
"any", // 15
"table", // 16
"union", // 17
"record", // 18
"types", // 19
"func", // 20
"file", // 21
"vector", // 22
"opaque", // 23
"type", // 24
"error", // 25
"double", // 4
"time", // 5
"interval", // 6
"string", // 7
"pattern", // 8
"enum", // 9
"timer", // 10
"port", // 11
"addr", // 12
"subnet", // 13
"any", // 14
"table", // 15
"union", // 16
"record", // 17
"types", // 18
"func", // 19
"file", // 20
"vector", // 21
"opaque", // 22
"type", // 23
"error", // 24
};
if ( int(t) >= NUM_TYPES )
@ -203,7 +202,6 @@ TypePtr Type::ShallowClone()
case TYPE_BOOL:
case TYPE_INT:
case TYPE_COUNT:
case TYPE_COUNTER:
case TYPE_DOUBLE:
case TYPE_TIME:
case TYPE_INTERVAL:
@ -1543,7 +1541,6 @@ bool same_type(const Type& arg_t1, const Type& arg_t2,
case TYPE_BOOL:
case TYPE_INT:
case TYPE_COUNT:
case TYPE_COUNTER:
case TYPE_DOUBLE:
case TYPE_TIME:
case TYPE_INTERVAL:
@ -1745,7 +1742,6 @@ bool is_assignable(TypeTag t)
case TYPE_BOOL:
case TYPE_INT:
case TYPE_COUNT:
case TYPE_COUNTER:
case TYPE_DOUBLE:
case TYPE_TIME:
case TYPE_INTERVAL:
@ -1797,8 +1793,6 @@ TypeTag max_type(TypeTag t1, TypeTag t2)
CHECK_TYPE(TYPE_INT);
CHECK_TYPE(TYPE_COUNT);
// Note - mixing two TYPE_COUNTER's still promotes to
// a TYPE_COUNT.
return TYPE_COUNT;
}
else

View file

@ -39,28 +39,27 @@ enum TypeTag {
TYPE_BOOL, // 1
TYPE_INT, // 2
TYPE_COUNT, // 3
TYPE_COUNTER, // 4
TYPE_DOUBLE, // 5
TYPE_TIME, // 6
TYPE_INTERVAL, // 7
TYPE_STRING, // 8
TYPE_PATTERN, // 9
TYPE_ENUM, // 10
TYPE_TIMER, // 11
TYPE_PORT, // 12
TYPE_ADDR, // 13
TYPE_SUBNET, // 14
TYPE_ANY, // 15
TYPE_TABLE, // 16
TYPE_UNION, // 17
TYPE_RECORD, // 18
TYPE_LIST, // 19
TYPE_FUNC, // 20
TYPE_FILE, // 21
TYPE_VECTOR, // 22
TYPE_OPAQUE, // 23
TYPE_TYPE, // 24
TYPE_ERROR // 25
TYPE_DOUBLE, // 4
TYPE_TIME, // 5
TYPE_INTERVAL, // 6
TYPE_STRING, // 7
TYPE_PATTERN, // 8
TYPE_ENUM, // 9
TYPE_TIMER, // 10
TYPE_PORT, // 11
TYPE_ADDR, // 12
TYPE_SUBNET, // 13
TYPE_ANY, // 14
TYPE_TABLE, // 15
TYPE_UNION, // 16
TYPE_RECORD, // 17
TYPE_LIST, // 18
TYPE_FUNC, // 19
TYPE_FILE, // 20
TYPE_VECTOR, // 21
TYPE_OPAQUE, // 22
TYPE_TYPE, // 23
TYPE_ERROR // 24
#define NUM_TYPES (int(TYPE_ERROR) + 1)
};
@ -97,7 +96,6 @@ constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept
return TYPE_INTERNAL_INT;
case TYPE_COUNT:
case TYPE_COUNTER:
case TYPE_PORT:
return TYPE_INTERNAL_UNSIGNED;
@ -818,7 +816,7 @@ inline bool is_assignable(Type* t)
{ return zeek::is_assignable(t->Tag()); }
// True if the given type tag corresponds to an integral type.
inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); }
inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT ); }
// True if the given type tag corresponds to an arithmetic type.
inline bool IsArithmetic(TypeTag t) { return (IsIntegral(t) || t == TYPE_DOUBLE); }
@ -937,8 +935,6 @@ constexpr auto TYPE_BOOL = zeek::TYPE_BOOL;
constexpr auto TYPE_INT = zeek::TYPE_INT;
[[deprecated("Remove in v4.1. Use zeek::TYPE_COUNT instead.")]]
constexpr auto TYPE_COUNT = zeek::TYPE_COUNT;
[[deprecated("Remove in v4.1. Use zeek::TYPE_COUNTER instead.")]]
constexpr auto TYPE_COUNTER = zeek::TYPE_COUNTER;
[[deprecated("Remove in v4.1. Use zeek::TYPE_DOUBLE instead.")]]
constexpr auto TYPE_DOUBLE = zeek::TYPE_DOUBLE;
[[deprecated("Remove in v4.1. Use zeek::TYPE_TIME instead.")]]

View file

@ -517,10 +517,6 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
writer.Uint64(val->AsCount());
break;
case TYPE_COUNTER:
writer.Uint64(val->AsCounter());
break;
case TYPE_TIME:
writer.Double(val->AsTime());
break;
@ -3449,7 +3445,7 @@ ValPtr check_and_promote(ValPtr v,
t->Error("overflow promoting from signed/double to unsigned arithmetic value", v.get(), false, expr_location);
return nullptr;
}
else if ( t_tag == TYPE_COUNT || t_tag == TYPE_COUNTER )
else if ( t_tag == TYPE_COUNT )
promoted_v = zeek::val_mgr->Count(v->CoerceToUnsigned());
else // port
{

View file

@ -232,7 +232,6 @@ public:
CONST_ACCESSOR2(zeek::TYPE_BOOL, bool, int_val, AsBool)
CONST_ACCESSOR2(zeek::TYPE_INT, bro_int_t, int_val, AsInt)
CONST_ACCESSOR2(zeek::TYPE_COUNT, bro_uint_t, uint_val, AsCount)
CONST_ACCESSOR2(zeek::TYPE_COUNTER, bro_uint_t, uint_val, AsCounter)
CONST_ACCESSOR2(zeek::TYPE_DOUBLE, double, double_val, AsDouble)
CONST_ACCESSOR2(zeek::TYPE_TIME, double, double_val, AsTime)
CONST_ACCESSOR2(zeek::TYPE_INTERVAL, double, double_val, AsInterval)

View file

@ -117,7 +117,6 @@ zeek::ValPtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t)
case zeek::TYPE_INT:
return zeek::val_mgr->Int(v);
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return zeek::val_mgr->Count(v);
default:
reporter->Error("bad asn1_integer_to_val tag: %s", zeek::type_name(t));

View file

@ -93,8 +93,6 @@ struct val_converter {
{
if ( type->Tag() == zeek::TYPE_COUNT )
return zeek::val_mgr->Count(a);
if ( type->Tag() == zeek::TYPE_COUNTER )
return zeek::val_mgr->Count(a);
return nullptr;
}
@ -463,8 +461,6 @@ struct type_checker {
{
if ( type->Tag() == zeek::TYPE_COUNT )
return true;
if ( type->Tag() == zeek::TYPE_COUNTER )
return true;
return false;
}
@ -796,8 +792,6 @@ broker::expected<broker::data> bro_broker::val_to_data(const zeek::Val* v)
return {v->AsInt()};
case zeek::TYPE_COUNT:
return {v->AsCount()};
case zeek::TYPE_COUNTER:
return {v->AsCounter()};
case zeek::TYPE_PORT:
{
auto p = v->AsPortVal();

View file

@ -800,7 +800,6 @@ bool Manager::IsCompatibleType(zeek::Type* t, bool atomic_only)
case zeek::TYPE_BOOL:
case zeek::TYPE_INT:
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
case zeek::TYPE_PORT:
case zeek::TYPE_SUBNET:
case zeek::TYPE_ADDR:
@ -1919,7 +1918,6 @@ int Manager::GetValueLength(const Value* val) const
break;
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
length += sizeof(val->val.uint_val);
break;
@ -2015,7 +2013,6 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const
return sizeof(val->val.int_val);
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
memcpy(data+startpos, (const void*) &(val->val.uint_val), sizeof(val->val.uint_val));
return sizeof(val->val.uint_val);
@ -2204,7 +2201,6 @@ zeek::Val* Manager::ValueToVal(const Stream* i, const Value* val, zeek::Type* re
return zeek::val_mgr->Int(val->val.int_val).release();
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return zeek::val_mgr->Count(val->val.int_val).release();
case zeek::TYPE_DOUBLE:

View file

@ -159,7 +159,6 @@ threading::Value* Benchmark::EntryToVal(zeek::TypeTag type, zeek::TypeTag subtyp
break;
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
val->val.uint_val = random();
break;

View file

@ -183,7 +183,6 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p
break;
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
val->val.uint_val = sqlite3_column_int64(st, pos);
break;

View file

@ -956,7 +956,6 @@ threading::Value* Manager::ValToLogVal(zeek::Val* val, zeek::Type* ty)
}
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
lval->val.uint_val = val->InternalUnsigned();
break;

View file

@ -64,7 +64,6 @@ string SQLite::GetTableType(int arg_type, int arg_subtype) {
case zeek::TYPE_INT:
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
case zeek::TYPE_PORT: // note that we do not save the protocol at the moment. Just like in the case of the ascii-writer
type = "integer";
break;
@ -250,7 +249,6 @@ int SQLite::AddParams(Value* val, int pos)
return sqlite3_bind_int(st, pos, val->val.int_val);
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return sqlite3_bind_int(st, pos, val->val.uint_val);
case zeek::TYPE_PORT:

View file

@ -10,7 +10,7 @@
%token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY
%token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF
%token TOK_BOOL TOK_BREAK TOK_CASE TOK_OPTION TOK_CONST
%token TOK_CONSTANT TOK_COPY TOK_COUNT TOK_COUNTER TOK_DEFAULT TOK_DELETE
%token TOK_CONSTANT TOK_COPY TOK_COUNT TOK_DEFAULT TOK_DELETE
%token TOK_DOUBLE TOK_ELSE TOK_ENUM TOK_EVENT TOK_EXPORT TOK_FALLTHROUGH
%token TOK_FILE TOK_FOR TOK_FUNCTION TOK_GLOBAL TOK_HOOK TOK_ID TOK_IF TOK_INT
%token TOK_INTERVAL TOK_LIST TOK_LOCAL TOK_MODULE
@ -840,11 +840,6 @@ type:
$$ = zeek::base_type(zeek::TYPE_COUNT)->Ref();
}
| TOK_COUNTER {
zeek::detail::set_location(@1);
$$ = zeek::base_type(zeek::TYPE_COUNTER)->Ref();
}
| TOK_DOUBLE {
zeek::detail::set_location(@1);
$$ = zeek::base_type(zeek::TYPE_DOUBLE)->Ref();

View file

@ -220,7 +220,6 @@ option return TOK_OPTION;
const return TOK_CONST;
copy return TOK_COPY;
count return TOK_COUNT;
counter return TOK_COUNTER;
default return TOK_DEFAULT;
delete return TOK_DELETE;
double return TOK_DOUBLE;

View file

@ -131,7 +131,6 @@ bool Value::IsCompatibleType(zeek::Type* t, bool atomic_only)
case zeek::TYPE_BOOL:
case zeek::TYPE_INT:
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
case zeek::TYPE_PORT:
case zeek::TYPE_SUBNET:
case zeek::TYPE_ADDR:
@ -192,7 +191,6 @@ bool Value::Read(SerializationFormat* fmt)
return fmt->Read(&val.int_val, "int");
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return fmt->Read(&val.uint_val, "uint");
case zeek::TYPE_PORT: {
@ -339,7 +337,6 @@ bool Value::Write(SerializationFormat* fmt) const
return fmt->Write(val.int_val, "int");
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return fmt->Write(val.uint_val, "uint");
case zeek::TYPE_PORT:
@ -452,7 +449,6 @@ zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool&
return zeek::val_mgr->Int(val->val.int_val).release();
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return zeek::val_mgr->Count(val->val.int_val).release();
case zeek::TYPE_DOUBLE:

View file

@ -90,7 +90,6 @@ bool Ascii::Describe(ODesc* desc, threading::Value* val, const string& name) con
break;
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
desc->Add(val->val.uint_val);
break;
@ -260,7 +259,6 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, zeek::T
break;
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
val->val.uint_val = strtoull(start, &end, 10);
if ( CheckNumberError(start, end) )
goto parse_error;

View file

@ -106,7 +106,6 @@ void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& na
break;
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
writer.Uint64(val->val.uint_val);
break;

View file

@ -48,7 +48,7 @@ bro_int_t parse_int(const char*& fmt)
}
static zeek::TypeTag ok_d_fmt[] = {
zeek::TYPE_BOOL, zeek::TYPE_ENUM, zeek::TYPE_INT, zeek::TYPE_COUNT, zeek::TYPE_COUNTER, zeek::TYPE_PORT,
zeek::TYPE_BOOL, zeek::TYPE_ENUM, zeek::TYPE_INT, zeek::TYPE_COUNT, zeek::TYPE_PORT,
zeek::TYPE_SUBNET,
zeek::TYPE_ERROR
};