* src/SDCCval.c, src/SDCCmain.c, src/SDCC.lex,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 7 Aug 2008 21:44:41 +0000 (21:44 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 7 Aug 2008 21:44:41 +0000 (21:44 +0000)
  device/lib/pic/Makefile.rules, device/lib/ds390/Makefile.in,
  device/lib/ds400/Makefile.in, device/lib/hc08/Makefile.in,
  support/cpp/libcpp/lex.c,  doc/sdccman.lyx:
  applied modified patsh 2038174: Add support for binary constants v2
  thanks Mauro Giachero

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

ChangeLog
device/lib/ds390/Makefile.in
device/lib/ds400/Makefile.in
device/lib/hc08/Makefile.in
device/lib/pic/Makefile.rules
doc/sdccman.lyx
src/SDCC.lex
src/SDCCmain.c
src/SDCCval.c
support/cpp/libcpp/lex.c

index 069ab8edca6d6a399f5daa107f623c5784ef88c6..13c222655045790ecd6f0f70bb70705f6ad483f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-08-07 Borut Razem <borut.razem AT siol.net>
+
+       * src/SDCCval.c, src/SDCCmain.c, src/SDCC.lex,
+         device/lib/pic/Makefile.rules, device/lib/ds390/Makefile.in,
+         device/lib/ds400/Makefile.in, device/lib/hc08/Makefile.in,
+         support/cpp/libcpp/lex.c,  doc/sdccman.lyx:
+         applied modified patsh 2038174: Add support for binary constants v2
+         thanks Mauro Giachero
+
 2008-08-04 Raphael Neider <rneider AT web.de>
 
        * doc/sdccman.lyx,
 
 2007-11-12 Borut Razem <borut.razem AT siol.net>
 
-       * as\z80\asmain.c, as\z80\asm.h, as\z80\assym.c, as\z80\asdata.c,
-         as\z80\asout.c, as\z80\aslist.c:
+       * as/z80/asmain.c, as/z80/asm.h, as/z80/assym.c, as/z80/asdata.c,
+         as/z80/asout.c, as/z80/aslist.c:
          fixed bug #1817005 - as-z80 chokes on long labels
 
 2007-11-11 Maarten Brock <sourceforge.brock AT dse.nl>
 
 2006-04-18 Borut Razem <borut.razem AT siol.net>
 
-       * support/scripts/sdcc.nsi: removed unexisting ${DEV_ROOT}\lib\pic\*.o,
-         ${DEV_ROOT}\lib\src\pic\libdev\*.S, ${DEV_ROOT}\lib\src\pic\libdev\*.inc
+       * support/scripts/sdcc.nsi: removed unexisting ${DEV_ROOT}/lib/pic/*.o,
+         ${DEV_ROOT}/lib/src/pic/libdev/*.S, ${DEV_ROOT}/lib/src/pic/libdev/*.inc
 
 2006-04-17 Borut Razem <borut.razem AT siol.net>
 
index 3dda5c5c0a9645455879af86a9d078c6580cc0b0..4dbedf34f6a0a66ec80ed8522938ca37eeb3ae39 100644 (file)
@@ -10,7 +10,7 @@ OBJECTS = tinibios.rel memcpyx.rel  lcd390.rel i2c390.rel rtc390.rel putchar.rel
 SOURCES = $(patsubst %.rel,%.c,$(OBJECTS))
 
 CPPFLAGS = -I$(srcdir)/../../include
-CFLAGS = -mds390 $(CPPFLAGS) $(VERBOSE) --std-c89
+CFLAGS = -mds390 $(CPPFLAGS) $(VERBOSE) --std-c99
 
 all: $(OBJECTS) libds390.lib
 
index fab404a63f7fb0e8bdb608e26cba9efd54a0858c..234df089677e14e14e17e3e832f0c0538c4f8e60 100644 (file)
@@ -10,7 +10,7 @@ OBJECTS = tinibios.rel memcpyx.rel ds400rom.rel
 SOURCES = $(patsubst %.rel,%.c,$(OBJECTS))
 
 CPPFLAGS = -I$(srcdir)/../../include
-CFLAGS = -mds400 $(CPPFLAGS) $(VERBOSE) --std-c89
+CFLAGS = -mds400 $(CPPFLAGS) $(VERBOSE) --std-c99
 
 all: $(OBJECTS) libds400.lib
 
index 5482da00044996276fecea21a5df8444c6d7f7ad..56596653ee1d3f751c0024ea01f617fdf21a5558 100644 (file)
@@ -15,7 +15,7 @@ CC = $(SCC)
 AS = $(SAS)
 ASFLAGS = -plosgff
 
-CFLAGS = -I$(srcdir)/../../include -I. --std-c89
+CFLAGS = -I$(srcdir)/../../include -I. --std-c99
 
 all: $(LIB)
 
index 3cb7efb80597449f7e2d4ad10a9867849153de5c..6813ae0304985f05444c07f56ca3cdd4b08c7d04 100644 (file)
@@ -58,7 +58,7 @@ recurse : force
        $(Q)+for DIR in $(SUBDIRS) ; do \
                [ -f "$(srcdir)/$${DIR}.ignore" ] && $(GREP) "^$${ARCH}$$" "$${DIR}.ignore" > /dev/null 2>&1 || ( \
                        $(MKDIR) "$(top_builddir)/$(builddir)/$${DIR}"; \
-                       $(MAKE) -C "$${DIR}" builddir="$(builddir)/$${DIR}" $(MAKECMDGOALS); \
+                       CFLAGS="$(CFLAGS)" $(MAKE) -C "$${DIR}" builddir="$(builddir)/$${DIR}" $(MAKECMDGOALS); \
                ) || exit 1; \
        done
 else
index 746bb8be33b933605498404d48b588beb09019b0..f0035c83e2f0223572ed45e129dff8f505d750b8 100644 (file)
@@ -1158,6 +1158,14 @@ b = !b; /* toggles b */
 In previous versions, both forms would have toggled the bit.
 \end_layout
 
+\begin_layout Itemize
+in older versions, the preprocessor was always called with -std=c99 regardless
+ of the --std-xxx setting.
+ This is no longer true, and can cause compilation failures on code built
+ with --std-c89 but using c99 preprocessor features, such as one-line (//)
+ comments
+\end_layout
+
 \begin_layout Standard
 
 \emph on
@@ -8028,6 +8036,7 @@ linkOption[,linkOption]
 
 \end_inset
 
+
 \begin_inset LatexCommand \label{lyx:-Wl option}
 
 \end_inset
@@ -10834,6 +10843,7 @@ status collapsed
 
 \end_inset
 
+
 \begin_inset LatexCommand \label{lyx:-codeseg}
 
 \end_inset
@@ -13213,6 +13223,31 @@ The xdata storage class declares a variable that can reside anywhere in
 \end_inset
 
 
+\end_layout
+
+\begin_layout Section
+Other SDCC language extensions
+\begin_inset LatexCommand \index{Other SDCC language extensions}
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Subsection
+Binary constants
+\end_layout
+
+\begin_layout Standard
+SDCC supports the use of binary constants, such as 0b01100010.
+ This feature is only enabled when the compiler is invoked using --std-sdccxx.
+\end_layout
+
+\begin_layout Standard
+\begin_inset VSpace bigskip
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
index 6567003c575dfd329e9cfdadf1736369e48975de..0fc43d00445ed1bd3f5881bb047b091f04423282 100644 (file)
@@ -22,6 +22,7 @@
   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+B       [0-1]
 D       [0-9]
 L       [a-zA-Z_$]
 H       [a-fA-F0-9]
@@ -199,6 +200,15 @@ _?"_asm"         {
   count();
   return(check_type());
 }
+0[bB]{B}+{IS}? {
+  if (!options.std_sdcc)
+    {
+      yyerror("binary (0b) constants are not allowed in ISO C");
+    }
+  count();
+  yylval.val = constVal(yytext);
+  return(CONSTANT);
+}
 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
 0[0-7]*{IS}?     { count(); yylval.val = constVal(yytext); return(CONSTANT); }
 [1-9]{D}*{IS}?      { count(); yylval.val = constVal(yytext); return(CONSTANT); }
index ec234ecb2713f200424ec341d73b980ac2b4148b..cfdbb10a6cc2c6a3c3df3f320ff7680914642d46 100644 (file)
@@ -283,7 +283,7 @@ static const char *_baseValues[] = {
   NULL
 };
 
-static const char *_preCmd = "{cpp} -nostdinc -Wall -std=c99 {cppextraopts} \"{fullsrcfilename}\" \"{cppoutfilename}\"";
+static const char *_preCmd = "{cpp} -nostdinc -Wall {cppstd}{cppextraopts} \"{fullsrcfilename}\" \"{cppoutfilename}\"";
 
 PORT *port;
 
@@ -2254,6 +2254,20 @@ initValues (void)
       setMainValue ("linkdstfilename", "{stdlinkdstfilename}");
     }
 
+  /*
+   * Make sure the preprocessor is called with the "-std" option
+   * corresponding to the --std used to start sdcc
+   */
+  if (options.std_c99)
+    {
+      if (!options.std_sdcc)
+        setMainValue ("cppstd", "-std=c99 ");
+    }
+  else
+    {
+      if (!options.std_sdcc)
+        setMainValue ("cppstd", "-std=c89 ");
+    }
 }
 
 static void doPrintSearchDirs(void)
index 649388f7f6e0c442cf0d15949e880495fe81a883..de08d2a6cdb632183032f34cdc0cb97606e4e735 100644 (file)
@@ -698,9 +698,9 @@ constFixed16x16Val (const char *s)
 value *constVal (const char *s)
 {
   value *val;
-  bool hex = FALSE, octal = FALSE;
   char *p;
   double dval;
+  bool is_integral = 0;
 
   val = newValue ();            /* alloc space for value   */
 
@@ -710,27 +710,22 @@ value *constVal (const char *s)
   SPEC_NOUN (val->type) = V_CHAR;
   SPEC_USIGN (val->type) = 0;
 
-  if (s[0] == '0')
-    {
-      if (s[1] == 'x' || s[1] == 'X')
-        hex = TRUE;
-      else if (isdigit(s[1]))
-        octal = TRUE;
-    }
-
   errno = 0;
-  if (hex || octal)
+  if (s[0] == '0')
     {
-      dval = strtoul (s, &p, 0);
-      if (errno)
-        {
-          dval = 4294967295.0;
-          werror (W_INVALID_INT_CONST, s, dval);
-        }
+      if (s[1] == 'b' || s[1] == 'B')
+        dval = strtoul (s + 2, &p, 2);
+      else
+        dval = strtoul (s, &p, 0);
+      is_integral = 1;
     }
   else
+    dval = strtod (s, &p);
+
+  if (errno)
     {
-      dval = strtod(s, &p);
+      dval = 4294967295.0;
+      werror (W_INVALID_INT_CONST, s, dval);
     }
 
   /* Setup the flags first */
@@ -779,7 +774,7 @@ value *constVal (const char *s)
             }
           else if (dval > 0x7fff && !SPEC_USIGN (val->type))
             { /* check if we have to promote to long int */
-              if ((hex || octal) && /* hex or octal constants may be stored in unsigned type */
+              if (is_integral && /* integral (hex, octal and binary)  constants may be stored in unsigned type */
                 dval <= 0xffff)
                 {
                   SPEC_USIGN (val->type) = 1;
index 78df1dffb7d068e127b9063a7813168c825812d5..ab04177ea05734ba958e087f98e1f5b5c7ef509f 100644 (file)
@@ -622,7 +622,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
 #define get_effective_char(pfile) (*pfile->buffer->cur++)
 #define BACKUP() (--pfile->buffer->cur)
 
-  enum num_type_e { NT_DEC, NT_HEX } num_type = NT_DEC;
+  enum num_type_e { NT_DEC, NT_HEX, NT_BIN } num_type = NT_DEC;
   enum num_part_e { NP_WHOLE, NP_FRACT, NP_EXP, NP_INT_SUFFIX, NP_FLOAT_SUFFIX } num_part = NP_WHOLE;
 
   uchar c = *(pfile->buffer->cur - 1);
@@ -636,7 +636,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
       num_part = NP_FRACT;
       ++len;
       obstack_1grow (stack, '.');
-      c = get_effective_char(pfile);
+      c = get_effective_char (pfile);
     }
   else
     {
@@ -645,7 +645,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
           has_whole = 1;
           ++len;
           obstack_1grow (stack, c);
-          c = get_effective_char(pfile);
+          c = get_effective_char (pfile);
 
           switch (c)
             {
@@ -654,14 +654,25 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
               num_type = NT_HEX;
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
+              break;
+
+            case 'B':
+            case 'b':
+              if (!CPP_OPTION (pfile, std))
+                {
+                  num_type = NT_BIN;
+                  ++len;
+                  obstack_1grow (stack, c);
+                  c = get_effective_char (pfile);
+                }
               break;
 
             case '.':
               num_part = NP_FRACT;
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
               break;
             }
         }
@@ -679,7 +690,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                   has_whole = 1;
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
                 }
 
               if ('.' == c)
@@ -687,7 +698,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                   num_part = NP_FRACT;
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
                   continue;
                 }
               else if ('E' == c || 'e' == c)
@@ -697,21 +708,53 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                     num_part = NP_EXP;
                     ++len;
                     obstack_1grow (stack, c);
-                    c = get_effective_char(pfile);
+                    c = get_effective_char (pfile);
                     continue;
                   }
                   else
                     break;
                 }
             }
-          else
+          else if (NT_HEX == num_type)
             {
               while (ISXDIGIT (c))
                 {
                   has_whole = 1;
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
+                }
+
+              if ('.' == c)
+                {
+                  num_part = NP_FRACT;
+                  ++len;
+                  obstack_1grow (stack, c);
+                  c = get_effective_char (pfile);
+                  continue;
+                }
+              else if ('P' == c || 'p' == c)
+                {
+                  if (has_whole || has_fract)
+                    {
+                      num_part = NP_EXP;
+                      ++len;
+                      obstack_1grow (stack, c);
+                      c = get_effective_char (pfile);
+                      continue;
+                    }
+                  else
+                    break;
+                }
+            }
+          else /* (NT_BIN == num_type) */
+            {
+              while ((c=='0') || (c=='1'))
+                {
+                  has_whole = 1;
+                  ++len;
+                  obstack_1grow (stack, c);
+                  c = get_effective_char (pfile);
                 }
 
               if ('.' == c)
@@ -719,7 +762,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                   num_part = NP_FRACT;
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
                   continue;
                 }
               else if ('P' == c || 'p' == c)
@@ -729,7 +772,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                       num_part = NP_EXP;
                       ++len;
                       obstack_1grow (stack, c);
-                      c = get_effective_char(pfile);
+                      c = get_effective_char (pfile);
                       continue;
                     }
                   else
@@ -747,7 +790,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                   has_fract = 1;
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
                 }
 
               if ('E' == c || 'e' == c)
@@ -757,7 +800,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                       num_part = NP_EXP;
                       ++len;
                       obstack_1grow (stack, c);
-                      c = get_effective_char(pfile);
+                      c = get_effective_char (pfile);
                       continue;
                     }
                 }
@@ -769,7 +812,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                   has_fract = 1;
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
                 }
 
               if ('P' == c || 'p' == c)
@@ -779,7 +822,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
                       num_part = NP_EXP;
                       ++len;
                       obstack_1grow (stack, c);
-                      c = get_effective_char(pfile);
+                      c = get_effective_char (pfile);
                       continue;
                     }
                 }
@@ -792,14 +835,14 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
             {
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
             }
 
           while (ISDIGIT (c))
             {
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
             }
 
           num_part = NP_FLOAT_SUFFIX;
@@ -812,20 +855,20 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
 
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
 
               if (c == prevc)
                 {
                   ++len;
                   obstack_1grow (stack, c);
-                  c = get_effective_char(pfile);
+                  c = get_effective_char (pfile);
                 }
             }
           else if ('U' == c || 'u' == c)
             {
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
             }
           break;
 
@@ -834,13 +877,13 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number)
             {
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
             }
           else if ('L' == c || 'l' == c)
             {
               ++len;
               obstack_1grow (stack, c);
-              c = get_effective_char(pfile);
+              c = get_effective_char (pfile);
             }
           break;
         }
@@ -1303,7 +1346,7 @@ _cpp_lex_direct (cpp_reader *pfile)
       {
         struct normalize_state nst = INITIAL_NORMALIZE_STATE;
         result->type = CPP_NUMBER;
-        if (CPP_OPTION(pfile, pedantic_parse_number))
+        if (CPP_OPTION (pfile, pedantic_parse_number))
           pedantic_lex_number (pfile, &result->val.str);
         else
           lex_number (pfile, &result->val.str, &nst);
@@ -1341,7 +1384,7 @@ _cpp_lex_direct (cpp_reader *pfile)
 
       /* SDCC _asm specific */
       /* handle _asm ... _endasm ;  */
-      if (CPP_OPTION(pfile, preproc_asm) == 0 && result->val.node == pfile->spec_nodes.n__asm)
+      if (CPP_OPTION (pfile, preproc_asm) == 0 && result->val.node == pfile->spec_nodes.n__asm)
         {
           comment_start = buffer->cur;
           result->type = CPP_ASM;
@@ -1484,7 +1527,7 @@ _cpp_lex_direct (cpp_reader *pfile)
         {
           struct normalize_state nst = INITIAL_NORMALIZE_STATE;
           result->type = CPP_NUMBER;
-          if (CPP_OPTION(pfile, pedantic_parse_number))
+          if (CPP_OPTION (pfile, pedantic_parse_number))
             pedantic_lex_number (pfile, &result->val.str);
           else
             lex_number (pfile, &result->val.str, &nst);