Author Topic: C beautifier - else & return statements - v22.0.2.1  (Read 3099 times)

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
C beautifier - else & return statements - v22.0.2.1
« on: September 12, 2018, 06:07:27 PM »
I am running the beautifier on a C file. However, I cannot get the results I am looking for. I have found on a previous post that the beautifier does not have settings to put a blank line before if, while, do, & for.

https://community.slickedit.com/index.php/topic,16330.0.html

So, maybe there is no setting for this either. I have attached two files, before & after. Here are couple of snippets with tabs replaced as spaces to hold formatting in the forum text:


    FlashProgram_WIR_routine(address, Data); /* Process routine in RAM */
    ExitCritical();                      /* Enable all low level interrupts */
    if(AccessError())                   /* Is an access error detected ? */
        return ERR_NOTAVAIL;               /* If yes then return the error */
    return Err;
-------------------------------------
WANT

    ExitCritical();                      /* Enable all low level interrupts */
                         <<--- space here, covered in a previous post though
    if(AccessError())                   /* Is an access error detected ? */
        return ERR_NOTAVAIL;               /* If yes then return the error */
                           <<--- space here   
    return Err;
-------------------------------------
   else
   {
      setReg(PFIU_PE, 0);                /* Clear Program enable register */
      if(Command == MASS_ERASE)       /* Is the mass erase operation requested? */
      { setReg(PFIU_EE, 0x4000);          /* Write page number and enable intelligent erase */
         setRegBit(PFIU_CNTL, MAS1);      /* If yes, then enable mass erase */
      }
      else setReg(PFIU_EE, (address >> 8) + 0x4000); /* Write page number and enable intelligent erase */
   }
-------------------------------------
WANT

   else
   {
      setReg(PFIU_PE, 0);                /* Clear Program enable register */
                            <<--- space here, covered in a previous post though
      if(Command == MASS_ERASE)       /* Is the mass erase operation requested? */
      { setReg(PFIU_EE, 0x4000);          /* Write page number and enable intelligent erase */
         setRegBit(PFIU_CNTL, MAS1);      /* If yes, then enable mass erase */
      }
      else    <<----- statement on same line as else moved underneath else
     {         
           setReg(PFIU_EE, (address >> 8) + 0x4000); /* Write page number and enable intelligent erase */
      }        <<----- if the preceding if for this else had braces, not single-line statement, then wrap braces around block even if single line.
   }                        Or, would be OK to just put single-line statement without braces, if brace checking of prior if proves problematic.


« Last Edit: September 12, 2018, 08:01:37 PM by JimmieC »

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #1 on: September 12, 2018, 06:40:47 PM »
There are some other areas of interest as well.

Beautifed file, line 220, mempcpy, beautifier un-indented 3 move instructions

Beautifed file, line 304, WriteWords, need option to use braces on parent for loop if next line is not a single-line

Beautifed file, line 305, WriteWords, braces for if statement are indented

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #2 on: September 12, 2018, 06:47:50 PM »

Beautifed file, line 436, FlashProgram_SetByteFlash, want a space between variables & code.

   word Data16;
   byte rot;
                <<------ Want a space here.
    rot = (byte)((Addr % 2) * 8);





JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #3 on: September 12, 2018, 07:02:14 PM »
Beautifed file, line 261, procflash, code on same line as brace

        if(Command == MASS_ERASE)       /* Is the mass erase operation requested? */
        { setReg(PFIU_EE, 0x4000);          /* Write page number and enable intelligent erase */
            setRegBit(PFIU_CNTL, MAS1);      /* If yes, then enable mass erase */
        }


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #4 on: September 12, 2018, 08:27:17 PM »
Beautifed file, line 261, procflash, code on same line as brace

        if(Command == MASS_ERASE)       /* Is the mass erase operation requested? */
        { setReg(PFIU_EE, 0x4000);          /* Write page number and enable intelligent erase */
            setRegBit(PFIU_CNTL, MAS1);      /* If yes, then enable mass erase */
        }


Please post your user.cfg.xml. That will give us your beautify profile settings. I wasn't able to reproduce this by just changing the "if" brace style.

Your other posts are feature requests. All good ones.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #5 on: September 12, 2018, 08:37:23 PM »
Here is the user.cfg.xml file.

I did dork with the beautify settings a little after I posted to the forum. I don't think I changed anything substantial; Was trying to get rid of the blank line after the opening paren of a function. I changed that setting.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #6 on: September 12, 2018, 08:50:12 PM »
In my earlier post:

Beautifed file, line 305, WriteWords, braces for if statement are indented

This is actually OK. The whole if statement is correctly indented. And, the braces are properly underneath the if. So, cancel this one.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #7 on: September 13, 2018, 02:33:36 PM »
Ok. 

I'm debugging the brace without the newline now.  I see what's wrong, and am deciding how to fix it now, so I expect it to be in the next v23 beta drop.

I need to take a closer look at the other features, but it's safe to say any of those would be post v23.0.0.

JimmieC

  • Senior Community Member
  • Posts: 490
  • Hero Points: 17
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #8 on: September 13, 2018, 03:18:57 PM »
Yeah, most of the stuff I reported works out to be new features.

Just below the brace without newline, is an else without newline for the single-line statement:
-----------------
else setReg(PFIU_EE, (address >> 8) + 0x4000); /* Write page number and enable intelligent erase */
-----------------
else
    setReg(PFIU_EE, (address >> 8) + 0x4000); /* Write page number and enable intelligent erase */
-----------------

 I think that counts a bug too? My comment about optionally wrapping it in braces is a new feature. But, without adding braces, should that be put on a newline at least?

Not a front-burner issue anyway.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #9 on: September 13, 2018, 05:25:04 PM »
You can change the "Unblocked else statement on same line" to Off under Newlines -> 'if' statements for that.   I'd turn off the "Unblocked then statement on the same line" too, for consistency.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: C beautifier - else & return statements - v22.0.2.1
« Reply #10 on: September 18, 2018, 01:51:12 PM »
Just confirming the fix for the brace without a newline will be in the next drop. Thanks.