Make options redef-able by default.

This commit is contained in:
Johanna Amann 2018-08-10 11:45:37 -07:00
parent 26ea1999ec
commit c34fbee0d1
4 changed files with 22 additions and 1 deletions

View file

@ -294,6 +294,22 @@ void ID::RemoveAttr(attr_tag a)
} }
} }
void ID::SetOption()
{
if ( is_option )
return;
is_option = true;
// option implied redefinable
if ( ! IsRedefinable() )
{
attr_list* attr = new attr_list;
attr->append(new Attr(ATTR_REDEF));
AddAttrs(new Attributes(attr, Type(), false));
}
}
void ID::EvalFunc(Expr* ef, Expr* ev) void ID::EvalFunc(Expr* ef, Expr* ev)
{ {
Expr* arg1 = new ConstExpr(val->Ref()); Expr* arg1 = new ConstExpr(val->Ref());

View file

@ -60,7 +60,7 @@ public:
void SetConst() { is_const = true; } void SetConst() { is_const = true; }
bool IsConst() const { return is_const; } bool IsConst() const { return is_const; }
void SetOption() { is_option = true; } void SetOption();
bool IsOption() const { return is_option; } bool IsOption() const { return is_option; }
void SetEnumConst() { is_enum_const = true; } void SetEnumConst() { is_enum_const = true; }

View file

@ -1 +1,2 @@
6 6
7

View file

@ -2,11 +2,15 @@
# @TEST-EXEC: btest-diff .stdout # @TEST-EXEC: btest-diff .stdout
# options are allowed to be redef-able. # options are allowed to be redef-able.
# And they are even redef-able by default.
option testopt = 5 &redef; option testopt = 5 &redef;
redef testopt = 6; redef testopt = 6;
option anotheropt = 6;
redef anotheropt = 7;
event bro_init() { event bro_init() {
print testopt; print testopt;
print anotheropt;
} }