Permalink
Browse files

Start recording the positions of routines.

  • Loading branch information...
1 parent aa584a2 commit 11f2ce16f017c885cbe1daafd5e510adb1c9950a @jnthn committed Oct 11, 2012
Showing with 41 additions and 0 deletions.
  1. +28 −0 bin/perl6-debug.nqp
  2. +13 −0 lib/Debugger/UI/CommandLine.pm
View
@@ -275,6 +275,34 @@ class Perl6::HookActions is Perl6::Actions {
));
}
}
+
+ sub routine_hook($/, $body, $type, $name) {
+ if $*DEBUG_HOOKS.has_hook('routine_region') {
+ my $file := pir::find_caller_lex__Ps('$?FILES') // '<unknown>';
+ $*DEBUG_HOOKS.get_hook('routine_region')($file, $/.from, $/.to, $type, $name);
+ }
+ }
+
+ method routine_declarator:sym<sub>($/) {
+ Perl6::Actions.routine_declarator:sym<sub>($/);
+ routine_hook($/, $<routine_def>, 'sub',
+ $<routine_def><deflongname> ?? ~$<routine_def><deflongname>[0] !! '');
+ }
+ method routine_declarator:sym<method>($/) {
+ Perl6::Actions.routine_declarator:sym<method>($/);
+ routine_hook($/, $<method_def>, 'method',
+ $<method_def><longname> ?? ~$<method_def><longname> !! '');
+ }
+ method routine_declarator:sym<submethod>($/) {
+ Perl6::Actions.routine_declarator:sym<submethod>($/);
+ routine_hook($/, $<method_def>, 'submethod',
+ $<method_def><longname> ?? ~$<method_def><longname> !! '');
+ }
+ method routine_declarator:sym<macro>($/) {
+ Perl6::Actions.routine_declarator:sym<macro>($/);
+ routine_hook($/, $<macro_def>, 'macro',
+ $<macro_def><deflongname> ?? ~$<macro_def><deflongname>[0] !! '');
+ }
}
class Perl6::HookGrammar is Perl6::Grammar {
@@ -22,6 +22,12 @@ my class SourceFile {
has @!lines;
has @!line_offsets;
has @!regex_regions;
+ has %!routine_regions;
+
+ my class RoutineInfo {
+ has $.type;
+ has $.name;
+ }
method BUILD(:$!filename, :$!source) {
# Ensure source ends with a newline.
@@ -45,6 +51,10 @@ my class SourceFile {
@!regex_regions.push(item $from_pos..$to_pos);
}
+ method add_routine_region($from_pos, $to_pos, $type, $name) {
+ %!routine_regions{item $from_pos..$to_pos} = RoutineInfo.new(:$type, :$name);
+ }
+
method line_of($pos, $def_line, $def_pos) {
my $last_p = 0;
for @!line_offsets.kv -> $l, $p {
@@ -406,6 +416,9 @@ $*DEBUG_HOOKS.set_hook('new_file', -> $filename, $source {
}
%sources{$filename} = SourceFile.new(:$filename, :$source);
});
+$*DEBUG_HOOKS.set_hook('routine_region', -> $filename, $from_pos, $to_pos, $type, $name {
+ %sources{$filename}.add_routine_region($from_pos, $to_pos, $type, $name);
+});
$*DEBUG_HOOKS.set_hook('statement_simple', -> $filename, $ctx, $from, $to {
if DebugState.should_break_at($filename, $from, $to) {
say %sources{$filename}.summary_around($from, $to, $ctx);

0 comments on commit 11f2ce1

Please sign in to comment.