Fix bug when generating integer with leading zero (octal value for C compiler)
authorlaurent
Mon, 06 Jun 2011 11:01:47 +0200
changeset 312 29add821207d
parent 311 8fcea60029de
child 313 90c3772e6547
Fix bug when generating integer with leading zero (octal value for C compiler)
stage4/generate_c/generate_c_base.cc
--- a/stage4/generate_c/generate_c_base.cc	Fri Jun 03 17:14:24 2011 +0100
+++ b/stage4/generate_c/generate_c_base.cc	Mon Jun 06 11:01:47 2011 +0200
@@ -105,9 +105,17 @@
 
     void *print_striped_token(token_c *token, int offset = 0) {
       std::string str = "";
-      for (unsigned int i = offset; i < strlen(token->value); i++)
-        if (token->value[i] != '_')
+      bool leading_zero = true;
+      for (unsigned int i = offset; i < strlen(token->value); i++) {
+        if (leading_zero &&
+        	(token->value[i] != '0' ||
+        	 i == strlen(token->value) - 1 ||
+        	 token->value[i + 1] == '.'
+        	))
+          leading_zero = false;
+    	if (!leading_zero && token->value[i] != '_')
           str += token->value[i];
+      }
       return s4o.printupper(str);
     }
 
@@ -420,7 +428,7 @@
 
 
 /* SYM_TOKEN(fixed_point_c) */
-void *visit(fixed_point_c *symbol) {return print_token(symbol);}
+void *visit(fixed_point_c *symbol) {return print_striped_token(symbol);}
 
 
 /* SYM_REF2(days_c, days, hours) */