diff --git a/src/ID.cc b/src/ID.cc index aa965b880e..a308ffa81d 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -248,6 +248,16 @@ void ID::UpdateValAttrs() } } +void ID::MakeDeprecated() + { + if ( IsDeprecated() ) + return; + + attr_list* attr = new attr_list; + attr->append(new Attr(ATTR_DEPRECATED)); + AddAttrs(new Attributes(attr, Type(), false)); + } + void ID::AddAttrs(Attributes* a) { if ( attrs ) diff --git a/src/ID.h b/src/ID.h index ca5d222373..805a8e391b 100644 --- a/src/ID.h +++ b/src/ID.h @@ -83,6 +83,8 @@ public: bool IsDeprecated() const { return FindAttr(ATTR_DEPRECATED) != 0; } + void MakeDeprecated(); + void Error(const char* msg, const BroObj* o2 = 0); void Describe(ODesc* d) const; diff --git a/src/Type.cc b/src/Type.cc index b5466c27ba..9aa86da8dc 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1479,11 +1479,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, id->SetEnumConst(); if ( deprecated ) - { - attr_list* attr = new attr_list; - attr->append(new Attr(ATTR_DEPRECATED)); - id->AddAttrs(new Attributes(attr, id->Type(), false)); - } + id->MakeDeprecated(); broxygen_mgr->Identifier(id); } diff --git a/src/Var.cc b/src/Var.cc index 0a196b9cac..95ec5802ef 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -435,6 +435,10 @@ void end_func(Stmt* body, attr_list* attrs) loop_over_list(*attrs, i) { Attr* a = (*attrs)[i]; + + if ( a->Tag() == ATTR_DEPRECATED ) + continue; + if ( a->Tag() != ATTR_PRIORITY ) { a->Error("illegal attribute for function body"); diff --git a/src/parse.y b/src/parse.y index 9261775932..f74880dc13 100644 --- a/src/parse.y +++ b/src/parse.y @@ -227,6 +227,18 @@ static bool expr_is_table_type_name(const Expr* expr) return false; } + +static bool has_attr(const attr_list* al, attr_tag tag) + { + if ( ! al ) + return false; + + for ( int i = 0; i < al->length(); ++i ) + if ( (*al)[i]->Tag() == tag ) + return true; + + return false; + } %} %union { @@ -1147,6 +1159,9 @@ func_body: { saved_in_init.push_back(in_init); in_init = 0; + + if ( has_attr($1, ATTR_DEPRECATED) ) + current_scope()->ScopeID()->MakeDeprecated(); } stmt_list @@ -1571,7 +1586,13 @@ global_or_event_id: $$->Error("already a local identifier"); if ( $$->IsDeprecated() ) - reporter->Warning("deprecated (%s)", $$->Name()); + { + BroType* t = $$->Type(); + + if ( t->Tag() != TYPE_FUNC || + t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) + reporter->Warning("deprecated (%s)", $$->Name()); + } delete [] $1; } diff --git a/testing/btest/Baseline/language.deprecated/out b/testing/btest/Baseline/language.deprecated/out index 9587bf033f..5bdf87a62b 100644 --- a/testing/btest/Baseline/language.deprecated/out +++ b/testing/btest/Baseline/language.deprecated/out @@ -15,6 +15,8 @@ warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 55: deprecated (my_event) warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 60: deprecated (my_hook) warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 65: deprecated (blah) +warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 74: deprecated (dont_use_me) +warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 79: deprecated (dont_use_me_either) ZERO ONE TWO diff --git a/testing/btest/language/deprecated.bro b/testing/btest/language/deprecated.bro index 0a6d269fad..ec9c3c9e1e 100644 --- a/testing/btest/language/deprecated.bro +++ b/testing/btest/language/deprecated.bro @@ -66,3 +66,15 @@ function hmm(b: blah) { print b; } + +global dont_use_me: function() &deprecated; + +function dont_use_me() + { + dont_use_me(); + } + +function dont_use_me_either() &deprecated + { + dont_use_me_either(); + }