Skip to contentSkip to conversation

Another space oddity

cocci Andrzej Hajda 2 participants 5 messages Dec 14, 2022 – Dec 19, 2022

lore
Share & tools
lore
#0 lore raw

Hi,

I have found another strange space/newline behavior when changing iterator loops:
Following script:
@@
iterator name for0;
@@
        for0()
-       {
                0;
-       }

@@
iterator name for0;
@@
        for0()
-               { 1; }
+               1;

@@
iterator name for0;
@@
-       for0() { 2; }
+       for0() 2;
-----------
On file:
int f() {
        for0() {
                0;
        }

        for0() {
                1;
        }

        for0() {
                2;
        }
}
Produces output:
int f() {
        for0()

                0;

        for0() 1;

        for0 ()
                2;
}
---
Ie. in cases:
0 - it adds extra line,
1 - removes existing line,
2 - produces correct output, but modifies iterator header (I would like to avoid, extra space between for0 and '('.

I would expect 0 and 1 produce correct indentation in 0 and 1, is it possible to fix it?

Regards
Andrzej

#1 lore raw
Quoted 58 lines · Andrzej Hajda

Hi,

I have found another strange space/newline behavior when changing iterator loops:
Following script:
@@
iterator name for0;
@@
        for0()
-       {
                0;
-       }

@@
iterator name for0;
@@
        for0()
-               { 1; }
+               1;

@@
iterator name for0;
@@
-       for0() { 2; }
+       for0() 2;
-----------
On file:
int f() {
        for0() {
                0;
        }

        for0() {
                1;
        }

        for0() {
                2;
        }
}
Produces output:
int f() {
        for0()

                0;

        for0() 1;

        for0 ()
                2;
}
---
Ie. in cases:
0 - it adds extra line,
1 - removes existing line,
2 - produces correct output, but modifies iterator header (I would like to avoid, extra space between for0 and '('.

Quoted 2 lines

I would expect 0 and 1 produce correct indentation in 0 and 1, is it possible to fix it?

Thanks for the report and the nice small examples. I will look into it.

julia

#2 lore raw
Quoted 62 lines · Julia Lawall
Quoted 58 lines · Andrzej Hajda

Hi,

I have found another strange space/newline behavior when changing iterator loops:
Following script:
@@
iterator name for0;
@@
        for0()
-       {
                0;
-       }

@@
iterator name for0;
@@
        for0()
-               { 1; }
+               1;

@@
iterator name for0;
@@
-       for0() { 2; }
+       for0() 2;
-----------
On file:
int f() {
        for0() {
                0;
        }

        for0() {
                1;
        }

        for0() {
                2;
        }
}
Produces output:
int f() {
        for0()

                0;

        for0() 1;

        for0 ()
                2;
}
---
Ie. in cases:
0 - it adds extra line,
1 - removes existing line,
2 - produces correct output, but modifies iterator header (I would like to avoid, extra space between for0 and '('.

Quoted 4 lines
Quoted 2 lines

I would expect 0 and 1 produce correct indentation in 0 and 1, is it possible to fix it?

Thanks for the report and the nice small examples. I will look into it.

Surprisingly this performs nicely spaced transformation, even without adding space after for0:
@@
iterator name for0;
@@
- for0() {
+ for0()

                0;

- }
--------

Andrzej

Quoted 2 lines

julia

#3 lore raw
In reply to Andrzej Hajda
Quoted 48 lines · Andrzej Hajda

Hi,

I have found another strange space/newline behavior when changing iterator loops:
Following script:
@@
iterator name for0;
@@
        for0()
-       {
                0;
-       }

@@
iterator name for0;
@@
        for0()
-               { 1; }
+               1;

@@
iterator name for0;
@@
-       for0() { 2; }
+       for0() 2;
-----------
On file:
int f() {
        for0() {
                0;
        }

        for0() {
                1;
        }

        for0() {
                2;
        }
}
Produces output:
int f() {
        for0()

                0;

        for0() 1;

Quoted 9 lines

        for0 ()
                2;
}
---
Ie. in cases:
0 - it adds extra line,
1 - removes existing line,
2 - produces correct output, but modifies iterator header (I would like to avoid, extra space between for0 and '('.

To avoid the space, you can use the argument --smpl-spacing. Then it will follow the spacing strategy found in the semantic patch.

julia

#4 lore raw
Quoted 60 lines · Julia Lawall
Quoted 48 lines · Andrzej Hajda

Hi,

I have found another strange space/newline behavior when changing iterator loops:
Following script:
@@
iterator name for0;
@@
        for0()
-       {
                0;
-       }

@@
iterator name for0;
@@
        for0()
-               { 1; }
+               1;

@@
iterator name for0;
@@
-       for0() { 2; }
+       for0() 2;
-----------
On file:
int f() {
        for0() {
                0;
        }

        for0() {
                1;
        }

        for0() {
                2;
        }
}
Produces output:
int f() {
        for0()

                0;

        for0() 1;

Quoted 9 lines

        for0 ()
                2;
}
---
Ie. in cases:
0 - it adds extra line,
1 - removes existing line,
2 - produces correct output, but modifies iterator header (I would like to avoid, extra space between for0 and '('.

Quoted 2 lines

To avoid the space, you can use the argument --smpl-spacing. Then it will follow the spacing strategy found in the semantic patch.

Thanks for the hint.

Regards
Andrzej

Quoted 2 lines

julia