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

Enable the ternary operator to evaluate builtin calls #1405

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

suyuee
Copy link
Contributor

@suyuee suyuee commented Jul 1, 2020

Currently, the ternary operator can only works to evaluate strings and integers. This PR tries to include builtin calls:

# bpftrace -e 'BEGIN { pid > 10000 ? printf("%s %d\n", comm, pid) : exit(); }'

Although if-else statement can server the purpose, using ternary can be more concise especially when users run bpftrace in comand line. In bpftrace, builtin calls have none types so it makes sense for the ternary operator to support them. Resolves #1333.

Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md

@danobi
Copy link
Member

danobi commented Jul 1, 2020

For anyone else following along, this same behavior is allowed in C/C++: https://godbolt.org/z/H2q2Yt

@suyuee suyuee marked this pull request as ready for review July 1, 2020 03:55
tests/runtime/other Outdated Show resolved Hide resolved
Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

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

LGTM, but please push @fbs 's change

@fbs fbs added this to the 0.11.0 milestone Jul 2, 2020
@danobi
Copy link
Member

danobi commented Jul 2, 2020

@ember526 can you also include the non checklist bits in the PR description in your commit message? 80 column wide formatting, though.

Currently, the ternary operator can only works to evaluate strings and
integers. This tries to include builtin calls:
```
# bpftrace -e 'BEGIN { pid > 10000 ? printf("%s %d\n", comm, pid) : exit(); }'
```

Although if-else statement can serve the purpose, using ternary can be
more concise especially when users run bpftrace in comand line. In
bpftrace, builtin calls have `none` types so it makes sense for the
ternary operator to support them. Resolves bpftrace#1333.
@suyuee
Copy link
Contributor Author

suyuee commented Jul 2, 2020

@danobi Sure. Hope this will do.

@danobi danobi merged commit c4619d0 into bpftrace:master Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ternary operator should be able to support none types
3 participants