Commit graph

344 commits

Author SHA1 Message Date
Vern Paxson
441baaf2c1 added &no_ZAM_opt/&no_CPP_opt attributes and --no-opt-files/--no-opt-funcs for controlling skipping script optimization 2025-09-23 09:05:40 -07:00
Vern Paxson
b442c25389 Deprecate SetType, as it can be replaced by TableType 2025-09-17 14:09:58 -07:00
Tim Wojtulewicz
e3b22cd21f Merge remote-tracking branch 'origin/topic/vern/emphasize-IDPtrs'
* origin/topic/vern/emphasize-IDPtrs:
  fixup! fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  annotate a number of BTests as unsuited for -O gen-C++ testing due to multiple Zeek runs
  BTest baseline updates for -O gen-C++ - all minor tweaks
  BTest updates for script optimization tracking of BiFs
  regression test for former ASAN issue with script optimization of lambdas
  shift much of the internal use of ID* identifier pointers over to IDPtr objects
  maintenance update for script optimization's knowledge of BiFs
  logger fix for interoperability with -O gen-C++ code
2025-09-03 15:33:43 -07:00
Vern Paxson
693aa244f9 shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:19:31 -07:00
Vern Paxson
36862a18d6 tightened up parsing of $field=X record constructor expressions 2025-08-31 15:14:26 -07:00
Evan Typanski
4445bc1daf Fix parameter attributes pretending to be records
Parameters relied on is_record for a couple of validations, but they are
not records and should not be treated as such. This way we can validate
&optional better.
2025-08-14 12:00:15 -04:00
Vern Paxson
5c63133226 isolate Location specifics to private class variables to enforce correct line number ordering 2025-07-08 10:39:28 +02:00
Evan Typanski
826ed4cef5 Remove list from Zeek grammar
Using it would make Zeek segfault (at least in locals). It has been an
error for 15 years.
2025-06-20 15:53:15 -04:00
Tim Wojtulewicz
e618d00326 Remove including <cinttypes> from util.h 2025-05-16 10:14:37 -07:00
Tim Wojtulewicz
55e458c5f7 Add comment annotation to disable copying redef value into docs 2025-04-01 10:23:55 -07:00
Tim Wojtulewicz
61cd5779f2 Reformat embedded C++ code in bison/flex files 2025-03-04 09:33:30 -07:00
Evan Typanski
7160e074f6 Do not export locals
Fixes #4227
2025-02-12 13:49:12 -08:00
Evan Typanski
0c27aa6c50 Make types into constants
Closes #4173

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.
2025-01-24 13:57:28 -05:00
Vern Paxson
0e5bece385 "add" and "delete" are now expressions rather than statements 2024-05-29 12:40:06 -07:00
Arne Welzel
f3cbfa9c25 parse: Support @if conditionals in record definitions
Closes #3531
2024-01-08 15:21:48 +01:00
Vern Paxson
a927d61e59 minor fixes for script optimization, exporting of attr_name, script layout tweak 2023-12-04 16:48:19 -08:00
Vern Paxson
434a7e059d introduce internal "mask" expression node to avoid mixed-type overloading of "/" 2023-09-26 14:39:26 -07:00
Robin Sommer
8a3d645caf
Zeekygen: Refine location tracking for Spicy events.
When Spicy defines an event through EVT, it would end up with
more-or-less random, stale Zeek-side location information. Now making
sure it's unset, plus then using any script-side prototype we may
encounter later to update it.

Also fixing a couple location comparisons that I believe were broken
because we do sometimes copy location objects and hence can't compare
by pointer.
2023-09-21 10:54:03 +02:00
Vern Paxson
3925ff4592 addressed performance and correctness issues flagged by Coverity 2023-08-15 16:07:49 -07:00
Arne Welzel
431767d04b Add &default_insert attribute for tables
This is based on the discussion in zeek/zeek#2668. Using &default with tables
can be confusing as the default value is not inserted. The following example
prints an empty table at the end even new Service records was instantiated.

    type Service: record {
        occurrences: count &default=0;
        last_seen: time &default=network_time();
    };

    global services: table[string] of Service &default=Service();

    event zeek_init()
        {
        services["http"]$occurrences += 1;
        services["http"]$last_seen = network_time();

        print services;
        }

Changing above &default to &default_insert will insert the newly created
default value upon a missed lookup and act less surprising.

Other examples that caused confusion previously revolved around table of sets
 or table of vectors and `add` or `+=` not working as expected.

    tbl_of_vector["http"] += 1
    add tbl_of_set["http"][1];
2023-08-04 12:30:36 +02:00
Arne Welzel
b6bff8aa37 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::
2023-07-12 17:29:51 +02:00
Vern Paxson
1b2cd0c767 migrated some raw pointers to smart pointers 2023-07-11 16:04:30 -07:00
Arne Welzel
12a5616f4d Support :: prefix to reference global namespace, deprecate GLOBAL::
Closes #2709
2023-07-11 12:51:21 +02:00
Tim Wojtulewicz
cd7ebdb2ed A handful of int-to-bool conversions 2023-07-07 09:17:05 -07:00
Arne Welzel
4cde1c3c3f global_ids(): Include module names
Ad-hoc include module names in the global_ids() table. Table values will
have the type_name field set to "module" and their key in the table is
prefixed with "module " to avoid clashes with existing global identifiers
shadowing module names (Management::Node being an existing example).

Closes #3136
2023-07-05 14:09:20 +02:00
Vern Paxson
46983cfb2f refinements to LambdaExpr's to provide flexibility, support for ZVal captures 2023-06-30 09:36:14 +02:00
Vern Paxson
b6464814c9 the "Capture" struct is now a class 2023-06-30 09:36:14 +02:00
Arne Welzel
25ea678626 Stmt: Introduce assert statement and related hooks
including two hooks called assertion_failure() and assertion_result() for
customization and tracking of assertion results.
2023-06-12 18:16:02 +02:00
Tim Wojtulewicz
5a3abbe364 Revert "Merge remote-tracking branch 'origin/topic/vern/at-if-analyze'"
This reverts commit 4e797ddbbc, reversing
changes made to 3ac28ba5a2.
2023-05-31 09:20:33 +02:00
Vern Paxson
e441ba394a updates reflecting review comments 2023-05-25 18:00:13 -07:00
Vern Paxson
9f4da24644 "if ( ... ) &analyze" language feature 2023-05-19 12:46:01 -07:00
Tim Wojtulewicz
e07f3f305d Remove parser error message for bro_init, et al 2023-05-02 12:06:41 -07:00
Arne Welzel
384b4de764 Switch deprecations to reporter->Deprecation()
Removes a bit of reliance around the magic DoLog() rendering at the
cost of needing to open-code some of it. The new obj_desc_short()
helper makes that acceptable, though.
2023-04-04 16:05:08 +02:00
Vern Paxson
0c434ca4f8 changed function_ingredients struct to FunctionIngredients class with accessors 2023-04-02 11:34:16 -07:00
Arne Welzel
12d5dca70f parse.y: Make out-of-scope use errors
This was marked to be done in Zeek 5.1, so do it now. The message
didn't include a version, unfortunately, but minimally there was
a comment when it should happen.
2023-03-20 21:35:48 +01:00
Arne Welzel
2f4f01d3f5 parse.y: Improve error reporting of type redef
It's happening regularly to me that I forget the type specifier when redef'ing
records or enums and usually it takes me a while to figure out what's going
on as the errors are not descriptive. Improve the error reporting and just
bail as there's no sensible way to continue.

Closes #2777
2023-02-21 11:58:33 +01:00
Arne Welzel
203a309612 parse.y: Allow trailing commas for table, set, vector and record construction
Python, Ruby, Javascript, Go, ..., allow use of trailing commas and is even
recommended in some style-guides as it keeps diffs smaller. The black formatter
for Python even goes as far to take a trailing comma as an indication to
format a list one-item on a line.

It has been a bit unusual to not be able to put trailing commas in Zeek
scripts, so this change allows for it.

It explicitly prevents trailing commas in list expressions on the left
hand side. Concretely, this disallows trailing commas in the key list
expression during table initializations.

It probably allows for commas in more places that I haven't fully grasped.
Maybe we should tighten those down again if we find them surprising.
2022-12-01 12:05:29 +01:00
Vern Paxson
baf2a91a85 Type coercion fix: transform +=/-= operators with arithmetic targets to explict assignments 2022-11-22 13:01:10 -08:00
Josh Soref
cd201aa24e Spelling src
These are non-functional changes.

* accounting
* activation
* actual
* added
* addresult
* aggregable
* aligned
* alternatively
* ambiguous
* analysis
* analyzer
* anticlimactic
* apparently
* application
* appropriate
* arithmetic
* assignment
* assigns
* associated
* authentication
* authoritative
* barrier
* boundary
* broccoli
* buffering
* caching
* called
* canonicalized
* capturing
* certificates
* ciphersuite
* columns
* communication
* comparison
* comparisons
* compilation
* component
* concatenating
* concatenation
* connection
* convenience
* correctly
* corresponding
* could
* counting
* data
* declared
* decryption
* defining
* dependent
* deprecated
* detached
* dictionary
* directional
* directly
* directory
* discarding
* disconnecting
* distinguishes
* documentation
* elsewhere
* emitted
* empty
* endianness
* endpoint
* enumerator
* essentially
* evaluated
* everything
* exactly
* execute
* explicit
* expressions
* facilitates
* fiddling
* filesystem
* flag
* flagged
* for
* fragments
* guarantee
* guaranteed
* happen
* happening
* hemisphere
* identifier
* identifies
* identify
* implementation
* implemented
* implementing
* including
* inconsistency
* indeterminate
* indices
* individual
* information
* initial
* initialization
* initialize
* initialized
* initializes
* instantiate
* instantiated
* instantiates
* interface
* internal
* interpreted
* interpreter
* into
* it
* iterators
* length
* likely
* log
* longer
* mainly
* mark
* maximum
* message
* minimum
* module
* must
* name
* namespace
* necessary
* nonexistent
* not
* notifications
* notifier
* number
* objects
* occurred
* operations
* original
* otherwise
* output
* overridden
* override
* overriding
* overwriting
* ownership
* parameters
* particular
* payload
* persistent
* potential
* precision
* preexisting
* preservation
* preserved
* primarily
* probably
* procedure
* proceed
* process
* processed
* processes
* processing
* propagate
* propagated
* prototype
* provides
* publishing
* purposes
* queue
* reached
* reason
* reassem
* reassemble
* reassembler
* recommend
* record
* reduction
* reference
* regularly
* representation
* request
* reserved
* retrieve
* returning
* separate
* should
* shouldn't
* significant
* signing
* simplified
* simultaneously
* single
* somebody
* sources
* specific
* specification
* specified
* specifies
* specify
* statement
* subdirectories
* succeeded
* successful
* successfully
* supplied
* synchronization
* tag
* temporarily
* terminating
* that
* the
* transmitted
* true
* truncated
* try
* understand
* unescaped
* unforwarding
* unknown
* unknowndata
* unspecified
* update
* usually
* which
* wildcard

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-11-09 12:08:15 -05:00
Arne Welzel
850aaaa5a8 parse.y: Traverse AST post parsing to detect break/next usage issues
Seemed easiest to do it via the traversal infrastructure as we do not
otherwise track enough context/scope when instantiating break or next
statements.

Might be worth moving this out of src/parse.y, but didn't exactly know
where. Or maybe we wait until there's more such trivial validations
popping up

Fixes #2440
2022-10-28 12:53:37 +02:00
Arne Welzel
2ad609cbbb Reintroduce event groups
This started with reverting commit 52cd02173d
and then rewriting it to be per handler rather than handler identifier
and adding support for hooks as well as adding implicit module groups.
2022-10-25 18:03:26 +02:00
Arne Welzel
46334f8b59 Introduce special treatment for the blank identifier _
Mostly: Do not instantiate variables within for loops and allow
reusing differently typed blanks which previously wasn't possible.

This may be missing some corner-cases, but the added tests seem
to work as expected and nothing else fell apart it seems.
2022-10-24 10:36:01 +02:00
Tim Wojtulewicz
bd7df9e2bf Add &ordered attribute for tables/sets 2022-10-16 15:31:42 -07:00
Vern Paxson
1af905a14f restructured tracking of initializations of globals for script compilation 2022-09-29 15:08:53 -07:00
Arne Welzel
171846a37a parse.y/directives: Reject directives as statements
Avoid the issue outlined in #2289 where the @if or @else is taken as the
statement of an `if`, `for` or `while` by rejecting such constructs.

Effectively this means the following scripts are now rejected:

    # Print's "cond true" with Zeek 5.0 even though the `if ( F )`
    # should be in effect.

    if ( F )
        @if ( T )
            print "cond true";
        @else
            print "cond false";
        @endif

or

    # Print's "hello" once with Zeek 5.0
    local v = vector( 1, 2, 3 );

    for ( i in v )
        @if ( T )
        print("hello")
        @endif

To make above work as intended, additional braces can be used.

    if ( T )
        {
    @if ( cond )
            print "cond true";
    @else
            print "cond false";
    @endif
        }

    for ( i in v )
        {
    @if ( T )
        print("hello")
    @endif
        }
2022-08-26 09:42:50 +02:00
Tim Wojtulewicz
8829490045 Merge remote-tracking branch 'origin/topic/awelzel/2075-if-conditional-parsing'
* origin/topic/awelzel/2075-if-conditional-parsing:
  parse.y/anonymous_function: Allow conditionals between begin_lambda and lambda_body
2022-08-23 20:28:17 -07:00
Tim Wojtulewicz
687dd05ddb GH-163: Use ID name (including module name) to create EventExpr when possible
The change to the capture-loss test is actually a fix for a bug exposed by the
code change. Previously it wasn't firing the scheduled event because of a failed
name lookup. Now that the lookup has been fixed, the event happens twice.
2022-08-17 13:15:01 -07:00
Arne Welzel
c6ca89a590 parse.y/anonymous_function: Allow conditionals between begin_lambda and lambda_body
This is to allow conditional statements following a lambda header
(begin_lambda) just as is done with func_hdr conditional_list func_body.
2022-08-17 13:40:25 +02:00
Robin Sommer
ee7288b1e6
Merge remote-tracking branch 'origin/topic/awelzel/record-field-redef'
* origin/topic/awelzel/record-field-redef:
  Support redef'ing the &log attribute of record fields
2022-08-11 11:59:26 +02:00
Arne Welzel
985bbe4e57 Support redef'ing the &log attribute of record fields
Add new syntax for adding and removing attributes from record fields:

    redef RecordType$field_name += { &log };
    redef RecordType$field_name -= { &log };

For now this only allowed for the &log attribute as the semantics are clear.
For &default and &optional the semantics aren't obvious and no use-cases have
been identified where those would make sense to change.

This enables a mechanism to add potentially interesting fields to the typical
Info records in base scripts, but letting users opt-into actually including
them into their log. At the same time, users that find specific fields in a
standard log uninteresting can opt-out without using `Log::Filter$exclude`
which can be difficult to use correctly. Patching or forking external packages
to remove columns from a log can also be avoided with this mechanism.

Closes #2000.
2022-08-10 17:27:05 +02:00