This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[fixed-point] Patch for decimal fixed-point constants without exponents


Hello,

  This patch supports decimal fixed-point constants without exponents,
based on the spec.  Will add this to the testsuite.  Thanks!

decimal-fixed-constant:
	digit-sequence exponent-part(opt) fixed-suffix

Ex:
_Accum k0 = 0k;
_Accum k1 = 9999.0e0k;
_Accum k2 = 9999.0k;
_Accum k3 = 9999k;
_Accum k4 = 9999e0k;
_Accum k5 = 09999k;
_Accum k6 = 09999e0k;
_Accum k7 = 09999.0e0k;
_Accum k8 = 09999.0k;
_Accum k9 = 0x270fp0k;
_Accum k10 = 0x270f.0p0k;

_Accum k11 = 0x270f.0k; // ERROR! binary-exponent-part is missing.
_Accum k12 = 0x270fk; // ERROR! binary-exponent-part is missing.

Regards,
Chao-ying

libcpp/ChangeLog
2007-01-24  Chao-ying Fu  <fu@mips.com>

	* expr.c (cpp_classify_number): Support decimal fixed-point
	constants without exponents.

Index: expr.c
===================================================================
--- expr.c	(revision 121062)
+++ expr.c	(working copy)
@@ -252,6 +252,23 @@
 	}
     }
 
+  /* The suffix may be for decimal fixed-point constants without exponent.  */
+  if (radix != 16 && float_flag == NOT_FLOAT)
+    {
+      result = interpret_float_suffix (str, limit - str);
+      if ((result & CPP_N_FRACT) || (result & CPP_N_ACCUM))
+	{
+	  result |= CPP_N_FLOATING;
+	  /* We need to restore the radix to 10, if the radix is 8.  */
+	  if (radix == 8)
+	    radix = 10;
+
+	  goto syntax_ok;
+	}
+      else
+	result = 0;
+    }
+
   if (float_flag != NOT_FLOAT && radix == 8)
     radix = 10;
 
@@ -341,6 +358,7 @@
       result |= CPP_N_INTEGER;
     }
 
+ syntax_ok:
   if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
     cpp_error (pfile, CPP_DL_PEDWARN,
 	       "imaginary constants are a GCC extension");


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]