Frank wrote:
As you probably know, GPC currently converts all identifiers to first letter upper-case/rest lower-case. Since this is often not nice, I plan to change this. This would affect at least the following things:
It is not clear to me what change you propose.
You probably mean (because this is easiest to implement) to (optionally?) drop the conversion altogether and consequently have case-sensitive identifiers. This is contrary to Pascal standards, but has some advantages in the C/Unix-dominated tool world.
Of course, I would NOT recommend
program Example1;
const MIXEDCASE = True;
var MixedCase: Integer; mixedCase: Real;
ALTERNATIVELY, it might be possible to convert all occurences of the same identifier (modulo case) to the casing found on the defining occurrence. Thus
program Example2;
var MixedCase: Integer;
...
readln ( mixedCase ) ; writeln ( mixedcase )
would work properly and all external handling would be via the identifier MixedCase.
This also seems easy to implement (at the expense of a slightly more expense compare for lookup) and more in line with Pascal:
When creating a symbol-table entry you store the casing as found. When looking up a name you compare names modulo case (e.g. convert both comparands to lower case), when you get a hit you use the actual casing found in the symbol table.
This makes Example1 illegal and makes Example2 work as expected.
While I'm at it, it might be easy to add a warning if an identifier is used with varying case (something like `var Foo: Integer; [...] WriteLn (FOO)').
Such an option would be quite helpful, even if you do not make changes to the case handling.
- Any ideas for the name of the option? (`-Widentifier-case'?)
Seems fine.
- Default? (I suppose off, though I think I myself would prefer on.)
I would prefer on, because we have come to know that case variations of the same identifier are confusing.
- Should it work across units/modules? Or should it be a tri-state
option (never/current file/global)?
Across units/modules would be best, but I can imagine that with legacy code it might be helpful to restrict the scope of the checking.
Tom