[svn:parrot] r38875 - in trunk: lib/Parrot/Pmc2c t/tools

Infinoid at svn.parrot.org Infinoid at svn.parrot.org
Sun May 17 19:47:59 UTC 2009


Author: Infinoid
Date: Sun May 17 19:47:58 2009
New Revision: 38875
URL: https://trac.parrot.org/parrot/changeset/38875

Log:
[pmc2c] Line numbering isn't quite right, fix it (and add tests).

Modified:
   trunk/lib/Parrot/Pmc2c/Parser.pm
   trunk/t/tools/pmc2c.t

Modified: trunk/lib/Parrot/Pmc2c/Parser.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/Parser.pm	Sun May 17 19:47:52 2009	(r38874)
+++ trunk/lib/Parrot/Pmc2c/Parser.pm	Sun May 17 19:47:58 2009	(r38875)
@@ -159,7 +159,7 @@
         @modifiers = split /\s/, $4;
         $comment = $5;
 
-        $lineno++;
+        $lineno += count_newlines($1);
 
         $pmc->add_attribute(Parrot::Pmc2c::Attribute->new(
             {
@@ -221,6 +221,7 @@
         }
 
         ( my $methodblock, $pmcbody ) = extract_balanced($pmcbody);
+        my $block_lines = count_newlines($methodblock);
 
         $methodblock = strip_outer_brackets($methodblock);
 
@@ -288,9 +289,14 @@
             $pmc->add_method($method);
         }
 
-        $lineno += count_newlines($methodblock);
+        $lineno += $block_lines;
     }
 
+    # include the remainder in the line count, minus the last one
+    # (the last one is included in the postamble directly)
+    chomp $pmcbody;
+    $lineno += count_newlines($pmcbody);
+
     return ($lineno, $class_init);
 }
 

Modified: trunk/t/tools/pmc2c.t
==============================================================================
--- trunk/t/tools/pmc2c.t	Sun May 17 19:47:52 2009	(r38874)
+++ trunk/t/tools/pmc2c.t	Sun May 17 19:47:58 2009	(r38875)
@@ -28,7 +28,7 @@
 
 use Fatal qw{open close};
 use Test::More;
-use Parrot::Test tests => 11;
+use Parrot::Test tests => 13;
 use Parrot::Config;
 
 my $pmc2c = join $PConfig{slash}, qw(. tools build pmc2c.pl);
@@ -191,6 +191,53 @@
 #line 4
 END_C
 
+# test attr/comment line numbering
+pmc2c_output_like( <<'END_PMC', <<'END_C', 'line+pod' );
+pmclass a {
+    ATTR int foo;
+
+    /* Comment comment comment.
+     * Blah blah blah.
+     */
+
+    VTABLE void init() {
+        Parrot_a_attributes * attrs =
+                mem_allocate_zeroed_typed(Parrot_a_attributes);
+
+        attrs->hash = pmc_new(interp, enum_class_Hash);
+
+        PMC_data(SELF) = attrs;
+    }
+}
+END_PMC
+static  void 
+Parrot_a_init(PARROT_INTERP, PMC *pmc)
+{
+#line 8
+END_C
+
+# test EOF/coda line numbering
+# Note: We can't test the whole thing, as the filename component varies
+pmc2c_output_like( <<'END_PMC', <<'END_C', 'line+pod' );
+pmclass a {
+    ATTR int foo;
+
+    /* Comment comment comment.
+     * Blah blah blah.
+     */
+
+    VTABLE void init() {
+        PMC_data(SELF) = NULL;
+    }
+
+}
+
+/* foo bar */
+END_PMC
+} /* Parrot_a_class_init */
+#line 11
+END_C
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4


More information about the parrot-commits mailing list