Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const_expr_visitor, use it when compiling/cloning/stringing #837

Merged
merged 1 commit into from
Jan 20, 2023

Conversation

mstemm
Copy link
Contributor

@mstemm mstemm commented Jan 19, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap-engine-udig

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

In some cases, we want to ensure that a visitor does not change the ast. This includes cases where the ast pointer used by the visitor is read-only.

To support these use cases, add a const_expr_visitor interface where all the visit() methods take a const argument.

Also add variants of accept() that take const_expr_visitor arguments and call the const_expr_visitors visit() method.

Compiling, cloning, and stringifying asts are all cases that should not change the underlying ast, so switch those to use const_expr_visitor instead of expr_visitor.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Add a const AST visitor variant that does not change the ast. Modify ast compiler, clone, stringify to use the const variant.

In some cases, we want to ensure that a visitor does *not* change the
ast. This includes cases where the ast pointer used by the visitor is
read-only.

To support these use cases, add a const_expr_visitor interface where
all the visit() methods take a const argument.

Also add variants of accept() that take const_expr_visitor arguments
and call the const_expr_visitors visit() method.

Compiling, cloning, and stringifying asts are all cases that should
not change the underlying ast, so switch those to use
const_expr_visitor instead of expr_visitor.

A couple of compile private methods had to be changed to take const
arguments. They already didn't modify those arguments, so it was a
safe change.

Signed-off-by: Mark Stemm <[email protected]>
@mstemm mstemm force-pushed the make-ast-arguments-const-when-possible branch from 29cedf0 to 16db068 Compare January 19, 2023 22:27
@mstemm
Copy link
Contributor Author

mstemm commented Jan 19, 2023

I did also build falco with this branch and the changes didn't cause any problems. The falco build itself did fail, but I suspect that's because other libs changes (looks like removing using namespace from header files) caused errors. Falco probably hasn't caught up to the tip of the libs master branch yet.

Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely! I was thinking to add the same changes somewhere in the future, thanks for the effort.

/approve

@poiana
Copy link
Contributor

poiana commented Jan 20, 2023

LGTM label has been added.

Git tree hash: a968d2ea9e5db8968bffd02c0518447c6b3f4e2a

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana poiana merged commit e4d1cec into master Jan 20, 2023
@poiana poiana deleted the make-ast-arguments-const-when-possible branch January 20, 2023 10:59
@poiana
Copy link
Contributor

poiana commented Jan 20, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, jasondellaluce, mstemm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,jasondellaluce,mstemm]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

mstemm added a commit that referenced this pull request Mar 27, 2023
Following on the changes in
#837, add a const variant of
base_expr_visitor. This allows definining subclasses that want to
traverse an ast read-only without implementng all the methods.

Signed-off-by: Mark Stemm <[email protected]>
poiana pushed a commit that referenced this pull request Mar 28, 2023
Following on the changes in
#837, add a const variant of
base_expr_visitor. This allows definining subclasses that want to
traverse an ast read-only without implementng all the methods.

Signed-off-by: Mark Stemm <[email protected]>
araujof pushed a commit to sysflow-telemetry/libs that referenced this pull request Mar 30, 2023
Following on the changes in
falcosecurity#837, add a const variant of
base_expr_visitor. This allows definining subclasses that want to
traverse an ast read-only without implementng all the methods.

Signed-off-by: Mark Stemm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants