Merge remote-tracking branch 'origin/topic/awelzel/2709-colon-colon-for-global'

* origin/topic/awelzel/2709-colon-colon-for-global:
  ci: Bust Ubuntu 22.10 image cache
  Support :: prefix to reference global namespace, deprecate GLOBAL::
This commit is contained in:
Arne Welzel 2023-07-12 17:29:26 +02:00
commit b6bff8aa37
29 changed files with 486 additions and 22 deletions

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/deprecate-global.zeek, line 22: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::test_function)
warning in <...>/deprecate-global.zeek, line 26: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::X)

View file

@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
X, shadows ::X (42)
::X, 42
GLOBAL::X, 42

View file

@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
::zeek_init()

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 3: syntax error, at or near "::disabling_analyzer"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 5: cannot use :: prefix in export section: ::c

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 2: syntax error, at or near "::a"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 4: unknown identifier ::missing, at or near "::missing"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 9: unknown identifier MyModule::f, at or near "MyModule::f"

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/global-colon-colon-errors.zeek, line 7: syntax error, at or near "::a"

View file

@ -0,0 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
connection, MyModule::connection, {
[y] = [type_name=count, log=F, value=<uninitialized>, default_val=<uninitialized>, optional=T]
}
::connection, connection, [type_name=count, log=F, value=<uninitialized>, default_val=<uninitialized>, optional=T]

View file

@ -0,0 +1,9 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/global-colon-colon.zeek, line 67: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::X)
warning in <...>/global-colon-colon.zeek, line 75: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::my_hook)
warning in <...>/global-colon-colon.zeek, line 82: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::func)
warning in <...>/global-colon-colon.zeek, line 89: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::funcX)
warning in <...>/global-colon-colon.zeek, line 110: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::X)
warning in <...>/global-colon-colon.zeek, line 118: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::my_hook)
warning in <...>/global-colon-colon.zeek, line 125: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::func)
warning in <...>/global-colon-colon.zeek, line 132: Remove in v7.1: Use :: instead of GLOBAL:: (GLOBAL::funcX)

View file

@ -0,0 +1,75 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
(MyModule) print X
MyModule X
(MyModule) print MyModule::X
MyModule X
(MyModule) print GLOBAL::X
global X
(MyModule) print ::X
global X
(MyModule) hook my_hook()
MyModule::my_hook() (in GLOBAL)
MyModule::my_hook()
(MyModule) hook MyModule::my_hook()
MyModule::my_hook() (in GLOBAL)
MyModule::my_hook()
(MyModule) hook GLOBAL::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(MyModule) hook ::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(MyModule) call func()
MyModule::func()
(MyModule) call GLOBAL::func()
GLOBAL::func()
(MyModule) call ::func()
GLOBAL::func()
(MyModule) call funcX()
::funcX() (in MyModule)
(MyModule) call GLOBAL::funcX()
::funcX() (in MyModule)
(MyModule) call ::funcX()
::funcX() (in MyModule)
(G) print X
global X
(G) print MyModule::X
MyModule X
(G) print GLOBAL::X
global X
(G) print ::X
global X
(G) hook my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(G) MyModule::my_hook()
MyModule::my_hook() (in GLOBAL)
MyModule::my_hook()
(G) hook GLOBAL::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(G) hook ::my_hook()
my_hook() (in GLOBAL)
::my_hook() (in GLOBAL)
::my_hook() (in MyModule using ::)
(G) call func()
GLOBAL::func()
(G) call GLOBAL::func()
GLOBAL::func()
(G) call ::func()
GLOBAL::func()
(G) call funcX()
::funcX() (in MyModule)
(G) call GLOBAL::funcX()
::funcX() (in MyModule)
(G) call ::funcX()
::funcX() (in MyModule)
MyModule::my_event() (in MyModule)
MyModule::my_event() (in GLOBAL)
my_event() (in GLOBAL)
::my_event() in (in GLOBAL)
::my_event() (in MyModule)

View file

@ -0,0 +1,27 @@
# @TEST-DOC: Adapt in v7.1 to check for errors upon GLOBAL accesses.
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
module GLOBAL;
function test_function() { }
global X = 42;
module MyModule;
global X = fmt("shadows ::X (%s)", ::X);
event zeek_init()
{
test_function();
::test_function();
GLOBAL::test_function();
print "X", X;
print "::X", ::X;
print "GLOBAL::X", GLOBAL::X;
}

View file

@ -11,4 +11,4 @@ export {
type foo: enum { a, b };
}
print GLOBAL::a, GLOBAL::b, a, b, c;
print ::a, ::b, a, b, c;

View file

@ -0,0 +1,23 @@
# @TEST-DOC: Shadow zeek_init() event, demonstrate ::zeek_init() usage.
#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
module MyModule;
export {
## MyModule::zeek_init() shadows global zeek_init() event.
global zeek_init: event();
}
# This is never invoked!
event zeek_init()
{
print "MyModule::zeek_init() - FAIL";
}
event ::zeek_init()
{
print "::zeek_init()";
}

View file

@ -0,0 +1,45 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT >&2
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
event zeek_init()
{
# Do not allow local variables with ::prefix.
local ::a = 1;
}
@TEST-START-NEXT
# Do not allow :: prefix for an identifier containing a module.
hook ::Analyzer::disabling_analyzer(c: connection, atype: AllAnalyzers::Tag, aid: count) { }
@TEST-START-NEXT
# Do not allow exporting names with ::
module MyModule;
export {
global ::c = 1;
global ::h: hook();
}
@TEST-START-NEXT
# Do not allow :: prefix on parameter names.
function f(::a: string) { }
@TEST-START-NEXT
# Non-existing global identifier.
event zeek_init()
{
print ::missing;
}
@TEST-START-NEXT
module MyModule;
function ::f() {
}
event zeek_init()
{
MyModule::f();
}

View file

@ -0,0 +1,26 @@
# @TEST-DOC: redef of ::type works when global type is shadowed by module.
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: btest-diff .stderr
module MyModule;
# Module private connection type.
type connection: record { };
# Redefing the moduleconnection record.
redef record connection += {
y: count &optional;
};
# Redefing the global connection record.
redef record ::connection += {
x: count &optional;
};
event zeek_init()
{
print "connection", connection, record_fields(connection);
print "::connection", ::connection, record_fields(::connection)["x"];
}

View file

@ -0,0 +1,165 @@
# @TEST-DOC: GLOBAL:: and just :: are the same, adapt with v7.1 to remove GLOBAL:: usage.
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
module GLOBAL;
global X = "global X";
global my_hook: hook();
global my_event: event();
function func() {
print " GLOBAL::func()";
}
module MyModule;
export {
global X = "MyModule X";
global my_hook: hook();
global my_event: event();
global func: function();
}
# This implements MyModule::my_hook()
hook my_hook() &priority=9
{
print " MyModule::my_hook()";
}
# This implements GLOBAL::my_hook()
hook ::my_hook() &priority=8
{
print " ::my_hook() (in MyModule using ::)";
}
event my_event() &priority=9
{
print " MyModule::my_event() (in MyModule)";
}
event ::my_event() &priority=8
{
print " ::my_event() (in MyModule)";
}
function func()
{
print " MyModule::func()";
}
# This one is a bit funky: Defines a global function while in a module.
function ::funcX()
{
print " ::funcX() (in MyModule)";
}
event zeek_init() &priority=5
{
print "(MyModule) print X";
print fmt(" %s", X);
print "(MyModule) print MyModule::X";
print fmt(" %s", MyModule::X);
print "(MyModule) print GLOBAL::X";
print fmt(" %s", GLOBAL::X);
print "(MyModule) print ::X";
print fmt(" %s", ::X);
print "(MyModule) hook my_hook()";
hook my_hook(); # This uses MyModule::my_hook();
print "(MyModule) hook MyModule::my_hook()";
hook MyModule::my_hook(); # This uses MyModule::hook();
print "(MyModule) hook GLOBAL::my_hook()";
hook GLOBAL::my_hook();
print "(MyModule) hook ::my_hook()";
hook ::my_hook();
print "(MyModule) call func()";
func();
print "(MyModule) call GLOBAL::func()";
GLOBAL::func();
print "(MyModule) call ::func()";
::func();
print "(MyModule) call funcX()";
funcX();
print "(MyModule) call GLOBAL::funcX()";
GLOBAL::funcX();
print "(MyModule) call ::funcX()";
::funcX();
# This schedules MyEvent::my_event()
event my_event();
# This schedules the GLOBAL::my_event();
event ::my_event();
}
module GLOBAL;
event zeek_init() &priority=5
{
print "(G) print X";
print fmt(" %s", X);
print "(G) print MyModule::X";
print fmt(" %s", MyModule::X);
print "(G) print GLOBAL::X";
print fmt(" %s", GLOBAL::X);
print "(G) print ::X";
print fmt(" %s", ::X);
print "(G) hook my_hook()";
hook my_hook(); # This uses GLOBAL::my_hook();
print "(G) MyModule::my_hook()";
hook MyModule::my_hook(); # This uses MyModule::hook();
print "(G) hook GLOBAL::my_hook()";
hook GLOBAL::my_hook();
print "(G) hook ::my_hook()";
hook ::my_hook();
print "(G) call func()";
func();
print "(G) call GLOBAL::func()";
GLOBAL::func();
print "(G) call ::func()";
::func();
print "(G) call funcX()";
funcX();
print "(G) call GLOBAL::funcX()";
GLOBAL::funcX();
print "(G) call ::funcX()";
::funcX();
}
hook my_hook() &priority=10
{
print " my_hook() (in GLOBAL)";
}
hook ::my_hook() &priority=10
{
print " ::my_hook() (in GLOBAL)";
}
hook MyModule::my_hook() &priority=10
{
print " MyModule::my_hook() (in GLOBAL)";
}
event MyModule::my_event() &priority=9
{
print " MyModule::my_event() (in GLOBAL)";
}
event my_event() &priority=10
{
print " my_event() (in GLOBAL)";
}
event ::my_event() &priority=10
{
print " ::my_event() in (in GLOBAL)";
}

View file

@ -28,7 +28,7 @@ event zeek_init()
{
test_case( "function", T );
test_case( "global variable", num == 123 );
test_case( "fully qualified global variable", GLOBAL::num == 123 ); # test for BIT-1758 : GLOBAL scope ID discovery bug
test_case( "fully qualified global variable", ::num == 123 );
test_case( "const", daysperyear == 365 );
event testevent( "foo" );
}