Permalink
Browse files

Can generate multiple modules now

  • Loading branch information...
Skarsnik committed Aug 17, 2017
1 parent 129642d commit e2dacfc5c02b9f01ed3e59c95082d4725d7e437b
Showing with 80 additions and 69 deletions.
  1. +2 −2 bin/gptrixie
  2. +77 −66 lib/GPT/FileGenerator.pm6
  3. +1 −1 libxml2.gpt
View
@@ -37,9 +37,9 @@ sub MAIN(
if $gptfile.defined {
read-gpt-file($gptfile);
$gmerge-stypedef = %GPT::FileGenerator::conf<merge-struct-typedef>:exists;
$gmerge-stypedef = $GPT::FileGenerator::merge-typedef-struct;
my AllTheThings $att = do-magic($header-file, @gccoptions);
generate-module($att);
generate-modules($att);
return 0;
}
if $castxml.defined {
View
@@ -2,94 +2,105 @@ use GPT::Class;
use GPT::DumbGenerator;
module GPT::FileGenerator {
our %conf;
our $merge-typedef-struct;
my @modules-conf;
my @files;
my @user-excludes;
sub read-gpt-file($filepath) is export {
use MONKEY-SEE-NO-EVAL;
my $gpt-conf = EVAL($filepath.IO.slurp);
%conf = $gpt-conf if $gpt-conf ~~ Hash;
say $gpt-conf.perl, $gpt-conf.WHAT;
if $gpt-conf ~~ Hash {
$merge-typedef-struct = $gpt-conf<merge-struct-typedef>;
@modules-conf.push($gpt-conf);
}
if $gpt-conf ~~ Array {
for @$gpt-conf -> $mod-conf {
say $mod-conf.perl , $mod-conf.WHAT;
$merge-typedef-struct = True if ! $merge-typedef-struct.defined and $mod-conf<merge-struct-typedef>;
@modules-conf.push($mod-conf);
}
}
}
sub generate-modules($att) is export {
dg-init($att);
@files := %conf<files> if %conf<files>:exists;
@user-excludes := %conf<exclude-files> if %conf<exclude-files>:exists;
my @exclude-structs;
@exclude-structs := %conf<exclude-structs> if %conf<exclude-structs>:exists;
my @exclude-functions;
@exclude-functions := %conf<exclude-functions> if %conf<exclude-functions>:exists;
my @exclude-enums;
@exclude-enums := %conf<exclude-enums> if %conf<exclude-enums>:exists;
my $file = %conf<module-name>.subst('::', '-') ~ '.pm6';
note "Generating $file";
my $fh = open $file, :w;
for @modules-conf -> %conf {
@files := %conf<files> if %conf<files>:exists;
@user-excludes := %conf<exclude-files> if %conf<exclude-files>:exists;
my @exclude-structs;
@exclude-structs := %conf<exclude-structs> if %conf<exclude-structs>:exists;
my @exclude-functions;
@exclude-functions := %conf<exclude-functions> if %conf<exclude-functions>:exists;
my @exclude-enums;
@exclude-enums := %conf<exclude-enums> if %conf<exclude-enums>:exists;
my $file = %conf<module-name>.subst('::', '-', :g) ~ '.pm6';
note "Generating $file";
my $fh = open $file, :w;
$fh.say: '## This file was generated by the Great and Powerful Trixie';
$fh.say: "use NativeCall;";
$fh.say: "unit module %conf<module-name>;";
$fh.say: 'sub GenMyLibName {';
$fh.say: ' use NativeCall :TEST;';
$fh.say: ' %*ENV<' ~ %conf<env-name>
~ '> || guess_library_name(("'
~ %conf<clib-name> ~ '", '
~ %conf<clib-abiversion>.perl ~ '))}';
$fh.say: 'constant LIB = &GenMyLibName;';
my %h = dg-generate-enums();
$fh.say: '## Enumerations';
my %sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v -> $ob {
next if $ob<obj>.name (<=) @exclude-enums;
$fh.say: $ob<p6str>;
$fh.say: '## This file was generated by the Great and Powerful Trixie';
$fh.say: "use NativeCall;";
$fh.say: "unit module %conf<module-name>;";
$fh.say: 'sub GenMyLibName {';
$fh.say: ' use NativeCall :TEST;';
$fh.say: ' %*ENV<' ~ %conf<env-name>
~ '> || guess_library_name(("'
~ %conf<clib-name> ~ '", '
~ %conf<clib-abiversion>.perl ~ '))}';
$fh.say: 'constant LIB = &GenMyLibName;';
my %h = dg-generate-enums();
$fh.say: '## Enumerations';
my %sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v -> $ob {
next if $ob<obj>.name (<=) @exclude-enums;
$fh.say: $ob<p6str>;
}
}
}
%h = dg-generate-structs();
$fh.say: "";
$fh.say: '## Structures' ~ "\n";
%sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v.kv -> $i, $ob {
if $ob<obj> ~~ Struct {
if @v[$i + 1].defined and @v[$i + 1]<obj> ~~ AnonymousUnion and @v[$i + 1]<obj>.struct.defined {
$fh.say: @v[$i + 1]<p6str>;
%h = dg-generate-structs();
$fh.say: "";
$fh.say: '## Structures' ~ "\n";
%sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v.kv -> $i, $ob {
if $ob<obj> ~~ Struct {
if @v[$i + 1].defined and @v[$i + 1]<obj> ~~ AnonymousUnion and @v[$i + 1]<obj>.struct.defined {
$fh.say: @v[$i + 1]<p6str>;
}
}
if !($ob<obj> ~~ AnonymousUnion and $ob<obj>.struct.defined) {
$fh.say: $ob<p6str>;
}
}
if !($ob<obj> ~~ AnonymousUnion and $ob<obj>.struct.defined) {
}
$fh.say: "";
$fh.say: '## Extras stuff' ~ "\n";
dg-generate-extra();
%h = dg-generate-functions();
$fh.say: '## Functions' ~ "\n";
%sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v -> $ob {
$fh.say: $ob<p6str>;
}
}
}
$fh.say: "";
$fh.say: '## Extras stuff' ~ "\n";
dg-generate-extra();
%h = dg-generate-functions();
$fh.say: '## Functions' ~ "\n";
%sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v -> $ob {
$fh.say: $ob<p6str>;
}
}
$fh.say: "";
$fh.say: '## Externs' ~ "\n";
%h = dg-generate-externs();
%sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v -> $ob {
$fh.say: $ob<p6str>;
$fh.say: "";
$fh.say: '## Externs' ~ "\n";
%h = dg-generate-externs();
%sortedh = sort-by-file(%h.values);
for %sortedh.kv -> $k, @v {
$fh.say: "\n# == {$att.files{$k}} ==\n";
for @v -> $ob {
$fh.say: $ob<p6str>;
}
}
}
}
sub files-filter($file-id, $file) returns Bool {
my $basename = $file.IO.basename;
View
@@ -5,7 +5,7 @@ env-name => 'PERL6_LIBXML2LIB',
clib-name => 'xml2',
clib-abiversion => v2,
merge-struct-typedef => True,
files => ['parser.h'],
files => ['parser.h', 's:xmlIO.h'],
},
{
module-name => 'LibXML2::Tree::Binding',

0 comments on commit e2dacfc

Please sign in to comment.