PSI_DECL(int execvp, [(const char *file, char **argv)])
PSI_DECL(int faccessat, [(int fd, const char *path, int amode, int flag)])
PSI_DECL(int fchdir, [(int fildes)])
- PSI_DECL(int fchown, [(int fildes, uid_t owner, gid_tgroup)])
+ PSI_DECL(int fchown, [(int fildes, uid_t owner, gid_t group)])
PSI_DECL(int fchownat, [(int fd, const char *path, uid_t owner, gid_t group, int flag)])
PSI_DECL(int fdatasync, [(int fildes)])
PSI_DECL(int fexecve, [(int fd, char **argv, char **envp)])
PSI_DECL(int nice, [(int incr)])
PSI_DECL(long pathconf, [(const char *path, int name)])
PSI_DECL(int pause, [(void)])
- PSI_DECL(int pipe, [(int fildes@<:@2:>@)])
+ PSI_DECL(int pipe, [(int fildes@<:@2@:>@)])
PSI_DECL(ssize_t pread, [(int fildes, void *buf, size_t nbyte, off_t offset)])
PSI_DECL(ssize_t pwrite, [(int fildes, const void *buf, size_t nbyte, off_t offset)])
PSI_DECL(ssize_t read, [(int fd, void *buf, size_t count)])
decl_union *dunion = init_decl_union(predef_union->var_name, dargs);
dunion->size = predef_union->size;
- dunion->align = dunion->offset;
+ dunion->align = predef_union->offset;
for (member = &predef_union[1]; member->type_tag; ++member) {
decl_type *type;
decl_var *dvar;
static inline void dump_struct(int fd, decl_struct *strct) {
size_t j;
- dprintf(fd, "struct %s::(%zu)", strct->name, strct->size);
+ dprintf(fd, "struct %s::(%zu, %zu)", strct->name, strct->align, strct->size);
if (strct->args && strct->args->count) {
dprintf(fd, " {\n");
for (j = 0; j < strct->args->count; ++j) {
for (i = 0; i < structs->count; ++i) {
decl_struct *strct = structs->list[i];
-
dump_struct(fd, strct);
dprintf(fd, "\n");
}
}
+static inline void dump_union(int fd, decl_union *unn) {
+ size_t j;
+
+ dprintf(fd, "union %s::(%zu, %zu) {\n", unn->name, unn->align, unn->size);
+ for (j = 0; j < unn->args->count; ++j) {
+ decl_arg *uarg = unn->args->args[j];
+
+ dprintf(fd, "\t");
+ dump_decl_arg(fd, uarg);
+ dprintf(fd, "::(%zu, %zu);\n", uarg->layout->pos, uarg->layout->len);
+ }
+ dprintf(fd, "}");
+}
+
+static inline void dump_unions(int fd, decl_unions *unions) {
+ size_t i;
+
+ for (i = 0; i < unions->count; ++i) {
+ decl_union *unn = unions->list[i];
+
+ dump_union(fd, unn);
+ dprintf(fd, "\n");
+ }
+}
+
static inline void dump_enum(int fd, decl_enum *e) {
size_t j;
dump_typedefs(fd, C->defs);
dprintf(fd, "\n");
}
-
+ if (C->unions) {
+ dump_unions(fd, C->unions);
+ dprintf(fd, "\n");
+ }
if (C->structs) {
dump_structs(fd, C->structs);
dprintf(fd, "\n");
- #ifdef HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* pre-validate any structs/unions/enums */
switch (real->type) {
case PSI_T_STRUCT:
- if ((current && current == real->strct) || !validate_decl_struct(data, real->strct)) {
+ if (current && current == real->strct) {
+ return 1;
+ }
+ if (!validate_decl_struct(data, real->strct)) {
return 0;
}
break;
case PSI_T_UNION:
- if ((current && current == real->unn) || !validate_decl_union(data, real->unn)) {
+ if (current && current == real->unn) {
+ return 1;
+ }
+ if (!validate_decl_union(data, real->unn)) {
return 0;
}
break;
case PSI_T_ENUM:
- if ((current && current == real->enm) || !validate_decl_enum(data, real->enm)) {
+ if (current && current == real->enm) {
+ return 1;
+ }
+ if (!validate_decl_enum(data, real->enm)) {
return 0;
}
break;
size_t i, count = C->count++, check_round, check_count;
decl_typedefs *check_defs = P->defs;
decl_structs *check_structs = P->structs;
+ decl_unions *check_unions = P->unions;
decl_enums *check_enums = P->enums;
unsigned silent = C->flags & PSI_PARSER_SILENT;
for (check_round = 0, check_count = 0; CHECK_TOTAL && check_count != CHECK_TOTAL; ++check_round) {
decl_typedefs *recheck_defs = NULL;
decl_structs *recheck_structs = NULL;
+ decl_unions *recheck_unions = NULL;
decl_enums *recheck_enums = NULL;
check_count = CHECK_TOTAL;
recheck_structs = add_decl_struct(recheck_structs, check_structs->list[i]);
}
}
+ for (i = 0; i < CHECK_COUNT(unions); ++i) {
+ if (validate_decl_union(PSI_DATA(C), check_unions->list[i])) {
+ C->unions = add_decl_union(C->unions, check_unions->list[i]);
+ } else {
+ recheck_unions = add_decl_union(recheck_unions, check_unions->list[i]);
+ }
+ }
for (i = 0; i < CHECK_COUNT(enums); ++i) {
if (validate_decl_enum(PSI_DATA(C), check_enums->list[i])) {
C->enums = add_decl_enum(C->enums, check_enums->list[i]);
REVALIDATE(defs);
REVALIDATE(structs);
+ REVALIDATE(unions);
REVALIDATE(enums);
if (check_round == 0 && !silent) {
static inline ffi_type *psi_ffi_decl_type(decl_type *type) {
decl_type *real = real_decl_type(type);
- if (real->type == PSI_T_STRUCT) {
+ switch (real->type) {
+ case PSI_T_STRUCT:
if (!real->strct->engine.type) {
ffi_type *strct = calloc(1, sizeof(ffi_type));
}
return real->strct->engine.type;
+
+ case PSI_T_UNION:
+ return psi_ffi_decl_arg_type(real->unn->args->args[0]);
+
+ default:
+ return psi_ffi_token_type(real->type);
}
- return psi_ffi_token_type(real->type);
}
static inline ffi_type *psi_ffi_decl_arg_type(decl_arg *darg) {
if (darg->var->pointer_level) {
%type decl_struct {decl_struct*}
%destructor decl_struct {free_decl_struct($$);}
-decl_struct(strct) ::= STRUCT NAME(N) struct_size(size_) decl_struct_args(args). {
+decl_struct(strct) ::= STRUCT NAME(N) align_and_size(as) decl_struct_args(args). {
strct = init_decl_struct(N->text, args);
- strct->size = size_;
+ strct->align = as.a;
+ strct->size = as.s;
strct->token = N;
}
-%type struct_size {size_t}
-struct_size(size) ::= . {
- size = 0;
+%type align_and_size { struct {size_t a; size_t s; } }
+align_and_size(as) ::= . {
+ as.a = 0;
+ as.s = 0;
}
-struct_size(size) ::= COLON COLON LPAREN NUMBER(SIZ) RPAREN. {
- size = atol(SIZ->text);
- free(SIZ);
+align_and_size(as) ::= COLON COLON LPAREN NUMBER(A) COMMA NUMBER(S) RPAREN. {
+ as.a = atol(A->text);
+ as.s = atol(S->text);
+ free(A);
+ free(S);
}
%type decl_union {decl_union*}
%destructor decl_union {free_decl_union($$);}
-decl_union(u) ::= UNION NAME(N) struct_size(size_) decl_struct_args(args). {
+decl_union(u) ::= UNION NAME(N) align_and_size(as) decl_struct_args(args). {
u = init_decl_union(N->text, args);
- u->size = size_;
+ u->align = as.a;
+ u->size = as.s;
u->token = N;
}
free_decl($$->type->func);
}
}
-decl_typedef_body_ex(def) ::= struct_name(N) struct_size(size_) decl_struct_args_block(args) decl_var(var). {
+decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var);
def->type->token = PSI_TokenCopy(N);
def->type->strct = init_decl_struct(N->text, args);
def->type->strct->token = N;
- def->type->strct->size = size_;
+ def->type->strct->align = as.a;
+ def->type->strct->size = as.s;
}
-decl_typedef_body_ex(def) ::= union_name(N) struct_size(size_) decl_struct_args_block(args) decl_var(var). {
+decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). {
def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var);
def->type->token = PSI_TokenCopy(N);
def->type->unn = init_decl_union(N->text, args);
def->type->unn->token = N;
- def->type->unn->size = size_;
+ def->type->unn->align = as.a;
+ def->type->unn->size = as.s;
}
decl_typedef_body_ex(def) ::= decl_enum(e) NAME(ALIAS). {
def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0));
-extern int pipe(int fds[2]);
+//extern int pipe(int fildes[2]);
function \pipe(array &$fds = null) : int {
return to_int(pipe);
- let fds = calloc(2, psi\SIZEOF_INT);
- set $fds = to_array(fds[2]);
+ let fildes = calloc(2, psi\SIZEOF_INT);
+ set $fds = to_array(fildes[2]);
}