mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/outer_param_binding'
That works. Just renaming "param" to "ID", as locals are affected as well. BIT-1233 #merged * origin/topic/jsiwek/outer_param_binding: Detect functions that try to bind variables from an outer scope.
This commit is contained in:
commit
a3b2e3a2b4
6 changed files with 131 additions and 51 deletions
6
CHANGES
6
CHANGES
|
@ -1,4 +1,10 @@
|
||||||
|
|
||||||
|
2.3-121 | 2014-08-22 15:22:15 -0700
|
||||||
|
|
||||||
|
* Detect functions that try to bind variables from an outer scope
|
||||||
|
and raise an error saying that's not supported. Addresses
|
||||||
|
BIT-1233. (Jon Siwek)
|
||||||
|
|
||||||
2.3-116 | 2014-08-21 16:04:13 -0500
|
2.3-116 | 2014-08-21 16:04:13 -0500
|
||||||
|
|
||||||
* Adding plugin testing to Makefile's test-all. (Robin Sommer)
|
* Adding plugin testing to Makefile's test-all. (Robin Sommer)
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
2.3-116
|
2.3-121
|
||||||
|
|
|
@ -660,8 +660,13 @@ void Case::Describe(ODesc* d) const
|
||||||
|
|
||||||
TraversalCode Case::Traverse(TraversalCallback* cb) const
|
TraversalCode Case::Traverse(TraversalCallback* cb) const
|
||||||
{
|
{
|
||||||
TraversalCode tc = cases->Traverse(cb);
|
TraversalCode tc;
|
||||||
|
|
||||||
|
if ( cases )
|
||||||
|
{
|
||||||
|
tc = cases->Traverse(cb);
|
||||||
HANDLE_TC_STMT_PRE(tc);
|
HANDLE_TC_STMT_PRE(tc);
|
||||||
|
}
|
||||||
|
|
||||||
tc = s->Traverse(cb);
|
tc = s->Traverse(cb);
|
||||||
HANDLE_TC_STMT_PRE(tc);
|
HANDLE_TC_STMT_PRE(tc);
|
||||||
|
|
39
src/Var.cc
39
src/Var.cc
|
@ -9,6 +9,7 @@
|
||||||
#include "Serializer.h"
|
#include "Serializer.h"
|
||||||
#include "RemoteSerializer.h"
|
#include "RemoteSerializer.h"
|
||||||
#include "EventRegistry.h"
|
#include "EventRegistry.h"
|
||||||
|
#include "Traverse.h"
|
||||||
|
|
||||||
static Val* init_val(Expr* init, const BroType* t, Val* aggr)
|
static Val* init_val(Expr* init, const BroType* t, Val* aggr)
|
||||||
{
|
{
|
||||||
|
@ -392,6 +393,34 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OuterIDBindingFinder : public TraversalCallback {
|
||||||
|
public:
|
||||||
|
OuterIDBindingFinder(Scope* s)
|
||||||
|
: scope(s) { }
|
||||||
|
|
||||||
|
virtual TraversalCode PreExpr(const Expr*);
|
||||||
|
|
||||||
|
Scope* scope;
|
||||||
|
vector<const NameExpr*> outer_id_references;
|
||||||
|
};
|
||||||
|
|
||||||
|
TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
|
||||||
|
{
|
||||||
|
if ( expr->Tag() != EXPR_NAME )
|
||||||
|
return TC_CONTINUE;
|
||||||
|
|
||||||
|
const NameExpr* e = static_cast<const NameExpr*>(expr);
|
||||||
|
|
||||||
|
if ( e->Id()->IsGlobal() )
|
||||||
|
return TC_CONTINUE;
|
||||||
|
|
||||||
|
if ( scope->GetIDs()->Lookup(e->Id()->Name()) )
|
||||||
|
return TC_CONTINUE;
|
||||||
|
|
||||||
|
outer_id_references.push_back(e);
|
||||||
|
return TC_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
void end_func(Stmt* body, attr_list* attrs)
|
void end_func(Stmt* body, attr_list* attrs)
|
||||||
{
|
{
|
||||||
int frame_size = current_scope()->Length();
|
int frame_size = current_scope()->Length();
|
||||||
|
@ -429,6 +458,16 @@ void end_func(Stmt* body, attr_list* attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( streq(id->Name(), "anonymous-function") )
|
||||||
|
{
|
||||||
|
OuterIDBindingFinder cb(scope);
|
||||||
|
body->Traverse(&cb);
|
||||||
|
|
||||||
|
for ( size_t i = 0; i < cb.outer_id_references.size(); ++i )
|
||||||
|
cb.outer_id_references[i]->Error(
|
||||||
|
"referencing outer function IDs not supported");
|
||||||
|
}
|
||||||
|
|
||||||
if ( id->HasVal() )
|
if ( id->HasVal() )
|
||||||
id->ID_Val()->AsFunc()->AddBody(body, inits, frame_size, priority);
|
id->ID_Val()->AsFunc()->AddBody(body, inits, frame_size, priority);
|
||||||
else
|
else
|
||||||
|
|
3
testing/btest/Baseline/language.outer_param_binding/out
Normal file
3
testing/btest/Baseline/language.outer_param_binding/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
error in /home/robin/bro/master/testing/btest/.tmp/language.outer_param_binding/outer_param_binding.bro, line 16: referencing outer function IDs not supported (c)
|
||||||
|
error in /home/robin/bro/master/testing/btest/.tmp/language.outer_param_binding/outer_param_binding.bro, line 16: referencing outer function IDs not supported (d)
|
||||||
|
error in /home/robin/bro/master/testing/btest/.tmp/language.outer_param_binding/outer_param_binding.bro, line 17: referencing outer function IDs not supported (b)
|
27
testing/btest/language/outer_param_binding.bro
Normal file
27
testing/btest/language/outer_param_binding.bro
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# @TEST-EXEC-FAIL: bro -b %INPUT >out 2>&1
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||||
|
|
||||||
|
type Foo: record {
|
||||||
|
x: function(a: string) : string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function bar(b: string, c: string)
|
||||||
|
{
|
||||||
|
local f: Foo;
|
||||||
|
local d = 8;
|
||||||
|
f = [$x=function(a: string) : string
|
||||||
|
{
|
||||||
|
local x = 0;
|
||||||
|
print x;
|
||||||
|
print c, d;
|
||||||
|
return cat(a, " ", b);
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
print f$x("2");
|
||||||
|
}
|
||||||
|
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
bar("1", "20");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue