Permalink
Browse files

Fix the FileGenerator and how Pointer to structure are handled.

  • Loading branch information...
Skarsnik committed Mar 15, 2016
1 parent 61b0630 commit a034e99feaa9c9175f64174d61861640eeebf753
Showing with 25 additions and 4 deletions.
  1. +3 −0 examples/gumbo.gpt
  2. +8 −1 examples/test.h
  3. +5 −1 lib/GPT/DumbGenerator.pm6
  4. +9 −2 lib/GPT/FileGenerator.pm6
View
@@ -1,5 +1,8 @@
(
module-name => 'Gumbo::Binding',
+env-name => 'PERL6_GUMBOLIB',
+clib-name => 'gumbo',
+clib-abiversion => v1,
merge-struct-typedef => True,
files => ['gumbo.h'],
exclude-enums => ['GumboTag']
View
@@ -21,11 +21,18 @@ struct s2 {
double d[4];
};
+typedef struct s2 type2;
+
+struct s3 {
+ type2 foo;
+};
+
void pretty_print(const char *toprint);
void *do_stuff(s1 s,
size_t piko,
bool b,
const char** const plo
);
-int flood(char &ref);
+int flood(char &ref);
+void testhello(type2 n);
@@ -82,6 +82,10 @@ sub resolve-type($t, $cpt = 0, :$context = "Foo") is export {
return 'Pointer';
}
}
+ return resolve-type($t.ref-type, $cpt + 1) if ($t.ref-type ~~ StructType) ||
+ ($t.ref-type ~~ QualifiedType and $t.ref-type.ref-type ~~ StructType) ||
+ ($t.ref-type ~~ TypeDefType and $t.ref-type.ref-type ~~ StructType) ||
+ ($t.ref-type ~~ QualifiedType and $t.ref-type.ref-type ~~ TypeDefType and $t.ref-type.ref-type.ref-type ~~ StructType);
return 'Pointer[' ~ resolve-type($t.ref-type, $cpt + 1, :$context) ~ ']';
}
@@ -235,7 +239,7 @@ sub dg-generate-structs is export {
sub dg-generate-externs is export {
my %toret;
for $allthings.variables -> $v {
- %toret{$v.name}<p6str> = 'our '~ resolve-type($v.type) ~ ' $' ~ $v.name ~ ' is export = cglobals(LIB, "' ~ $v.name ~ '", ' ~ resolve-type($v.type) ~ ');';
+ %toret{$v.name}<p6str> = 'our $' ~ $v.name ~ ' is export = cglobal(LIB, "' ~ $v.name ~ '", ' ~ resolve-type($v.type) ~ ');';
%toret{$v.name}<obj> = $v;
}
return %toret;
View
@@ -26,8 +26,15 @@ module GPT::FileGenerator {
my $fh = open $file, :w;
$fh.say: '## This file was generated by the Great and Powerful Trixie';
- $fh.say: "";
- $fh.say: "unit module %conf<module-name>";
+ $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);

0 comments on commit a034e99

Please sign in to comment.