Var/Func: Render function parameters using comma, not semicolon

A bit larger follow-up to what Tim pointed out: Function prototype descriptions
previously used semicolons to separate parameters.

Switch to use commas when a RecordType is used as function parameter.
Use existing "func_args" naming for consistency.
This commit is contained in:
Arne Welzel 2023-10-04 16:33:22 +02:00
parent 8ede22f6ec
commit 8109bbc52f
22 changed files with 50 additions and 32 deletions

View file

@ -835,7 +835,7 @@ void FuncType::DoDescribe(ODesc* d) const
{
d->Add(FlavorString());
d->Add("(");
args->DescribeFields(d);
args->DescribeFields(d, true);
d->Add(")");
if ( yield )
@ -849,7 +849,7 @@ void FuncType::DoDescribe(ODesc* d) const
d->Add(int(Tag()));
d->Add(flavor);
d->Add(yield != nullptr);
args->DescribeFields(d);
args->DescribeFields(d, true);
if ( yield )
yield->Describe(d);
}
@ -1477,7 +1477,7 @@ void RecordType::AddFieldsDirectly(const type_decl_list& others, bool add_log_at
num_fields = types->length();
}
void RecordType::DescribeFields(ODesc* d) const
void RecordType::DescribeFields(ODesc* d, bool func_args) const
{
if ( d->IsReadable() )
{
@ -1501,7 +1501,13 @@ void RecordType::DescribeFields(ODesc* d) const
td->attrs->Describe(d);
}
d->Add(";");
if ( func_args )
{
if ( i + 1 < num_fields )
d->Add(",");
}
else
d->Add(";");
}
}

View file

@ -718,7 +718,7 @@ public:
void AddFieldsDirectly(const type_decl_list& types, bool add_log_attr = false);
void DescribeReST(ODesc* d, bool roles_only = false) const override;
void DescribeFields(ODesc* d) const;
void DescribeFields(ODesc* d, bool func_args = false) const;
void DescribeFieldsReST(ODesc* d, bool func_args) const;
bool IsFieldDeprecated(int field) const

View file

@ -57,7 +57,7 @@ static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs)
if ( auto p = canon_ft->FindPrototype(*alt_args); p )
{
alt_ft->Error("alternate function prototype already exists", p->args.get());
alt_ft->Error("alternate function prototype already exists", p->args.get(), true);
return false;
}

View file

@ -20,7 +20,7 @@ set[port,string]
table[count] of string
table[string] of table[addr,port] of string
record { c:count; s:string; }
function(aa:int; bb:int;) : bool
function(aa:int, bb:int) : bool
function() : any
function() : void
file of string

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 5 and <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 4: alternate function prototype arg 'nope' not found in canonical prototype (event(nope:string; cantdothis:count;) and event(s:string; c:count;))
error in <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 8 and <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 7: alternate function prototype arg 'andnotthiseither' not found in canonical prototype (hook(andnotthiseither:addr;) : bool and hook(s:string; c:count;) : bool)
error in <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 5 and <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 4: alternate function prototype arg 'nope' not found in canonical prototype (event(nope:string, cantdothis:count) and event(s:string, c:count))
error in <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 8 and <...>/alternate-event-hook-prototypes-invalid-arg.zeek, line 7: alternate function prototype arg 'andnotthiseither' not found in canonical prototype (hook(andnotthiseither:addr) : bool and hook(s:string, c:count) : bool)

View file

@ -1,5 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/alternate-event-hook-prototypes.zeek, line 68 and <...>/alternate-event-hook-prototypes.zeek, line 13: use of deprecated 'my_hook' prototype (hook(c:count;) : bool)
warning in <...>/alternate-event-hook-prototypes.zeek, line 68 and <...>/alternate-event-hook-prototypes.zeek, line 13: use of deprecated 'my_hook' prototype (hook(c:count) : bool)
my_hook, infinite, 13
my_hook, 13, infinite
my_hook, infinite

View file

@ -1,2 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in ./bad.zeek, line 2 and ./bad.zeek, line 1: alternate function prototype arguments may not have attributes: arg 'a' (event(c:string; b:string; a:string &default=A, &optional;) and event(a:string; b:string; c:string &default=C, &optional;))
error in ./bad.zeek, line 2 and ./bad.zeek, line 1: alternate function prototype arguments may not have attributes: arg 'a' (event(c:string, b:string, a:string &default=A, &optional) and event(a:string, b:string, c:string &default=C, &optional))

View file

@ -1,4 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 11 and <...>/alternate-prototypes-deprecated-args.zeek, line 7: use of deprecated parameter 'b': Don't use 'b' (event(a:string; b:string; c:string;))
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 30 and <...>/alternate-prototypes-deprecated-args.zeek, line 9: use of deprecated 'myev' prototype: Don't use this prototype (event(a:string; b:string;))
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 11 and <...>/alternate-prototypes-deprecated-args.zeek, line 7: use of deprecated parameter 'b': Don't use 'b' (event(a:string, b:string, c:string))
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 30 and <...>/alternate-prototypes-deprecated-args.zeek, line 9: use of deprecated 'myev' prototype: Don't use this prototype (event(a:string, b:string))
error in ./hide.zeek, line 5: unknown identifier b, at or near "b"

View file

@ -1,6 +1,6 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 11 and <...>/alternate-prototypes-deprecated-args.zeek, line 7: use of deprecated parameter 'b': Don't use 'b' (event(a:string; b:string; c:string;))
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 30 and <...>/alternate-prototypes-deprecated-args.zeek, line 9: use of deprecated 'myev' prototype: Don't use this prototype (event(a:string; b:string;))
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 11 and <...>/alternate-prototypes-deprecated-args.zeek, line 7: use of deprecated parameter 'b': Don't use 'b' (event(a:string, b:string, c:string))
warning in <...>/alternate-prototypes-deprecated-args.zeek, line 30 and <...>/alternate-prototypes-deprecated-args.zeek, line 9: use of deprecated 'myev' prototype: Don't use this prototype (event(a:string, b:string))
myev (canon), one, two, three
myev (new), one, three, [1, 2, 3]
myev (new), one, three, 0

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
cookie
function(pass_name:string;) : function(ts:time;) : time, function(ts:time;) : time, time, 1660671192.0
function(pass_name:string) : function(ts:time) : time, function(ts:time) : time, time, 1660671192.0

View file

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

View file

@ -1,2 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
function(ts_str:string; offset:count &default=10, &optional;) : time, time, 1660671202.0
function(ts_str:string, offset:count &default=10, &optional) : time, time, 1660671202.0

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
cookie
function(pass_name:string;) : function(ts:time;) : time, function(ts:time;) : time, time, 1660671192.0
function(pass_name:string) : function(ts:time) : time, function(ts:time) : time, time, 1660671192.0

View file

@ -2,7 +2,7 @@
warning in <...>/expire-func-type-check.zeek, line 16: Wrong number of arguments for function. Expected 2, got 0. (function() : interval)
error in <...>/expire-func-type-check.zeek, line 38: &expire_func argument type clash (&expire_func=invalid_expire_func_no_params)
error in <...>/expire-func-type-check.zeek, line 39: &expire_func must yield a value of type interval (&expire_func=invalid_expire_func_no_return)
warning in <...>/expire-func-type-check.zeek, line 22: Wrong number of arguments for function. Expected 3, got 2. (function(t:table[addr,port] of set[addr]; s:set[addr,port];) : interval)
warning in <...>/expire-func-type-check.zeek, line 22: Wrong number of arguments for function. Expected 3, got 2. (function(t:table[addr,port] of set[addr], s:set[addr,port]) : interval)
error in <...>/expire-func-type-check.zeek, line 40: &expire_func argument type clash (&expire_func=invalid_expire_func_index_params)
error in <...>/expire-func-type-check.zeek, line 41: &expire_func attribute is not a function (&expire_func=invalid_expire_func_because_its_an_event)
error in <...>/expire-func-type-check.zeek, line 42: &expire_func attribute is not a function (&expire_func=invalid_expire_func_because_its_a_hook)

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.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (hook() : bool and event())
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (function() : void and event())

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.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (hook() : bool and function() : void)
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (event() and function() : void)

View file

@ -1,2 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: alternate function prototype already exists (event() and record { })
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: alternate function prototype already exists (event())

View file

@ -1,3 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (hook() : bool and event())
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (function() : void and event())
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: alternate function prototype already exists (event(x:bool, y:count))

View file

@ -1,3 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (hook() : bool and function() : void)
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (event() and function() : void)
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: alternate function prototype arg 'xx' not found in canonical prototype (event(xx:bool) and event(x:bool))

View file

@ -1,9 +1,9 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 13 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event(c:count; s:string;) and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 18 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event(s:string;) and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 23 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event(c:count;) and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 13 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event(c:count, s:string) and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 18 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event(s:string) and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 23 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event(c:count) and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 28 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 4: use of undeclared alternate prototype (event() and my_event)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 38 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook(c:count; s:string;) : bool and my_hook)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 43 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook(s:string;) : bool and my_hook)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 48 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook(c:count;) : bool and my_hook)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 38 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook(c:count, s:string) : bool and my_hook)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 43 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook(s:string) : bool and my_hook)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 48 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook(c:count) : bool and my_hook)
error in <...>/undeclared-alternate-event-hook-prototype.zeek, line 53 and <...>/undeclared-alternate-event-hook-prototype.zeek, line 6: use of undeclared alternate prototype (hook() : bool and my_hook)

View file

@ -1,4 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/bad-eval-condition.zeek, line 9: Wrong number of arguments for function. Expected 2, got 1. (function(state:signature_state;) : bool)
warning in <...>/bad-eval-condition.zeek, line 9: Wrong number of arguments for function. Expected 2, got 1. (function(state:signature_state) : bool)
error: Error in signature (./blah.sig:6): eval function parameters must be a 'signature_state' and a 'string' type (mark_conn)

View file

@ -42,6 +42,14 @@ event zeek_init()
global ev: event();
global ev: event();
@TEST-START-NEXT
global ev: event(x: bool, y: count);
global ev: event(x: bool, y: count);
@TEST-START-NEXT
global ev: event(x: bool);
global ev: event(xx: bool);
@TEST-START-NEXT
global f: event();
global f: hook();