Skip to contentSkip to conversation

Avoiding metavariable confusion for duplicate identifiers?

cocci Markus Elfring 2 participants 12 messages Jun 28, 2025 – Jun 29, 2025

lore
Share & tools
lore
#1 lore raw
Quoted 13 lines · Markus Elfring

Hello,

I imagine that a known function definition can be converted into a source code transformation like the following.
https://elixir.bootlin.com/linux/v6.16-rc3/source/include/uapi/linux/cec.h#L84-L90

Another SmPL script example:
@replacement@
@@

(quoted diff) +1 -1
-msg -> msg [ 0 ] & 0xf
+cec_msg_destination(msg)
Quoted 2 lines

Now I wonder which metavariable selections would be appropriate for such an use case.

I'm not sure what the concern is. If you want a metavariable that can match both occurrences of msg, then that would be an identifier.

julia

#2 lore raw
Quoted 10 lines
Quoted 8 lines

@replacement@
@@

(quoted diff) +1 -1
-msg -> msg [ 0 ] & 0xf
+cec_msg_destination(msg)

Now I wonder which metavariable selections would be appropriate for such an use case.

I'm not sure what the concern is.

Data processing configuration challenges might become clearer. I suggest to take another look at corresponding case distinctions.

Quoted 2 lines

If you want a metavariable that can
match both occurrences of msg,

This is probably unlikely if I would like to refer to a single function input parameter.

Quoted 1 line

then that would be an identifier.

I would prefer to distinguish a function argument from a data structure member (despite of identical names in this case).
Can a manual rename be avoided here?

Regards,
Markus

#3 lore raw
Quoted 18 lines · Markus Elfring
Quoted 10 lines
Quoted 8 lines

@replacement@
@@

(quoted diff) +1 -1
-msg -> msg [ 0 ] & 0xf
+cec_msg_destination(msg)

Now I wonder which metavariable selections would be appropriate for such an use case.

I'm not sure what the concern is.

Data processing configuration challenges might become clearer. I suggest to take another look at corresponding case distinctions.

Quoted 2 lines

If you want a metavariable that can
match both occurrences of msg,

Quoted 8 lines

This is probably unlikely if I would like to refer to a single function input parameter.

Quoted 1 line

then that would be an identifier.

I would prefer to distinguish a function argument from a data structure member (despite of identical names in this case).
Can a manual rename be avoided here?

If you want a metavariable name that is different, then use a different name.

julia

#4 lore raw
Quoted 5 lines
Quoted 3 lines

I would prefer to distinguish a function argument from a data structure member (despite of identical names in this case).
Can a manual rename be avoided here?

If you want a metavariable name that is different, then use a different name.

A manual identifier selection can occasionally succeed. Which chances do you see for automatic data processing here?

Regards,
Markus

#5 lore raw
Quoted 7 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines

I would prefer to distinguish a function argument from a data structure member (despite of identical names in this case).
Can a manual rename be avoided here?

If you want a metavariable name that is different, then use a different name.

A manual identifier selection can occasionally succeed. Which chances do you see for automatic data processing here?

I really have no idea what you want to do. Please write a complete semantic patch and provide a complete (but minimal) example of code that you want it to apply to, and the expected effect.

julia

#6 lore raw
Quoted 5 lines
Quoted 1 line

Which chances do you see for automatic data processing here?

I really have no idea what you want to do. Please write a complete semantic patch and provide a complete (but minimal) example of code that you want it to apply to, and the expected effect.

I showed variations of a known use case.
I demonstrated that selected function implementations can be extracted. Duplicate identifiers can be applied even in a single return expression (for example).
Known functions can occasionally be called then more often.

Regards,
Markus

#7 lore raw
Quoted 10 lines · Markus Elfring
Quoted 5 lines
Quoted 1 line

Which chances do you see for automatic data processing here?

I really have no idea what you want to do. Please write a complete semantic patch and provide a complete (but minimal) example of code that you want it to apply to, and the expected effect.

I showed variations of a known use case.
I demonstrated that selected function implementations can be extracted. Duplicate identifiers can be applied even in a single return expression (for example).
Known functions can occasionally be called then more often.

You provided the example:

@replacement@
@@
-msg -> msg [ 0 ] & 0xf
+cec_msg_destination(msg)

If you don't want to ensure that the expression is called msg, you can write:

@replacement@
expression amsg;
@@
-amsg->msg[0] & 0xf
+cec_msg_destination(amsg)

What is the concern you are getting at?

julia

#8 lore raw
Quoted 5 lines

You provided the example:

@replacement@
@@
-msg -> msg [ 0 ] & 0xf

I tried to indicate this source code was automatically determined from the original function definition.

Quoted 1 line

+cec_msg_destination(msg)

It is probably desirable to perform corresponding calls.

Review

Quoted 8 lines

If you don't want to ensure that the expression is called msg, you can write:

@replacement@
expression amsg;
@@

(quoted diff) +1 -1
-amsg->msg[0] & 0xf
+cec_msg_destination(amsg)

You point the possibility out for another manual rename.

Quoted 1 line

What is the concern you are getting at?

I imagine that an automatic separation of involved identifiers would occasionally be more desirable.

Regards,
Markus

#10 lore raw
Quoted 2 lines · Markus Elfring
Quoted 1 line

What is the concern you are getting at?

Under which circumstances would you put such identifiers into different name spaces?

None. Doing something like you suggest would reduce the expressiveness of the language, and doesn't seem at all like a good idea.

julia

#11 lore raw
Quoted 4 lines
Quoted 1 line

Under which circumstances would you put such identifiers into different name spaces?

None. Doing something like you suggest would reduce the expressiveness of the language,

I do not follow such a concern.

Quoted 1 line

and doesn't seem at all like a good idea.

1. Is there a general need to distinguish member names anyhow from other identifiers?
https://cppreference.com/w/c/language/operator_member_access.html#Member_access_through_pointer

2. Do you plan to extend the support for the C++ key word “namespace”?
https://cppreference.com/w/cpp/language/namespace.html

Regards,
Markus