workaround for old libffi
[m6w6/ext-psi] / src / context.c
index 5b08426a96bfecf7692b14b0a482508f6b207615..3b5c734e106da577a7aa90a3cf4bea0d876eecab 100644 (file)
 #include "php.h"
 #include "php_scandir.h"
 #include "php_psi.h"
-#include "context.h"
-#include "parser.h"
 
 #include "libjit.h"
 #include "libffi.h"
@@ -182,6 +180,10 @@ static struct psi_predef_decl {
        PSI_DECLS
        {0}
 };
+static struct psi_predef_decl psi_predef_vararg_decls[] = {
+       PSI_VA_DECLS
+       {0}
+};
 
 static struct psi_predef_struct {
        token_t type_tag;
@@ -294,8 +296,10 @@ static inline int validate_constant(PSI_Data *data, constant *c) {
 
 static inline int validate_decl_arg(PSI_Data *data, decl_arg *arg) {
        if (!validate_decl_type(data, arg->type)) {
-               data->error(PSI_WARNING, "Cannot use '%s'(%d) as type for '%s'",
-                       arg->type->name, arg->type->type, arg->var->name);
+               data->error(PSI_WARNING, "Cannot use '%s'(%d) as type for decl var '%s'"
+                               " in %s on line %zu at col %zu",
+                       arg->type->name, arg->type->type, arg->var->name,
+                       arg->type->token->file, arg->type->token->line, arg->type->token->col);
                return 0;
        }
        return 1;
@@ -992,6 +996,24 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr
                decl_args *args = init_decl_args(NULL);
                decl *decl = init_decl(init_decl_abi("default"), func, args);
 
+               for (farg = &predef_decl[1]; farg->type_tag; ++farg) {
+                       decl_type *arg_type = init_decl_type(farg->type_tag, farg->type_name);
+                       decl_var *arg_var = init_decl_var(farg->var_name, farg->pointer_level, farg->array_size);
+                       decl_arg *darg = init_decl_arg(arg_type, arg_var);
+                       args = add_decl_arg(args, darg);
+               }
+
+               T.decls = add_decl(T.decls, decl);
+               predef_decl = farg;
+       }
+
+       for (predef_decl = &psi_predef_vararg_decls[0]; predef_decl->type_tag; ++predef_decl) {
+               struct psi_predef_decl *farg;
+               decl_type *ftype = init_decl_type(predef_decl->type_tag, predef_decl->type_name);
+               decl_var *fname = init_decl_var(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size);
+               decl_arg *func = init_decl_arg(ftype, fname);
+               decl_args *args = init_decl_args(NULL);
+               decl *decl = init_decl(init_decl_abi("default"), func, args);
 
                for (farg = &predef_decl[1]; farg->type_tag; ++farg) {
                        decl_type *arg_type = init_decl_type(farg->type_tag, farg->type_name);
@@ -999,6 +1021,7 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr
                        decl_arg *darg = init_decl_arg(arg_type, arg_var);
                        args = add_decl_arg(args, darg);
                }
+               args->varargs = 1;
 
                T.decls = add_decl(T.decls, decl);
                predef_decl = farg;
@@ -1214,9 +1237,9 @@ zend_function_entry *PSI_ContextCompile(PSI_Context *C)
 }
 
 
-void PSI_ContextCall(PSI_Context *C, impl_val *ret_val, decl *decl)
+void PSI_ContextCall(PSI_Context *C, decl_callinfo *decl_call, impl_vararg *va)
 {
-       C->ops->call(C, ret_val, decl);
+       C->ops->call(C, decl_call, va);
 }
 
 static inline void dump_decl_type(int fd, decl_type *t) {
@@ -1371,11 +1394,16 @@ void PSI_ContextDump(PSI_Context *C, int fd)
                        dprintf(fd, "%s ", decl->abi->convention);
                        dump_decl_arg(fd, decl->func);
                        dprintf(fd, "(");
-                       if (decl->args) for (j = 0; j < decl->args->count; ++j) {
-                               if (j) {
-                                       dprintf(fd, ", ");
+                       if (decl->args) {
+                               for (j = 0; j < decl->args->count; ++j) {
+                                       if (j) {
+                                               dprintf(fd, ", ");
+                                       }
+                                       dump_decl_arg(fd, decl->args->args[j]);
+                               }
+                               if (decl->args->varargs) {
+                                       dprintf(fd, ", ...");
                                }
-                               dump_decl_arg(fd, decl->args->args[j]);
                        }
                        dprintf(fd, ");\n");
                }
@@ -1386,16 +1414,26 @@ void PSI_ContextDump(PSI_Context *C, int fd)
                        impl *impl = C->impls->list[i];
 
                        dprintf(fd, "function %s(", impl->func->name);
-                       if (impl->func->args) for (j = 0; j < impl->func->args->count; ++j) {
-                               impl_arg *iarg = impl->func->args->args[j];
-
-                               dprintf(fd, "%s%s %s$%s",
-                                               j ? ", " : "",
-                                               iarg->type->name,
-                                               iarg->var->reference ? "&" : "",
-                                               iarg->var->name);
-                               if (iarg->def) {
-                                       dprintf(fd, " = %s", iarg->def->text);
+                       if (impl->func->args) {
+                               for (j = 0; j < impl->func->args->count; ++j) {
+                                       impl_arg *iarg = impl->func->args->args[j];
+
+                                       dprintf(fd, "%s%s %s$%s",
+                                                       j ? ", " : "",
+                                                       iarg->type->name,
+                                                       iarg->var->reference ? "&" : "",
+                                                       iarg->var->name);
+                                       if (iarg->def) {
+                                               dprintf(fd, " = %s", iarg->def->text);
+                                       }
+                               }
+                               if (impl->func->args->vararg.name) {
+                                       impl_arg *vararg = impl->func->args->vararg.name;
+
+                                       dprintf(fd, ", %s %s...$%s",
+                                                       vararg->type->name,
+                                                       vararg->var->reference ? "&" : "",
+                                                       vararg->var->name);
                                }
                        }
                        dprintf(fd, ") : %s%s {\n",