* src/SDCCmain.c (setDefaultOptions, optionsTable[], parseCmdLine),
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 26 Mar 2005 06:07:40 +0000 (06:07 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 26 Mar 2005 06:07:40 +0000 (06:07 +0000)
* src/z80/main.c (_keywords[]),
* src/SDCCglobal.h (struct options),
* src/SDCC.y,
* src/SDCC.lex (isTargetKeyword, doPragma, pragma_tbl[]): new pragmas
to enable/disable SDCC and C99 extensions/keywords (std_c89, std_sdcc89,
std_c99, std_sdcc99). Also, equivalent command line options (--std-c89,
--std-sdcc89, --std-c99, --std-sdcc99). SDCC specific keywords are
always available in leading double underscore form. The C99 support is
mostly missing, but it's a start.
* support/regression/tests/bug-227710.c: fixed nonconforming use of
reserved identifier "__data".

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3707 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCC.lex
src/SDCC.y
src/SDCCglobl.h
src/SDCCmain.c
src/z80/main.c
support/regression/tests/bug-227710.c

index e91caa9c8803aa51bd549690da972dabca957e6e..6bd37ede3454b0c301e9e0062196f4f1fd7cf2c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2005-03-26 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * src/SDCCmain.c (setDefaultOptions, optionsTable[], parseCmdLine),
+       * src/z80/main.c (_keywords[]),
+       * src/SDCCglobal.h (struct options),
+       * src/SDCC.y,
+       * src/SDCC.lex (isTargetKeyword, doPragma, pragma_tbl[]): new pragmas
+       to enable/disable SDCC and C99 extensions/keywords (std_c89, std_sdcc89,
+       std_c99, std_sdcc99). Also, equivalent command line options (--std-c89,
+       --std-sdcc89, --std-c99, --std-sdcc99). SDCC specific keywords are
+       always available in leading double underscore form. The C99 support is
+       mostly missing, but it's a start.
+       * support/regression/tests/bug-227710.c: fixed nonconforming use of
+       reserved identifier "__data".
+
 2005-03-24 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/mcs51/peeph.def: fixed bug 1170013
index 43074e9d810e42152ffc5a08e5b3a05bfccaa7ae..169d9aea6719dd79d97e3393aa86257d01d3a05b 100644 (file)
@@ -40,6 +40,11 @@ IS      (u|U|l|L)*
 #define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
                                 check_type())
 
+#define TKEYWORDSDCC(token) return (options.std_sdcc && isTargetKeyword(yytext)\
+                                    ? token : check_type())
+
+#define TKEYWORD99(token) return (options.std_c99 ? token : check_type())
+
 extern int lineno, column;
 extern char *filename;
 
@@ -61,18 +66,27 @@ static int checkCurrFile(char *s);
 
 %x asm
 %%
-"_asm"         {
+_?"_asm"         {
   count();
+  if (!options.std_sdcc && yytext[1] != '_')
+    return check_type();
   assert(asmbuff.alloc == 0 && asmbuff.len == 0 && asmbuff.buf == NULL);
   dbuf_init(&asmbuff, INITIAL_INLINEASM);
   BEGIN(asm);
 }
-<asm>"_endasm" {
+<asm>_?"_endasm" {
   count();
-  yylval.yyinline = dbuf_c_str(&asmbuff);
-  dbuf_detach(&asmbuff);
-  BEGIN(INITIAL);
-  return (INLINEASM);
+  if (!options.std_sdcc && yytext[1] != '_')
+    {
+      dbuf_append(&asmbuff, yytext, strlen(yytext));
+    }
+  else
+    {
+      yylval.yyinline = dbuf_c_str(&asmbuff);
+      dbuf_detach(&asmbuff);
+      BEGIN(INITIAL);
+      return (INLINEASM);
+    }
 }
 <asm>\n        {
   count();
@@ -81,49 +95,69 @@ static int checkCurrFile(char *s);
 <asm>.         {
   dbuf_append(&asmbuff, yytext, 1);
 }
-"at"           { count(); TKEYWORD(AT); }
+"at"           { count(); TKEYWORDSDCC(AT); }
+"__at"         { count(); TKEYWORD(AT); }
 "auto"         { count(); return(AUTO); }
-"bit"          { count(); TKEYWORD(BIT); }
+"bit"          { count(); TKEYWORDSDCC(BIT); }
+"__bit"        { count(); TKEYWORD(BIT); }
 "break"        { count(); return(BREAK); }
 "case"         { count(); return(CASE); }
 "char"         { count(); return(CHAR); }
-"code"         { count(); TKEYWORD(CODE); }
+"code"         { count(); TKEYWORDSDCC(CODE); }
+"__code"       { count(); TKEYWORD(CODE); }
 "const"        { count(); return(CONST); }
 "continue"     { count(); return(CONTINUE); }
-"critical"     { count(); TKEYWORD(CRITICAL); }
-"data"         { count(); TKEYWORD(DATA); }
+"critical"     { count(); TKEYWORDSDCC(CRITICAL); }
+"__critical"   { count(); TKEYWORD(CRITICAL); }
+"data"         { count(); TKEYWORDSDCC(DATA); }
+"__data"       { count(); TKEYWORD(DATA); }
 "default"      { count(); return(DEFAULT); }
 "do"           { count(); return(DO); }
 "double"       { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); }
 "else"         { count(); return(ELSE); }
 "enum"         { count(); return(ENUM); }
 "extern"       { count(); return(EXTERN); }
-"far"          { count(); TKEYWORD(XDATA); }
-"eeprom"       { count(); TKEYWORD(EEPROM); }
+"far"          { count(); TKEYWORDSDCC(XDATA); }
+"__far"        { count(); TKEYWORD(XDATA); }
+"eeprom"       { count(); TKEYWORDSDCC(EEPROM); }
+"__eeprom"     { count(); TKEYWORD(EEPROM); }
 "float"        { count(); return(FLOAT); }
-"flash"        { count(); TKEYWORD(CODE); }
+"flash"        { count(); TKEYWORDSDCC(CODE); }
+"__flash"      { count(); TKEYWORD(CODE); }
 "for"          { count(); return(FOR); }
 "goto"         { count(); return(GOTO); }
-"idata"        { count(); TKEYWORD(IDATA); }
+"idata"        { count(); TKEYWORDSDCC(IDATA); }
+"__idata"      { count(); TKEYWORD(IDATA); }
 "if"           { count(); return(IF); }
 "int"          { count(); return(INT); }
-"interrupt"    { count(); return(INTERRUPT); }
-"nonbanked"    { count(); TKEYWORD(NONBANKED); }
-"banked"       { count(); TKEYWORD(BANKED); }
+"interrupt"    { count(); TKEYWORDSDCC(INTERRUPT); }
+"__interrupt"  { count(); TKEYWORD(INTERRUPT); }
+"nonbanked"    { count(); TKEYWORDSDCC(NONBANKED); }
+"__nonbanked"  { count(); TKEYWORD(NONBANKED); }
+"banked"       { count(); TKEYWORDSDCC(BANKED); }
+"__banked"     { count(); TKEYWORD(BANKED); }
 "long"         { count(); return(LONG); }
-"near"         { count(); TKEYWORD(DATA); }
-"pdata"        { count(); TKEYWORD(PDATA); }
-"reentrant"    { count(); TKEYWORD(REENTRANT); }
-"shadowregs"   { count(); TKEYWORD(SHADOWREGS); }
-"wparam"       { count(); TKEYWORD(WPARAM); }
+"near"         { count(); TKEYWORDSDCC(DATA); }
+"__near"       { count(); TKEYWORD(DATA); }
+"pdata"        { count(); TKEYWORDSDCC(PDATA); }
+"__pdata"      { count(); TKEYWORD(PDATA); }
+"reentrant"    { count(); TKEYWORDSDCC(REENTRANT); }
+"__reentrant"  { count(); TKEYWORD(REENTRANT); }
+"shadowregs"   { count(); TKEYWORDSDCC(SHADOWREGS); }
+"__shadowregs" { count(); TKEYWORD(SHADOWREGS); }
+"wparam"       { count(); TKEYWORDSDCC(WPARAM); }
+"__wparam"     { count(); TKEYWORD(WPARAM); }
 "register"     { count(); return(REGISTER); }
 "return"       { count(); return(RETURN); }
-"sfr"          { count(); TKEYWORD(SFR); }
-"sbit"         { count(); TKEYWORD(SBIT); }
+"sfr"          { count(); TKEYWORDSDCC(SFR); }
+"__sfr"        { count(); TKEYWORD(SFR); }
+"sbit"         { count(); TKEYWORDSDCC(SBIT); }
+"__sbit"       { count(); TKEYWORD(SBIT); }
 "short"        { count(); return(SHORT); }
 "signed"       { count(); return(SIGNED); }
 "sizeof"       { count(); return(SIZEOF); }
-"sram"         { count(); TKEYWORD(XDATA); }
+"sram"         { count(); TKEYWORDSDCC(XDATA); }
+"__sram"       { count(); TKEYWORD(XDATA); }
 "static"       { count(); return(STATIC); }
 "struct"       { count(); return(STRUCT); }
 "switch"       { count(); return(SWITCH); }
@@ -132,14 +166,20 @@ static int checkCurrFile(char *s);
 "unsigned"     { count(); return(UNSIGNED); }
 "void"         { count(); return(VOID); }
 "volatile"     { count(); return(VOLATILE); }
-"using"        { count(); TKEYWORD(USING); }
-"_naked"       { count(); TKEYWORD(NAKED); }
+"using"        { count(); TKEYWORDSDCC(USING); }
+"__using"      { count(); TKEYWORD(USING); }
+"_naked"       { count(); TKEYWORDSDCC(NAKED); }
+"__naked"      { count(); TKEYWORD(NAKED); }
 "while"        { count(); return(WHILE); }
-"xdata"        { count(); TKEYWORD(XDATA); }
+"xdata"        { count(); TKEYWORDSDCC(XDATA); }
+"__xdata"      { count(); TKEYWORD(XDATA); }
 "..."          { count(); return(VAR_ARGS); }
 "__typeof"     { count(); return TYPEOF; }
 "_JavaNative"  { count(); TKEYWORD(JAVANATIVE); }
-"_overlay"     { count(); TKEYWORD(OVERLAY); }
+"_overlay"     { count(); TKEYWORDSDCC(OVERLAY); }
+"__overlay"    { count(); TKEYWORD(OVERLAY); }
+"inline"       { count(); TKEYWORD99(INLINE); }
+"restrict"     { count(); TKEYWORD99(RESTRICT); }
 {L}({L}|{D})*  { count(); return(check_type()); }
 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
 0[0-7]*{IS}?     { count(); yylval.val = constVal(yytext); return(CONSTANT); }
@@ -421,7 +461,11 @@ enum pragma_id {
      P_DISABLEWARN,
      P_OPTCODESPEED,
      P_OPTCODESIZE,
-     P_OPTCODEBALANCED
+     P_OPTCODEBALANCED,
+     P_STD_C89,
+     P_STD_C99,
+     P_STD_SDCC89,
+     P_STD_SDCC99
 };
 
 
@@ -617,7 +661,26 @@ static void doPragma(int op, char *cp)
     optimize.codeSpeed = 0;
     optimize.codeSize = 0;
     break;
-
+  
+  case P_STD_C89:
+    options.std_c99 = 0;
+    options.std_sdcc = 0;
+    break;
+  
+  case P_STD_C99:
+    options.std_c99 = 1;
+    options.std_sdcc = 0;
+    break;
+  
+  case P_STD_SDCC89:
+    options.std_c99 = 0;
+    options.std_sdcc = 1;
+    break;
+  
+  case P_STD_SDCC99:
+    options.std_c99 = 1;
+    options.std_sdcc = 1;
+    break;
   }
 }
 
@@ -652,6 +715,10 @@ static int process_pragma(char *s)
     { "opt_code_speed", P_OPTCODESPEED, 0 },
     { "opt_code_size",  P_OPTCODESIZE,  0 },
     { "opt_code_balanced",  P_OPTCODEBALANCED,  0 },
+    { "std_c89",       P_STD_C89, 0 },
+    { "std_c99",       P_STD_C99, 0 },
+    { "std_sdcc89",    P_STD_SDCC89, 0 },
+    { "std_sdcc99",    P_STD_SDCC99, 0 },
 
     /*
      * The following lines are deprecated pragmas,
@@ -727,12 +794,30 @@ static int isTargetKeyword(char *s)
 
   if (port->keywords == NULL)
     return 0;
-  for (i = 0 ; port->keywords[i] ; i++ ) {
-    if (strcmp(port->keywords[i],s) == 0)
-      return 1;
-  }
+  
+  if (s[0] == '_' && s[1] == '_')
+    {
+      /* Keywords in the port's array have either 0 or 1 underscore, */
+      /* so skip over the appropriate number of chars when comparing */
+      for (i = 0 ; port->keywords[i] ; i++ )
+        {
+          if (port->keywords[i][0] == '_' &&
+              strcmp(port->keywords[i],s+1) == 0)
+            return 1;
+          else if (strcmp(port->keywords[i],s+2) == 0)
+            return 1;
+        }
+    }
+  else
+    {
+      for (i = 0 ; port->keywords[i] ; i++ )
+        {
+          if (strcmp(port->keywords[i],s) == 0)
+            return 1;
+        }
+    }
 
-    return 0;
+  return 0;
 }
 
 int yywrap(void)
index 3e3c7b3eba875d405f0c2b20f98c77329d954d17..0a4f6a8d6fff1765643f81e66215e144c56e2d5e 100644 (file)
@@ -99,7 +99,7 @@ bool uselessDecl = TRUE;
 %token BITWISEAND UNARYMINUS IPUSH IPOP PCALL  ENDFUNCTION JUMPTABLE
 %token RRC RLC 
 %token CAST CALL PARAM NULLOP BLOCK LABEL RECEIVE SEND ARRAYINIT
-%token DUMMY_READ_VOLATILE ENDCRITICAL SWAP
+%token DUMMY_READ_VOLATILE ENDCRITICAL SWAP INLINE RESTRICT
 
 %type <yyint>  Interrupt_storage
 %type <sym> identifier  declarator  declarator2 declarator3 enumerator_list enumerator
index b60bc26d2c086a37cfe411fcf1bb7f670a2257ff..8e4e7dc16acef2380ac7e6695b873425f512d807 100644 (file)
@@ -251,6 +251,8 @@ struct options
     int vc_err_style;           /* errors and warnings are compatible with Micro$oft visual studio */
     int use_stdout;             /* send errors to stdout instead of stderr */
     int no_std_crt0;            /*For the z80/gbz80 do not link default crt0.o*/
+    int std_c99;               /* enable C99 keywords/constructs */
+    int std_sdcc;              /* enable SDCC extensions to C */
     /* sets */
     set *calleeSavesSet;        /* list of functions using callee save */
     set *excludeRegsSet;        /* registers excluded from saving */
index 86440ad3e0adf447826de80b97ba6cbe1a5036c1..8f6b7c759142378341568596610222609565f8ba 100644 (file)
@@ -135,6 +135,10 @@ char buffer[PATH_MAX * 2];
 #define OPTION_NO_PEEP_COMMENTS "--no-peep-comments"
 #define OPTION_OPT_CODE_SPEED   "--opt-code-speed"
 #define OPTION_OPT_CODE_SIZE    "--opt-code-size"
+#define OPTION_STD_C89          "--std-c89"
+#define OPTION_STD_C99          "--std-c99"
+#define OPTION_STD_SDCC89       "--std-sdcc89"
+#define OPTION_STD_SDCC99       "--std-sdcc99"
 
 static const OPTION
 optionsTable[] = {
@@ -165,7 +169,11 @@ optionsTable[] = {
     { 0,    OPTION_DISABLE_WARNING, NULL, "<nnnn> Disable specific warning" },
     { 0,    "--debug",              &options.debug, "Enable debugging symbol output" },
     { 0,    "--cyclomatic",         &options.cyclomatic, "Display complexity of compiled functions" },
-
+    { 0,    OPTION_STD_C89,         NULL, "Use C89 standard only" },
+    { 0,    OPTION_STD_SDCC89,      NULL, "Use C89 standard with SDCC extensions (default)" },
+    { 0,    OPTION_STD_C99,         NULL, "Use C99 standard only (incomplete)" },
+    { 0,    OPTION_STD_SDCC99,      NULL, "Use C99 standard with SDCC extensions (incomplete)" },
+    
     { 0,    NULL,                   NULL, "Code generation options"},    
     { 'm',  NULL,                   NULL, "Set the port to use e.g. -mz80." },
     { 'p',  NULL,                   NULL, "Select port specific processor e.g. -mpic14 -p16f84" },
@@ -548,6 +556,8 @@ setDefaultOptions (void)
   options.nostdinc = 0;
   options.verbose = 0;
   options.shortis8bits = 0;
+  options.std_sdcc = 1;         /* enable SDCC language extensions */
+  options.std_c99 = 0;          /* default to C89 until more C99 support */
 
   options.stack10bit=0;
 
@@ -1078,6 +1088,34 @@ parseCmdLine (int argc, char **argv)
               continue;
             }
 
+          if (strcmp (argv[i], OPTION_STD_C89) == 0)
+            {
+              options.std_c99 = 0;
+              options.std_sdcc = 0;
+              continue;
+            }
+          
+          if (strcmp (argv[i], OPTION_STD_C99) == 0)
+            {
+              options.std_c99 = 1;
+              options.std_sdcc = 0;
+              continue;
+            }
+
+          if (strcmp (argv[i], OPTION_STD_SDCC89) == 0)
+            {
+              options.std_c99 = 0;
+              options.std_sdcc = 1;
+              continue;
+            }
+          
+          if (strcmp (argv[i], OPTION_STD_SDCC99) == 0)
+            {
+              options.std_c99 = 1;
+              options.std_sdcc = 1;
+              continue;
+            }
+
           if (!port->parseOption (&argc, argv, &i))
             {
               werror (W_UNKNOWN_OPTION, argv[i]);
index 8fb6b0a2d18ef96d13784d134f62ddb09dbb1e97..3706b1721dab148f1467afebb71a76328b75cd48 100644 (file)
@@ -82,6 +82,7 @@ static char *_keywords[] =
   "at",       //.p.t.20030714 adding support for 'sfr at ADDR' construct
   "_naked",   //.p.t.20030714 adding support for '_naked' functions
   "critical",
+  "interrupt",
   NULL
 };
 
index bd16d6697d69a414fbc8352dd87039e47f63b400..013ddea84fba74ab55ef370b480b3ddeb2cc4557 100644 (file)
@@ -2,7 +2,7 @@
  */
 #include <testfwk.h>
 
-static unsigned char __data[] = {
+static unsigned char dataset[] = {
     1, 2, 3, 4
 };
 
@@ -22,7 +22,7 @@ foo(void)
 void
 testPostIncrement(void)
 {
-    p = __data;
+    p = dataset;
     ASSERT(foo() == 1);
     ASSERT(foo() == 2);
     ASSERT(foo() == 3);