J. David Bryan wrote:
Running gpc-20060325 on i486-pc-mingw32 (gcc-3.4.6), I wish to use an "asm" statement and the predefined identifiers "Cardinal" and "ParamCount" in an Extended Pascal program. However, the following program fails to compile:
{$ extended-pascal } {$ enable-keyword asm } {$ enable-predefined-identifier Cardinal } {$ enable-predefined-identifier ParamCount }
program Predefs;
var C : Cardinal; I : integer;
begin asm ('nop'); I := ParamCount; C := 1 end.
With "gpc -c predefs.pas", I get:
predefs.pas:1: warning: compiler directives are a UCSD Pascal extension predefs.pas: In main program: predefs.pas:12: error: `asm' is an extension of Borland Pascal, traditional predefs.pas:12: error: Macintosh Pascal predefs.pas:13: error: `ParamCount' is an extension of Borland Pascal
Note from the above that "Cardinal" is being enabled by the directives, whereas "ParamCount" and "asm" are not.
I get the same results if I specify the compiler switches on the command line (e.g., "--enable-keyword=asm", etc.) instead of within the program. I see the same behavior with gpc-20051116.
Is this a compiler bug, or am I doing something wrong?
1) GPC documentation of "--enable-keyword" probably could be improved. the "--enable-keyword" and "--disable-keyword" are _not_ intended to create a new dialect. Rather, they are intended as a help to avoid conflicts betwen identifiers and keywords: "--disable-keyword" makes sure that a given name is treated as identifier (avoiding a parse error or unwanted interpretation). "--enable-keyword" allows to get back keyword that was previously diabled. Currently there should be little (maybe even no) need to use "--disable-keyword" as intended: the parser is now much better at distinguising identifiers and keywords. "--disable-keyword" also works quite well to _restrict_ available language. However, "--enable-keyword" just causes GPC to recognize given keyword, but otherwise do not influence the accepted language. Since by default all keywords are allowed and dialect choice just rejects constucts outside given dialect, "--enable-keyword" in fact can not enable a new construct -- it can only turn on previously disabled keyword.
2) "--enable-predefined-identifier" is a relatively new addition to GPC. ATM it works like "--enable-keyword": it assigns to an identifer its predefined meaning, but do not affect other checks in the compiler. In particular, builtin routines remain effectively disabled (and "ParamCount" is a routine (function)). "Cardinal" works since it is a type.
I am not sure if we should change what GPC is doing. We probably could remove dialect check for builtin routines, but for keywords things are more tricky: a set of dialects in which a constuct is valid may be smaller then set of dialects in which keywords involved in the constuct are valid -- so we still need dialect checks. Also, a single keyword may be used in multiple constructs (and GPC extensions tends to re-use keywords if possible). So, I am not sure how useful would be ability to enable all constructs involwing given keyword.