[svn:parrot] r43533 - trunk/compilers/imcc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Fri Jan 22 07:48:10 UTC 2010


Author: chromatic
Date: Fri Jan 22 07:48:09 2010
New Revision: 43533
URL: https://trac.parrot.org/parrot/changeset/43533

Log:
[IMCC] Refactored a magic constant into intention-revealing code and commented
another magic constant.  It's IMCC, so it's a minor change, but it's a minor
change for the better.  Credit goes to dukeleto for the suggestion.

Modified:
   trunk/compilers/imcc/imcc.l
   trunk/compilers/imcc/imclexer.c

Modified: trunk/compilers/imcc/imcc.l
==============================================================================
--- trunk/compilers/imcc/imcc.l	Fri Jan 22 07:31:52 2010	(r43532)
+++ trunk/compilers/imcc/imcc.l	Fri Jan 22 07:48:09 2010	(r43533)
@@ -726,12 +726,15 @@
                 "Invalid LABEL outside of macro");
         }
         else {
-            const size_t len   = strlen(IMCC_INFO(interp)->cur_macro_name)
-                                + yyleng + 12;
-            char * const label = (char *)mem_sys_allocate(len);
-
-            snprintf(label, len, "local__%s__%s__$",
-                IMCC_INFO(interp)->cur_macro_name, yytext+2);
+            char * const fmt    = "local__%s__%s__$";
+            const size_t fmtlen = strlen(fmt) - (2 * strlen("%s"));
+            const size_t len    = strlen(IMCC_INFO(interp)->cur_macro_name)
+                                + yyleng + fmtlen;
+            char * const label  = (char *)mem_sys_allocate(len);
+
+            /* skip over ".$" prefix with the +2 */
+            snprintf(label, len, fmt,
+                IMCC_INFO(interp)->cur_macro_name, yytext + 2);
 
             if (valp->s)
                 mem_sys_free(valp->s);

Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c	Fri Jan 22 07:31:52 2010	(r43532)
+++ trunk/compilers/imcc/imclexer.c	Fri Jan 22 07:48:09 2010	(r43533)
@@ -3909,12 +3909,14 @@
                 "Invalid LABEL outside of macro");
         }
         else {
-            const size_t len   = strlen(IMCC_INFO(interp)->cur_macro_name)
-                                + yyleng + 12;
-            char * const label = (char *)mem_sys_allocate(len);
+            char * const fmt    = "local__%s__%s__$";
+            const size_t fmtlen = strlen(fmt) - ( 2 * strlen("%s") );
+            const size_t len    = strlen(IMCC_INFO(interp)->cur_macro_name)
+                                + yyleng + fmtlen;
+            char * const label  = (char *)mem_sys_allocate(len);
 
-            snprintf(label, len, "local__%s__%s__$",
-                IMCC_INFO(interp)->cur_macro_name, yytext+2);
+            snprintf(label, len, fmt,
+                IMCC_INFO(interp)->cur_macro_name, yytext + 2);
 
             if (valp->s)
                 mem_sys_free(valp->s);
@@ -3927,49 +3929,49 @@
 	YY_BREAK
 case 141:
 YY_RULE_SETUP
-#line 745 "compilers/imcc/imcc.l"
+#line 747 "compilers/imcc/imcc.l"
 /* skip leading ws */;
 	YY_BREAK
 case 142:
 YY_RULE_SETUP
-#line 746 "compilers/imcc/imcc.l"
+#line 748 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, ' ');
 	YY_BREAK
 case 143:
 YY_RULE_SETUP
-#line 747 "compilers/imcc/imcc.l"
+#line 749 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, REG);
 	YY_BREAK
 case 144:
 YY_RULE_SETUP
-#line 748 "compilers/imcc/imcc.l"
+#line 750 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, REG);
 	YY_BREAK
 case 145:
 YY_RULE_SETUP
-#line 749 "compilers/imcc/imcc.l"
+#line 751 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, IDENTIFIER);
 	YY_BREAK
 case 146:
 YY_RULE_SETUP
-#line 750 "compilers/imcc/imcc.l"
+#line 752 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, MACRO);
 	YY_BREAK
 case 147:
 YY_RULE_SETUP
-#line 751 "compilers/imcc/imcc.l"
+#line 753 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, yytext[0]);
 	YY_BREAK
 case YY_STATE_EOF(macro):
-#line 752 "compilers/imcc/imcc.l"
+#line 754 "compilers/imcc/imcc.l"
 yyterminate();
 	YY_BREAK
 case 148:
 YY_RULE_SETUP
-#line 754 "compilers/imcc/imcc.l"
+#line 756 "compilers/imcc/imcc.l"
 ECHO;
 	YY_BREAK
-#line 3973 "compilers/imcc/imclexer.c"
+#line 3975 "compilers/imcc/imclexer.c"
 case YY_STATE_EOF(pod):
 case YY_STATE_EOF(cmt1):
 case YY_STATE_EOF(cmt2):
@@ -5171,7 +5173,7 @@
 
 #define YYTABLES_NAME "yytables"
 
-#line 754 "compilers/imcc/imcc.l"
+#line 756 "compilers/imcc/imcc.l"
 
 
 


More information about the parrot-commits mailing list