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

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

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

Kristóf Umann 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

Kristóf Umann 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

Kristóf Umann 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

Kristóf Umann 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

Kristóf Umann 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

Kristóf Umann 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

Kristóf Umann 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