Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Indanz
Copy link
Contributor

@Indanz Indanz commented Nov 10, 2025

Useful to implement multiple API definitions for syscalls with optional arguments.

Useful for e.g. PR #1547 and PR #889 or any future API expansion with optional arguments added to existing syscalls.

mc = str(condition_to_cpp(method.getElementsByTagName("condition")))
if mid+mc not in invocation_ids:
invocation_ids.add(mid+mc)
invocation_labels.append((mid, mc))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the correctness of adding multiple of the same label ("id") is non-obvious here and it would be worth it to explain it more...

You somewhat described it in 1547, but I don't understand how exactly duplicate enum values would be OK, precisely?

Like

enum invocation_label {
    InvalidInvocation,
    {%- for label, condition in invocations %}
    {%- if condition %}
#if {{condition}}
    {%- endif %}
    {{label}},
    {%- if condition %}
#endif
    {%- endif %}
    {%- endfor %}
    nInvocationLabels
};

would produce an enum like?

enum invocation_label {
   Invalid,
   LabelOne,
   LabelOne,
   // etc
}

I don't understand how that works, unless the conditions are disjoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't remember whether I needed to add that to make it work, or that it fixes a theoretical problem. I suspect it's the former, but not sure.

It handles the case where there are multiple labels with the same name, but different conditions. Of course, if #1542 gets implemented, this won't be needed any more.

Example:

enum invocation_label {
   Invalid,
#if A
   LabelOne,
#endif
#if B
   LabelOne,
#endif
   // etc
}

Co-authored-by: Indan Zupancic <[email protected]>
Signed-off-by: Corey Lewis <[email protected]>
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.

3 participants