Author Topic: Strict and AutoCase  (Read 3490 times)

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Strict and AutoCase
« on: 2009-Feb-19 »
Hi Gernot

Could I request two teeny additional features for GLB in the editor and compiler to be added to the wish list?

First one is could you add a strict option in GLB to fail compilation with an error instead of a warning when a variable has not been declared.  Make this an option that is off by default so not to cause any compatibility problems with older code and those that don't want it.  See reasons why below.

Second one is could you add an option to the editor to not change the case of what you type when it detects a reserved word.  And add a button to reformat the current code window (force case, spacing, indenting etc) so you can tidy up your code when you need to.  I know some people will like it, so again as an option, but for me it tends to get in the way.  The colour coding is not a problem (and is helpful) but the change to UPPERCASE changes your program.



The reason for the two above requests are that often, while in a procedure for example, I declare a local variable that starts with a reserved word, such as MAX for example, often GLB will jump in and change that part to upper case.  For example if I have a variable called "maxt" it I press del key to remove the 't' then max becomes MAX.  If I leave it as-is, and now have a new variable called MAXt, a different variable to maxt.  See code below.

Example:
FUNCTION test1:
   LOCAL maxt
   maxt=0
   MAXt=1
   
   PRINT maxt + " " + MAXt,0,0
   SHOWSCREEN
   KEYWAIT
ENDFUNCTION

in the compilation log (but only when in debug mode):
"test.gbas"(4) warning : implicitly created GLOBAL  : MAXt


The output from the above is "0 1" because we've now got two different variables.  If you have debug mode off you don't even see the warnings.

Would it be possible to add these features?  The strict option would stop any errors being introduced and if we could turn off auto formatting we could avoid the annoying renaming (by change to uppercase) of variables when we don't want them to.  It's a pain to avoid every reserved word as part of a variable name or to retyping in lowercase.
« Last Edit: 2009-Feb-19 by AndyH »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10759
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Strict and AutoCase
« Reply #1 on: 2009-Feb-19 »
So, would it be OK to reformat the code when you press the compile button?
I can add that option, yes.

The strict is a bit complicated, because what if you have 3 different files. A strict for each file?
Or like a preprocessor setting:

STRICT TRUE
some code here
STRICT FALSE
Some bad code here
...


?

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Re: Strict and AutoCase
« Reply #2 on: 2009-Feb-19 »
At compilation - yes, that sounds good.

For strict, it would be easier to do (from a users point of view) if it was a project setting that is applied to all files in that project.  If you leave it OFF by default when creating a project compile and warn as normal.  If the project setting is changed to ON convert those warnings into errors.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10759
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Strict and AutoCase
« Reply #3 on: 2009-Feb-20 »
Great idea. Update is online.

Hatonastick

  • Guest
Re: Strict and AutoCase
« Reply #4 on: 2009-Feb-20 »
Man, you are quick. :)

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Re: Strict and AutoCase
« Reply #5 on: 2009-Feb-20 »
Fantastic, thanks Gernot.  I think there might be a glitch with inline code though?

C:\DOCUME~1\AndyH\LOCALS~1\Temp\glbasic\gpc_temp3.cpp: In function `float __GLBASIC__::qInvSqrt(float)':
C:\DOCUME~1\AndyH\LOCALS~1\Temp\glbasic\gpc_temp3.cpp:917: error: `RETURN' was not declared in this scope
C:\DOCUME~1\AndyH\LOCALS~1\Temp\glbasic\gpc_temp3.cpp:917: error: expected `;' before "x"
C:\DOCUME~1\AndyH\LOCALS~1\Temp\glbasic\gpc_temp3.cpp: In function `DGInt __GLBASIC__::QSQR(DGInt)':
C:\DOCUME~1\AndyH\LOCALS~1\Temp\glbasic\gpc_temp3.cpp:932: error: `RETURN' was not declared in this scope
C:\DOCUME~1\AndyH\LOCALS~1\Temp\glbasic\gpc_temp3.cpp:932: error: expected `;' before numeric constant
*** FATAL ERROR - Please post this output in the forum

this points to....

/* ---- INLINE ---- */
float qInvSqrt(float x){
   float xhalf = 0.5f * x;
   int i = *(int*)&x; // store floating-point bits in integer
   i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method
   x = *(float*)&i; // convert new bits into float
   x = x*(1.5f - xhalf*x*x); // One round of Newton's method
   RETURN x;
}

/* ---- ENDINLINE ---- */
// ------------------------ //


And the GLBasic code is:

INLINE
float qInvSqrt(float x){
   float xhalf = 0.5f * x;
   int i = *(int*)&x; // store floating-point bits in integer
   i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method
   x = *(float*)&i; // convert new bits into float
   x = x*(1.5f - xhalf*x*x); // One round of Newton's method
   RETURN x;
}
ENDINLINE

float x is defined as the parameter passed.

Hatonastick

  • Guest
Re: Strict and AutoCase
« Reply #6 on: 2009-Feb-20 »
Yeah it's reformatting C keywords into uppercase which isn't a good thing.  ie. 'RETURN' should be 'return'.  I hit the same problem while recompiling my Mersenne Twister library with the latest release.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10759
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Strict and AutoCase
« Reply #7 on: 2009-Mar-09 »
still?

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
Re: Strict and AutoCase
« Reply #8 on: 2009-Mar-09 »
OK for me now.