mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Revert "Merge remote-tracking branch 'origin/topic/etyp/type-const'"
This reverts commit53982aabfa
, reversing changes made to8c28e47dc1
.
This commit is contained in:
parent
1b122a919d
commit
5d9aa52122
8 changed files with 34 additions and 120 deletions
14
CHANGES
14
CHANGES
|
@ -1,17 +1,3 @@
|
||||||
7.2.0-dev.118 | 2025-01-24 15:42:51 -0700
|
|
||||||
|
|
||||||
* Make types into constants (Evan Typanski, Corelight)
|
|
||||||
|
|
||||||
This allows types to be used in expressions, but they can't be
|
|
||||||
reassigned. Note that this was meant to be a special "type expression" -
|
|
||||||
but that is unnecessary complexity.
|
|
||||||
|
|
||||||
Type expressions would allow access to the type without going through
|
|
||||||
its constant value, but the constant value is never changed, so it's
|
|
||||||
simply a few more checks if necessary when functionality gets expanded.
|
|
||||||
This way, ZAM and other code will not need updates, so the potential for
|
|
||||||
increased work in the future is probably not worth caring about.
|
|
||||||
|
|
||||||
7.2.0-dev.116 | 2025-01-24 11:42:14 -0700
|
7.2.0-dev.116 | 2025-01-24 11:42:14 -0700
|
||||||
|
|
||||||
* Fix errors from rst linting on the generated docs (Tim Wojtulewicz, Corelight)
|
* Fix errors from rst linting on the generated docs (Tim Wojtulewicz, Corelight)
|
||||||
|
|
3
NEWS
3
NEWS
|
@ -16,9 +16,6 @@ New Functionality
|
||||||
Zeek now raises a warning when a script declares these events while this
|
Zeek now raises a warning when a script declares these events while this
|
||||||
option is set to true.
|
option is set to true.
|
||||||
|
|
||||||
- Types can now be used as constants in Zeek script. This allows types to be
|
|
||||||
directly passed into BIFs without aliasing.
|
|
||||||
|
|
||||||
Changed Functionality
|
Changed Functionality
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
7.2.0-dev.118
|
7.2.0-dev.116
|
||||||
|
|
93
src/parse.y
93
src/parse.y
|
@ -64,7 +64,7 @@
|
||||||
%type <expr> expr opt_expr rhs opt_init anonymous_function lambda_body index_slice opt_deprecated when_condition
|
%type <expr> expr opt_expr rhs opt_init anonymous_function lambda_body index_slice opt_deprecated when_condition
|
||||||
%type <event_expr> event
|
%type <event_expr> event
|
||||||
%type <stmt> stmt stmt_list func_body for_head
|
%type <stmt> stmt stmt_list func_body for_head
|
||||||
%type <type> simple_type type opt_type enum_body
|
%type <type> type opt_type enum_body
|
||||||
%type <func_type> func_hdr func_params
|
%type <func_type> func_hdr func_params
|
||||||
%type <type_l> type_list
|
%type <type_l> type_list
|
||||||
%type <type_decl> type_decl formal_args_decl
|
%type <type_decl> type_decl formal_args_decl
|
||||||
|
@ -765,10 +765,6 @@ expr:
|
||||||
reporter->Error("index slice assignment may not be used"
|
reporter->Error("index slice assignment may not be used"
|
||||||
" in arbitrary expression contexts, only"
|
" in arbitrary expression contexts, only"
|
||||||
" as a statement");
|
" as a statement");
|
||||||
// Type types cannot be reassigned because that could require parse-time
|
|
||||||
// control flow to resolve a variable's type
|
|
||||||
if ( $1->Tag() == EXPR_NAME && $1->GetType()->Tag() == TYPE_TYPE )
|
|
||||||
$1->Error("type variables cannot be reassigned");
|
|
||||||
|
|
||||||
$$ = get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $4}, in_init).release();
|
$$ = get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $4}, in_init).release();
|
||||||
}
|
}
|
||||||
|
@ -1030,13 +1026,6 @@ expr:
|
||||||
$$ = new ConstExpr({AdoptRef{}, $1});
|
$$ = new ConstExpr({AdoptRef{}, $1});
|
||||||
}
|
}
|
||||||
|
|
||||||
| simple_type
|
|
||||||
{
|
|
||||||
set_location(@1);
|
|
||||||
TypePtr ty{AdoptRef(), $1};
|
|
||||||
$$ = new ConstExpr(make_intrusive<TypeVal>(ty, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
| '/' { begin_RE(); } TOK_PATTERN_TEXT TOK_PATTERN_END
|
| '/' { begin_RE(); } TOK_PATTERN_TEXT TOK_PATTERN_END
|
||||||
{
|
{
|
||||||
set_location(@3);
|
set_location(@3);
|
||||||
|
@ -1164,75 +1153,63 @@ enum_body_elem:
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
simple_type:
|
type:
|
||||||
TOK_BOOL
|
TOK_BOOL {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_BOOL)->Ref();
|
$$ = base_type(TYPE_BOOL)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_INT
|
| TOK_INT {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_INT)->Ref();
|
$$ = base_type(TYPE_INT)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_COUNT
|
| TOK_COUNT {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_COUNT)->Ref();
|
$$ = base_type(TYPE_COUNT)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_DOUBLE
|
| TOK_DOUBLE {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_DOUBLE)->Ref();
|
$$ = base_type(TYPE_DOUBLE)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_TIME
|
| TOK_TIME {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_TIME)->Ref();
|
$$ = base_type(TYPE_TIME)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_INTERVAL
|
| TOK_INTERVAL {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_INTERVAL)->Ref();
|
$$ = base_type(TYPE_INTERVAL)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_STRING
|
| TOK_STRING {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_STRING)->Ref();
|
$$ = base_type(TYPE_STRING)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_PATTERN
|
| TOK_PATTERN {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_PATTERN)->Ref();
|
$$ = base_type(TYPE_PATTERN)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_PORT
|
| TOK_PORT {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_PORT)->Ref();
|
$$ = base_type(TYPE_PORT)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_ADDR
|
| TOK_ADDR {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_ADDR)->Ref();
|
$$ = base_type(TYPE_ADDR)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_SUBNET
|
| TOK_SUBNET {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_SUBNET)->Ref();
|
$$ = base_type(TYPE_SUBNET)->Ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_ANY
|
| TOK_ANY {
|
||||||
{
|
|
||||||
set_location(@1);
|
set_location(@1);
|
||||||
$$ = base_type(TYPE_ANY)->Ref();
|
$$ = base_type(TYPE_ANY)->Ref();
|
||||||
}
|
}
|
||||||
|
@ -1288,6 +1265,24 @@ simple_type:
|
||||||
$$ = new VectorType({AdoptRef{}, $3});
|
$$ = new VectorType({AdoptRef{}, $3});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
| TOK_FUNCTION func_params
|
||||||
|
{
|
||||||
|
set_location(@1, @2);
|
||||||
|
$$ = $2;
|
||||||
|
}
|
||||||
|
|
||||||
|
| TOK_EVENT '(' formal_args ')'
|
||||||
|
{
|
||||||
|
set_location(@1, @3);
|
||||||
|
$$ = new FuncType({AdoptRef{}, $3}, nullptr, FUNC_FLAVOR_EVENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
| TOK_HOOK '(' formal_args ')'
|
||||||
|
{
|
||||||
|
set_location(@1, @3);
|
||||||
|
$$ = new FuncType({AdoptRef{}, $3}, base_type(TYPE_BOOL), FUNC_FLAVOR_HOOK);
|
||||||
|
}
|
||||||
|
|
||||||
| TOK_FILE TOK_OF type
|
| TOK_FILE TOK_OF type
|
||||||
{
|
{
|
||||||
set_location(@1, @3);
|
set_location(@1, @3);
|
||||||
|
@ -1306,31 +1301,9 @@ simple_type:
|
||||||
$$ = new OpaqueType($3);
|
$$ = new OpaqueType($3);
|
||||||
}
|
}
|
||||||
|
|
||||||
type:
|
|
||||||
simple_type
|
|
||||||
| TOK_FUNCTION func_params
|
|
||||||
{
|
|
||||||
set_location(@1, @2);
|
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
|
|
||||||
| TOK_HOOK '(' formal_args ')'
|
|
||||||
{
|
|
||||||
set_location(@1, @3);
|
|
||||||
$$ = new FuncType({AdoptRef{}, $3}, base_type(TYPE_BOOL), FUNC_FLAVOR_HOOK);
|
|
||||||
}
|
|
||||||
|
|
||||||
| TOK_EVENT '(' formal_args ')'
|
|
||||||
{
|
|
||||||
set_location(@1, @3);
|
|
||||||
$$ = new FuncType({AdoptRef{}, $3}, nullptr, FUNC_FLAVOR_EVENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
| resolve_id
|
| resolve_id
|
||||||
{
|
{
|
||||||
if ( $1 && $1->GetType()->Tag() == TYPE_TYPE )
|
if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) )
|
||||||
$$ = $1->GetType()->AsTypeType()->GetType()->Ref();
|
|
||||||
else if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) )
|
|
||||||
{
|
{
|
||||||
NullStmt here;
|
NullStmt here;
|
||||||
if ( $1 )
|
if ( $1 )
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
|
||||||
error in <...>/type-expr-assignment.zeek, line 8: type variables cannot be reassigned (str)
|
|
|
@ -1,6 +0,0 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
|
||||||
hi there :)
|
|
||||||
hey!!
|
|
||||||
42
|
|
||||||
[v=aoeu, valid=T]
|
|
||||||
type
|
|
|
@ -1,11 +0,0 @@
|
||||||
# @TEST-DOC: Ensure redefining a type expression ID is an error
|
|
||||||
# @TEST-EXEC-FAIL: zeek -b %INPUT
|
|
||||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
|
||||||
|
|
||||||
event zeek_init()
|
|
||||||
{
|
|
||||||
local str = string;
|
|
||||||
str = count;
|
|
||||||
local my_string: str = "aoeu"; # This will still be a string
|
|
||||||
print my_string;
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
# @TEST-DOC: Test valid use of type expressions in scripts
|
|
||||||
# @TEST-EXEC: zeek -b %INPUT
|
|
||||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER= btest-diff .stdout
|
|
||||||
|
|
||||||
global global_str = string;
|
|
||||||
global my_global_string: global_str = "hey!!";
|
|
||||||
|
|
||||||
event zeek_init()
|
|
||||||
{
|
|
||||||
local str = string;
|
|
||||||
local my_string: str = "hi there :)";
|
|
||||||
print my_string;
|
|
||||||
print my_global_string;
|
|
||||||
|
|
||||||
local integer = int;
|
|
||||||
local my_int: integer = 41;
|
|
||||||
my_int += 1;
|
|
||||||
print my_int;
|
|
||||||
|
|
||||||
# Try a couple of functions that take types
|
|
||||||
print from_json("\"aoeu\"", string);
|
|
||||||
print type_name(string);
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue