Re: [llvm-dev] clang-format behaviour for braced lists indent

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
Hi Shoaib,

Is this what you need? Can you send the .clang-format file you used?

build$ cat BracedList.cpp

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

                                CDDDP83848_BMSR_REGISTER,

                                CDDDP83848_PHYIDR1_REGISTER,

                                CDDDP83848_PHYIDR2_REGISTER,

                                CDDDP83848_PHYSTS_REGISTER,

                                CDDDP83848_RBR_REGISTER};

build$ bin/clang-format BracedList.cpp

static uint8 CddDp83848Reg[] = {

    CDDDP83848_BMCR_REGISTER,

    CDDDP83848_BMSR_REGISTER,

    CDDDP83848_PHYIDR1_REGISTER,

    CDDDP83848_PHYIDR2_REGISTER,

    CDDDP83848_PHYSTS_REGISTER,

    CDDDP83848_RBR_REGISTER};

build$ 


Regards,

Owen

On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <[hidden email]> wrote:

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
Hi,

Shoaib was so nice to forward this to the correct list. Yes, that's what I'd need. Deafult or LLVM style would generate this but only because of the low ColumnLimit, which is 120 (and in future even 150) for my case. At least that's what I've figured when comparing against the LLVM style dump.

I've attached the clang-format file as well as the source file - maybe the files got lost while forwarding.

Cheers, Martin




On 10 Sep 2019, at 10:41, Owen Pan <[hidden email]> wrote:

Hi Shoaib,

Is this what you need? Can you send the .clang-format file you used?

build$ cat BracedList.cpp
static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
                                CDDDP83848_BMSR_REGISTER,
                                CDDDP83848_PHYIDR1_REGISTER,
                                CDDDP83848_PHYIDR2_REGISTER,
                                CDDDP83848_PHYSTS_REGISTER,
                                CDDDP83848_RBR_REGISTER};
build$ bin/clang-format BracedList.cpp
static uint8 CddDp83848Reg[] = {
    CDDDP83848_BMCR_REGISTER,
    CDDDP83848_BMSR_REGISTER,
    CDDDP83848_PHYIDR1_REGISTER,
    CDDDP83848_PHYIDR2_REGISTER,
    CDDDP83848_PHYSTS_REGISTER,
    CDDDP83848_RBR_REGISTER};
build$ 

Regards,

Owen

On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <[hidden email]> wrote:

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

ATT11905.clang-format (3K) Download Attachment
SomeUnit.c (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
Hi Martin,

Please see below:

build$ cp ATT11905.clang-format .clang-format

build$ bin/clang-format SomeUnit.c > SomeUnit.c.c-f

build$ diff SomeUnit.c SomeUnit.c.c-f

30,35c30,36

< static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

<                                 CDDDP83848_BMSR_REGISTER,

<                                 CDDDP83848_PHYIDR1_REGISTER,

<                                 CDDDP83848_PHYIDR2_REGISTER,

<                                 CDDDP83848_PHYSTS_REGISTER,

<                                 CDDDP83848_RBR_REGISTER};

---

> static uint8 CddDp83848Reg[] = {

>     CDDDP83848_BMCR_REGISTER,

>     CDDDP83848_BMSR_REGISTER,

>     CDDDP83848_PHYIDR1_REGISTER,

>     CDDDP83848_PHYIDR2_REGISTER,

>     CDDDP83848_PHYSTS_REGISTER,

>     CDDDP83848_RBR_REGISTER};

build$ 


I will create a patch and commit the fix in a few days.

Regards,

Owen

On Tue, Sep 10, 2019 at 2:08 AM martin lampacher <[hidden email]> wrote:
Hi,

Shoaib was so nice to forward this to the correct list. Yes, that's what I'd need. Deafult or LLVM style would generate this but only because of the low ColumnLimit, which is 120 (and in future even 150) for my case. At least that's what I've figured when comparing against the LLVM style dump.

I've attached the clang-format file as well as the source file - maybe the files got lost while forwarding.

Cheers, Martin


On 10 Sep 2019, at 10:41, Owen Pan <[hidden email]> wrote:

Hi Shoaib,

Is this what you need? Can you send the .clang-format file you used?

build$ cat BracedList.cpp
static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
                                CDDDP83848_BMSR_REGISTER,
                                CDDDP83848_PHYIDR1_REGISTER,
                                CDDDP83848_PHYIDR2_REGISTER,
                                CDDDP83848_PHYSTS_REGISTER,
                                CDDDP83848_RBR_REGISTER};
build$ bin/clang-format BracedList.cpp
static uint8 CddDp83848Reg[] = {
    CDDDP83848_BMCR_REGISTER,
    CDDDP83848_BMSR_REGISTER,
    CDDDP83848_PHYIDR1_REGISTER,
    CDDDP83848_PHYIDR2_REGISTER,
    CDDDP83848_PHYSTS_REGISTER,
    CDDDP83848_RBR_REGISTER};
build$ 

Regards,

Owen

On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <[hidden email]> wrote:

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
Hi Owen,

looking good, thanks a lot! Will this patch be part of the 9.0 release?

Cheers.M

On 10 Sep 2019, at 12:19, Owen Pan <[hidden email]> wrote:

Hi Martin,

Please see below:

build$ cp ATT11905.clang-format .clang-format
build$ bin/clang-format SomeUnit.c > SomeUnit.c.c-f
build$ diff SomeUnit.c SomeUnit.c.c-f
30,35c30,36
< static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
<                                 CDDDP83848_BMSR_REGISTER,
<                                 CDDDP83848_PHYIDR1_REGISTER,
<                                 CDDDP83848_PHYIDR2_REGISTER,
<                                 CDDDP83848_PHYSTS_REGISTER,
<                                 CDDDP83848_RBR_REGISTER};
---
> static uint8 CddDp83848Reg[] = {
>     CDDDP83848_BMCR_REGISTER,
>     CDDDP83848_BMSR_REGISTER,
>     CDDDP83848_PHYIDR1_REGISTER,
>     CDDDP83848_PHYIDR2_REGISTER,
>     CDDDP83848_PHYSTS_REGISTER,
>     CDDDP83848_RBR_REGISTER};
build$ 

I will create a patch and commit the fix in a few days.

Regards,

Owen

On Tue, Sep 10, 2019 at 2:08 AM martin lampacher <[hidden email]> wrote:
Hi,

Shoaib was so nice to forward this to the correct list. Yes, that's what I'd need. Deafult or LLVM style would generate this but only because of the low ColumnLimit, which is 120 (and in future even 150) for my case. At least that's what I've figured when comparing against the LLVM style dump.

I've attached the clang-format file as well as the source file - maybe the files got lost while forwarding.

Cheers, Martin


On 10 Sep 2019, at 10:41, Owen Pan <[hidden email]> wrote:

Hi Shoaib,

Is this what you need? Can you send the .clang-format file you used?

build$ cat BracedList.cpp
static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
                                CDDDP83848_BMSR_REGISTER,
                                CDDDP83848_PHYIDR1_REGISTER,
                                CDDDP83848_PHYIDR2_REGISTER,
                                CDDDP83848_PHYSTS_REGISTER,
                                CDDDP83848_RBR_REGISTER};
build$ bin/clang-format BracedList.cpp
static uint8 CddDp83848Reg[] = {
    CDDDP83848_BMCR_REGISTER,
    CDDDP83848_BMSR_REGISTER,
    CDDDP83848_PHYIDR1_REGISTER,
    CDDDP83848_PHYIDR2_REGISTER,
    CDDDP83848_PHYSTS_REGISTER,
    CDDDP83848_RBR_REGISTER};
build$ 

Regards,

Owen

On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <[hidden email]> wrote:

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
I have committed the fix into r371571. It won't be part of 9.0.0, but you can get it from trunk if you want it now.

Regards,

Owen

On Tue, Sep 10, 2019 at 4:15 AM martin lampacher <[hidden email]> wrote:
Hi Owen,

looking good, thanks a lot! Will this patch be part of the 9.0 release?

Cheers.M

On 10 Sep 2019, at 12:19, Owen Pan <[hidden email]> wrote:

Hi Martin,

Please see below:

build$ cp ATT11905.clang-format .clang-format
build$ bin/clang-format SomeUnit.c > SomeUnit.c.c-f
build$ diff SomeUnit.c SomeUnit.c.c-f
30,35c30,36
< static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
<                                 CDDDP83848_BMSR_REGISTER,
<                                 CDDDP83848_PHYIDR1_REGISTER,
<                                 CDDDP83848_PHYIDR2_REGISTER,
<                                 CDDDP83848_PHYSTS_REGISTER,
<                                 CDDDP83848_RBR_REGISTER};
---
> static uint8 CddDp83848Reg[] = {
>     CDDDP83848_BMCR_REGISTER,
>     CDDDP83848_BMSR_REGISTER,
>     CDDDP83848_PHYIDR1_REGISTER,
>     CDDDP83848_PHYIDR2_REGISTER,
>     CDDDP83848_PHYSTS_REGISTER,
>     CDDDP83848_RBR_REGISTER};
build$ 

I will create a patch and commit the fix in a few days.

Regards,

Owen

On Tue, Sep 10, 2019 at 2:08 AM martin lampacher <[hidden email]> wrote:
Hi,

Shoaib was so nice to forward this to the correct list. Yes, that's what I'd need. Deafult or LLVM style would generate this but only because of the low ColumnLimit, which is 120 (and in future even 150) for my case. At least that's what I've figured when comparing against the LLVM style dump.

I've attached the clang-format file as well as the source file - maybe the files got lost while forwarding.

Cheers, Martin


On 10 Sep 2019, at 10:41, Owen Pan <[hidden email]> wrote:

Hi Shoaib,

Is this what you need? Can you send the .clang-format file you used?

build$ cat BracedList.cpp
static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
                                CDDDP83848_BMSR_REGISTER,
                                CDDDP83848_PHYIDR1_REGISTER,
                                CDDDP83848_PHYIDR2_REGISTER,
                                CDDDP83848_PHYSTS_REGISTER,
                                CDDDP83848_RBR_REGISTER};
build$ bin/clang-format BracedList.cpp
static uint8 CddDp83848Reg[] = {
    CDDDP83848_BMCR_REGISTER,
    CDDDP83848_BMSR_REGISTER,
    CDDDP83848_PHYIDR1_REGISTER,
    CDDDP83848_PHYIDR2_REGISTER,
    CDDDP83848_PHYSTS_REGISTER,
    CDDDP83848_RBR_REGISTER};
build$ 

Regards,

Owen

On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <[hidden email]> wrote:

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
Ok cool, will have a look at it and maybe build clang-format for internal use. Thanks a lot for looking into it / fixing it !

Cheers.M

On 11 Sep 2019, at 01:50, Owen Pan <[hidden email]> wrote:

I have committed the fix into r371571. It won't be part of 9.0.0, but you can get it from trunk if you want it now.

Regards,

Owen

On Tue, Sep 10, 2019 at 4:15 AM martin lampacher <[hidden email]> wrote:
Hi Owen,

looking good, thanks a lot! Will this patch be part of the 9.0 release?

Cheers.M

On 10 Sep 2019, at 12:19, Owen Pan <[hidden email]> wrote:

Hi Martin,

Please see below:

build$ cp ATT11905.clang-format .clang-format
build$ bin/clang-format SomeUnit.c > SomeUnit.c.c-f
build$ diff SomeUnit.c SomeUnit.c.c-f
30,35c30,36
< static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
<                                 CDDDP83848_BMSR_REGISTER,
<                                 CDDDP83848_PHYIDR1_REGISTER,
<                                 CDDDP83848_PHYIDR2_REGISTER,
<                                 CDDDP83848_PHYSTS_REGISTER,
<                                 CDDDP83848_RBR_REGISTER};
---
> static uint8 CddDp83848Reg[] = {
>     CDDDP83848_BMCR_REGISTER,
>     CDDDP83848_BMSR_REGISTER,
>     CDDDP83848_PHYIDR1_REGISTER,
>     CDDDP83848_PHYIDR2_REGISTER,
>     CDDDP83848_PHYSTS_REGISTER,
>     CDDDP83848_RBR_REGISTER};
build$ 

I will create a patch and commit the fix in a few days.

Regards,

Owen

On Tue, Sep 10, 2019 at 2:08 AM martin lampacher <[hidden email]> wrote:
Hi,

Shoaib was so nice to forward this to the correct list. Yes, that's what I'd need. Deafult or LLVM style would generate this but only because of the low ColumnLimit, which is 120 (and in future even 150) for my case. At least that's what I've figured when comparing against the LLVM style dump.

I've attached the clang-format file as well as the source file - maybe the files got lost while forwarding.

Cheers, Martin


On 10 Sep 2019, at 10:41, Owen Pan <[hidden email]> wrote:

Hi Shoaib,

Is this what you need? Can you send the .clang-format file you used?

build$ cat BracedList.cpp
static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,
                                CDDDP83848_BMSR_REGISTER,
                                CDDDP83848_PHYIDR1_REGISTER,
                                CDDDP83848_PHYIDR2_REGISTER,
                                CDDDP83848_PHYSTS_REGISTER,
                                CDDDP83848_RBR_REGISTER};
build$ bin/clang-format BracedList.cpp
static uint8 CddDp83848Reg[] = {
    CDDDP83848_BMCR_REGISTER,
    CDDDP83848_BMSR_REGISTER,
    CDDDP83848_PHYIDR1_REGISTER,
    CDDDP83848_PHYIDR2_REGISTER,
    CDDDP83848_PHYSTS_REGISTER,
    CDDDP83848_RBR_REGISTER};
build$ 

Regards,

Owen

On Mon, Sep 9, 2019 at 8:23 AM Shoaib Meenai via cfe-dev <[hidden email]> wrote:

(forwarding this to cfe-dev and BCC'ing llvm-dev, since cfe-dev is a better place for clang-format queries)

 

From: llvm-dev <[hidden email]> on behalf of martin lampacher via llvm-dev <[hidden email]>
Reply-To: martin lampacher <[hidden email]>
Date: Monday, September 9, 2019 at 12:04 AM
To: LLVM Development List <[hidden email]>
Subject: [llvm-dev] clang-format behaviour for braced lists indent

 

Hello,

 

I've introduced clang-format (current version 8.0) to enforce some company coding guideline but I am struggling with list initializers.

 

The formatter works nicely with function declarations and function calls and aligns arguments on break like that:

 

 

static void someUnitInternalFunction(

 

    const uint32 someParameter,

 

    uint32 *somePointer,

 

    uint32 normalParameter,

 

    uint8 anotherParameterLong);

 

 



uint32 SomeUnitWithSomeVeryLongFunctionName(

 

    uint32 parameterOne,

 

    uint32 parameterTwo,

 

    uint32 parameterThree,

 

    uint32 parameterFour)

 

{

 

    someUnitInternalFunction(

 

        someInternalVariableWithSomeVeryLongName,

 

        &yetAnotherInternalVariableLongNameStyle,

 

        nowThisNameIsShorter,

 

        nowThisNameIsShorter);

 

}

 

 

 

 

This matches the configured continuation indent width. For lists, however, the indent does not match what I've expected: A list that exceeds the configured margin is formatted as following (I'm using Cpp11BracedListStyle: true):

 

 

static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,

 

                                CDDDP83848_BMSR_REGISTER,

 

                                CDDDP83848_PHYIDR1_REGISTER,

 

                                CDDDP83848_PHYIDR2_REGISTER,

 

                                CDDDP83848_PHYSTS_REGISTER,

 

                                CDDDP83848_RBR_REGISTER};

 

 

Whereas I'd expect it the following style:

 

 

static uint8 CddDp83848Reg[] = {

 

    CDDDP83848_BMCR_REGISTER,

 

    CDDDP83848_BMSR_REGISTER,

 

    CDDDP83848_PHYIDR1_REGISTER,

 

    CDDDP83848_PHYIDR2_REGISTER,

 

    CDDDP83848_PHYSTS_REGISTER,

 

    CDDDP83848_RBR_REGISTER};

 

 

According to the documentation

 

Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the {} were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.

 

And I have the following setting: ContinuationIndentWidth: 4. As you can see the function call is formatted nicely whereas the list initializer isn't, according to the documentation the formatting should be the same.

 

Can someone please help me out here? I've checked several settings and can't make clang-format indent initializers according to the (admittedly a bit special) style.

 

Thanks and BR,

Martin

 

Attached demo file and clang-format settings

 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] clang-format behaviour for braced lists indent

suyash singh via cfe-dev
Hi Martin,

It seems to work well using the clang-format file you gave me before:

bin$ clang-format -version

clang-format version 10.0.0 (https://github.com/llvm/llvm-project.git 90c78073f73eac58f4f8b4772a896dc8aac023bc)

bin$ clang-format

// shows behaviour of clang-format for line-breaks with initializers

static t_component_list _component_list_variable[]

    = {E_COMPONENT_LIST_VALUE_0,

       E_COMPONENT_LIST_VALUE_1,

       E_COMPONENT_LIST_VALUE_0,

       E_COMPONENT_LIST_VALUE_1,

       E_COMPONENT_LIST_VALUE_0,

       E_COMPONENT_LIST_OTHER_VALUE};

// shows behaviour of clang-format for line-breaks with initializers

static t_component_list _component_list_variable[] = {

    E_COMPONENT_LIST_VALUE_0,

    E_COMPONENT_LIST_VALUE_1,

    E_COMPONENT_LIST_VALUE_0,

    E_COMPONENT_LIST_VALUE_1,

    E_COMPONENT_LIST_VALUE_0,

    E_COMPONENT_LIST_OTHER_VALUE};

bin$ cat .clang-format

---

Language: Cpp

BasedOnStyle: LLVM

# https://clang.llvm.org/docs/ClangFormatStyleOptions.html

# compare against `clang-format --style=webkit -dump-config > .clang-format`

AccessModifierOffset: -4

AlignAfterOpenBracket: AlwaysBreak

AlignConsecutiveAssignments: true

# aligns struct members but then also declarations, function prototypes

AlignConsecutiveDeclarations: false

# NYI in clang-format-8

# AlignConsecutiveMacros: true

AlignEscapedNewlines: Left

AlignOperands:   false

AlignTrailingComments: true

# AllowAllArgumentsOnNextLine: true

AllowAllParametersOfDeclarationOnNextLine: false

AllowShortBlocksOnASingleLine: false

AllowShortCaseLabelsOnASingleLine: false

AllowShortFunctionsOnASingleLine: None

AllowShortIfStatementsOnASingleLine: false

AllowShortLoopsOnASingleLine: false

AlwaysBreakBeforeMultilineStrings : true

AlwaysBreakAfterDefinitionReturnType: None

AlwaysBreakAfterReturnType: None

AlwaysBreakBeforeMultilineStrings: false

AlwaysBreakTemplateDeclarations: MultiLine

BinPackArguments: false

BinPackParameters: false

BraceWrapping:

#  AfterCaseLabel:  true

  AfterClass:      true

  AfterControlStatement: true

  AfterEnum:       true

  AfterFunction:   true

  AfterNamespace:  false

  AfterObjCDeclaration: false

  AfterStruct:     true

  AfterUnion:      true

  AfterExternBlock: true

  BeforeCatch:     true

  BeforeElse:      true

  IndentBraces:    false

  SplitEmptyFunction: true

  SplitEmptyRecord: true

  SplitEmptyNamespace: true

BreakBeforeBinaryOperators: None

BreakBeforeBraces: Custom

BreakBeforeInheritanceComma: false

BreakInheritanceList: BeforeComma

BreakBeforeTernaryOperators: true

BreakConstructorInitializersBeforeComma: true

BreakConstructorInitializers: BeforeComma

BreakAfterJavaFieldAnnotations: false

BreakStringLiterals: true

ColumnLimit:     120

CommentPragmas:  '^ IWYU pragma:'

CompactNamespaces: false

ConstructorInitializerAllOnOneLineOrOnePerLine: true

ConstructorInitializerIndentWidth: 4

ContinuationIndentWidth: 4

Cpp11BracedListStyle: true

DerivePointerAlignment: false

DisableFormat:   false

ExperimentalAutoDetectBinPacking: false

FixNamespaceComments: false

ForEachMacros:

  - foreach

  - Q_FOREACH

  - BOOST_FOREACH

IncludeBlocks:   Preserve

IncludeCategories:

  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'

    Priority:        2

  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'

    Priority:        3

  - Regex:           '.*'

    Priority:        1

IncludeIsMainRegex: '(Test)?$'

IndentCaseLabels: true

# doesn't seemt to work

# IndentPPDirectives: BeforeHash

IndentWidth:     4

IndentWrappedFunctionNames: false

JavaScriptQuotes: Leave

JavaScriptWrapImports: true

KeepEmptyLinesAtTheStartOfBlocks: false

MacroBlockBegin: ''

MacroBlockEnd:   ''

MaxEmptyLinesToKeep: 1

NamespaceIndentation: All

ObjCBinPackProtocolList: Auto

ObjCBlockIndentWidth: 2

ObjCSpaceAfterProperty: false

ObjCSpaceBeforeProtocolList: true

PenaltyBreakAssignment: 2

PenaltyBreakBeforeFirstCallParameter: 19

PenaltyBreakComment: 300

PenaltyBreakFirstLessLess: 120

PenaltyBreakString: 1000

PenaltyBreakTemplateDeclaration: 10

PenaltyExcessCharacter: 1000000

PenaltyReturnTypeOnItsOwnLine: 2000000

PointerAlignment: Right

ReflowComments:  true

SortIncludes:    true

SortUsingDeclarations: true

SpaceAfterCStyleCast: true

SpaceAfterTemplateKeyword: true

SpaceBeforeAssignmentOperators: true

SpaceBeforeCpp11BracedList: true

SpaceBeforeCtorInitializerColon: true

SpaceBeforeInheritanceColon: true

SpaceBeforeParens: ControlStatements

SpaceBeforeRangeBasedForLoopColon: true

SpaceInEmptyParentheses: false

SpacesBeforeTrailingComments: 1

SpacesInAngles:  false

SpacesInContainerLiterals: false

SpacesInCStyleCastParentheses: false

SpacesInParentheses: false

SpacesInSquareBrackets: false

Standard:        Cpp11

StatementMacros:

  - Q_UNUSED

  - QT_REQUIRE_VERSION

# using a big tab-width so abuse is shown immediately

TabWidth:        8

UseTab:          Never

...

bin$ 


On Fri, Feb 28, 2020 at 10:28 PM martin lampacher <[hidden email]> wrote:
hi owen,

i've been using my pre-built clang-format from SVN now for a while and tried to switch to clang-format-10, where i'm running into a similar issue. was this fix never merged or maybe it got lost during the transition to git?

i'm seeing the following output now for such a formatted list:

// shows behaviour of clang-format for line-breaks with initializers
static t_component_list _component_list_variable[]
= {E_COMPONENT_LIST_VALUE_0,
E_COMPONENT_LIST_VALUE_1,
E_COMPONENT_LIST_VALUE_0,
E_COMPONENT_LIST_VALUE_1,
E_COMPONENT_LIST_VALUE_0,
E_COMPONENT_LIST_OTHER_VALUE};

where i'd expect

// shows behaviour of clang-format for line-breaks with initializers
static t_component_list _component_list_variable[] = {
E_COMPONENT_LIST_VALUE_0,
E_COMPONENT_LIST_VALUE_1,
E_COMPONENT_LIST_VALUE_0,
E_COMPONENT_LIST_VALUE_1,
E_COMPONENT_LIST_VALUE_0,
E_COMPONENT_LIST_OTHER_VALUE};

cheers.m

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev