On Thu, 12 Jul 2007 09:26:25 -0700
Mark Glines <[EMAIL PROTECTED]> wrote:
> > Interestingly, if I take all of the crud in this pmclass statement
> > and stick them all on one line, like this:
> > 
> > pmclass Perl6Str extends String does string dynpmc group perl6_group
> > hll Perl6 maps String {
> > 
> > ...The #line numbers do not change at all (get_string in the .c file
> > is still #lined to 154), but now the get_string implementation in
> > the .pmc file is also on line 154, so everything lines up.
> 
> I don't have a fix (yet), but here's a patch to add a couple of tests
> for it.  One test makes sure it emits the right #line when a complex
> pmclass statement is all on one line, and the second makes sure #line
> is adjusted when pmclass *isn't* on the same line.
> 
> The first test succeeds, the second one fails.


In the pmc2c parser, parse_pmc() calls parse_flags() to parse the
pmclass line, and sort out all of the necessary attributes.
parse_flags() consumes everything from "pmclass" to "{", and parse_pmc
assumes that it was all on one line, and just uses the the magic number
1 to represent that line.

So here's a patch.  It's a bit quick & dirty, but it'll work.  A
cleaner solution would probably involve adding a fourth returned
parameter from parse_flags: a line-count.  Ends up being the same
thing, really... just keeps the knowledge of the pmclass line's format
localized to the parse_flags() function.

Mark
=== lib/Parrot/Pmc2c/Parser.pm
==================================================================
--- lib/Parrot/Pmc2c/Parser.pm	(revision 21442)
+++ lib/Parrot/Pmc2c/Parser.pm	(local)
@@ -67,10 +67,14 @@
 sub parse_pmc {
     my ( $code, $opt ) = @_;
 
+    my $lineno = 1;
+    if($code =~ /(pmclass[^{]+{)/) {
+        $lineno += count_newlines($1);
+    }
     my ( $pre, $classname, $flags_ref ) = parse_flags( \$code );
     my ( $classblock, $post ) = extract_balanced($code);
 
-    my $lineno = 1 + count_newlines($pre);
+    $lineno += count_newlines($pre);
     $classblock = substr( $classblock, 1, -1 );    # trim out the { }
 
     my ( @methods, %meth_hash, $class_init );

Reply via email to