Skip to content

Commit

Permalink
Change lists deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarsnik committed Aug 30, 2017
1 parent 9fc132c commit 054af77
Showing 1 changed file with 60 additions and 11 deletions.
71 changes: 60 additions & 11 deletions lib/GPT/HandleFileDeps.pm6
Expand Up @@ -2,43 +2,92 @@ use GPT::Class;


unit module GPT::HandleFileDeps; unit module GPT::HandleFileDeps;


my @files-searched;
my %alldeps;

sub print-deps($att, %deps, $depth) {
say %alldeps.perl;
for %alldeps.kv -> $file-id, $deps {
say "==For file {$att.files{$file-id}}==";
my %deps = $deps;
for %deps<structs>.kv -> $sname, $sinfo {
say ' ' x $depth * 2, "Struct $sname has field(s) depending on other files";
for $sinfo.kv -> $fname, $field-info {
say ' ' x $depth * 2, ' ', "$fname : ", $field-info<field>.type.Str, " from ", $att.files{$field-info<file-id>};
}
for %deps<functions>.kv -> $fname, $finfo {
say ' ' x $depth * 2, "Function $fname has argument(s) depending on other files";
for $finfo.kv -> $arg-name, $arg-info {
say ' ' x $depth * 2, ' Argument ', "'$arg-name' : ", $arg-info<argument>.type.Str, " from ", $att.files{$arg-info<file-id>};
}
}
}
}
}


sub list-deps($att, $filename) is export { sub list-deps($att, $filename) is export {
for $att.files.kv -> $f-id, $f-name { for $att.files.kv -> $f-id, $f-name {
my $basename = $f-name.IO.basename; my $basename = $f-name.IO.basename;
if $basename eq $filename { if $basename eq $filename {
my @files-deps; my @files-deps;
my %deps = find-deps($f-id, $att); my %deps = find-deps($f-id, $att);
for %deps<structs>.kv -> $sname, $sinfo { print-deps($att, %deps, 0);
say "Struct $sname has field depending on other files"; #for %deps<structs>.kv -> $sname, $sinfo {
for $sinfo.kv -> $fname, $field-info { # for $sinfo.kv -> $fname, $field-info {
say "--", "$fname : ", $field-info<field>.type.Str, " from ", $att.files{$field-info<file-id>}; # @files-deps.push($att.files{$field-info<file-id>});
@files-deps.push($att.files{$field-info<file-id>}); # }
} #}
} say "Dependancies are : ", (%alldeps.keys.map:{$att.files{$_}}).join(' - ');
say "Dependancies are : ", @files-deps.unique.join(' - ');
return; return;
} }
} }
sub find-deps ($file-id, $alltt) { sub find-deps($file-id, $alltt) {
#say "Find dep : " ~ $att.files{$file-id}; @files-searched = Empty;
%alldeps = Empty;
partial-find-deps($file-id, $alltt);
}

sub partial-find-deps ($file-id, $alltt) {
say "Find dep : " ~ $att.files{$file-id};
my %toret; my %toret;
@files-searched.append($file-id);
for $alltt.structs.kv -> $k, $struct { for $alltt.structs.kv -> $k, $struct {
if ($struct.file-id eq $file-id) { if ($struct.file-id eq $file-id) {
for $struct.fields -> $field { for $struct.fields -> $field {
my $c-location = get-clocation($field.type); my $c-location = get-clocation($field.type);
if $c-location.defined && $c-location.file-id ne $file-id { if $c-location.defined && $c-location.file-id ne $file-id {
say "structs";
%toret<structs>{$struct.name}{$field.name}<field> = $field; %toret<structs>{$struct.name}{$field.name}<field> = $field;
%toret<structs>{$struct.name}{$field.name}<file-id> = $c-location.file-id; %toret<structs>{$struct.name}{$field.name}<file-id> = $c-location.file-id;
%toret<structs>{$struct.name}{$field.name}<deps> = find-deps($c-location.file-id, $alltt); unless @files-searched.contains: $c-location.file-id {
%toret<structs>{$struct.name}{$field.name}<deps> = partial-find-deps($c-location.file-id, $alltt);
}
} }
} }
} }
} }
for $alltt.functions -> $function {
if $function.file-id eq $file-id {
for $function.arguments -> $arg {
my $c-location = get-clocation($arg.type);
if $c-location.defined && $c-location.file-id ne $file-id {
say $function.name, $arg.name, $file-id, $arg.type.Str, " ^ " , $c-location;
%toret<functions>{$function.name}{$arg.name}<argument> = $arg;
%toret<functions>{$function.name}{$arg.name}<file-id> = $c-location.file-id;
unless @files-searched.contains: $c-location.file-id {
%toret<functions>{$function.name}{$arg.name}<deps> = partial-find-deps($c-location.file-id, $alltt);
}
}
}
}
}
sub get-clocation(Type $t) { sub get-clocation(Type $t) {
return $t if ($t ~~ CLocation && $t ~~ DirectType); return $t if ($t ~~ CLocation && $t ~~ DirectType);
return get-clocation($t.ref-type) if ($t ~~ IndirectType); return get-clocation($t.ref-type) if ($t ~~ IndirectType);
return Any:U; return Any:U;
} }
%alldeps{$file-id} = %toret;
return %toret; return %toret;
} }
} }

0 comments on commit 054af77

Please sign in to comment.